Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy...
[pandora-kernel.git] / drivers / ata / sata_sil24.c
index e2cccc7..864c1c1 100644 (file)
@@ -30,7 +30,7 @@
 #include <linux/libata.h>
 
 #define DRV_NAME       "sata_sil24"
-#define DRV_VERSION    "1.0"
+#define DRV_VERSION    "1.1"
 
 /*
  * Port request block (PRB) 32 bytes
@@ -63,6 +63,21 @@ enum {
        SIL24_HOST_BAR          = 0,
        SIL24_PORT_BAR          = 2,
 
+       /* sil24 fetches in chunks of 64bytes.  The first block
+        * contains the PRB and two SGEs.  From the second block, it's
+        * consisted of four SGEs and called SGT.  Calculate the
+        * number of SGTs that fit into one page.
+        */
+       SIL24_PRB_SZ            = sizeof(struct sil24_prb)
+                                 + 2 * sizeof(struct sil24_sge),
+       SIL24_MAX_SGT           = (PAGE_SIZE - SIL24_PRB_SZ)
+                                 / (4 * sizeof(struct sil24_sge)),
+
+       /* This will give us one unused SGEs for ATA.  This extra SGE
+        * will be used to store CDB for ATAPI devices.
+        */
+       SIL24_MAX_SGE           = 4 * SIL24_MAX_SGT + 1,
+
        /*
         * Global controller registers (128 bytes @ BAR0)
         */
