Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[cascardo/linux.git] / drivers / ata / libata-core.c
index 88e2dd0..c43de9a 100644 (file)
@@ -111,8 +111,9 @@ MODULE_VERSION(DRV_VERSION);
 /**
  *     ata_tf_to_fis - Convert ATA taskfile to SATA FIS structure
  *     @tf: Taskfile to convert
- *     @fis: Buffer into which data will output
  *     @pmp: Port multiplier port
+ *     @is_cmd: This FIS is for command
+ *     @fis: Buffer into which data will output
  *
  *     Converts a standard ATA taskfile to a Serial ATA
  *     FIS structure (Register - Host to Device).
@@ -120,12 +121,13 @@ MODULE_VERSION(DRV_VERSION);
  *     LOCKING:
  *     Inherited from caller.
  */
-
-void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp)
+void ata_tf_to_fis(const struct ata_taskfile *tf, u8 pmp, int is_cmd, u8 *fis)
 {
-       fis[0] = 0x27;  /* Register - Host to Device FIS */
-       fis[1] = (pmp & 0xf) | (1 << 7); /* Port multiplier number,
-                                           bit 7 indicates Command FIS */
+       fis[0] = 0x27;                  /* Register - Host to Device FIS */
+       fis[1] = pmp & 0xf;             /* Port multiplier number*/
+       if (is_cmd)
+               fis[1] |= (1 << 7);     /* bit 7 indicates Command FIS */
+
        fis[2] = tf->command;
        fis[3] = tf->feature;
 
@@ -1721,7 +1723,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
                tf.protocol = ATA_PROT_NODATA;
                tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
                err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
-               if (err_mask) {
+               if (err_mask && id[2] != 0x738c) {
                        rc = -EIO;
                        reason = "SPINUP failed";
                        goto err_out;
@@ -1909,8 +1911,9 @@ int ata_dev_configure(struct ata_device *dev)
                                        dev->flags |= ATA_DFLAG_FLUSH_EXT;
                        }
 
-                       if (ata_id_hpa_enabled(dev->id))
-                               dev->n_sectors = ata_hpa_resize(dev);
+                       if (!(dev->horkage & ATA_HORKAGE_BROKEN_HPA) &&
+                           ata_id_hpa_enabled(dev->id))
+                               dev->n_sectors = ata_hpa_resize(dev);
 
                        /* config NCQ */
                        ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
@@ -2387,21 +2390,35 @@ int sata_down_spd_limit(struct ata_port *ap)
        u32 sstatus, spd, mask;
        int rc, highbit;
 
+       if (!sata_scr_valid(ap))
+               return -EOPNOTSUPP;
+
+       /* If SCR can be read, use it to determine the current SPD.
+        * If not, use cached value in ap->sata_spd.
+        */
        rc = sata_scr_read(ap, SCR_STATUS, &sstatus);
-       if (rc)
-               return rc;
+       if (rc == 0)
+               spd = (sstatus >> 4) & 0xf;
+       else
+               spd = ap->sata_spd;
 
        mask = ap->sata_spd_limit;
        if (mask <= 1)
                return -EINVAL;
+
+       /* unconditionally mask off the highest bit */
        highbit = fls(mask) - 1;
        mask &= ~(1 << highbit);
 
-       spd = (sstatus >> 4) & 0xf;
-       if (spd <= 1)
-               return -EINVAL;
-       spd--;
-       mask &= (1 << spd) - 1;
+       /* Mask off all speeds higher than or equal to the current
+        * one.  Force 1.5Gbps if current SPD is not available.
+        */
+       if (spd > 1)
+               mask &= (1 << (spd - 1)) - 1;
+       else
+               mask &= 1;
+
+       /* were we already at the bottom? */
        if (!mask)
                return -EINVAL;
 
@@ -3251,9 +3268,11 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
                last = cur;
                last_jiffies = jiffies;
 
-               /* check deadline */
+               /* Check deadline.  If debouncing failed, return
+                * -EPIPE to tell upper layer to lower link speed.
+                */
                if (time_after(jiffies, deadline))
-                       return -EBUSY;
+                       return -EPIPE;
        }
 }
 
@@ -3682,11 +3701,16 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
                goto fail;
 
        /* verify n_sectors hasn't changed */
-       if (dev->class == ATA_DEV_ATA && dev->n_sectors != n_sectors) {
+       if (dev->class == ATA_DEV_ATA && n_sectors &&
+           dev->n_sectors != n_sectors) {
                ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch "
                               "%llu != %llu\n",
                               (unsigned long long)n_sectors,
                               (unsigned long long)dev->n_sectors);
+
+               /* restore original n_sectors */
+               dev->n_sectors = n_sectors;
+
                rc = -ENODEV;
                goto fail;
        }
