libata: remove irq_on from ata_bus_reset() and ata_std_postreset()
[pandora-kernel.git] / drivers / ata / libata-core.c
index bfc59a1..88e2dd0 100644 (file)
@@ -71,6 +71,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
                                        u16 heads, u16 sectors);
 static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
 static void ata_dev_xfermask(struct ata_device *dev);
+static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
 
 unsigned int ata_print_id = 1;
 static struct workqueue_struct *ata_wq;
@@ -1283,18 +1284,11 @@ static unsigned int ata_id_xfermask(const u16 *id)
 void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
                         unsigned long delay)
 {
-       int rc;
-
-       if (ap->pflags & ATA_PFLAG_FLUSH_PORT_TASK)
-               return;
-
        PREPARE_DELAYED_WORK(&ap->port_task, fn);
        ap->port_task_data = data;
 
-       rc = queue_delayed_work(ata_wq, &ap->port_task, delay);
-
-       /* rc == 0 means that another user is using port task */
-       WARN_ON(rc == 0);
+       /* may fail if ata_port_flush_task() in progress */
+       queue_delayed_work(ata_wq, &ap->port_task, delay);
 }
 
 /**
@@ -1309,32 +1303,9 @@ void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
  */
 void ata_port_flush_task(struct ata_port *ap)
 {
-       unsigned long flags;
-
        DPRINTK("ENTER\n");
 
-       spin_lock_irqsave(ap->lock, flags);
-       ap->pflags |= ATA_PFLAG_FLUSH_PORT_TASK;
-       spin_unlock_irqrestore(ap->lock, flags);
-
-       DPRINTK("flush #1\n");
-       cancel_work_sync(&ap->port_task.work); /* akpm: seems unneeded */
-
-       /*
-        * At this point, if a task is running, it's guaranteed to see
-        * the FLUSH flag; thus, it will never queue pio tasks again.
-        * Cancel and flush.
-        */
-       if (!cancel_delayed_work(&ap->port_task)) {
-               if (ata_msg_ctl(ap))
-                       ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n",
-                                       __FUNCTION__);
-               cancel_work_sync(&ap->port_task.work);
-       }
-
-       spin_lock_irqsave(ap->lock, flags);
-       ap->pflags &= ~ATA_PFLAG_FLUSH_PORT_TASK;
-       spin_unlock_irqrestore(ap->lock, flags);
+       cancel_rearming_delayed_work(&ap->port_task);
 
        if (ata_msg_ctl(ap))
                ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__);
@@ -1814,7 +1785,7 @@ static void ata_dev_config_ncq(struct ata_device *dev,
                desc[0] = '\0';
                return;
        }
