Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[pandora-kernel.git] / drivers / ata / libata-sff.c
index 7605028..10ee22a 100644 (file)
 
 #include "libata.h"
 
+/**
+ *     ata_irq_on - Enable interrupts on a port.
+ *     @ap: Port on which interrupts are enabled.
+ *
+ *     Enable interrupts on a legacy IDE device using MMIO or PIO,
+ *     wait for idle, clear any pending interrupts.
+ *
+ *     LOCKING:
+ *     Inherited from caller.
+ */
+u8 ata_irq_on(struct ata_port *ap)
+{
+       struct ata_ioports *ioaddr = &ap->ioaddr;
+       u8 tmp;
+
+       ap->ctl &= ~ATA_NIEN;
+       ap->last_ctl = ap->ctl;
+
+       if (ap->flags & ATA_FLAG_MMIO)
+               writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
+       else
+               outb(ap->ctl, ioaddr->ctl_addr);
+       tmp = ata_wait_idle(ap);
+
+       ap->ops->irq_clear(ap);
+
+       return tmp;
+}
+
 /**
  *     ata_tf_load_pio - send taskfile registers to host controller
  *     @ap: Port to which output is sent
@@ -671,6 +700,14 @@ void ata_bmdma_freeze(struct ata_port *ap)
                writeb(ap->ctl, (void __iomem *)ioaddr->ctl_addr);
        else
                outb(ap->ctl, ioaddr->ctl_addr);
+
+       /* Under certain circumstances, some controllers raise IRQ on
+        * ATA_NIEN manipulation.  Also, many controllers fail to mask
+        * previously pending IRQ on ATA_NIEN assertion.  Clear it.
+        */
+       ata_chk_status(ap);
+
+       ap->ops->irq_clear(ap);
 }
 
 /**
@@ -714,7 +751,6 @@ void ata_bmdma_drive_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
                        ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
                        ata_postreset_fn_t postreset)
 {
-       struct ata_eh_context *ehc = &ap->eh_context;
        struct ata_queued_cmd *qc;
        unsigned long flags;
        int thaw = 0;
@@ -732,9 +768,7 @@ void ata_bmdma_drive_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
                   qc->tf.protocol == ATA_PROT_ATAPI_DMA)) {
                u8 host_stat;
 
-               host_stat = ata_bmdma_status(ap);
-
-               ata_ehi_push_desc(&ehc->i, "BMDMA stat 0x%x", host_stat);
+               host_stat = ap->ops->bmdma_status(ap);
 
                /* BMDMA controllers indicate host bus error by
                 * setting DMA_ERR bit and timing out.  As it wasn't
@@ -828,7 +862,6 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
 
        probe_ent->irq = pdev->irq;
        probe_ent->irq_flags = IRQF_SHARED;
-       probe_ent->private_data = port[0]->private_data;
 
        if (ports & ATA_PORT_PRIMARY) {
                probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);
@@ -858,6 +891,7 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
                        probe_ent->port[p].bmdma_addr = bmdma;
                }
                ata_std_ports(&probe_ent->port[p]);
+               probe_ent->pinfo2 = port[1];
                p++;
        }
 
@@ -877,10 +911,10 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
                return NULL;
 
        probe_ent->n_ports = 2;
-       probe_ent->private_data = port[0]->private_data;
+       probe_ent->irq_flags = IRQF_SHARED;
 
        if (port_mask & ATA_PORT_PRIMARY) {
-               probe_ent->irq = 14;
+               probe_ent->irq = ATA_PRIMARY_IRQ;
                probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD;
                probe_ent->port[0].altstatus_addr =
                probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL;
@@ -895,9 +929,9 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
 
        if (port_mask & ATA_PORT_SECONDARY) {
                if (probe_ent->irq)
-                       probe_ent->irq2 = 15;
+                       probe_ent->irq2 = ATA_SECONDARY_IRQ;
                else
-                       probe_ent->irq = 15;
+                       probe_ent->irq = ATA_SECONDARY_IRQ;
                probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD;
                probe_ent->port[1].altstatus_addr =
                probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL;
@@ -907,6 +941,9 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
                                probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
                }
                ata_std_ports(&probe_ent->port[1]);
+
+               /* FIXME: could be pointing to stack area; must copy */
+               probe_ent->pinfo2 = port[1];
        } else
                probe_ent->dummy_port_mask |= ATA_PORT_SECONDARY;
 
