]> err.no Git - linux-2.6/blobdiff - drivers/ata/libata-core.c
ahci: clean up PORT_IRQ_BAD_PMP enabling
[linux-2.6] / drivers / ata / libata-core.c
index 376dbd80cc93ae2611fe6fc378ce20f42a922462..db760e2dc30b44525fa0d82ee5339a2ef5eaad22 100644 (file)
@@ -97,13 +97,17 @@ static int ata_ignore_hpa = 0;
 module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644);
 MODULE_PARM_DESC(ignore_hpa, "Ignore HPA limit (0=keep BIOS limits, 1=ignore limits, using full disk)");
 
+static int libata_dma_mask = ATA_DMA_MASK_ATA|ATA_DMA_MASK_ATAPI|ATA_DMA_MASK_CFA;
+module_param_named(dma, libata_dma_mask, int, 0444);
+MODULE_PARM_DESC(dma, "DMA enable/disable (0x1==ATA, 0x2==ATAPI, 0x4==CF)");
+
 static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
 module_param(ata_probe_timeout, int, 0444);
 MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
 
-int libata_noacpi = 1;
+int libata_noacpi = 0;
 module_param_named(noacpi, libata_noacpi, int, 0444);
-MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
+MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in probe/suspend/resume when set");
 
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Library module for ATA devices");
@@ -670,29 +674,49 @@ static unsigned int ata_devchk(struct ata_port *ap, unsigned int device)
  *     None.
  *
  *     RETURNS:
- *     Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, or %ATA_DEV_UNKNOWN
- *     the event of failure.
+ *     Device type, %ATA_DEV_ATA, %ATA_DEV_ATAPI, %ATA_DEV_PMP or
+ *     %ATA_DEV_UNKNOWN the event of failure.
  */
-
 unsigned int ata_dev_classify(const struct ata_taskfile *tf)
 {
        /* Apple's open source Darwin code hints that some devices only
         * put a proper signature into the LBA mid/high registers,
         * So, we only check those.  It's sufficient for uniqueness.
+        *
+        * ATA/ATAPI-7 (d1532v1r1: Feb. 19, 2003) specified separate
+        * signatures for ATA and ATAPI devices attached on SerialATA,
+        * 0x3c/0xc3 and 0x69/0x96 respectively.  However, SerialATA
+        * spec has never mentioned about using different signatures
+        * for ATA/ATAPI devices.  Then, Serial ATA II: Port
+        * Multiplier specification began to use 0x69/0x96 to identify
+        * port multpliers and 0x3c/0xc3 to identify SEMB device.
+        * ATA/ATAPI-7 dropped descriptions about 0x3c/0xc3 and
+        * 0x69/0x96 shortly and described them as reserved for
+        * SerialATA.
+        *
+        * We follow the current spec and consider that 0x69/0x96
+        * identifies a port multiplier and 0x3c/0xc3 a SEMB device.
         */
-
-       if (((tf->lbam == 0) && (tf->lbah == 0)) ||
-           ((tf->lbam == 0x3c) && (tf->lbah == 0xc3))) {
+       if ((tf->lbam == 0) && (tf->lbah == 0)) {
                DPRINTK("found ATA device by sig\n");
                return ATA_DEV_ATA;
        }
 
-       if (((tf->lbam == 0x14) && (tf->lbah == 0xeb)) ||
-           ((tf->lbam == 0x69) && (tf->lbah == 0x96))) {
+       if ((tf->lbam == 0x14) && (tf->lbah == 0xeb)) {
                DPRINTK("found ATAPI device by sig\n");
                return ATA_DEV_ATAPI;
        }
 
+       if ((tf->lbam == 0x69) && (tf->lbah == 0x96)) {
+               DPRINTK("found PMP device by sig\n");
+               return ATA_DEV_PMP;
+       }
+
+       if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) {
+               printk("ata: SEMB device ignored\n");
+               return ATA_DEV_SEMB_UNSUP; /* not yet */
+       }
+
        DPRINTK("unknown device\n");
        return ATA_DEV_UNKNOWN;
 }
@@ -915,7 +939,8 @@ static int ata_read_native_max_address(struct ata_device *dev, u64 *max_sectors)
                *max_sectors = ata_tf_to_lba48(&tf);
        else
                *max_sectors = ata_tf_to_lba(&tf);
-
+        if (dev->horkage & ATA_HORKAGE_HPA_SIZE)
+               (*max_sectors)--;
        return 0;
 }
 