-       if (ata_device_blacklisted(dev) & ATA_HORKAGE_NONCQ) {
+       if (dev->horkage & ATA_HORKAGE_NONCQ) {
                snprintf(desc, desc_sz, "NCQ (not used)");
                return;
        }
@@ -1845,7 +1816,8 @@ static void ata_dev_config_ncq(struct ata_device *dev,
 int ata_dev_configure(struct ata_device *dev)
 {
        struct ata_port *ap = dev->ap;
-       int print_info = ap->eh_context.i.flags & ATA_EHI_PRINTINFO;
+       struct ata_eh_context *ehc = &ap->eh_context;
+       int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
        const u16 *id = dev->id;
        unsigned int xfer_mask;
        char revbuf[7];         /* XYZ-99\0 */
@@ -1862,15 +1834,13 @@ int ata_dev_configure(struct ata_device *dev)
        if (ata_msg_probe(ap))
                ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
 
-       /* set _SDD */
-       rc = ata_acpi_push_id(dev);
-       if (rc) {
-               ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n",
-                       rc);
-       }
+       /* set horkage */
+       dev->horkage |= ata_dev_blacklisted(dev);
 
-       /* retrieve and execute the ATA task file of _GTF */
-       ata_acpi_exec_tfs(ap);
+       /* let ACPI work its magic */
+       rc = ata_acpi_on_devcfg(dev);
+       if (rc)
+               return rc;
 
        /* print device capabilities */
        if (ata_msg_probe(ap))
@@ -2042,7 +2012,7 @@ int ata_dev_configure(struct ata_device *dev)
                dev->max_sectors = ATA_MAX_SECTORS;
        }
 
-       if (ata_device_blacklisted(dev) & ATA_HORKAGE_MAX_SEC_128)
+       if (dev->horkage & ATA_HORKAGE_MAX_SEC_128)
                dev->max_sectors = min_t(unsigned int, ATA_MAX_SECTORS_128,
                                         dev->max_sectors);
 
@@ -3194,9 +3164,6 @@ void ata_bus_reset(struct ata_port *ap)
        if ((slave_possible) && (err != 0x81))
                ap->device[1].class = ata_dev_try_classify(ap, 1, &err);
 
-       /* re-enable interrupts */
-       ap->ops->irq_on(ap);
-
        /* is double-select really necessary? */
        if (ap->device[1].class != ATA_DEV_NONE)
                ap->ops->dev_select(ap, 1);
@@ -3359,7 +3326,7 @@ int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
                return 0;
 
        /* if SATA, resume phy */
-       if (ap->cbl == ATA_CBL_SATA) {
+       if (ap->flags & ATA_FLAG_SATA) {
                rc = sata_phy_resume(ap, timing, deadline);
                /* whine about phy resume failure but proceed */
                if (rc && rc != -EOPNOTSUPP)
@@ -3581,10 +3548,6 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
        if (sata_scr_read(ap, SCR_ERROR, &serror) == 0)
                sata_scr_write(ap, SCR_ERROR, serror);
 
-       /* re-enable interrupts */
-       if (!ap->ops->error_handler)
-               ap->ops->irq_on(ap);
-
        /* is double-select really necessary? */
        if (classes[0] != ATA_DEV_NONE)
                ap->ops->dev_select(ap, 1);
@@ -3774,6 +3737,8 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "SAMSUNG CD-ROM SN-124","N001",       ATA_HORKAGE_NODMA },
        { "Seagate STT20000A", NULL,            ATA_HORKAGE_NODMA },
        { "IOMEGA  ZIP 250       ATAPI", NULL,  ATA_HORKAGE_NODMA }, /* temporary fix */
+       { "IOMEGA  ZIP 250       ATAPI       Floppy",
+                               NULL,           ATA_HORKAGE_NODMA },
 
        /* Weird ATAPI devices */
        { "TORiSAN DVD-ROM DRD-N216", NULL,     ATA_HORKAGE_MAX_SEC_128 },
@@ -3787,7 +3752,10 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "FUJITSU MHT2060BH",  NULL,           ATA_HORKAGE_NONCQ },
        /* NCQ is broken */
        { "Maxtor 6L250S0",     "BANC1G10",     ATA_HORKAGE_NONCQ },
+       { "Maxtor 6B200M0",     "BANC1BM0",     ATA_HORKAGE_NONCQ },
        { "Maxtor 6B200M0",     "BANC1B10",     ATA_HORKAGE_NONCQ },
+       { "HITACHI HDS7250SASUN500G 0621KTAWSD", "K2AOAJ0AHITACHI",
+        ATA_HORKAGE_NONCQ },
        /* NCQ hard hangs device under heavier load, needs hard power cycle */
        { "Maxtor 6B250S0",     "BANC1B70",     ATA_HORKAGE_NONCQ },
        /* Blacklist entries taken from Silicon Image 3124/3132
@@ -3798,7 +3766,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* Drives which do spurious command completion */
        { "HTS541680J9SA00",    "SB2IC7EP",     ATA_HORKAGE_NONCQ, },
        { "HTS541612J9SA00",    "SBDIC7JP",     ATA_HORKAGE_NONCQ, },
+       { "Hitachi HTS541616J9SA00", "SB4OC70P", ATA_HORKAGE_NONCQ, },
        { "WDC WD740ADFD-00NLR1", NULL,         ATA_HORKAGE_NONCQ, },
+       { "FUJITSU MHV2080BH",  "00840028",     ATA_HORKAGE_NONCQ, },
 
        /* Devices with NCQ limits */
 
@@ -3806,7 +3776,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { }
 };
 
