libata-sff: clean up inheritance in several drivers
[safe/jmp/linux-2.6] / drivers / ata / sata_mv.c
index fffba9b..a033710 100644 (file)
 #include <linux/dmapool.h>
 #include <linux/dma-mapping.h>
 #include <linux/device.h>
+#include <linux/clk.h>
 #include <linux/platform_device.h>
 #include <linux/ata_platform.h>
 #include <linux/mbus.h>
 #include <linux/bitops.h>
+#include <linux/gfp.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_device.h>
@@ -293,6 +295,10 @@ enum {
        FISCFG_WAIT_DEV_ERR     = (1 << 8),     /* wait for host on DevErr */
        FISCFG_SINGLE_SYNC      = (1 << 16),    /* SYNC on DMA activation */
 
+       PHY_MODE9_GEN2          = 0x398,
+       PHY_MODE9_GEN1          = 0x39c,
+       PHYCFG_OFS              = 0x3a0,        /* only in 65n devices */
+
        MV5_PHY_MODE            = 0x74,
        MV5_LTMODE              = 0x30,
        MV5_PHY_CTL             = 0x0C,
@@ -534,6 +540,7 @@ struct mv_port_signal {
 
 struct mv_host_priv {
        u32                     hp_flags;
+       unsigned int            board_idx;
        u32                     main_irq_mask;
        struct mv_port_signal   signal[8];
        const struct mv_hw_ops  *ops;
@@ -544,6 +551,10 @@ struct mv_host_priv {
        u32                     irq_cause_offset;
        u32                     irq_mask_offset;
        u32                     unmask_all_irqs;
+
+#if defined(CONFIG_HAVE_CLK)
+       struct clk              *clk;
+#endif
        /*
         * These consistent DMA memory pools give us guaranteed
         * alignment for hardware-accessed data structures,
@@ -609,6 +620,8 @@ static int mv_soc_reset_hc(struct mv_host_priv *hpriv,
 static void mv_soc_reset_flash(struct mv_host_priv *hpriv,
                                      void __iomem *mmio);
 static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio);
+static void mv_soc_65n_phy_errata(struct mv_host_priv *hpriv,
+                                 void __iomem *mmio, unsigned int port);
 static void mv_reset_pci_bus(struct ata_host *host, void __iomem *mmio);
 static void mv_reset_channel(struct mv_host_priv *hpriv, void __iomem *mmio,
                             unsigned int port_no);
@@ -673,16 +686,27 @@ static struct ata_port_operations mv5_ops = {
 };
 
 static struct ata_port_operations mv6_ops = {
-       .inherits               = &mv5_ops,
+       .inherits               = &ata_bmdma_port_ops,
+
+       .lost_interrupt         = ATA_OP_NULL,
+
+       .qc_defer               = mv_qc_defer,
+       .qc_prep                = mv_qc_prep,
+       .qc_issue               = mv_qc_issue,
+
        .dev_config             = mv6_dev_config,
-       .scr_read               = mv_scr_read,
-       .scr_write              = mv_scr_write,
 
+       .freeze                 = mv_eh_freeze,
+       .thaw                   = mv_eh_thaw,
+       .hardreset              = mv_hardreset,
+       .softreset              = mv_softreset,
        .pmp_hardreset          = mv_pmp_hardreset,
        .pmp_softreset          = mv_softreset,
-       .softreset              = mv_softreset,
        .error_handler          = mv_pmp_error_handler,
 
+       .scr_read               = mv_scr_read,
+       .scr_write              = mv_scr_write,
+
        .sff_check_status       = mv_sff_check_status,
        .sff_irq_clear          = mv_sff_irq_clear,
        .check_atapi_dma        = mv_check_atapi_dma,
@@ -690,6 +714,11 @@ static struct ata_port_operations mv6_ops = {
        .bmdma_start            = mv_bmdma_start,
        .bmdma_stop             = mv_bmdma_stop,
        .bmdma_status           = mv_bmdma_status,
+
+       .port_start             = mv_port_start,
+       .port_stop              = mv_port_stop,
+
+       .mode_filter            = ATA_OP_NULL,  /* will be removed soon */
 };
 
 static struct ata_port_operations mv_iie_ops = {
@@ -807,6 +836,14 @@ static const struct mv_hw_ops mv_soc_ops = {
        .reset_bus              = mv_soc_reset_bus,
 };
 
+static const struct mv_hw_ops mv_soc_65n_ops = {
+       .phy_errata             = mv_soc_65n_phy_errata,
+       .enable_leds            = mv_soc_enable_leds,
+       .reset_hc               = mv_soc_reset_hc,
+       .reset_flash            = mv_soc_reset_flash,
+       .reset_bus              = mv_soc_reset_bus,
+};
+
 /*
  * Functions
  */
@@ -1368,6 +1405,25 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
         */
        if (pp->pp_flags & MV_PP_FLAG_DELAYED_EH)
                return ATA_DEFER_PORT;
+
+       /* PIO commands need exclusive link: no other commands [DMA or PIO]
+        * can run concurrently.
+        * set excl_link when we want to send a PIO command in DMA mode
+        * or a non-NCQ command in NCQ mode.
+        * When we receive a command from that link, and there are no
+        * outstanding commands, mark a flag to clear excl_link and let
+        * the command go through.
+        */
+       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;
+                       return 0;
+               } else
+                       return ATA_DEFER_PORT;
+       }
+
        /*
         * If the port is completely idle, then allow the new qc.
         */
@@ -1381,8 +1437,14 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
         * doesn't allow it.
         */
        if ((pp->pp_flags & MV_PP_FLAG_EDMA_EN) &&
-           (pp->pp_flags & MV_PP_FLAG_NCQ_EN) && ata_is_ncq(qc->tf.protocol))
-               return 0;
+           (pp->pp_flags & MV_PP_FLAG_NCQ_EN)) {
+               if (ata_is_ncq(qc->tf.protocol))
+                       return 0;
+               else {
+                       ap->excl_link = link;
+                       return ATA_DEFER_PORT;
+               }
+       }
 
        return ATA_DEFER_PORT;
 }