@@ -950,9 +975,12 @@ static int ata_set_max_sectors(struct ata_device *dev, u64 new_sectors)
                tf.hob_lbal = (new_sectors >> 24) & 0xff;
                tf.hob_lbam = (new_sectors >> 32) & 0xff;
                tf.hob_lbah = (new_sectors >> 40) & 0xff;
-       } else
+       } else {
                tf.command = ATA_CMD_SET_MAX;
 
+               tf.device |= (new_sectors >> 24) & 0xf;
+       }
+
        tf.protocol |= ATA_PROT_NODATA;
        tf.device |= ATA_LBA;
 
@@ -2016,6 +2044,7 @@ int ata_dev_configure(struct ata_device *dev)
        else if (dev->class == ATA_DEV_ATAPI) {
                const char *cdb_intr_string = "";
                const char *atapi_an_string = "";
+               u32 sntf;
 
                rc = atapi_cdb_len(id);
                if ((rc < 12) || (rc > ATAPI_CDB_LEN)) {
@@ -2027,11 +2056,14 @@ int ata_dev_configure(struct ata_device *dev)
                }
                dev->cdb_len = (unsigned int) rc;
 
-               /*
-                * check to see if this ATAPI device supports
-                * Asynchronous Notification
+               /* Enable ATAPI AN if both the host and device have
+                * the support.  If PMP is attached, SNTF is required
+                * to enable ATAPI AN to discern between PHY status
+                * changed notifications and ATAPI ANs.
                 */
-               if ((ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id)) {
+               if ((ap->flags & ATA_FLAG_AN) && ata_id_has_atapi_AN(id) &&
+                   (!ap->nr_pmp_links ||
+                    sata_scr_read(&ap->link, SCR_NOTIFICATION, &sntf) == 0)) {
                        unsigned int err_mask;
 
                        /* issue SET feature command to turn this on */
@@ -2889,14 +2921,27 @@ int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev)
        /* step 1: calculate xfer_mask */
        ata_link_for_each_dev(dev, link) {
                unsigned int pio_mask, dma_mask;
+               unsigned int mode_mask;
 
                if (!ata_dev_enabled(dev))
                        continue;
 
+               mode_mask = ATA_DMA_MASK_ATA;
+               if (dev->class == ATA_DEV_ATAPI)
+                       mode_mask = ATA_DMA_MASK_ATAPI;
+               else if (ata_id_is_cfa(dev->id))
+                       mode_mask = ATA_DMA_MASK_CFA;
+
                ata_dev_xfermask(dev);
 
                pio_mask = ata_pack_xfermask(dev->pio_mask, 0, 0);
                dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
+
+               if (libata_dma_mask & mode_mask)
+                       dma_mask = ata_pack_xfermask(0, dev->mwdma_mask, dev->udma_mask);
+               else
+                       dma_mask = 0;
+
                dev->pio_mode = ata_xfer_mask2mode(pio_mask);
                dev->dma_mode = ata_xfer_mask2mode(dma_mask);
 
@@ -3164,6 +3209,8 @@ static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
                             unsigned long deadline)
 {
        struct ata_ioports *ioaddr = &ap->ioaddr;
+       struct ata_device *dev;
+       int i = 0;
 
        DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
 
@@ -3174,6 +3221,25 @@ static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
        udelay(20);     /* FIXME: flush */
        iowrite8(ap->ctl, ioaddr->ctl_addr);
 
+       /* If we issued an SRST then an ATA drive (not ATAPI)
+        * may have changed configuration and be in PIO0 timing. If
+        * we did a hard reset (or are coming from power on) this is
+        * true for ATA or ATAPI. Until we've set a suitable controller
+        * mode we should not touch the bus as we may be talking too fast.
+        */
+
+       ata_link_for_each_dev(dev, &ap->link)
+               dev->pio_mode = XFER_PIO_0;
+
+       /* If the controller has a pio mode setup function then use
+          it to set the chipset to rights. Don't touch the DMA setup
+          as that will be dealt with when revalidating */
+       if (ap->ops->set_piomode) {
+               ata_link_for_each_dev(dev, &ap->link)
+                       if (devmask & (1 << i++))
+                               ap->ops->set_piomode(ap, dev);
+       }
+
        /* spec mandates ">= 2ms" before checking status.
         * We wait 150ms, because that was the magic delay used for
         * ATAPI devices in Hale Landis's ATADRVR, for the period of time
@@ -3418,6 +3484,12 @@ int ata_std_prereset(struct ata_link *link, unsigned long deadline)
            (link->flags & ATA_LFLAG_HRST_TO_RESUME))
                ehc->i.action |= ATA_EH_HARDRESET;
 
+       /* Some PMPs don't work with only SRST, force hardreset if PMP
+        * is supported.
+        */
+       if (ap->flags & ATA_FLAG_PMP)
+               ehc->i.action |= ATA_EH_HARDRESET;
+
        /* if we're about to do hardreset, nothing more to do */
        if (ehc->i.action & ATA_EH_HARDRESET)
                return 0;
@@ -3608,6 +3680,16 @@ int sata_std_hardreset(struct ata_link *link, unsigned int *class,
        /* wait a while before checking status, see SRST for more info */
        msleep(150);
 
+       /* If PMP is supported, we have to do follow-up SRST.  Note
+        * that some PMPs don't send D2H Reg FIS after hardreset at
+        * all if the first port is empty.  Wait for it just for a
+        * second and request follow-up SRST.
+        */
+       if (ap->flags & ATA_FLAG_PMP) {
+               ata_wait_ready(ap, jiffies + HZ);
+               return -EAGAIN;
+       }
+
        rc = ata_wait_ready(ap, deadline);
        /* link occupied, -ENODEV too is an error */
        if (rc) {
@@ -3857,6 +3939,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "IOMEGA  ZIP 250       ATAPI", NULL,  ATA_HORKAGE_NODMA }, /* temporary fix */
        { "IOMEGA  ZIP 250       ATAPI       Floppy",
                                NULL,           ATA_HORKAGE_NODMA },
+       /* Odd clown on sil3726/4726 PMPs */
+       { "Config  Disk",       NULL,           ATA_HORKAGE_NODMA |
+                                               ATA_HORKAGE_SKIP_PM },
 
        /* Weird ATAPI devices */
        { "TORiSAN DVD-ROM DRD-N216", NULL,     ATA_HORKAGE_MAX_SEC_128 },
@@ -3871,8 +3956,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* NCQ is broken */
        { "Maxtor *",           "BANC*",        ATA_HORKAGE_NONCQ },
        { "Maxtor 7V300F0",     "VA111630",     ATA_HORKAGE_NONCQ },
-       { "HITACHI HDS7250SASUN500G 0621KTAWSD", "K2AOAJ0AHITACHI",
-         ATA_HORKAGE_NONCQ },
+       { "HITACHI HDS7250SASUN500G*", NULL,    ATA_HORKAGE_NONCQ },
+       { "HITACHI HDS7225SBSUN250G*", NULL,    ATA_HORKAGE_NONCQ },
+       { "ST380817AS",         "3.42",         ATA_HORKAGE_NONCQ },
 
        /* Blacklist entries taken from Silicon Image 3124/3132
           Windows driver .inf file - also several Linux problem reports */
@@ -3882,11 +3968,16 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* Drives which do spurious command completion */
        { "HTS541680J9SA00",    "SB2IC7EP",     ATA_HORKAGE_NONCQ, },
        { "HTS541612J9SA00",    "SBDIC7JP",     ATA_HORKAGE_NONCQ, },
+       { "HDT722516DLA380",    "V43OA96A",     ATA_HORKAGE_NONCQ, },
        { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, },
        { "WDC WD740ADFD-00NLR1", NULL,         ATA_HORKAGE_NONCQ, },
+       { "WDC WD3200AAJS-00RYA0", "12.01B01",  ATA_HORKAGE_NONCQ, },
        { "FUJITSU MHV2080BH",  "00840028",     ATA_HORKAGE_NONCQ, },
+       { "ST9120822AS",        "3.CLF",        ATA_HORKAGE_NONCQ, },
        { "ST9160821AS",        "3.CLF",        ATA_HORKAGE_NONCQ, },
-       { "ST3160812AS",        "3.AD",         ATA_HORKAGE_NONCQ, },
+       { "ST9160821AS",        "3.ALD",        ATA_HORKAGE_NONCQ, },
+       { "ST3160812AS",        "3.ADJ",        ATA_HORKAGE_NONCQ, },
+       { "ST980813AS",         "3.ADB",        ATA_HORKAGE_NONCQ, },
        { "SAMSUNG HD401LJ",    "ZZ100-15",     ATA_HORKAGE_NONCQ, },
 
        /* devices which puke on READ_NATIVE_MAX */
@@ -3895,6 +3986,10 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA },
        { "MAXTOR 6L080L4",     "A93.0500",     ATA_HORKAGE_BROKEN_HPA },
 
+       /* Devices which report 1 sector over size HPA */
+       { "ST340823A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
+       { "ST320413A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
+
        /* End Marker */
        { }
 };
@@ -5948,22 +6043,26 @@ int sata_scr_valid(struct ata_link *link)
  *     @val: Place to store read value
  *
  *     Read SCR register @reg of @link into *@val.  This function is
- *     guaranteed to succeed if the cable type of the port is SATA
- *     and the port implements ->scr_read.
+ *     guaranteed to succeed if @link is ap->link, the cable type of
+ *     the port is SATA and the port implements ->scr_read.
  *
  *     LOCKING:
- *     None.
+ *     None if @link is ap->link.  Kernel thread context otherwise.
  *
  *     RETURNS:
  *     0 on success, negative errno on failure.
  */
 int sata_scr_read(struct ata_link *link, int reg, u32 *val)
 {
-       struct ata_port *ap = link->ap;
+       if (ata_is_host_link(link)) {
+               struct ata_port *ap = link->ap;
+
+               if (sata_scr_valid(link))
+                       return ap->ops->scr_read(ap, reg, val);
+               return -EOPNOTSUPP;
+       }
 
-       if (sata_scr_valid(link))
-               return ap->ops->scr_read(ap, reg, val);
-       return -EOPNOTSUPP;
+       return sata_pmp_scr_read(link, reg, val);
 }
 
 /**
@@ -5973,22 +6072,26 @@ int sata_scr_read(struct ata_link *link, int reg, u32 *val)
  *     @val: value to write
  *
  *     Write @val to SCR register @reg of @link.  This function is
- *     guaranteed to succeed if the cable type of the port is SATA
- *     and the port implements ->scr_read.
+ *     guaranteed to succeed if @link is ap->link, the cable type of
+ *     the port is SATA and the port implements ->scr_read.
  *
  *     LOCKING:
- *     None.
+ *     None if @link is ap->link.  Kernel thread context otherwise.
  *
  *     RETURNS:
  *     0 on success, negative errno on failure.
  */
 int sata_scr_write(struct ata_link *link, int reg, u32 val)
 {
-       struct ata_port *ap = link->ap;
+       if (ata_is_host_link(link)) {
+               struct ata_port *ap = link->ap;
+
+               if (sata_scr_valid(link))
+                       return ap->ops->scr_write(ap, reg, val);
+               return -EOPNOTSUPP;
+       }
 
-       if (sata_scr_valid(link))
-               return ap->ops->scr_write(ap, reg, val);
-       return -EOPNOTSUPP;
+       return sata_pmp_scr_write(link, reg, val);
 }
 
 /**
@@ -6001,23 +6104,27 @@ int sata_scr_write(struct ata_link *link, int reg, u32 val)
  *     function performs flush after writing to the register.
  *
  *     LOCKING:
- *     None.
+ *     None if @link is ap->link.  Kernel thread context otherwise.
  *
  *     RETURNS:
  *     0 on success, negative errno on failure.
  */
 int sata_scr_write_flush(struct ata_link *link, int reg, u32 val)
 {
-       struct ata_port *ap = link->ap;
-       int rc;
+       if (ata_is_host_link(link)) {
+               struct ata_port *ap = link->ap;
+               int rc;
 
-       if (sata_scr_valid(link)) {
-               rc = ap->ops->scr_write(ap, reg, val);
-               if (rc == 0)
-                       rc = ap->ops->scr_read(ap, reg, &val);
-               return rc;
+               if (sata_scr_valid(link)) {
+                       rc = ap->ops->scr_write(ap, reg, val);
+                       if (rc == 0)
+                               rc = ap->ops->scr_read(ap, reg, &val);
+                       return rc;
+               }
+               return -EOPNOTSUPP;
        }
-       return -EOPNOTSUPP;
+
+       return sata_pmp_scr_write(link, reg, val);
 }
 
 /**
@@ -6406,6 +6513,7 @@ static void ata_host_release(struct device *gendev, void *res)
                if (ap->scsi_host)
                        scsi_host_put(ap->scsi_host);
 
+               kfree(ap->pmp_link);
                kfree(ap);
                host->ports[i] = NULL;
        }
@@ -6665,13 +6773,14 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
                xfer_mask = ata_pack_xfermask(ap->pio_mask, ap->mwdma_mask,
                                              ap->udma_mask);
 
-               if (!ata_port_is_dummy(ap))
+               if (!ata_port_is_dummy(ap)) {
                        ata_port_printk(ap, KERN_INFO,
                                        "%cATA max %s %s\n",
                                        (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P',
                                        ata_mode_string(xfer_mask),
                                        ap->link.eh_info.desc);
-               else
+                       ata_ehi_clear_desc(&ap->link.eh_info);
+               } else
                        ata_port_printk(ap, KERN_INFO, "DUMMY\n");
        }
 
@@ -7236,6 +7345,15 @@ EXPORT_SYMBOL_GPL(ata_pci_default_filter);
 EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
 #endif /* CONFIG_PCI */
 
+EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch);
+EXPORT_SYMBOL_GPL(sata_pmp_read_init_tf);
+EXPORT_SYMBOL_GPL(sata_pmp_read_val);
+EXPORT_SYMBOL_GPL(sata_pmp_write_init_tf);
+EXPORT_SYMBOL_GPL(sata_pmp_std_prereset);
+EXPORT_SYMBOL_GPL(sata_pmp_std_hardreset);
+EXPORT_SYMBOL_GPL(sata_pmp_std_postreset);
+EXPORT_SYMBOL_GPL(sata_pmp_do_eh);
+
 EXPORT_SYMBOL_GPL(__ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_push_desc);
 EXPORT_SYMBOL_GPL(ata_ehi_clear_desc);
@@ -7248,6 +7366,7 @@ EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
 EXPORT_SYMBOL_GPL(ata_link_abort);
 EXPORT_SYMBOL_GPL(ata_port_abort);
 EXPORT_SYMBOL_GPL(ata_port_freeze);
+EXPORT_SYMBOL_GPL(sata_async_notification);
 EXPORT_SYMBOL_GPL(ata_eh_freeze_port);
 EXPORT_SYMBOL_GPL(ata_eh_thaw_port);
 EXPORT_SYMBOL_GPL(ata_eh_qc_complete);