vserver 1.9.5.x5
[linux-2.6.git] / drivers / ide / ide-probe.c
index 61c72a7..417783f 100644 (file)
@@ -180,12 +180,6 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
        if (cmd == WIN_PIDENTIFY) {
                u8 type = (id->config >> 8) & 0x1f;
                printk("ATAPI ");
-#ifdef CONFIG_BLK_DEV_PDC4030
-               if (hwif->channel == 1 && hwif->chipset == ide_pdc4030) {
-                       printk(" -- not supported on 2nd Promise port\n");
-                       goto err_misc;
-               }
-#endif /* CONFIG_BLK_DEV_PDC4030 */
                switch (type) {
                        case ide_floppy:
                                if (!strstr(id->model, "CD-ROM")) {
@@ -297,13 +291,9 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
                /* disable dma & overlap */
                hwif->OUTB(0, IDE_FEATURE_REG);
 
-       if (hwif->identify != NULL) {
-               if (hwif->identify(drive))
-                       return 1;
-       } else {
-               /* ask drive for ID */
-               hwif->OUTB(cmd, IDE_COMMAND_REG);
-       }
+       /* ask drive for ID */
+       hwif->OUTB(cmd, IDE_COMMAND_REG);
+
        timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
        timeout += jiffies;
        do {
@@ -662,6 +652,43 @@ static int wait_hwif_ready(ide_hwif_t *hwif)
        return rc;
 }
 
+/**
+ *     ide_undecoded_slave     -       look for bad CF adapters
+ *     @hwif: interface
+ *
+ *     Analyse the drives on the interface and attempt to decide if we
+ *     have the same drive viewed twice. This occurs with crap CF adapters
+ *     and PCMCIA sometimes.
+ */
+
+void ide_undecoded_slave(ide_hwif_t *hwif)
+{
+       ide_drive_t *drive0 = &hwif->drives[0];
+       ide_drive_t *drive1 = &hwif->drives[1];
+
+       if (drive0->present == 0 || drive1->present == 0)
+               return;
+
+       /* If the models don't match they are not the same product */
+       if (strcmp(drive0->id->model, drive1->id->model))
+               return;
+
+       /* Serial numbers do not match */
+       if (strncmp(drive0->id->serial_no, drive1->id->serial_no, 20))
+               return;
+
+       /* No serial number, thankfully very rare for CF */
+       if (drive0->id->serial_no[0] == 0)
+               return;
+
+       /* Appears to be an IDE flash adapter with decode bugs */
+       printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
+
+       drive1->present = 0;
+}
+
+EXPORT_SYMBOL_GPL(ide_undecoded_slave);
+
 /*
  * This routine only knows how to look for drive units 0 and 1
  * on an interface, so any setting of MAX_DRIVES > 2 won't work here.
@@ -676,9 +703,6 @@ static void probe_hwif(ide_hwif_t *hwif)
                return;
 
        if ((hwif->chipset != ide_4drives || !hwif->mate || !hwif->mate->present) &&
-#ifdef CONFIG_BLK_DEV_PDC4030
-           (hwif->chipset != ide_pdc4030 || hwif->channel == 0) &&
-#endif /* CONFIG_BLK_DEV_PDC4030 */
            (ide_hwif_request_regions(hwif))) {
                u16 msgout = 0;
                for (unit = 0; unit < MAX_DRIVES; ++unit) {
@@ -725,7 +749,7 @@ static void probe_hwif(ide_hwif_t *hwif)
         *  
         *  BenH.
         */
-       if (wait_hwif_ready(hwif))
+       if (wait_hwif_ready(hwif) == -EBUSY)
                printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name);
 
        /*
@@ -736,18 +760,6 @@ static void probe_hwif(ide_hwif_t *hwif)
                ide_drive_t *drive = &hwif->drives[unit];
                drive->dn = (hwif->channel ? 2 : 0) + unit;
                (void) probe_for_drive(drive);
-               if (drive->present && hwif->present && unit == 1) {
-                       if (strcmp(hwif->drives[0].id->model, drive->id->model) == 0 &&
-                           /* Don't do this for noprobe or non ATA */
-                           strcmp(drive->id->model, "UNKNOWN") &&
-                           /* And beware of confused Maxtor drives that go "M0000000000"
-                             "The SN# is garbage in the ID block..." [Eric] */
-                           strncmp(drive->id->serial_no, "M0000000000000000000", 20) &&
-                           strncmp(hwif->drives[0].id->serial_no, drive->id->serial_no, 20) == 0) {
-                               printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
-                               drive->present = 0;
-                       }
-               }
                if (drive->present && !hwif->present) {
                        hwif->present = 1;
                        if (hwif->chipset != ide_4drives ||
@@ -821,10 +833,19 @@ static void probe_hwif(ide_hwif_t *hwif)
 }
 
 static int hwif_init(ide_hwif_t *hwif);
-int probe_hwif_init (ide_hwif_t *hwif)
+
+int probe_hwif_init_with_fixup(ide_hwif_t *hwif, void (*fixup)(ide_hwif_t *hwif))
 {
        probe_hwif(hwif);
-       hwif_init(hwif);
+
+       if (fixup)
+               fixup(hwif);
+
+       if (!hwif_init(hwif)) {
+               printk(KERN_INFO "%s: failed to initialize IDE interface\n",
+                                hwif->name);
+               return -1;
+       }
 
        if (hwif->present) {
                u16 unit = 0;
@@ -841,6 +862,11 @@ int probe_hwif_init (ide_hwif_t *hwif)
        return 0;
 }
 
+int probe_hwif_init(ide_hwif_t *hwif)
+{
+       return probe_hwif_init_with_fixup(hwif, NULL);
+}
+
 EXPORT_SYMBOL(probe_hwif_init);
 
 #if MAX_HWIFS > 1
@@ -1127,7 +1153,7 @@ static int ata_lock(dev_t dev, void *data)
 
 extern ide_driver_t idedefault_driver;
 
-struct kobject *ata_probe(dev_t dev, int *part, void *data)
+static struct kobject *ata_probe(dev_t dev, int *part, void *data)
 {
        ide_hwif_t *hwif = data;
        int unit = *part >> PARTN_BITS;
@@ -1222,8 +1248,9 @@ static int hwif_init(ide_hwif_t *hwif)
 {
        int old_irq, unit;
 
+       /* Return success if no device is connected */
        if (!hwif->present)
-               return 0;
+               return 1;
 
        if (!hwif->irq) {
                if (!(hwif->irq = ide_default_irq(hwif->io_ports[IDE_DATA_OFFSET])))
@@ -1246,6 +1273,16 @@ static int hwif_init(ide_hwif_t *hwif)
        if (register_blkdev(hwif->major, hwif->name))
                return 0;
 
+       if (!hwif->sg_max_nents)
+               hwif->sg_max_nents = PRD_ENTRIES;
+
+       hwif->sg_table = kmalloc(sizeof(struct scatterlist)*hwif->sg_max_nents,
+                                GFP_KERNEL);
+       if (!hwif->sg_table) {
+               printk(KERN_ERR "%s: unable to allocate SG table.\n", hwif->name);
+               goto out;
+       }
+
        if (alloc_disks(hwif) < 0)
                goto out;
        
@@ -1295,9 +1332,6 @@ int ideprobe_init (void)
        for (index = 0; index < MAX_HWIFS; ++index)
                probe[index] = !ide_hwifs[index].present;
 
-       /*
-        * Probe for drives in the usual way.. CMOS/BIOS, then poke at ports
-        */
        for (index = 0; index < MAX_HWIFS; ++index)
                if (probe[index])
                        probe_hwif(&ide_hwifs[index]);