@@ -944,35 +981,21 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
 {
        struct ata_probe_ent *probe_ent = NULL;
        struct ata_port_info *port[2];
-       u8 tmp8, mask;
+       u8 mask;
        unsigned int legacy_mode = 0;
        int disable_dev_on_err = 1;
        int rc;
 
        DPRINTK("ENTER\n");
 
+       BUG_ON(n_ports < 1 || n_ports > 2);
+
        port[0] = port_info[0];
        if (n_ports > 1)
                port[1] = port_info[1];
        else
                port[1] = port[0];
 
-       if ((port[0]->flags & ATA_FLAG_NO_LEGACY) == 0
-           && (pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
-               /* TODO: What if one channel is in native mode ... */
-               pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
-               mask = (1 << 2) | (1 << 0);
-               if ((tmp8 & mask) != mask)
-                       legacy_mode = (1 << 3);
-       }
-
-       /* FIXME... */
-       if ((!legacy_mode) && (n_ports > 2)) {
-               printk(KERN_ERR "ata: BUG: native mode, n_ports > 2\n");
-               n_ports = 2;
-               /* For now */
-       }
-
        /* FIXME: Really for ATA it isn't safe because the device may be
           multi-purpose and we want to leave it alone if it was already
           enabled. Secondly for shared use as Arjan says we want refcounting
@@ -985,6 +1008,25 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
        if (rc)
                return rc;
 
+       if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
+               u8 tmp8;
+
+               /* TODO: What if one channel is in native mode ... */
+               pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
+               mask = (1 << 2) | (1 << 0);
+               if ((tmp8 & mask) != mask)
+                       legacy_mode = (1 << 3);
+#if defined(CONFIG_NO_ATA_LEGACY)
+               /* Some platforms with PCI limits cannot address compat
+                  port space. In that case we punt if their firmware has
+                  left a device in compatibility mode */
+               if (legacy_mode) {
+                       printk(KERN_ERR "ata: Compatibility mode ATA is not supported on this platform, skipping.\n");
+                       return -EOPNOTSUPP;
+               }
+#endif
+       }
+
        rc = pci_request_regions(pdev, DRV_NAME);
        if (rc) {
                disable_dev_on_err = 0;
@@ -997,11 +1039,16 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
                        res.start = ATA_PRIMARY_CMD;
                        res.end = ATA_PRIMARY_CMD + 8 - 1;
                        conflict = ____request_resource(&ioport_resource, &res);
+                       while (conflict->child)
+                               conflict = ____request_resource(conflict, &res);
                        if (!strcmp(conflict->name, "libata"))
                                legacy_mode |= ATA_PORT_PRIMARY;
                        else {
                                disable_dev_on_err = 0;
-                               printk(KERN_WARNING "ata: 0x%0X IDE port busy\n", ATA_PRIMARY_CMD);
+                               printk(KERN_WARNING "ata: 0x%0X IDE port busy\n" \
+                                                   "ata: conflict with %s\n",
+                                                   ATA_PRIMARY_CMD,
+                                                   conflict->name);
                        }
                } else
                        legacy_mode |= ATA_PORT_PRIMARY;
@@ -1011,11 +1058,16 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
                        res.start = ATA_SECONDARY_CMD;
                        res.end = ATA_SECONDARY_CMD + 8 - 1;
                        conflict = ____request_resource(&ioport_resource, &res);
+                       while (conflict->child)
+                               conflict = ____request_resource(conflict, &res);
                        if (!strcmp(conflict->name, "libata"))
                                legacy_mode |= ATA_PORT_SECONDARY;
                        else {
                                disable_dev_on_err = 0;
-                               printk(KERN_WARNING "ata: 0x%X IDE port busy\n", ATA_SECONDARY_CMD);
+                               printk(KERN_WARNING "ata: 0x%X IDE port busy\n" \
+                                                   "ata: conflict with %s\n",
+                                                   ATA_SECONDARY_CMD,
+                                                   conflict->name);
                        }
                } else
                        legacy_mode |= ATA_PORT_SECONDARY;
@@ -1027,7 +1079,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
                goto err_out_regions;
        }
 
-       /* FIXME: If we get no DMA mask we should fall back to PIO */
+       /* TODO: If we get no DMA mask we should fall back to PIO */
        rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
        if (rc)
                goto err_out_regions;
@@ -1050,13 +1102,17 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
 
        pci_set_master(pdev);
 
-       /* FIXME: check ata_device_add return */
-       ata_device_add(probe_ent);
+       if (!ata_device_add(probe_ent)) {
+               rc = -ENODEV;
+               goto err_out_ent;
+       }
 
        kfree(probe_ent);
 
        return 0;
 
+err_out_ent:
+       kfree(probe_ent);
 err_out_regions:
        if (legacy_mode & ATA_PORT_PRIMARY)
                release_region(ATA_PRIMARY_CMD, 8);