@@ -1881,6 +1943,39 @@ static u8 mv_bmdma_status(struct ata_port *ap)
        return status;
 }
 
+static void mv_rw_multi_errata_sata24(struct ata_queued_cmd *qc)
+{
+       struct ata_taskfile *tf = &qc->tf;
+       /*
+        * Workaround for 88SX60x1 FEr SATA#24.
+        *
+        * Chip may corrupt WRITEs if multi_count >= 4kB.
+        * Note that READs are unaffected.
+        *
+        * It's not clear if this errata really means "4K bytes",
+        * or if it always happens for multi_count > 7
+        * regardless of device sector_size.
+        *
+        * So, for safety, any write with multi_count > 7
+        * gets converted here into a regular PIO write instead:
+        */
+       if ((tf->flags & ATA_TFLAG_WRITE) && is_multi_taskfile(tf)) {
+               if (qc->dev->multi_count > 7) {
+                       switch (tf->command) {
+                       case ATA_CMD_WRITE_MULTI:
+                               tf->command = ATA_CMD_PIO_WRITE;
+                               break;
+                       case ATA_CMD_WRITE_MULTI_FUA_EXT:
+                               tf->flags &= ~ATA_TFLAG_FUA; /* ugh */
+                               /* fall through */
+                       case ATA_CMD_WRITE_MULTI_EXT:
+                               tf->command = ATA_CMD_PIO_WRITE_EXT;
+                               break;
+                       }
+               }
+       }
+}
+
 /**
  *      mv_qc_prep - Host specific command preparation.
  *      @qc: queued command to prepare
@@ -1898,17 +1993,24 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
        struct ata_port *ap = qc->ap;
        struct mv_port_priv *pp = ap->private_data;
        __le16 *cw;
-       struct ata_taskfile *tf;
+       struct ata_taskfile *tf = &qc->tf;
        u16 flags = 0;
        unsigned in_index;
 
-       if ((qc->tf.protocol != ATA_PROT_DMA) &&
-           (qc->tf.protocol != ATA_PROT_NCQ))
+       switch (tf->protocol) {
+       case ATA_PROT_DMA:
+       case ATA_PROT_NCQ:
+               break;  /* continue below */
+       case ATA_PROT_PIO:
+               mv_rw_multi_errata_sata24(qc);
+               return;
+       default:
                return;
+       }
 
        /* Fill in command request block
         */
-       if (!(qc->tf.flags & ATA_TFLAG_WRITE))
+       if (!(tf->flags & ATA_TFLAG_WRITE))
                flags |= CRQB_FLAG_READ;
        WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
        flags |= qc->tag << CRQB_TAG_SHIFT;
