--- linux-2.6.18.orig/drivers/scsi/libata-core.c 2006-09-29 16:58:38.000000000 +0800 +++ linux-2.6.18/drivers/scsi/libata-core.c 2006-09-30 12:44:32.000000000 +0800 @@ -2631,8 +2631,19 @@ int ata_std_prereset(struct ata_port *ap { struct ata_eh_context *ehc = &ap->eh_context; const unsigned long *timing = sata_ehc_deb_timing(ehc); + unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; + unsigned int devmask = 0; int rc; + if (ata_port_offline(ap)) + return 0; + + /* determine if device 0/1 are present */ + if (ata_devchk(ap, 0)) + devmask |= (1 << 0); + if (slave_possible && ata_devchk(ap, 1)) + devmask |= (1 << 1); + /* handle link resume & hotplug spinup */ if ((ehc->i.flags & ATA_EHI_RESUME_LINK) && (ap->flags & ATA_FLAG_HRST_TO_RESUME)) @@ -2660,7 +2671,8 @@ int ata_std_prereset(struct ata_port *ap /* Wait for !BSY if the controller can wait for the first D2H * Reg FIS and we don't know that no device is attached. */ - if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap)) + if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && + !ata_port_offline(ap) && devmask) ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); return 0; @@ -2697,6 +2709,10 @@ int ata_std_softreset(struct ata_port *a devmask |= (1 << 0); if (slave_possible && ata_devchk(ap, 1)) devmask |= (1 << 1); + + /* have not a invalid device been found */ + if (!devmask) + return 0; /* select device 0 again */ ap->ops->dev_select(ap, 0);