-unsigned long ata_device_blacklisted(const struct ata_device *dev)
+static unsigned long ata_dev_blacklisted(const struct ata_device *dev)
 {
        unsigned char model_num[ATA_ID_PROD_LEN + 1];
        unsigned char model_rev[ATA_ID_FW_REV_LEN + 1];
@@ -3836,7 +3806,7 @@ static int ata_dma_blacklisted(const struct ata_device *dev)
        if ((dev->ap->flags & ATA_FLAG_PIO_POLLING) &&
            (dev->flags & ATA_DFLAG_CDB_INTR))
                return 1;
-       return (ata_device_blacklisted(dev) & ATA_HORKAGE_NODMA) ? 1 : 0;
+       return (dev->horkage & ATA_HORKAGE_NODMA) ? 1 : 0;
 }
 
 /**
@@ -4105,6 +4075,68 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
                ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
 }
 
+/**
+ *     ata_fill_sg_dumb - Fill PCI IDE PRD table
+ *     @qc: Metadata associated with taskfile to be transferred
+ *
+ *     Fill PCI IDE PRD (scatter-gather) table with segments
+ *     associated with the current disk command. Perform the fill
+ *     so that we avoid writing any length 64K records for
+ *     controllers that don't follow the spec.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ *
+ */
+static void ata_fill_sg_dumb(struct ata_queued_cmd *qc)
+{
+       struct ata_port *ap = qc->ap;
+       struct scatterlist *sg;
+       unsigned int idx;
+
+       WARN_ON(qc->__sg == NULL);
+       WARN_ON(qc->n_elem == 0 && qc->pad_len == 0);
+
+       idx = 0;
+       ata_for_each_sg(sg, qc) {
+               u32 addr, offset;
+               u32 sg_len, len, blen;
+
+               /* determine if physical DMA addr spans 64K boundary.
+                * Note h/w doesn't support 64-bit, so we unconditionally
+                * truncate dma_addr_t to u32.
+                */
+               addr = (u32) sg_dma_address(sg);
+               sg_len = sg_dma_len(sg);
+
+               while (sg_len) {
+                       offset = addr & 0xffff;
+                       len = sg_len;
+                       if ((offset + sg_len) > 0x10000)
+                               len = 0x10000 - offset;
+
+                       blen = len & 0xffff;
+                       ap->prd[idx].addr = cpu_to_le32(addr);
+                       if (blen == 0) {
+                          /* Some PATA chipsets like the CS5530 can't
+                             cope with 0x0000 meaning 64K as the spec says */
+                               ap->prd[idx].flags_len = cpu_to_le32(0x8000);
+                               blen = 0x8000;
+                               ap->prd[++idx].addr = cpu_to_le32(addr + 0x8000);
+                       }
+                       ap->prd[idx].flags_len = cpu_to_le32(blen);
+                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
+
+                       idx++;
+                       sg_len -= len;
+                       addr += len;
+               }
+       }
+
+       if (idx)
+               ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+}
+
 /**
  *     ata_check_atapi_dma - Check whether ATAPI DMA can be supported
  *     @qc: Metadata associated with taskfile to check
@@ -4152,6 +4184,23 @@ void ata_qc_prep(struct ata_queued_cmd *qc)
        ata_fill_sg(qc);
 }
 
+/**
+ *     ata_dumb_qc_prep - Prepare taskfile for submission
+ *     @qc: Metadata associated with taskfile to be prepared
+ *
+ *     Prepare ATA taskfile for submission.
+ *
+ *     LOCKING:
+ *     spin_lock_irqsave(host lock)
+ */
+void ata_dumb_qc_prep(struct ata_queued_cmd *qc)
+{
+       if (!(qc->flags & ATA_QCFLAG_DMAMAP))
+               return;
+
+       ata_fill_sg_dumb(qc);
+}
+
 void ata_noop_qc_prep(struct ata_queued_cmd *qc) { }
 
 /**
@@ -4781,8 +4830,6 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
                } else
                        ata_qc_complete(qc);
        }
-
-       ata_altstatus(ap); /* flush */
 }
 
 /**
@@ -5661,7 +5708,7 @@ irqreturn_t ata_interrupt (int irq, void *dev_instance)
  */
 int sata_scr_valid(struct ata_port *ap)
 {
-       return ap->cbl == ATA_CBL_SATA && ap->ops->scr_read;
+       return (ap->flags & ATA_FLAG_SATA) && ap->ops->scr_read;
 }
 
 /**
@@ -6294,6 +6341,9 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
        if (rc)
                return rc;
 
+       /* associate with ACPI nodes */
+       ata_acpi_associate(host);
+
        /* set cable, sata_spd_limit and report */
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
@@ -6325,7 +6375,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
                if (!ata_port_is_dummy(ap))
                        ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p "
                                        "ctl 0x%p bmdma 0x%p irq %d\n",