@@ -1924,7 +2026,6 @@ static void mv_qc_prep(struct ata_queued_cmd *qc)
        pp->crqb[in_index].ctrl_flags = cpu_to_le16(flags);
 
        cw = &pp->crqb[in_index].ata_cmd[0];
-       tf = &qc->tf;
 
        /* Sadly, the CRQB cannot accomodate all registers--there are
         * only 11 bytes...so we must pick and choose required
@@ -1990,16 +2091,16 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
        struct ata_port *ap = qc->ap;
        struct mv_port_priv *pp = ap->private_data;
        struct mv_crqb_iie *crqb;
-       struct ata_taskfile *tf;
+       struct ata_taskfile *tf = &qc->tf;
        unsigned in_index;
        u32 flags = 0;
 
-       if ((qc->tf.protocol != ATA_PROT_DMA) &&
-           (qc->tf.protocol != ATA_PROT_NCQ))
+       if ((tf->protocol != ATA_PROT_DMA) &&
+           (tf->protocol != ATA_PROT_NCQ))
                return;
 
        /* Fill in Gen IIE command request block */
-       if (!(qc->tf.flags & ATA_TFLAG_WRITE))
+       if (!(tf->flags & ATA_TFLAG_WRITE))
                flags |= CRQB_FLAG_READ;
 
        WARN_ON(MV_MAX_Q_DEPTH <= qc->tag);
@@ -2015,7 +2116,6 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
        crqb->addr_hi = cpu_to_le32((pp->sg_tbl_dma[qc->tag] >> 16) >> 16);
        crqb->flags = cpu_to_le32(flags);
 
-       tf = &qc->tf;
        crqb->ata_cmd[0] = cpu_to_le32(
                        (tf->command << 16) |
                        (tf->feature << 24)
@@ -2140,7 +2240,7 @@ static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
        int err = 0;
 
        ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
-       err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
+       err = mv_send_fis(ap, fis, ARRAY_SIZE(fis));
        if (err)
                return err;
 
@@ -2271,13 +2371,9 @@ static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
        if (pp->pp_flags & MV_PP_FLAG_NCQ_EN)
                return NULL;
        qc = ata_qc_from_tag(ap, ap->link.active_tag);
-       if (qc) {
-               if (qc->tf.flags & ATA_TFLAG_POLLING)
-                       qc = NULL;
-               else if (!(qc->flags & ATA_QCFLAG_ACTIVE))
-                       qc = NULL;
-       }
-       return qc;
+       if (qc && !(qc->tf.flags & ATA_TFLAG_POLLING))
+               return qc;
+       return NULL;
 }
 
 static void mv_pmp_error_handler(struct ata_port *ap)
@@ -2462,9 +2558,7 @@ static void mv_unexpected_intr(struct ata_port *ap, int edma_was_enabled)
        char *when = "idle";
 
        ata_ehi_clear_desc(ehi);
-       if (!ap || (ap->flags & ATA_FLAG_DISABLED)) {
-               when = "disabled";
-       } else if (edma_was_enabled) {
+       if (edma_was_enabled) {
                when = "EDMA enabled";
        } else {
                struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->link.active_tag);
@@ -2698,10 +2792,6 @@ static void mv_port_intr(struct ata_port *ap, u32 port_cause)
        struct mv_port_priv *pp;
        int edma_was_enabled;
 
-       if (!ap || (ap->flags & ATA_FLAG_DISABLED)) {
-               mv_unexpected_intr(ap, 0);
-               return;
-       }
        /*
         * Grab a snapshot of the EDMA_EN flag setting,
         * so that we have a consistent view for this port,
@@ -3316,7 +3406,7 @@ static void mv_soc_reset_hc_port(struct mv_host_priv *hpriv,
        ZERO(0x024);            /* respq outp */
        ZERO(0x020);            /* respq inp */
        ZERO(0x02c);            /* test control */
-       writel(0xbc, port_mmio + EDMA_IORDY_TMOUT);
+       writel(0x800, port_mmio + EDMA_IORDY_TMOUT);
 }
 
 #undef ZERO
@@ -3359,6 +3449,53 @@ static void mv_soc_reset_bus(struct ata_host *host, void __iomem *mmio)
        return;
 }
 