@@ -168,7 +183,7 @@ enum {
 
        DEF_PORT_IRQ            = PORT_IRQ_COMPLETE | PORT_IRQ_ERROR |
                                  PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG |
-                                 PORT_IRQ_UNK_FIS,
+                                 PORT_IRQ_UNK_FIS | PORT_IRQ_SDB_NOTIFY,
 
        /* bits[27:16] are unmasked (raw) */
        PORT_IRQ_RAW_SHIFT      = 16,
@@ -237,7 +252,8 @@ enum {
        /* host flags */
        SIL24_COMMON_FLAGS      = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
                                  ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
-                                 ATA_FLAG_NCQ | ATA_FLAG_ACPI_SATA,
+                                 ATA_FLAG_NCQ | ATA_FLAG_ACPI_SATA |
+                                 ATA_FLAG_AN | ATA_FLAG_PMP,
        SIL24_COMMON_LFLAGS     = ATA_LFLAG_SKIP_D2H_BSY,
        SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */
 
@@ -246,13 +262,13 @@ enum {
 
 struct sil24_ata_block {
        struct sil24_prb prb;
-       struct sil24_sge sge[LIBATA_MAX_PRD];
+       struct sil24_sge sge[SIL24_MAX_SGE];
 };
 
 struct sil24_atapi_block {
        struct sil24_prb prb;
        u8 cdb[16];
-       struct sil24_sge sge[LIBATA_MAX_PRD - 1];
+       struct sil24_sge sge[SIL24_MAX_SGE];
 };
 
 union sil24_cmd_block {
@@ -264,11 +280,11 @@ static struct sil24_cerr_info {
        unsigned int err_mask, action;
        const char *desc;
 } sil24_cerr_db[] = {
-       [0]                     = { AC_ERR_DEV, ATA_EH_REVALIDATE,
+       [0]                     = { AC_ERR_DEV, 0,
                                    "device error" },
-       [PORT_CERR_DEV]         = { AC_ERR_DEV, ATA_EH_REVALIDATE,
+       [PORT_CERR_DEV]         = { AC_ERR_DEV, 0,
                                    "device error via D2H FIS" },
-       [PORT_CERR_SDB]         = { AC_ERR_DEV, ATA_EH_REVALIDATE,
+       [PORT_CERR_SDB]         = { AC_ERR_DEV, 0,
                                    "device error via SDB FIS" },
        [PORT_CERR_DATA]        = { AC_ERR_ATA_BUS, ATA_EH_SOFTRESET,
                                    "error in data FIS" },
@@ -285,7 +301,7 @@ static struct sil24_cerr_info {
        [PORT_CERR_PKT_PROT]    = { AC_ERR_HSM, ATA_EH_SOFTRESET,
                                    "invalid data directon for ATAPI CDB" },
        [PORT_CERR_SGT_BOUNDARY] = { AC_ERR_SYSTEM, ATA_EH_SOFTRESET,
-                                    "SGT no on qword boundary" },
+                                    "SGT not on qword boundary" },
        [PORT_CERR_SGT_TGTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
                                    "PCI target abort while fetching SGT" },
        [PORT_CERR_SGT_MSTABRT] = { AC_ERR_HOST_BUS, ATA_EH_SOFTRESET,
@@ -322,6 +338,7 @@ struct sil24_port_priv {
        union sil24_cmd_block *cmd_block;       /* 32 cmd blocks */
        dma_addr_t cmd_block_dma;               /* DMA base addr for them */
        struct ata_taskfile tf;                 /* Cached taskfile registers */
+       int do_port_rst;
 };
 
 static void sil24_dev_config(struct ata_device *dev);
@@ -329,9 +346,12 @@ static u8 sil24_check_status(struct ata_port *ap);
 static int sil24_scr_read(struct ata_port *ap, unsigned sc_reg, u32 *val);
 static int sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val);
 static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
+static int sil24_qc_defer(struct ata_queued_cmd *qc);
 static void sil24_qc_prep(struct ata_queued_cmd *qc);
 static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc);
 static void sil24_irq_clear(struct ata_port *ap);
+static void sil24_pmp_attach(struct ata_port *ap);
+static void sil24_pmp_detach(struct ata_port *ap);
 static void sil24_freeze(struct ata_port *ap);
 static void sil24_thaw(struct ata_port *ap);
 static void sil24_error_handler(struct ata_port *ap);
@@ -340,6 +360,7 @@ static int sil24_port_start(struct ata_port *ap);
 static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
 #ifdef CONFIG_PM
 static int sil24_pci_device_resume(struct pci_dev *pdev);
+static int sil24_port_resume(struct ata_port *ap);
 #endif
 
 static const struct pci_device_id sil24_pci_tbl[] = {
@@ -372,7 +393,7 @@ static struct scsi_host_template sil24_sht = {
        .change_queue_depth     = ata_scsi_change_queue_depth,
        .can_queue              = SIL24_MAX_CMDS,
        .this_id                = ATA_SHT_THIS_ID,
-       .sg_tablesize           = LIBATA_MAX_PRD,
+       .sg_tablesize           = SIL24_MAX_SGE,
        .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
        .emulated               = ATA_SHT_EMULATED,
        .use_clustering         = ATA_SHT_USE_CLUSTERING,
@@ -384,8 +405,6 @@ static struct scsi_host_template sil24_sht = {
 };
 
 static const struct ata_port_operations sil24_ops = {
-       .port_disable           = ata_port_disable,
-
        .dev_config             = sil24_dev_config,
 
        .check_status           = sil24_check_status,
@@ -394,22 +413,28 @@ static const struct ata_port_operations sil24_ops = {
 
        .tf_read                = sil24_tf_read,
 
+       .qc_defer               = sil24_qc_defer,
        .qc_prep                = sil24_qc_prep,
        .qc_issue               = sil24_qc_issue,
 
        .irq_clear              = sil24_irq_clear,
-       .irq_on                 = ata_dummy_irq_on,
-       .irq_ack                = ata_dummy_irq_ack,
 
        .scr_read               = sil24_scr_read,
        .scr_write              = sil24_scr_write,
 
+       .pmp_attach             = sil24_pmp_attach,
+       .pmp_detach             = sil24_pmp_detach,
+
        .freeze                 = sil24_freeze,
        .thaw                   = sil24_thaw,
        .error_handler          = sil24_error_handler,
        .post_internal_cmd      = sil24_post_internal_cmd,
 
        .port_start             = sil24_port_start,
+
+#ifdef CONFIG_PM
+       .port_resume            = sil24_port_resume,
+#endif
 };
 
 /*
@@ -523,19 +548,78 @@ static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
        *tf = pp->tf;
 }
 
+static void sil24_config_port(struct ata_port *ap)
+{
+       void __iomem *port = ap->ioaddr.cmd_addr;
+
+       /* configure IRQ WoC */
+       if (ap->flags & SIL24_FLAG_PCIX_IRQ_WOC)
+               writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
+       else
+               writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
+
+       /* zero error counters. */
+       writel(0x8000, port + PORT_DECODE_ERR_THRESH);
+       writel(0x8000, port + PORT_CRC_ERR_THRESH);
+       writel(0x8000, port + PORT_HSHK_ERR_THRESH);
+       writel(0x0000, port + PORT_DECODE_ERR_CNT);
+       writel(0x0000, port + PORT_CRC_ERR_CNT);
+       writel(0x0000, port + PORT_HSHK_ERR_CNT);
+
+       /* always use 64bit activation */
+       writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
+
+       /* clear port multiplier enable and resume bits */
+       writel(PORT_CS_PMP_EN | PORT_CS_PMP_RESUME, port + PORT_CTRL_CLR);
+}
+
+static void sil24_config_pmp(struct ata_port *ap, int attached)
+{
+       void __iomem *port = ap->ioaddr.cmd_addr;
+
+       if (attached)
+               writel(PORT_CS_PMP_EN, port + PORT_CTRL_STAT);
+       else
+               writel(PORT_CS_PMP_EN, port + PORT_CTRL_CLR);
+}
+
+static void sil24_clear_pmp(struct ata_port *ap)
+{
+       void __iomem *port = ap->ioaddr.cmd_addr;
+       int i;
+
+       writel(PORT_CS_PMP_RESUME, port + PORT_CTRL_CLR);
+
+       for (i = 0; i < SATA_PMP_MAX_PORTS; i++) {
+               void __iomem *pmp_base = port + PORT_PMP + i * PORT_PMP_SIZE;
+
+               writel(0, pmp_base + PORT_PMP_STATUS);
+               writel(0, pmp_base + PORT_PMP_QACTIVE);
+       }
+}
+
 static int sil24_init_port(struct ata_port *ap)
 {
        void __iomem *port = ap->ioaddr.cmd_addr;
+       struct sil24_port_priv *pp = ap->private_data;
        u32 tmp;
 
+       /* clear PMP error status */
+       if (ap->nr_pmp_links)
+               sil24_clear_pmp(ap);
+
        writel(PORT_CS_INIT, port + PORT_CTRL_STAT);
        ata_wait_register(port + PORT_CTRL_STAT,
                          PORT_CS_INIT, PORT_CS_INIT, 10, 100);
        tmp = ata_wait_register(port + PORT_CTRL_STAT,
                                PORT_CS_RDY, 0, 10, 100);
 
-       if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY)
+       if ((tmp & (PORT_CS_INIT | PORT_CS_RDY)) != PORT_CS_RDY) {
+               pp->do_port_rst = 1;
+               ap->link.eh_context.i.action |= ATA_EH_HARDRESET;
                return -EIO;
+       }
+
        return 0;
 }
 
@@ -605,7 +689,7 @@ static int sil24_do_softreset(struct ata_link *link, unsigned int *class,
 
        /* put the port into known state */
        if (sil24_init_port(ap)) {
-               reason ="port not ready";
+               reason = "port not ready";
                goto err;
        }
 
@@ -642,7 +726,7 @@ static int sil24_do_softreset(struct ata_link *link, unsigned int *class,
 static int sil24_softreset(struct ata_link *link, unsigned int *class,
                           unsigned long deadline)
 {
-       return sil24_do_softreset(link, class, 0, deadline);
+       return sil24_do_softreset(link, class, SATA_PMP_CTRL_PORT, deadline);
 }
 
 static int sil24_hardreset(struct ata_link *link, unsigned int *class,
@@ -650,10 +734,34 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class,
 {
        struct ata_port *ap = link->ap;
        void __iomem *port = ap->ioaddr.cmd_addr;
+       struct sil24_port_priv *pp = ap->private_data;
+       int did_port_rst = 0;
        const char *reason;
        int tout_msec, rc;
        u32 tmp;
 
+ retry:
+       /* Sometimes, DEV_RST is not enough to recover the controller.
+        * This happens often after PM DMA CS errata.
+        */
+       if (pp->do_port_rst) {
+               ata_port_printk(ap, KERN_WARNING, "controller in dubious "
+                               "state, performing PORT_RST\n");
+
+               writel(PORT_CS_PORT_RST, port + PORT_CTRL_STAT);
+               msleep(10);
+               writel(PORT_CS_PORT_RST, port + PORT_CTRL_CLR);
+               ata_wait_register(port + PORT_CTRL_STAT, PORT_CS_RDY, 0,
+                                 10, 5000);
+
+               /* restore port configuration */
+               sil24_config_port(ap);
+               sil24_config_pmp(ap, ap->nr_pmp_links);
+
+               pp->do_port_rst = 0;
+               did_port_rst = 1;
+       }
+
        /* sil24 does the right thing(tm) without any protection */
        sata_set_spd(link);
 
@@ -663,7 +771,8 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class,
 
        writel(PORT_CS_DEV_RST, port + PORT_CTRL_STAT);
        tmp = ata_wait_register(port + PORT_CTRL_STAT,
-                               PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10, tout_msec);
+                               PORT_CS_DEV_RST, PORT_CS_DEV_RST, 10,
+                               tout_msec);
 
        /* SStatus oscillates between zero and valid status after
         * DEV_RST, debounce it.
@@ -690,6 +799,11 @@ static int sil24_hardreset(struct ata_link *link, unsigned int *class,
        return -EAGAIN;
 
  err:
+       if (!did_port_rst) {
+               pp->do_port_rst = 1;
+               goto retry;
+       }
+
        ata_link_printk(link, KERN_ERR, "hardreset failed (%s)\n", reason);
        return -EIO;
 }
@@ -698,16 +812,66 @@ static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
                                 struct sil24_sge *sge)
 {
        struct scatterlist *sg;
+       struct sil24_sge *last_sge = NULL;
 
        ata_for_each_sg(sg, qc) {
                sge->addr = cpu_to_le64(sg_dma_address(sg));
                sge->cnt = cpu_to_le32(sg_dma_len(sg));
-               if (ata_sg_is_last(sg, qc))
-                       sge->flags = cpu_to_le32(SGE_TRM);
-               else
-                       sge->flags = 0;
+               sge->flags = 0;
+
+               last_sge = sge;
                sge++;
        }
+
+       if (likely(last_sge))
+               last_sge->flags = cpu_to_le32(SGE_TRM);
+}
+
+static int sil24_qc_defer(struct ata_queued_cmd *qc)
+{
+       struct ata_link *link = qc->dev->link;
+       struct ata_port *ap = link->ap;
+       u8 prot = qc->tf.protocol;
+
+       /*
+        * There is a bug in the chip:
+        * Port LRAM Causes the PRB/SGT Data to be Corrupted
+        * If the host issues a read request for LRAM and SActive registers
+        * while active commands are available in the port, PRB/SGT data in
+        * the LRAM can become corrupted. This issue applies only when
+        * reading from, but not writing to, the LRAM.
+        *
+        * Therefore, reading LRAM when there is no particular error [and
+        * other commands may be outstanding] is prohibited.
+        *
+        * To avoid this bug there are two situations where a command must run
+        * exclusive of any other commands on the port:
+        *
+        * - ATAPI commands which check the sense data
+        * - Passthrough ATA commands which always have ATA_QCFLAG_RESULT_TF
+        *   set.
+        *
+        */
+       int is_excl = (prot == ATA_PROT_ATAPI ||
+                      prot == ATA_PROT_ATAPI_NODATA ||
+                      prot == ATA_PROT_ATAPI_DMA ||
+                      (qc->flags & ATA_QCFLAG_RESULT_TF));
+
+       if (unlikely(ap->excl_link)) {
+               if (link == ap->excl_link) {
+                       if (ap->nr_active_links)
+                               return ATA_DEFER_PORT;
+                       qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
+               } else
+                       return ATA_DEFER_PORT;
+       } else if (unlikely(is_excl)) {
+               ap->excl_link = link;
+               if (ap->nr_active_links)
+                       return ATA_DEFER_PORT;
+               qc->flags |= ATA_QCFLAG_CLEAR_EXCL;
+       }
+
+       return ata_std_qc_defer(qc);
 }
 
 static void sil24_qc_prep(struct ata_queued_cmd *qc)
@@ -753,7 +917,7 @@ static void sil24_qc_prep(struct ata_queued_cmd *qc)
        }
 
        prb->ctrl = cpu_to_le16(ctrl);
-       ata_tf_to_fis(&qc->tf, 0, 1, prb->fis);
+       ata_tf_to_fis(&qc->tf, qc->dev->link->pmp, 1, prb->fis);
 
        if (qc->flags & ATA_QCFLAG_DMAMAP)
                sil24_fill_sg(qc, sge);
@@ -782,6 +946,39 @@ static void sil24_irq_clear(struct ata_port *ap)
        /* unused */
 }
 
+static void sil24_pmp_attach(struct ata_port *ap)
+{
+       sil24_config_pmp(ap, 1);
+       sil24_init_port(ap);
+}
+
+static void sil24_pmp_detach(struct ata_port *ap)
+{
+       sil24_init_port(ap);
+       sil24_config_pmp(ap, 0);
+}
+
+static int sil24_pmp_softreset(struct ata_link *link, unsigned int *class,
+                              unsigned long deadline)
+{
+       return sil24_do_softreset(link, class, link->pmp, deadline);
+}
+
+static int sil24_pmp_hardreset(struct ata_link *link, unsigned int *class,
+                              unsigned long deadline)
+{
+       int rc;
+
+       rc = sil24_init_port(link->ap);
+       if (rc) {
+               ata_link_printk(link, KERN_ERR,
+                               "hardreset failed (port not ready)\n");
+               return rc;
+       }
+
+       return sata_pmp_std_hardreset(link, class, deadline);
+}
+
 static void sil24_freeze(struct ata_port *ap)
 {
        void __iomem *port = ap->ioaddr.cmd_addr;
@@ -809,8 +1006,10 @@ static void sil24_error_intr(struct ata_port *ap)
 {
        void __iomem *port = ap->ioaddr.cmd_addr;
        struct sil24_port_priv *pp = ap->private_data;
-       struct ata_eh_info *ehi = &ap->link.eh_info;
-       int freeze = 0;
+       struct ata_queued_cmd *qc = NULL;
+       struct ata_link *link;
+       struct ata_eh_info *ehi;
+       int abort = 0, freeze = 0;
        u32 irq_stat;
 
        /* on error, we need to clear IRQ explicitly */
@@ -818,10 +1017,17 @@ static void sil24_error_intr(struct ata_port *ap)
        writel(irq_stat, port + PORT_IRQ_STAT);
 
        /* first, analyze and record host port events */
+       link = &ap->link;
+       ehi = &link->eh_info;
        ata_ehi_clear_desc(ehi);
 
        ata_ehi_push_desc(ehi, "irq_stat 0x%08x", irq_stat);
 
+       if (irq_stat & PORT_IRQ_SDB_NOTIFY) {
+               ata_ehi_push_desc(ehi, "SDB notify");
+               sata_async_notification(ap);
+       }
+
        if (irq_stat & (PORT_IRQ_PHYRDY_CHG | PORT_IRQ_DEV_XCHG)) {
                ata_ehi_hotplugged(ehi);
                ata_ehi_push_desc(ehi, "%s",
@@ -841,8 +1047,44 @@ static void sil24_error_intr(struct ata_port *ap)
        if (irq_stat & PORT_IRQ_ERROR) {
                struct sil24_cerr_info *ci = NULL;
                unsigned int err_mask = 0, action = 0;
-               struct ata_queued_cmd *qc;
-               u32 cerr;
+               u32 context, cerr;
+               int pmp;
+
+               abort = 1;
+
+               /* DMA Context Switch Failure in Port Multiplier Mode
+                * errata.  If we have active commands to 3 or more
+                * devices, any error condition on active devices can
+                * corrupt DMA context switching.
+                */
+               if (ap->nr_active_links >= 3) {
+                       ehi->err_mask |= AC_ERR_OTHER;
+                       ehi->action |= ATA_EH_HARDRESET;
+                       ata_ehi_push_desc(ehi, "PMP DMA CS errata");
+                       pp->do_port_rst = 1;
+                       freeze = 1;
+               }
+
+               /* find out the offending link and qc */
+               if (ap->nr_pmp_links) {
+                       context = readl(port + PORT_CONTEXT);
+                       pmp = (context >> 5) & 0xf;
+
+                       if (pmp < ap->nr_pmp_links) {
+                               link = &ap->pmp_link[pmp];
+                               ehi = &link->eh_info;
+                               qc = ata_qc_from_tag(ap, link->active_tag);
+
+                               ata_ehi_clear_desc(ehi);
+                               ata_ehi_push_desc(ehi, "irq_stat 0x%08x",
+                                                 irq_stat);
+                       } else {
+                               err_mask |= AC_ERR_HSM;
+                               action |= ATA_EH_HARDRESET;
+                               freeze = 1;
+                       }
+               } else
+                       qc = ata_qc_from_tag(ap, link->active_tag);
 
                /* analyze CMD_ERR */
                cerr = readl(port + PORT_CMD_ERR);
@@ -852,16 +1094,18 @@ static void sil24_error_intr(struct ata_port *ap)
                if (ci && ci->desc) {
                        err_mask |= ci->err_mask;
                        action |= ci->action;
+                       if (action & ATA_EH_RESET_MASK)
+                               freeze = 1;
                        ata_ehi_push_desc(ehi, "%s", ci->desc);
                } else {
                        err_mask |= AC_ERR_OTHER;
                        action |= ATA_EH_SOFTRESET;
+                       freeze = 1;
                        ata_ehi_push_desc(ehi, "unknown command error %d",
                                          cerr);
                }
 
                /* record error info */
-               qc = ata_qc_from_tag(ap, ap->link.active_tag);
                if (qc) {
                        sil24_read_tf(ap, qc->tag, &pp->tf);
                        qc->err_mask |= err_mask;
@@ -869,13 +1113,21 @@ static void sil24_error_intr(struct ata_port *ap)
                        ehi->err_mask |= err_mask;
 
                ehi->action |= action;
+
+               /* if PMP, resume */
+               if (ap->nr_pmp_links)
+                       writel(PORT_CS_PMP_RESUME, port + PORT_CTRL_STAT);
        }
 
        /* freeze or abort */
        if (freeze)
                ata_port_freeze(ap);
-       else
-               ata_port_abort(ap);
+       else if (abort) {
+               if (qc)
+                       ata_link_abort(qc->dev->link);
+               else
+                       ata_port_abort(ap);
+       }
 }
 
 static void sil24_finish_qc(struct ata_queued_cmd *qc)
@@ -968,16 +1220,18 @@ static irqreturn_t sil24_interrupt(int irq, void *dev_instance)
 
 static void sil24_error_handler(struct ata_port *ap)
 {
-       struct ata_eh_context *ehc = &ap->link.eh_context;
+       struct sil24_port_priv *pp = ap->private_data;
 
-       if (sil24_init_port(ap)) {
+       if (sil24_init_port(ap))
                ata_eh_freeze_port(ap);
-               ehc->i.action |= ATA_EH_HARDRESET;
-       }
 
        /* perform recovery */
-       ata_do_eh(ap, ata_std_prereset, sil24_softreset, sil24_hardreset,
-                 ata_std_postreset);
+       sata_pmp_do_eh(ap, ata_std_prereset, sil24_softreset, sil24_hardreset,
+                      ata_std_postreset, sata_pmp_std_prereset,
+                      sil24_pmp_softreset, sil24_pmp_hardreset,
+                      sata_pmp_std_postreset);
+
+       pp->do_port_rst = 0;
 }
 
 static void sil24_post_internal_cmd(struct ata_queued_cmd *qc)
@@ -985,8 +1239,8 @@ static void sil24_post_internal_cmd(struct ata_queued_cmd *qc)
        struct ata_port *ap = qc->ap;
 
        /* make DMA engine forget about the failed command */
-       if (qc->flags & ATA_QCFLAG_FAILED)
-               sil24_init_port(ap);
+       if ((qc->flags & ATA_QCFLAG_FAILED) && sil24_init_port(ap))
+               ata_eh_freeze_port(ap);
 }
 
 static int sil24_port_start(struct ata_port *ap)
@@ -1024,7 +1278,6 @@ static int sil24_port_start(struct ata_port *ap)
 static void sil24_init_controller(struct ata_host *host)
 {
        void __iomem *host_base = host->iomap[SIL24_HOST_BAR];
-       void __iomem *port_base = host->iomap[SIL24_PORT_BAR];
        u32 tmp;
        int i;
 
@@ -1036,7 +1289,8 @@ static void sil24_init_controller(struct ata_host *host)
 
        /* init ports */
        for (i = 0; i < host->n_ports; i++) {
-               void __iomem *port = port_base + i * PORT_REGS_SIZE;
+               struct ata_port *ap = host->ports[i];
+               void __iomem *port = ap->ioaddr.cmd_addr;
 
                /* Initial PHY setting */
                writel(0x20c, port + PORT_PHY_CFG);
@@ -1050,29 +1304,11 @@ static void sil24_init_controller(struct ata_host *host)
                                                PORT_CS_PORT_RST, 10, 100);
                        if (tmp & PORT_CS_PORT_RST)
                                dev_printk(KERN_ERR, host->dev,
-                                          "failed to clear port RST\n");
+                                          "failed to clear port RST\n");
                }
 
-               /* Configure IRQ WoC */
-               if (host->ports[0]->flags & SIL24_FLAG_PCIX_IRQ_WOC)
-                       writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_STAT);
-               else
-                       writel(PORT_CS_IRQ_WOC, port + PORT_CTRL_CLR);
-
-               /* Zero error counters. */
-               writel(0x8000, port + PORT_DECODE_ERR_THRESH);
-               writel(0x8000, port + PORT_CRC_ERR_THRESH);
-               writel(0x8000, port + PORT_HSHK_ERR_THRESH);
-               writel(0x0000, port + PORT_DECODE_ERR_CNT);
-               writel(0x0000, port + PORT_CRC_ERR_CNT);
-               writel(0x0000, port + PORT_HSHK_ERR_CNT);
-
-               /* Always use 64bit activation */
-               writel(PORT_CS_32BIT_ACTV, port + PORT_CTRL_CLR);
-
-               /* Clear port multiplier enable and resume bits */
-               writel(PORT_CS_PMP_EN | PORT_CS_PMP_RESUME,
-                      port + PORT_CTRL_CLR);
+               /* configure port */
+               sil24_config_port(ap);
        }
 
        /* Turn on interrupts */
@@ -1081,7 +1317,8 @@ static void sil24_init_controller(struct ata_host *host)
 
 static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-       static int printed_version = 0;
+       extern int __MARKER__sil24_cmd_block_is_sized_wrongly;
+       static int printed_version;
        struct ata_port_info pi = sil24_port_info[ent->driver_data];
        const struct ata_port_info *ppi[] = { &pi, NULL };
        void __iomem * const *iomap;
@@ -1089,6 +1326,10 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        int i, rc;
        u32 tmp;
 
+       /* cause link error if sil24_cmd_block is sized wrongly */
+       if (sizeof(union sil24_cmd_block) != PAGE_SIZE)
+               __MARKER__sil24_cmd_block_is_sized_wrongly = 1;
+
        if (!printed_version++)
                dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
 
@@ -1123,12 +1364,15 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        host->iomap = iomap;
 
        for (i = 0; i < host->n_ports; i++) {
-               void __iomem *port = iomap[SIL24_PORT_BAR] + i * PORT_REGS_SIZE;
+               struct ata_port *ap = host->ports[i];
+               size_t offset = ap->port_no * PORT_REGS_SIZE;
+               void __iomem *port = iomap[SIL24_PORT_BAR] + offset;
 
                host->ports[i]->ioaddr.cmd_addr = port;
                host->ports[i]->ioaddr.scr_addr = port + PORT_SCONTROL;
 
-               ata_std_ports(&host->ports[i]->ioaddr);
+               ata_port_pbar_desc(ap, SIL24_HOST_BAR, -1, "host");
+               ata_port_pbar_desc(ap, SIL24_PORT_BAR, offset, "port");
        }
 
        /* configure and activate the device */
@@ -1184,6 +1428,12 @@ static int sil24_pci_device_resume(struct pci_dev *pdev)
 
        return 0;
 }
+
+static int sil24_port_resume(struct ata_port *ap)
+{
+       sil24_config_pmp(ap, ap->nr_pmp_links);
+       return 0;
+}
 #endif
 
 static int __init sil24_init(void)