-                                       ap->cbl == ATA_CBL_SATA ? 'S' : 'P',
+                                       (ap->flags & ATA_FLAG_SATA) ? 'S' : 'P',
                                        ata_mode_string(xfer_mask),
                                        ap->ioaddr.cmd_addr,
                                        ap->ioaddr.ctl_addr,
@@ -6424,14 +6474,14 @@ int ata_host_activate(struct ata_host *host, int irq,
        if (rc)
                return rc;
 
+       /* Used to print device info at probe */
+       host->irq = irq;
+
        rc = ata_host_register(host, sht);
        /* if failed, just free the IRQ and leave ports alone */
        if (rc)
                devm_free_irq(host->dev, irq, host);
 
-       /* Used to print device info at probe */
-       host->irq = irq;
-
        return rc;
 }
 
@@ -6480,13 +6530,7 @@ void ata_port_detach(struct ata_port *ap)
        spin_unlock_irqrestore(ap->lock, flags);
 
        ata_port_wait_eh(ap);
-
-       /* Flush hotplug task.  The sequence is similar to
-        * ata_port_flush_task().
-        */
-       cancel_work_sync(&ap->hotplug_task.work); /* akpm: why? */
-       cancel_delayed_work(&ap->hotplug_task);
-       cancel_work_sync(&ap->hotplug_task.work);
+       cancel_rearming_delayed_work(&ap->hotplug_task);
 
  skip_eh:
        /* remove the associated SCSI host */
@@ -6823,6 +6867,7 @@ EXPORT_SYMBOL_GPL(ata_do_set_mode);
 EXPORT_SYMBOL_GPL(ata_data_xfer);
 EXPORT_SYMBOL_GPL(ata_data_xfer_noirq);
 EXPORT_SYMBOL_GPL(ata_qc_prep);
+EXPORT_SYMBOL_GPL(ata_dumb_qc_prep);
 EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
 EXPORT_SYMBOL_GPL(ata_bmdma_setup);
 EXPORT_SYMBOL_GPL(ata_bmdma_start);
@@ -6874,7 +6919,6 @@ EXPORT_SYMBOL_GPL(ata_host_resume);
 EXPORT_SYMBOL_GPL(ata_id_string);
 EXPORT_SYMBOL_GPL(ata_id_c_string);
 EXPORT_SYMBOL_GPL(ata_id_to_dma_mode);
-EXPORT_SYMBOL_GPL(ata_device_blacklisted);
 EXPORT_SYMBOL_GPL(ata_scsi_simulate);
 
 EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
@@ -6883,9 +6927,9 @@ EXPORT_SYMBOL_GPL(ata_timing_merge);
 
 #ifdef CONFIG_PCI
 EXPORT_SYMBOL_GPL(pci_test_config_bits);
-EXPORT_SYMBOL_GPL(ata_pci_init_native_host);
+EXPORT_SYMBOL_GPL(ata_pci_init_sff_host);
 EXPORT_SYMBOL_GPL(ata_pci_init_bmdma);
-EXPORT_SYMBOL_GPL(ata_pci_prepare_native_host);
+EXPORT_SYMBOL_GPL(ata_pci_prepare_sff_host);
 EXPORT_SYMBOL_GPL(ata_pci_init_one);
 EXPORT_SYMBOL_GPL(ata_pci_remove_one);
 #ifdef CONFIG_PM