+static void mv_soc_65n_phy_errata(struct mv_host_priv *hpriv,
+                                 void __iomem *mmio, unsigned int port)
+{
+       void __iomem *port_mmio = mv_port_base(mmio, port);
+       u32     reg;
+
+       reg = readl(port_mmio + PHY_MODE3);
+       reg &= ~(0x3 << 27);    /* SELMUPF (bits 28:27) to 1 */
+       reg |= (0x1 << 27);
+       reg &= ~(0x3 << 29);    /* SELMUPI (bits 30:29) to 1 */
+       reg |= (0x1 << 29);
+       writel(reg, port_mmio + PHY_MODE3);
+
+       reg = readl(port_mmio + PHY_MODE4);
+       reg &= ~0x1;    /* SATU_OD8 (bit 0) to 0, reserved bit 16 must be set */
+       reg |= (0x1 << 16);
+       writel(reg, port_mmio + PHY_MODE4);
+
+       reg = readl(port_mmio + PHY_MODE9_GEN2);
+       reg &= ~0xf;    /* TXAMP[3:0] (bits 3:0) to 8 */
+       reg |= 0x8;
+       reg &= ~(0x1 << 14);    /* TXAMP[4] (bit 14) to 0 */
+       writel(reg, port_mmio + PHY_MODE9_GEN2);
+
+       reg = readl(port_mmio + PHY_MODE9_GEN1);
+       reg &= ~0xf;    /* TXAMP[3:0] (bits 3:0) to 8 */
+       reg |= 0x8;
+       reg &= ~(0x1 << 14);    /* TXAMP[4] (bit 14) to 0 */
+       writel(reg, port_mmio + PHY_MODE9_GEN1);
+}
+
+/**
+ *     soc_is_65 - check if the soc is 65 nano device
+ *
+ *     Detect the type of the SoC, this is done by reading the PHYCFG_OFS
+ *     register, this register should contain non-zero value and it exists only
+ *     in the 65 nano devices, when reading it from older devices we get 0.
+ */
+static bool soc_is_65n(struct mv_host_priv *hpriv)
+{
+       void __iomem *port0_mmio = mv_port_base(hpriv->base, 0);
+
+       if (readl(port0_mmio + PHYCFG_OFS))
+               return true;
+       return false;
+}
+
 static void mv_setup_ifcfg(void __iomem *port_mmio, int want_gen2i)
 {
        u32 ifcfg = readl(port_mmio + SATA_IFCFG);
@@ -3525,9 +3662,6 @@ static void mv_port_init(struct ata_ioports *port,  void __iomem *port_mmio)
        /* special case: control/altstatus doesn't have ATA_REG_ address */
        port->altstatus_addr = port->ctl_addr = shd_base + SHD_CTL_AST;
 
-       /* unused: */
-       port->cmd_addr = port->bmdma_addr = port->scr_addr = NULL;
-
        /* Clear any currently outstanding port interrupt conditions */
        serr = port_mmio + mv_scr_offset(SCR_ERROR);
        writelfl(readl(serr), serr);
@@ -3699,7 +3833,10 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
                }
                break;
        case chip_soc:
-               hpriv->ops = &mv_soc_ops;
+               if (soc_is_65n(hpriv))
+                       hpriv->ops = &mv_soc_65n_ops;
+               else
+                       hpriv->ops = &mv_soc_ops;
                hp_flags |= MV_HP_FLAG_SOC | MV_HP_GEN_IIE |
                        MV_HP_ERRATA_60X1C0;
                break;
@@ -3727,7 +3864,6 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
 /**
  *      mv_init_host - Perform some early initialization of the host.
  *     @host: ATA host to initialize
- *      @board_idx: controller index
  *
  *      If possible, do an early global reset of the host.  Then do
  *      our port init and clear/unmask all/relevant host interrupts.
@@ -3735,13 +3871,13 @@ static int mv_chip_id(struct ata_host *host, unsigned int board_idx)
  *      LOCKING:
  *      Inherited from caller.
  */
