be2net: implement EEH pci error recovery handlers
[safe/jmp/linux-2.6] / drivers / ide / ide-probe.c
index fdd04bc..4d76ba4 100644 (file)
@@ -238,6 +238,7 @@ static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
  *     @drive: drive to identify
  *     @cmd: command to use
  *     @id: buffer for IDENTIFY data
+ *     @irq_ctx: flag set when called from the IRQ context
  *
  *     Sends an ATA(PI) IDENTIFY request to a drive and waits for a response.
  *
@@ -246,7 +247,7 @@ static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
  *                     2  device aborted the command (refused to identify itself)
  */
 
-int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
+int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id, int irq_ctx)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct ide_io_ports *io_ports = &hwif->io_ports;
@@ -263,7 +264,10 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
                tp_ops->write_devctl(hwif, ATA_NIEN | ATA_DEVCTL_OBS);
 
        /* take a deep breath */
-       msleep(50);
+       if (irq_ctx)
+               mdelay(50);
+       else
+               msleep(50);
 
        if (io_ports->ctl_addr &&
            (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0) {
@@ -295,12 +299,19 @@ int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
 
        timeout = ((cmd == ATA_CMD_ID_ATA) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
 
-       if (ide_busy_sleep(drive, timeout, use_altstatus))
-               return 1;
-
        /* wait for IRQ and ATA_DRQ */
-       msleep(50);
-       s = tp_ops->read_status(hwif);
+       if (irq_ctx) {
+               rc = __ide_wait_stat(drive, ATA_DRQ, BAD_R_STAT, timeout, &s);
+               if (rc)
+                       return 1;
+       } else {
+               rc = ide_busy_sleep(drive, timeout, use_altstatus);
+               if (rc)
+                       return 1;
+
+               msleep(50);
+               s = tp_ops->read_status(hwif);
+       }
 
        if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
                /* drive returned ID */
@@ -406,10 +417,10 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
 
        if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
            present || cmd == ATA_CMD_ID_ATAPI) {
-               rc = ide_dev_read_id(drive, cmd, id);
+               rc = ide_dev_read_id(drive, cmd, id, 0);
                if (rc)
                        /* failed: try again */
-                       rc = ide_dev_read_id(drive, cmd, id);
+                       rc = ide_dev_read_id(drive, cmd, id, 0);
 
                stat = tp_ops->read_status(hwif);
 
@@ -424,7 +435,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
                        msleep(50);
                        tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
                        (void)ide_busy_sleep(drive, WAIT_WORSTCASE, 0);
-                       rc = ide_dev_read_id(drive, cmd, id);
+                       rc = ide_dev_read_id(drive, cmd, id, 0);
                }
 
                /* ensure drive IRQ is clear */
@@ -535,7 +546,7 @@ static int ide_register_port(ide_hwif_t *hwif)
 
        /* register with global device tree */
        dev_set_name(&hwif->gendev, hwif->name);
-       hwif->gendev.driver_data = hwif;
+       dev_set_drvdata(&hwif->gendev, hwif);
        if (hwif->gendev.parent == NULL)
                hwif->gendev.parent = hwif->dev;
        hwif->gendev.release = hwif_release_dev;
@@ -818,6 +829,24 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
        return j;
 }
 
+static void ide_host_enable_irqs(struct ide_host *host)
+{
+       ide_hwif_t *hwif;
+       int i;
+
+       ide_host_for_each_port(i, hwif, host) {
+               if (hwif == NULL)
+                       continue;
+
+               /* clear any pending IRQs */
+               hwif->tp_ops->read_status(hwif);
+
+               /* unmask IRQs */
+               if (hwif->io_ports.ctl_addr)
+                       hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
+       }
+}
+
 /*
  * This routine sets up the IRQ for an IDE interface.
  */
@@ -831,9 +860,6 @@ static int init_irq (ide_hwif_t *hwif)
        if (irq_handler == NULL)
                irq_handler = ide_intr;
 
-       if (io_ports->ctl_addr)
-               hwif->tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS);
-
        if (request_irq(hwif->irq, irq_handler, sa, hwif->name, hwif))
                goto out_up;
 
@@ -987,9 +1013,9 @@ static void hwif_register_devices(ide_hwif_t *hwif)
                int ret;
 
                dev_set_name(dev, "%u.%u", hwif->index, i);
+               dev_set_drvdata(dev, drive);
                dev->parent = &hwif->gendev;
                dev->bus = &ide_bus_type;
-               dev->driver_data = drive;
                dev->release = drive_release_dev;
 
                ret = device_register(dev);
@@ -1020,15 +1046,6 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
                if (port_ops && port_ops->init_dev)
                        port_ops->init_dev(drive);
        }
-
-       ide_port_for_each_dev(i, drive, hwif) {
-               /*
-                * default to PIO Mode 0 before we figure out
-                * the most suited mode for the attached device
-                */
-               if (port_ops && port_ops->set_pio_mode)
-                       port_ops->set_pio_mode(drive, 0);
-       }
 }
 
 static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
@@ -1170,7 +1187,6 @@ static void ide_init_port_hw(ide_hwif_t *hwif, struct ide_hw *hw)
        hwif->irq = hw->irq;
        hwif->dev = hw->dev;
        hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
-       hwif->ack_intr = hw->ack_intr;
        hwif->config_data = hw->config;
 }
 
@@ -1187,7 +1203,7 @@ static int ide_find_port_slot(const struct ide_port_info *d)
 {
        int idx = -ENOENT;
        u8 bootable = (d && (d->host_flags & IDE_HFLAG_NON_BOOTABLE)) ? 0 : 1;
-       u8 i = (d && (d->host_flags & IDE_HFLAG_QD_2ND_PORT)) ? 1 : 0;;
+       u8 i = (d && (d->host_flags & IDE_HFLAG_QD_2ND_PORT)) ? 1 : 0;
 
        /*
         * Claim an unassigned slot.
@@ -1405,6 +1421,8 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
                        ide_port_tune_devices(hwif);
        }
 
+       ide_host_enable_irqs(host);
+
        ide_host_for_each_port(i, hwif, host) {
                if (hwif == NULL)
                        continue;