Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus
[safe/jmp/linux-2.6] / drivers / ata / libata-pmp.c
index 9c99861..619f2c3 100644 (file)
 #include <linux/libata.h>
 #include "libata.h"
 
+const struct ata_port_operations sata_pmp_port_ops = {
+       .inherits               = &sata_port_ops,
+       .pmp_prereset           = ata_std_prereset,
+       .pmp_hardreset          = sata_std_hardreset,
+       .pmp_postreset          = ata_std_postreset,
+       .error_handler          = sata_pmp_error_handler,
+};
+
 /**
  *     sata_pmp_read - read PMP register
  *     @link: link to read PMP register for
@@ -40,7 +48,7 @@ static unsigned int sata_pmp_read(struct ata_link *link, int reg, u32 *r_val)
        tf.device = link->pmp;
 
        err_mask = ata_exec_internal(pmp_dev, &tf, NULL, DMA_NONE, NULL, 0,
-                                    SATA_PMP_SCR_TIMEOUT);
+                                    SATA_PMP_RW_TIMEOUT);
        if (err_mask)
                return err_mask;
 
@@ -80,7 +88,7 @@ static unsigned int sata_pmp_write(struct ata_link *link, int reg, u32 val)
        tf.lbah = (val >> 24) & 0xff;
 
        return ata_exec_internal(pmp_dev, &tf, NULL, DMA_NONE, NULL, 0,
-                                SATA_PMP_SCR_TIMEOUT);
+                                SATA_PMP_RW_TIMEOUT);
 }
 
 /**
@@ -249,19 +257,6 @@ static int sata_pmp_configure(struct ata_device *dev, int print_info)
                goto fail;
        }
 
-       /* turn off notification till fan-out ports are reset and configured */
-       if (gscr[SATA_PMP_GSCR_FEAT_EN] & SATA_PMP_FEAT_NOTIFY) {
-               gscr[SATA_PMP_GSCR_FEAT_EN] &= ~SATA_PMP_FEAT_NOTIFY;
-
-               err_mask = sata_pmp_write(dev->link, SATA_PMP_GSCR_FEAT_EN,
-                                         gscr[SATA_PMP_GSCR_FEAT_EN]);
-               if (err_mask) {
-                       rc = -EIO;
-                       reason = "failed to write GSCR_FEAT_EN";
-                       goto fail;
-               }
-       }
-
        if (print_info) {
                ata_dev_printk(dev, KERN_INFO, "Port Multiplier %s, "
                               "0x%04x:0x%04x r%d, %d ports, feat 0x%x/0x%x\n",
@@ -326,10 +321,13 @@ static void sata_pmp_quirks(struct ata_port *ap)
 
        if (vendor == 0x1095 && devid == 0x3726) {
                /* sil3726 quirks */
-               ata_port_for_each_link(link, ap) {
-                       /* class code report is unreliable */
+               ata_for_each_link(link, ap, EDGE) {
+                       /* Class code report is unreliable and SRST
+                        * times out under certain configurations.
+                        */
                        if (link->pmp < 5)
-                               link->flags |= ATA_LFLAG_ASSUME_ATA;
+                               link->flags |= ATA_LFLAG_NO_SRST |
+                                              ATA_LFLAG_ASSUME_ATA;
 
                        /* port 5 is for SEMB device and it doesn't like SRST */
                        if (link->pmp == 5)
@@ -338,7 +336,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
                }
        } else if (vendor == 0x1095 && devid == 0x4723) {
                /* sil4723 quirks */
-               ata_port_for_each_link(link, ap) {
+               ata_for_each_link(link, ap, EDGE) {
                        /* class code report is unreliable */
                        if (link->pmp < 2)
                                link->flags |= ATA_LFLAG_ASSUME_ATA;
@@ -350,7 +348,7 @@ static void sata_pmp_quirks(struct ata_port *ap)
                }
        } else if (vendor == 0x1095 && devid == 0x4726) {
                /* sil4726 quirks */
-               ata_port_for_each_link(link, ap) {
+               ata_for_each_link(link, ap, EDGE) {
                        /* Class code report is unreliable and SRST
                         * times out under certain configurations.
                         * Config device can be at port 0 or 5 and
@@ -403,7 +401,7 @@ int sata_pmp_attach(struct ata_device *dev)
        int rc;
 
        /* is it hanging off the right place? */
-       if (!(ap->flags & ATA_FLAG_PMP)) {
+       if (!sata_pmp_supported(ap)) {
                ata_dev_printk(dev, KERN_ERR,
                               "host does not support Port Multiplier\n");
                return -EINVAL;
@@ -452,7 +450,7 @@ int sata_pmp_attach(struct ata_device *dev)
        if (ap->ops->pmp_attach)
                ap->ops->pmp_attach(ap);
 
-       ata_port_for_each_link(tlink, ap)
+       ata_for_each_link(tlink, ap, EDGE)
                sata_link_init_spd(tlink);
 
        ata_acpi_associate_sata_port(ap);
@@ -489,7 +487,7 @@ static void sata_pmp_detach(struct ata_device *dev)
        if (ap->ops->pmp_detach)
                ap->ops->pmp_detach(ap);
 
-       ata_port_for_each_link(tlink, ap)
+       ata_for_each_link(tlink, ap, EDGE)
                ata_eh_detach_dev(tlink->device);
 
        spin_lock_irqsave(ap->lock, flags);
@@ -692,8 +690,6 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
        if (ehc->i.action & ATA_EH_RESET) {
                struct ata_link *tlink;
 
-               ata_eh_freeze_port(ap);
-
                /* reset */
                rc = ata_eh_reset(link, 0, prereset, softreset, hardreset,
                                  postreset);
@@ -703,10 +699,8 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
                        goto fail;
                }
 
-               ata_eh_thaw_port(ap);
-
                /* PMP is reset, SErrors cannot be trusted, scan all */
-               ata_port_for_each_link(tlink, ap) {
+               ata_for_each_link(tlink, ap, EDGE) {
                        struct ata_eh_context *ehc = &tlink->eh_context;
 
                        ehc->i.probe_mask |= ATA_ALL_DEVICES;
@@ -733,19 +727,12 @@ static int sata_pmp_eh_recover_pmp(struct ata_port *ap,
                }
 
                if (tries) {
-                       int sleep = ehc->i.flags & ATA_EHI_DID_RESET;
-
                        /* consecutive revalidation failures? speed down */
                        if (reval_failed)
-                               sata_down_spd_limit(link);
+                               sata_down_spd_limit(link, 0);
                        else
                                reval_failed = 1;
 
-                       ata_dev_printk(dev, KERN_WARNING,
-                                      "retrying reset%s\n",
-                                      sleep ? " in 5 secs" : "");
-                       if (sleep)
-                               ssleep(5);
                        ehc->i.action |= ATA_EH_RESET;
                        goto retry;
                } else {
@@ -781,7 +768,7 @@ static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
 
        spin_lock_irqsave(ap->lock, flags);
 
-       ata_port_for_each_link(link, ap) {
+       ata_for_each_link(link, ap, EDGE) {
                if (!(link->flags & ATA_LFLAG_DISABLED))
                        continue;
 
@@ -791,7 +778,8 @@ static int sata_pmp_eh_handle_disabled_links(struct ata_port *ap)
                 * SError.N working.
                 */
                sata_link_hardreset(link, sata_deb_timing_normal,
-                               jiffies + ATA_TMOUT_INTERNAL_QUICK, NULL, NULL);
+                               ata_deadline(jiffies, ATA_TMOUT_INTERNAL_QUICK),
+                               NULL, NULL);
 
                /* unconditionally clear SError.N */
                rc = sata_scr_write(link, SCR_ERROR, SERR_PHYRDY_CHG);
@@ -856,6 +844,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
        struct ata_link *pmp_link = &ap->link;
        struct ata_device *pmp_dev = pmp_link->device;
        struct ata_eh_context *pmp_ehc = &pmp_link->eh_context;
+       u32 *gscr = pmp_dev->gscr;
        struct ata_link *link;
        struct ata_device *dev;
        unsigned int err_mask;
@@ -863,16 +852,16 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
        int cnt, rc;
 
        pmp_tries = ATA_EH_PMP_TRIES;
-       ata_port_for_each_link(link, ap)
+       ata_for_each_link(link, ap, EDGE)
                link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
 
  retry:
        /* PMP attached? */
-       if (!ap->nr_pmp_links) {
+       if (!sata_pmp_attached(ap)) {
                rc = ata_eh_recover(ap, ops->prereset, ops->softreset,
                                    ops->hardreset, ops->postreset, NULL);
                if (rc) {
-                       ata_link_for_each_dev(dev, &ap->link)
+                       ata_for_each_dev(dev, &ap->link, ALL)
                                ata_dev_disable(dev);
                        return rc;
                }
@@ -881,7 +870,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
                        return 0;
 
                /* new PMP online */
-               ata_port_for_each_link(link, ap)
+               ata_for_each_link(link, ap, EDGE)
                        link_tries[link->pmp] = ATA_EH_PMP_LINK_TRIES;
 
                /* fall through */
@@ -893,6 +882,22 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
        if (rc)
                goto pmp_fail;
 
+       /* PHY event notification can disturb reset and other recovery
+        * operations.  Turn it off.
+        */
+       if (gscr[SATA_PMP_GSCR_FEAT_EN] & SATA_PMP_FEAT_NOTIFY) {
+               gscr[SATA_PMP_GSCR_FEAT_EN] &= ~SATA_PMP_FEAT_NOTIFY;
+
+               err_mask = sata_pmp_write(pmp_link, SATA_PMP_GSCR_FEAT_EN,
+                                         gscr[SATA_PMP_GSCR_FEAT_EN]);
+               if (err_mask) {
+                       ata_link_printk(pmp_link, KERN_WARNING,
+                               "failed to disable NOTIFY (err_mask=0x%x)\n",
+                               err_mask);
+                       goto pmp_fail;
+               }
+       }
+
        /* handle disabled links */
        rc = sata_pmp_eh_handle_disabled_links(ap);
        if (rc)
@@ -915,10 +920,10 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
 
        /* enable notification */
        if (pmp_dev->flags & ATA_DFLAG_AN) {
-               pmp_dev->gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY;
+               gscr[SATA_PMP_GSCR_FEAT_EN] |= SATA_PMP_FEAT_NOTIFY;
 
-               err_mask = sata_pmp_write(pmp_dev->link, SATA_PMP_GSCR_FEAT_EN,
-                                         pmp_dev->gscr[SATA_PMP_GSCR_FEAT_EN]);
+               err_mask = sata_pmp_write(pmp_link, SATA_PMP_GSCR_FEAT_EN,
+                                         gscr[SATA_PMP_GSCR_FEAT_EN]);
                if (err_mask) {
                        ata_dev_printk(pmp_dev, KERN_ERR, "failed to write "
                                       "PMP_FEAT_EN (Emask=0x%x)\n", err_mask);
@@ -937,7 +942,7 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
        }
 
        cnt = 0;
-       ata_port_for_each_link(link, ap) {
+       ata_for_each_link(link, ap, EDGE) {
                if (!(gscr_error & (1 << link->pmp)))
                        continue;
 
@@ -975,14 +980,11 @@ static int sata_pmp_eh_recover(struct ata_port *ap)
        if (ap->pflags & ATA_PFLAG_UNLOADING)
                return rc;
 
-       if (!ap->nr_pmp_links)
+       if (!sata_pmp_attached(ap))
                goto retry;
 
        if (--pmp_tries) {
-               ata_port_printk(ap, KERN_WARNING,
-                               "failed to recover PMP, retrying in 5 secs\n");
                pmp_ehc->i.action |= ATA_EH_RESET;
-               ssleep(5);
                goto retry;
        }
 
@@ -1012,3 +1014,7 @@ void sata_pmp_error_handler(struct ata_port *ap)
        sata_pmp_eh_recover(ap);
        ata_eh_finish(ap);
 }
+
+EXPORT_SYMBOL_GPL(sata_pmp_port_ops);
+EXPORT_SYMBOL_GPL(sata_pmp_qc_defer_cmd_switch);
+EXPORT_SYMBOL_GPL(sata_pmp_error_handler);