-static int mv_init_host(struct ata_host *host, unsigned int board_idx)
+static int mv_init_host(struct ata_host *host)
 {
        int rc = 0, n_hc, port, hc;
        struct mv_host_priv *hpriv = host->private_data;
        void __iomem *mmio = hpriv->base;
 
-       rc = mv_chip_id(host, board_idx);
+       rc = mv_chip_id(host, hpriv->board_idx);
        if (rc)
                goto done;
 
@@ -3762,7 +3898,8 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
        n_hc = mv_get_hc_count(host->ports[0]->flags);
 
        for (port = 0; port < host->n_ports; port++)
-               hpriv->ops->read_preamp(hpriv, port, mmio);
+               if (hpriv->ops->read_preamp)
+                       hpriv->ops->read_preamp(hpriv, port, mmio);
 
        rc = hpriv->ops->reset_hc(hpriv, mmio, n_hc);
        if (rc)
@@ -3777,14 +3914,6 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
                void __iomem *port_mmio = mv_port_base(mmio, port);
 
                mv_port_init(&ap->ioaddr, port_mmio);
-
-#ifdef CONFIG_PCI
-               if (!IS_SOC(hpriv)) {
-                       unsigned int offset = port_mmio - mmio;
-                       ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio");
-                       ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port");
-               }
-#endif
        }
 
        for (hc = 0; hc < n_hc; hc++) {
@@ -3907,12 +4036,21 @@ static int mv_platform_probe(struct platform_device *pdev)
                return -ENOMEM;
        host->private_data = hpriv;
        hpriv->n_ports = n_ports;
+       hpriv->board_idx = chip_soc;
 
        host->iomap = NULL;
        hpriv->base = devm_ioremap(&pdev->dev, res->start,
-                                  res->end - res->start + 1);
+                                  resource_size(res));
        hpriv->base -= SATAHC0_REG_BASE;
 
+#if defined(CONFIG_HAVE_CLK)
+       hpriv->clk = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(hpriv->clk))
+               dev_notice(&pdev->dev, "cannot get clkdev\n");
+       else
+               clk_enable(hpriv->clk);
+#endif
+
        /*
         * (Re-)program MBUS remapping windows if we are asked to.
         */
@@ -3921,12 +4059,12 @@ static int mv_platform_probe(struct platform_device *pdev)
 
        rc = mv_create_dma_pools(hpriv, &pdev->dev);
        if (rc)
-               return rc;
+               goto err;
 
        /* initialize adapter */
-       rc = mv_init_host(host, chip_soc);
+       rc = mv_init_host(host);
        if (rc)
-               return rc;
+               goto err;
 
        dev_printk(KERN_INFO, &pdev->dev,
                   "slots %u ports %d\n", (unsigned)MV_MAX_Q_DEPTH,
@@ -3934,6 +4072,15 @@ static int mv_platform_probe(struct platform_device *pdev)
 
        return ata_host_activate(host, platform_get_irq(pdev, 0), mv_interrupt,
                                 IRQF_SHARED, &mv6_sht);
+err:
+#if defined(CONFIG_HAVE_CLK)
+       if (!IS_ERR(hpriv->clk)) {
+               clk_disable(hpriv->clk);
+               clk_put(hpriv->clk);
+       }
+#endif
+
+       return rc;
 }
 
 /*
@@ -3948,14 +4095,66 @@ static int __devexit mv_platform_remove(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct ata_host *host = dev_get_drvdata(dev);
-
+#if defined(CONFIG_HAVE_CLK)
+       struct mv_host_priv *hpriv = host->private_data;
+#endif
        ata_host_detach(host);
+
+#if defined(CONFIG_HAVE_CLK)
+       if (!IS_ERR(hpriv->clk)) {
+               clk_disable(hpriv->clk);
+               clk_put(hpriv->clk);
+       }
+#endif
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int mv_platform_suspend(struct platform_device *pdev, pm_message_t state)
+{
+       struct ata_host *host = dev_get_drvdata(&pdev->dev);
+       if (host)
+               return ata_host_suspend(host, state);
+       else
+               return 0;
+}
+
+static int mv_platform_resume(struct platform_device *pdev)
+{
+       struct ata_host *host = dev_get_drvdata(&pdev->dev);
+       int ret;
+
+       if (host) {
+               struct mv_host_priv *hpriv = host->private_data;
+               const struct mv_sata_platform_data *mv_platform_data = \
+                       pdev->dev.platform_data;
+               /*
+                * (Re-)program MBUS remapping windows if we are asked to.
+                */
+               if (mv_platform_data->dram != NULL)
+                       mv_conf_mbus_windows(hpriv, mv_platform_data->dram);
+
+               /* initialize adapter */
+               ret = mv_init_host(host);
+               if (ret) {
+                       printk(KERN_ERR DRV_NAME ": Error during HW init\n");
+                       return ret;
+               }
+               ata_host_resume(host);
+       }
+
        return 0;
 }
