]> err.no Git - linux-2.6/blobdiff - drivers/scsi/ahci.c
Merge branch 'upstream-fixes' into upstream
[linux-2.6] / drivers / scsi / ahci.c
index 82ecdef0c48b1873ed82677ec565c221fa874445..f1516ca2c52a69c6f4222a48191d512eb9b27fc1 100644 (file)
@@ -48,7 +48,7 @@
 #include <asm/io.h>
 
 #define DRV_NAME       "ahci"
-#define DRV_VERSION    "1.3"
+#define DRV_VERSION    "2.0"
 
 
 enum {
@@ -164,6 +164,7 @@ enum {
 
        /* ap->flags bits */
        AHCI_FLAG_RESET_NEEDS_CLO       = (1 << 24),
+       AHCI_FLAG_NO_NCQ                = (1 << 25),
 };
 
 struct ahci_cmd_hdr {
@@ -204,6 +205,8 @@ static irqreturn_t ahci_interrupt (int irq, void *dev_instance, struct pt_regs *
 static void ahci_irq_clear(struct ata_port *ap);
 static int ahci_port_start(struct ata_port *ap);
 static void ahci_port_stop(struct ata_port *ap);
+static int ahci_start_engine(void __iomem *port_mmio);
+static int ahci_stop_engine(void __iomem *port_mmio);
 static void ahci_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
 static void ahci_qc_prep(struct ata_queued_cmd *qc);
 static u8 ahci_check_status(struct ata_port *ap);
@@ -277,7 +280,7 @@ static const struct ata_port_info ahci_port_info[] = {
                .host_flags     = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
                                  ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
                                  ATA_FLAG_SKIP_D2H_BSY |
-                                 AHCI_FLAG_RESET_NEEDS_CLO,
+                                 AHCI_FLAG_RESET_NEEDS_CLO | AHCI_FLAG_NO_NCQ,
                .pio_mask       = 0x1f, /* pio0-4 */
                .udma_mask      = 0x7f, /* udma0-6 ; FIXME */
                .port_ops       = &ahci_ops,
@@ -320,8 +323,14 @@ static const struct pci_device_id ahci_pci_tbl[] = {
        /* JMicron */
        { 0x197b, 0x2360, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
          board_ahci }, /* JMicron JMB360 */
+       { 0x197b, 0x2361, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
+         board_ahci }, /* JMicron JMB361 */
        { 0x197b, 0x2363, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
          board_ahci }, /* JMicron JMB363 */
+       { 0x197b, 0x2365, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
+         board_ahci }, /* JMicron JMB365 */
+       { 0x197b, 0x2366, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
+         board_ahci }, /* JMicron JMB366 */
 
        /* ATI */
        { PCI_VENDOR_ID_ATI, 0x4380, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
@@ -501,41 +510,64 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
        writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4));
 }
 
-static int ahci_stop_engine(struct ata_port *ap)
+static int ahci_stop_engine(void __iomem *port_mmio)
 {
-       void __iomem *mmio = ap->host_set->mmio_base;
-       void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
-       int work;
        u32 tmp;
 
        tmp = readl(port_mmio + PORT_CMD);
+
+       /* Check if the HBA is idle */
+       if ((tmp & (PORT_CMD_START | PORT_CMD_LIST_ON)) == 0)
+               return 0;
+
+       /* Setting HBA to idle */
        tmp &= ~PORT_CMD_START;
        writel(tmp, port_mmio + PORT_CMD);
 
-       /* wait for engine to stop.  TODO: this could be
+       /* wait for engine to stop. This could be
         * as long as 500 msec
         */
-       work = 1000;
-       while (work-- > 0) {
-               tmp = readl(port_mmio + PORT_CMD);
-               if ((tmp & PORT_CMD_LIST_ON) == 0)
-                       return 0;
-               udelay(10);
-       }
+       tmp = ata_wait_register(port_mmio + PORT_CMD,
+                               PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1, 500);
+       if(tmp & PORT_CMD_LIST_ON)
+               return -EIO;
 
-       return -EIO;
+       return 0;
 }
 
-static void ahci_start_engine(struct ata_port *ap)
+static int ahci_start_engine(void __iomem *port_mmio)
 {
-       void __iomem *mmio = ap->host_set->mmio_base;
-       void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
        u32 tmp;
 
+       /*
+        * Get current status
+        */
        tmp = readl(port_mmio + PORT_CMD);
+
+       /*
+        * AHCI rev 1.1 section 10.3.1:
+        * Software shall not set PxCMD.ST to '1' until it verifies
+        * that PxCMD.CR is '0' and has set PxCMD.FRE to '1'
+        */
+       if ((tmp & PORT_CMD_FIS_RX) == 0)
+               return -EPERM;
+
+       /*
+        * wait for engine to become idle.
+        */
+       tmp = ata_wait_register(port_mmio + PORT_CMD,
+                               PORT_CMD_LIST_ON, PORT_CMD_LIST_ON, 1,500);
+       if(tmp & PORT_CMD_LIST_ON)
+               return -EBUSY;
+
+       /*
+        * Start DMA
+        */
        tmp |= PORT_CMD_START;
        writel(tmp, port_mmio + PORT_CMD);
        readl(port_mmio + PORT_CMD); /* flush */
+
+       return 0;
 }
 
 static unsigned int ahci_dev_classify(struct ata_port *ap)
@@ -619,7 +651,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
        }
 
        /* prepare for SRST (AHCI-1.1 10.4.1) */
-       rc = ahci_stop_engine(ap);
+       rc = ahci_stop_engine(port_mmio);
        if (rc) {
                reason = "failed to stop engine";
                goto fail_restart;
@@ -640,7 +672,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
        }
 
        /* restart engine */
-       ahci_start_engine(ap);
+       ahci_start_engine(port_mmio);
 
        ata_tf_init(ap->device, &tf);
        fis = pp->cmd_tbl;
@@ -699,7 +731,7 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
        return 0;
 
  fail_restart:
-       ahci_start_engine(ap);
+       ahci_start_engine(port_mmio);
  fail:
        ata_port_printk(ap, KERN_ERR, "softreset failed (%s)\n", reason);
        return rc;
@@ -710,11 +742,13 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
        struct ahci_port_priv *pp = ap->private_data;
        u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
        struct ata_taskfile tf;
+       void __iomem *mmio = ap->host_set->mmio_base;
+       void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
        int rc;
 
        DPRINTK("ENTER\n");
 
-       ahci_stop_engine(ap);
+       ahci_stop_engine(port_mmio);
 
        /* clear D2H reception area to properly wait for D2H FIS */
        ata_tf_init(ap->device, &tf);
@@ -723,7 +757,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
 
        rc = sata_std_hardreset(ap, class);
 
-       ahci_start_engine(ap);
+       ahci_start_engine(port_mmio);
 
        if (rc == 0 && ata_port_online(ap))
                *class = ahci_dev_classify(ap);
@@ -1045,10 +1079,13 @@ static void ahci_thaw(struct ata_port *ap)
 
 static void ahci_error_handler(struct ata_port *ap)
 {
-       if (!(ap->flags & ATA_FLAG_FROZEN)) {
+       void __iomem *mmio = ap->host_set->mmio_base;
+       void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
+
+       if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
                /* restart engine */
-               ahci_stop_engine(ap);
-               ahci_start_engine(ap);
+               ahci_stop_engine(port_mmio);
+               ahci_start_engine(port_mmio);
        }
 
        /* perform recovery */
@@ -1059,14 +1096,16 @@ static void ahci_error_handler(struct ata_port *ap)
 static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
+       void __iomem *mmio = ap->host_set->mmio_base;
+       void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
 
        if (qc->flags & ATA_QCFLAG_FAILED)
                qc->err_mask |= AC_ERR_OTHER;
 
        if (qc->err_mask) {
                /* make DMA engine forget about the failed command */
-               ahci_stop_engine(ap);
-               ahci_start_engine(ap);
+               ahci_stop_engine(port_mmio);
+               ahci_start_engine(port_mmio);
        }
 }
 
@@ -1316,6 +1355,17 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
        if (!printed_version++)
                dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
 
+       /* JMicron-specific fixup: make sure we're in AHCI mode */
+       /* This is protected from races with ata_jmicron by the pci probe
+          locking */
+       if (pdev->vendor == PCI_VENDOR_ID_JMICRON) {
+               /* AHCI enable, AHCI on function 0 */
+               pci_write_config_byte(pdev, 0x41, 0xa1);
+               /* Function 1 is the PATA controller */
+               if (PCI_FUNC(pdev->devfn))
+                       return -ENODEV;
+       }
+
        rc = pci_enable_device(pdev);
        if (rc)
                return rc;
@@ -1364,23 +1414,20 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
        probe_ent->port_ops     = ahci_port_info[board_idx].port_ops;
 
                probe_ent->irq = pdev->irq;
-               probe_ent->irq_flags = SA_SHIRQ;
+               probe_ent->irq_flags = IRQF_SHARED;
        probe_ent->mmio_base = mmio_base;
        probe_ent->private_data = hpriv;
 
        if (have_msi)
                hpriv->flags |= AHCI_FLAG_MSI;
 
-       /* JMicron-specific fixup: make sure we're in AHCI mode */
-       if (pdev->vendor == 0x197b)
-               pci_write_config_byte(pdev, 0x41, 0xa1);
-
        /* initialize adapter */
        rc = ahci_host_init(probe_ent);
        if (rc)
                goto err_out_hpriv;
 
-       if (hpriv->cap & HOST_CAP_NCQ)
+       if (!(probe_ent->host_flags & AHCI_FLAG_NO_NCQ) &&
+           (hpriv->cap & HOST_CAP_NCQ))
                probe_ent->host_flags |= ATA_FLAG_NCQ;
 
        ahci_print_info(probe_ent);