@@ -3769,8 +3793,14 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, },
        { "WDC WD740ADFD-00NLR1", NULL,         ATA_HORKAGE_NONCQ, },
        { "FUJITSU MHV2080BH",  "00840028",     ATA_HORKAGE_NONCQ, },
+       { "ST9160821AS",        "3.CLF",        ATA_HORKAGE_NONCQ, },
+       { "SAMSUNG HD401LJ",    "ZZ100-15",     ATA_HORKAGE_NONCQ, },
 
-       /* Devices with NCQ limits */
+       /* devices which puke on READ_NATIVE_MAX */
+       { "HDS724040KLSA80",    "KFAOA20N",     ATA_HORKAGE_BROKEN_HPA, },
+       { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
+       { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA },
+       { "MAXTOR 6L080L4",     "A93.0500",     ATA_HORKAGE_BROKEN_HPA },
 
        /* End Marker */
        { }
@@ -3960,6 +3990,11 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
        tf.device |= (heads - 1) & 0x0f; /* max head = num. of heads - 1 */
 
        err_mask = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
+       /* A clean abort indicates an original or just out of spec drive
+          and we should continue as we issue the setup based on the
+          drive reported working geometry */
+       if (err_mask == AC_ERR_DEV && (tf.feature & ATA_ABORTED))
+               err_mask = 0;
 
        DPRINTK("EXIT, err_mask=%x\n", err_mask);
        return err_mask;
@@ -5729,10 +5764,8 @@ int sata_scr_valid(struct ata_port *ap)
  */
 int sata_scr_read(struct ata_port *ap, int reg, u32 *val)
 {
-       if (sata_scr_valid(ap)) {
-               *val = ap->ops->scr_read(ap, reg);
-               return 0;
-       }
+       if (sata_scr_valid(ap))
+               return ap->ops->scr_read(ap, reg, val);
        return -EOPNOTSUPP;
 }
 
@@ -5754,10 +5787,8 @@ int sata_scr_read(struct ata_port *ap, int reg, u32 *val)
  */
 int sata_scr_write(struct ata_port *ap, int reg, u32 val)
 {
-       if (sata_scr_valid(ap)) {
-               ap->ops->scr_write(ap, reg, val);
-               return 0;
-       }
+       if (sata_scr_valid(ap))
+               return ap->ops->scr_write(ap, reg, val);
        return -EOPNOTSUPP;
 }
 
@@ -5778,10 +5809,13 @@ int sata_scr_write(struct ata_port *ap, int reg, u32 val)
  */
 int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val)
 {
+       int rc;
+
        if (sata_scr_valid(ap)) {
-               ap->ops->scr_write(ap, reg, val);
-               ap->ops->scr_read(ap, reg);
-               return 0;
+               rc = ap->ops->scr_write(ap, reg, val);
+               if (rc == 0)
+                       rc = ap->ops->scr_read(ap, reg, &val);
+               return rc;
        }
        return -EOPNOTSUPP;
 }
@@ -5993,6 +6027,7 @@ void ata_dev_init(struct ata_device *dev)
 
        /* SATA spd limit is bound to the first device */
        ap->sata_spd_limit = ap->hw_sata_spd_limit;
+       ap->sata_spd = 0;
 
        /* High bits of dev->flags are used to record warm plug
         * requests which occur asynchronously.  Synchronize using
@@ -6000,6 +6035,7 @@ void ata_dev_init(struct ata_device *dev)
         */
        spin_lock_irqsave(ap->lock, flags);
        dev->flags &= ~ATA_DFLAG_INIT_MASK;
+       dev->horkage = 0;
        spin_unlock_irqrestore(ap->lock, flags);
 
        memset((void *)dev + ATA_DEVICE_CLEAR_OFFSET, 0,
@@ -6058,6 +6094,9 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
        INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
        INIT_LIST_HEAD(&ap->eh_done_q);
        init_waitqueue_head(&ap->eh_wait_q);
+       init_timer_deferrable(&ap->fastdrain_timer);
+       ap->fastdrain_timer.function = ata_eh_fastdrain_timerfn;
+       ap->fastdrain_timer.data = (unsigned long)ap;
 
        ap->cbl = ATA_CBL_NONE;
 
@@ -6434,7 +6473,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
 
-               ata_scsi_scan_host(ap);
+               ata_scsi_scan_host(ap, 1);
        }
 
        return 0;
@@ -6942,6 +6981,9 @@ EXPORT_SYMBOL_GPL(ata_pci_default_filter);
 EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
 #endif /* CONFIG_PCI */
 
+EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
+EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
+EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
 EXPORT_SYMBOL_GPL(ata_eng_timeout);
 EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
 EXPORT_SYMBOL_GPL(ata_port_abort);