+#else
+#define mv_platform_suspend NULL
+#define mv_platform_resume NULL
+#endif
 
 static struct platform_driver mv_platform_driver = {
        .probe                  = mv_platform_probe,
        .remove                 = __devexit_p(mv_platform_remove),
+       .suspend                = mv_platform_suspend,
+       .resume                 = mv_platform_resume,
        .driver                 = {
                                   .name = DRV_NAME,
                                   .owner = THIS_MODULE,
@@ -3966,6 +4165,9 @@ static struct platform_driver mv_platform_driver = {
 #ifdef CONFIG_PCI
 static int mv_pci_init_one(struct pci_dev *pdev,
                           const struct pci_device_id *ent);
+#ifdef CONFIG_PM
+static int mv_pci_device_resume(struct pci_dev *pdev);
+#endif
 
 
 static struct pci_driver mv_pci_driver = {
@@ -3973,6 +4175,11 @@ static struct pci_driver mv_pci_driver = {
        .id_table               = mv_pci_tbl,
        .probe                  = mv_pci_init_one,
        .remove                 = ata_pci_remove_one,
+#ifdef CONFIG_PM
+       .suspend                = ata_pci_device_suspend,
+       .resume                 = mv_pci_device_resume,
+#endif
+
 };
 
 /* move to PCI layer or libata core? */
@@ -3980,10 +4187,10 @@ static int pci_go_64(struct pci_dev *pdev)
 {
        int rc;
 
-       if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
-               rc = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
+       if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
+               rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
                if (rc) {
-                       rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+                       rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
                        if (rc) {
                                dev_printk(KERN_ERR, &pdev->dev,
                                           "64-bit DMA enable failed\n");
@@ -3991,13 +4198,13 @@ static int pci_go_64(struct pci_dev *pdev)
                        }
                }
        } else {
-               rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+               rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
                if (rc) {
                        dev_printk(KERN_ERR, &pdev->dev,
                                   "32-bit DMA enable failed\n");
                        return rc;
                }
-               rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+               rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
                if (rc) {
                        dev_printk(KERN_ERR, &pdev->dev,
                                   "32-bit consistent DMA enable failed\n");
@@ -4066,7 +4273,7 @@ static int mv_pci_init_one(struct pci_dev *pdev,
        const struct ata_port_info *ppi[] = { &mv_port_info[board_idx], NULL };
        struct ata_host *host;
        struct mv_host_priv *hpriv;
-       int n_ports, rc;
+       int n_ports, port, rc;
 
        if (!printed_version++)
                dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
@@ -4080,6 +4287,7 @@ static int mv_pci_init_one(struct pci_dev *pdev,
                return -ENOMEM;
        host->private_data = hpriv;
        hpriv->n_ports = n_ports;
+       hpriv->board_idx = board_idx;
 
        /* acquire resources */
        rc = pcim_enable_device(pdev);
@@ -4102,8 +4310,17 @@ static int mv_pci_init_one(struct pci_dev *pdev,
        if (rc)
                return rc;
 
+       for (port = 0; port < host->n_ports; port++) {
+               struct ata_port *ap = host->ports[port];
+               void __iomem *port_mmio = mv_port_base(hpriv->base, port);
+               unsigned int offset = port_mmio - hpriv->base;
+
+               ata_port_pbar_desc(ap, MV_PRIMARY_BAR, -1, "mmio");
+               ata_port_pbar_desc(ap, MV_PRIMARY_BAR, offset, "port");
+       }
+
        /* initialize adapter */
-       rc = mv_init_host(host, board_idx);
+       rc = mv_init_host(host);
        if (rc)
                return rc;
 
@@ -4119,6 +4336,27 @@ static int mv_pci_init_one(struct pci_dev *pdev,
        return ata_host_activate(host, pdev->irq, mv_interrupt, IRQF_SHARED,
                                 IS_GEN_I(hpriv) ? &mv5_sht : &mv6_sht);
 }
+
+#ifdef CONFIG_PM
+static int mv_pci_device_resume(struct pci_dev *pdev)
+{
+       struct ata_host *host = dev_get_drvdata(&pdev->dev);
+       int rc;
+
+       rc = ata_pci_device_do_resume(pdev);
+       if (rc)
+               return rc;
+
+       /* initialize adapter */
+       rc = mv_init_host(host);
+       if (rc)
+               return rc;
+
+       ata_host_resume(host);
+
+       return 0;
+}
+#endif
 #endif
 
 static int mv_platform_probe(struct platform_device *pdev);