]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - drivers/ata/libata-core.c
libata-sff: port_task is SFF specific
[mv-sheeva.git] / drivers / ata / libata-core.c
index 4a28420efff22a2059c50bbe6a15804d79c73dc1..c47373f01f89dfadd6114d03d3b1bbed15970142 100644 (file)
 #include <linux/io.h>
 #include <linux/async.h>
 #include <linux/log2.h>
+#include <linux/slab.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_host.h>
 #include <linux/libata.h>
 #include <asm/byteorder.h>
 #include <linux/cdrom.h>
+#include <linux/ratelimit.h>
 
 #include "libata.h"
 
@@ -95,7 +97,6 @@ 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;
 
 struct workqueue_struct *ata_aux_wq;
 
@@ -1493,6 +1494,7 @@ static int ata_hpa_resize(struct ata_device *dev)
 {
        struct ata_eh_context *ehc = &dev->link->eh_context;
        int print_info = ehc->i.flags & ATA_EHI_PRINTINFO;
+       bool unlock_hpa = ata_ignore_hpa || dev->flags & ATA_DFLAG_UNLOCK_HPA;
        u64 sectors = ata_id_n_sectors(dev->id);
        u64 native_sectors;
        int rc;
@@ -1509,7 +1511,7 @@ static int ata_hpa_resize(struct ata_device *dev)
                /* If device aborted the command or HPA isn't going to
                 * be unlocked, skip HPA resizing.
                 */
-               if (rc == -EACCES || !ata_ignore_hpa) {
+               if (rc == -EACCES || !unlock_hpa) {
                        ata_dev_printk(dev, KERN_WARNING, "HPA support seems "
                                       "broken, skipping HPA handling\n");
                        dev->horkage |= ATA_HORKAGE_BROKEN_HPA;
@@ -1524,7 +1526,7 @@ static int ata_hpa_resize(struct ata_device *dev)
        dev->n_native_sectors = native_sectors;
 
        /* nothing to do? */
-       if (native_sectors <= sectors || !ata_ignore_hpa) {
+       if (native_sectors <= sectors || !unlock_hpa) {
                if (!print_info || native_sectors == sectors)
                        return 0;
 
@@ -1683,52 +1685,6 @@ unsigned long ata_id_xfermask(const u16 *id)
        return ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
 }
 
-/**
- *     ata_pio_queue_task - Queue port_task
- *     @ap: The ata_port to queue port_task for
- *     @data: data for @fn to use
- *     @delay: delay time in msecs for workqueue function
- *
- *     Schedule @fn(@data) for execution after @delay jiffies using
- *     port_task.  There is one port_task per port and it's the
- *     user(low level driver)'s responsibility to make sure that only
- *     one task is active at any given time.
- *
- *     libata core layer takes care of synchronization between
- *     port_task and EH.  ata_pio_queue_task() may be ignored for EH
- *     synchronization.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-void ata_pio_queue_task(struct ata_port *ap, void *data, unsigned long delay)
-{
-       ap->port_task_data = data;
-
-       /* may fail if ata_port_flush_task() in progress */
-       queue_delayed_work(ata_wq, &ap->port_task, msecs_to_jiffies(delay));
-}
-
-/**
- *     ata_port_flush_task - Flush port_task
- *     @ap: The ata_port to flush port_task for
- *
- *     After this function completes, port_task is guranteed not to
- *     be running or scheduled.
- *
- *     LOCKING:
- *     Kernel thread context (may sleep)
- */
-void ata_port_flush_task(struct ata_port *ap)
-{
-       DPRINTK("ENTER\n");
-
-       cancel_rearming_delayed_work(&ap->port_task);
-
-       if (ata_msg_ctl(ap))
-               ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __func__);
-}
-
 static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
 {
        struct completion *waiting = qc->private_data;
@@ -1850,7 +1806,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
 
        rc = wait_for_completion_timeout(&wait, msecs_to_jiffies(timeout));
 
-       ata_port_flush_task(ap);
+       ata_sff_flush_pio_task(ap);
 
        if (!rc) {
                spin_lock_irqsave(ap->lock, flags);
@@ -1904,22 +1860,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
        ap->qc_active = preempted_qc_active;
        ap->nr_active_links = preempted_nr_active_links;
 
-       /* XXX - Some LLDDs (sata_mv) disable port on command failure.
-        * Until those drivers are fixed, we detect the condition
-        * here, fail the command with AC_ERR_SYSTEM and reenable the
-        * port.
-        *
-        * Note that this doesn't change any behavior as internal
-        * command failure results in disabling the device in the
-        * higher layer for LLDDs without new reset/EH callbacks.
-        *
-        * Kill the following code as soon as those drivers are fixed.
-        */
-       if (ap->flags & ATA_FLAG_DISABLED) {
-               err_mask |= AC_ERR_SYSTEM;
-               ata_port_probe(ap);
-       }
-
        spin_unlock_irqrestore(ap->lock, flags);
 
        if ((err_mask & AC_ERR_TIMEOUT) && auto_timeout)
@@ -2765,8 +2705,6 @@ int ata_bus_probe(struct ata_port *ap)
        int rc;
        struct ata_device *dev;
 
-       ata_port_probe(ap);
-
        ata_for_each_dev(dev, &ap->link, ALL)
                tries[dev->devno] = ATA_PROBE_MAX_TRIES;
 
@@ -2794,8 +2732,7 @@ int ata_bus_probe(struct ata_port *ap)
        ap->ops->phy_reset(ap);
 
        ata_for_each_dev(dev, &ap->link, ALL) {
-               if (!(ap->flags & ATA_FLAG_DISABLED) &&
-                   dev->class != ATA_DEV_UNKNOWN)
+               if (dev->class != ATA_DEV_UNKNOWN)
                        classes[dev->devno] = dev->class;
                else
                        classes[dev->devno] = ATA_DEV_NONE;
@@ -2803,8 +2740,6 @@ int ata_bus_probe(struct ata_port *ap)
                dev->class = ATA_DEV_UNKNOWN;
        }
 
-       ata_port_probe(ap);
-
        /* read IDENTIFY page and configure devices. We have to do the identify
           specific sequence bass-ackwards so that PDIAG- is released by
           the slave device */
@@ -2854,8 +2789,6 @@ int ata_bus_probe(struct ata_port *ap)
        ata_for_each_dev(dev, &ap->link, ENABLED)
                return 0;
 
-       /* no device present, disable port */
-       ata_port_disable(ap);
        return -ENODEV;
 
  fail:
@@ -2886,22 +2819,6 @@ int ata_bus_probe(struct ata_port *ap)
        goto retry;
 }
 
-/**
- *     ata_port_probe - Mark port as enabled
- *     @ap: Port for which we indicate enablement
- *
- *     Modify @ap data structure such that the system
- *     thinks that the entire port is enabled.
- *
- *     LOCKING: host lock, or some other form of
- *     serialization.
- */
-
-void ata_port_probe(struct ata_port *ap)
-{
-       ap->flags &= ~ATA_FLAG_DISABLED;
-}
-
 /**
  *     sata_print_link_status - Print SATA link status
  *     @link: SATA link to printk link status about
@@ -2948,26 +2865,6 @@ struct ata_device *ata_dev_pair(struct ata_device *adev)
        return pair;
 }
 
-/**
- *     ata_port_disable - Disable port.
- *     @ap: Port to be disabled.
- *
- *     Modify @ap data structure such that the system
- *     thinks that the entire port is disabled, and should
- *     never attempt to probe or communicate with devices
- *     on this port.
- *
- *     LOCKING: host lock, or some other form of
- *     serialization.
- */
-
-void ata_port_disable(struct ata_port *ap)
-{
-       ap->link.device[0].class = ATA_DEV_NONE;
-       ap->link.device[1].class = ATA_DEV_NONE;
-       ap->flags |= ATA_FLAG_DISABLED;
-}
-
 /**
  *     sata_down_spd_limit - adjust SATA spd limit downward
  *     @link: Link to adjust SATA spd limit for
@@ -3629,9 +3526,15 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
                   int (*check_ready)(struct ata_link *link))
 {
        unsigned long start = jiffies;
-       unsigned long nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT);
+       unsigned long nodev_deadline;
        int warned = 0;
 
+       /* choose which 0xff timeout to use, read comment in libata.h */
+       if (link->ap->host->flags & ATA_HOST_PARALLEL_SCAN)
+               nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT_LONG);
+       else
+               nodev_deadline = ata_deadline(start, ATA_TMOUT_FF_WAIT);
+
        /* Slave readiness can't be tested separately from master.  On
         * M/S emulation configuration, this function should be called
         * only on the master and it will handle both master and slave.
@@ -3649,12 +3552,12 @@ int ata_wait_ready(struct ata_link *link, unsigned long deadline,
                if (ready > 0)
                        return 0;
 
-               /* -ENODEV could be transient.  Ignore -ENODEV if link
+               /*
+                * -ENODEV could be transient.  Ignore -ENODEV if link
                 * is online.  Also, some SATA devices take a long
-                * time to clear 0xff after reset.  For example,
-                * HHD424020F7SV00 iVDR needs >= 800ms while Quantum
-                * GoVault needs even more than that.  Wait for
-                * ATA_TMOUT_FF_WAIT on -ENODEV if link isn't offline.
+                * time to clear 0xff after reset.  Wait for
+                * ATA_TMOUT_FF_WAIT[_LONG] on -ENODEV if link isn't
+                * offline.
                 *
                 * Note that some PATA controllers (pata_ali) explode
                 * if status register is read more than once when
@@ -4185,36 +4088,51 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
                goto fail;
 
        /* verify n_sectors hasn't changed */
-       if (dev->class == ATA_DEV_ATA && n_sectors &&
-           dev->n_sectors != n_sectors) {
-               ata_dev_printk(dev, KERN_WARNING, "n_sectors mismatch "
-                              "%llu != %llu\n",
-                              (unsigned long long)n_sectors,
-                              (unsigned long long)dev->n_sectors);
-               /*
-                * Something could have caused HPA to be unlocked
-                * involuntarily.  If n_native_sectors hasn't changed
-                * and the new size matches it, keep the device.
-                */
-               if (dev->n_native_sectors == n_native_sectors &&
-                   dev->n_sectors > n_sectors &&
-                   dev->n_sectors == n_native_sectors) {
-                       ata_dev_printk(dev, KERN_WARNING,
-                                      "new n_sectors matches native, probably "
-                                      "late HPA unlock, continuing\n");
-                       /* keep using the old n_sectors */
-                       dev->n_sectors = n_sectors;
-               } else {
-                       /* restore original n_[native]_sectors and fail */
-                       dev->n_native_sectors = n_native_sectors;
-                       dev->n_sectors = n_sectors;
-                       rc = -ENODEV;
-                       goto fail;
-               }
+       if (dev->class != ATA_DEV_ATA || !n_sectors ||
+           dev->n_sectors == n_sectors)
+               return 0;
+
+       /* n_sectors has changed */
+       ata_dev_printk(dev, KERN_WARNING, "n_sectors mismatch %llu != %llu\n",
+                      (unsigned long long)n_sectors,
+                      (unsigned long long)dev->n_sectors);
+
+       /*
+        * Something could have caused HPA to be unlocked
+        * involuntarily.  If n_native_sectors hasn't changed and the
+        * new size matches it, keep the device.
+        */
+       if (dev->n_native_sectors == n_native_sectors &&
+           dev->n_sectors > n_sectors && dev->n_sectors == n_native_sectors) {
+               ata_dev_printk(dev, KERN_WARNING,
+                              "new n_sectors matches native, probably "
+                              "late HPA unlock, continuing\n");
+               /* keep using the old n_sectors */
+               dev->n_sectors = n_sectors;
+               return 0;
        }
 
-       return 0;
+       /*
+        * Some BIOSes boot w/o HPA but resume w/ HPA locked.  Try
+        * unlocking HPA in those cases.
+        *
+        * https://bugzilla.kernel.org/show_bug.cgi?id=15396
+        */
+       if (dev->n_native_sectors == n_native_sectors &&
+           dev->n_sectors < n_sectors && n_sectors == n_native_sectors &&
+           !(dev->horkage & ATA_HORKAGE_BROKEN_HPA)) {
+               ata_dev_printk(dev, KERN_WARNING,
+                              "old n_sectors matches native, probably "
+                              "late HPA lock, will try to unlock HPA\n");
+               /* try unlocking HPA */
+               dev->flags |= ATA_DFLAG_UNLOCK_HPA;
+               rc = -EIO;
+       } else
+               rc = -ENODEV;
 
+       /* restore original n_[native_]sectors and fail */
+       dev->n_native_sectors = n_native_sectors;
+       dev->n_sectors = n_sectors;
  fail:
        ata_dev_printk(dev, KERN_ERR, "revalidation failed (errno=%d)\n", rc);
        return rc;
@@ -4353,6 +4271,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "HTS541080G9SA00",    "MB4OC60D",     ATA_HORKAGE_NONCQ, },
        { "HTS541010G9SA00",    "MBZOC60D",     ATA_HORKAGE_NONCQ, },
 
+       /* https://bugzilla.kernel.org/show_bug.cgi?id=15573 */
+       { "C300-CTFDDAC128MAG", "0001",         ATA_HORKAGE_NONCQ, },
+
        /* devices which puke on READ_NATIVE_MAX */
        { "HDS724040KLSA80",    "KFAOA20N",     ATA_HORKAGE_BROKEN_HPA, },
        { "WDC WD3200JD-00KLB0", "WD-WCAMR1130137", ATA_HORKAGE_BROKEN_HPA },
@@ -5537,30 +5458,6 @@ void ata_host_resume(struct ata_host *host)
 }
 #endif
 
-/**
- *     ata_port_start - Set port up for dma.
- *     @ap: Port to initialize
- *
- *     Called just after data structures for each port are
- *     initialized.  Allocates space for PRD table.
- *
- *     May be used as the port_start() entry in ata_port_operations.
- *
- *     LOCKING:
- *     Inherited from caller.
- */
-int ata_port_start(struct ata_port *ap)
-{
-       struct device *dev = ap->dev;
-
-       ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma,
-                                     GFP_KERNEL);
-       if (!ap->prd)
-               return -ENOMEM;
-
-       return 0;
-}
-
 /**
  *     ata_dev_init - Initialize an ata_device structure
  *     @dev: Device structure to initialize
@@ -5689,12 +5586,9 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
 
        ap->pflags |= ATA_PFLAG_INITIALIZING;
        ap->lock = &host->lock;
-       ap->flags = ATA_FLAG_DISABLED;
        ap->print_id = -1;
-       ap->ctl = ATA_DEVCTL_OBS;
        ap->host = host;
        ap->dev = host->dev;
-       ap->last_ctl = 0xFF;
 
 #if defined(ATA_VERBOSE_DEBUG)
        /* turn on all debugging levels */
@@ -5705,11 +5599,6 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
 #endif
 
-#ifdef CONFIG_ATA_SFF
-       INIT_DELAYED_WORK(&ap->port_task, ata_pio_task);
-#else
-       INIT_DELAYED_WORK(&ap->port_task, NULL);
-#endif
        INIT_DELAYED_WORK(&ap->hotplug_task, ata_scsi_hotplug);
        INIT_WORK(&ap->scsi_rescan_task, ata_scsi_dev_rescan);
        INIT_LIST_HEAD(&ap->eh_done_q);
@@ -5727,6 +5616,8 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
        ap->stats.unhandled_irq = 1;
        ap->stats.idle_irq = 1;
 #endif
+       ata_sff_port_init(ap);
+
        return ap;
 }
 
@@ -6118,8 +6009,6 @@ static void async_port_probe(void *data, async_cookie_t cookie)
                struct ata_eh_info *ehi = &ap->link.eh_info;
                unsigned long flags;
 
-               ata_port_probe(ap);
-
                /* kick EH for boot probing */
                spin_lock_irqsave(ap->lock, flags);
 
@@ -6643,62 +6532,43 @@ static void __init ata_parse_force_param(void)
 
 static int __init ata_init(void)
 {
-       ata_parse_force_param();
+       int rc = -ENOMEM;
 
-       /*
-        * FIXME: In UP case, there is only one workqueue thread and if you
-        * have more than one PIO device, latency is bloody awful, with
-        * occasional multi-second "hiccups" as one PIO device waits for
-        * another.  It's an ugly wart that users DO occasionally complain
-        * about; luckily most users have at most one PIO polled device.
-        */
-       ata_wq = create_workqueue("ata");
-       if (!ata_wq)
-               goto free_force_tbl;
+       ata_parse_force_param();
 
        ata_aux_wq = create_singlethread_workqueue("ata_aux");
        if (!ata_aux_wq)
-               goto free_wq;
+               goto fail;
+
+       rc = ata_sff_init();
+       if (rc)
+               goto fail;
 
        printk(KERN_DEBUG "libata version " DRV_VERSION " loaded.\n");
        return 0;
 
-free_wq:
-       destroy_workqueue(ata_wq);
-free_force_tbl:
+fail:
        kfree(ata_force_tbl);
-       return -ENOMEM;
+       if (ata_aux_wq)
+               destroy_workqueue(ata_aux_wq);
+       return rc;
 }
 
 static void __exit ata_exit(void)
 {
+       ata_sff_exit();
        kfree(ata_force_tbl);
-       destroy_workqueue(ata_wq);
        destroy_workqueue(ata_aux_wq);
 }
 
 subsys_initcall(ata_init);
 module_exit(ata_exit);
 
-static unsigned long ratelimit_time;
-static DEFINE_SPINLOCK(ata_ratelimit_lock);
+static DEFINE_RATELIMIT_STATE(ratelimit, HZ / 5, 1);
 
 int ata_ratelimit(void)
 {
-       int rc;
-       unsigned long flags;
-
-       spin_lock_irqsave(&ata_ratelimit_lock, flags);
-
-       if (time_after(jiffies, ratelimit_time)) {
-               rc = 1;
-               ratelimit_time = jiffies + (HZ/5);
-       } else
-               rc = 0;
-
-       spin_unlock_irqrestore(&ata_ratelimit_lock, flags);
-
-       return rc;
+       return __ratelimit(&ratelimit);
 }
 
 /**
@@ -6806,11 +6676,9 @@ EXPORT_SYMBOL_GPL(ata_xfer_mode2mask);
 EXPORT_SYMBOL_GPL(ata_xfer_mode2shift);
 EXPORT_SYMBOL_GPL(ata_mode_string);
 EXPORT_SYMBOL_GPL(ata_id_xfermask);
-EXPORT_SYMBOL_GPL(ata_port_start);
 EXPORT_SYMBOL_GPL(ata_do_set_mode);
 EXPORT_SYMBOL_GPL(ata_std_qc_defer);
 EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
-EXPORT_SYMBOL_GPL(ata_port_probe);
 EXPORT_SYMBOL_GPL(ata_dev_disable);
 EXPORT_SYMBOL_GPL(sata_set_spd);
 EXPORT_SYMBOL_GPL(ata_wait_after_reset);
@@ -6822,7 +6690,6 @@ EXPORT_SYMBOL_GPL(sata_std_hardreset);
 EXPORT_SYMBOL_GPL(ata_std_postreset);
 EXPORT_SYMBOL_GPL(ata_dev_classify);
 EXPORT_SYMBOL_GPL(ata_dev_pair);
-EXPORT_SYMBOL_GPL(ata_port_disable);
 EXPORT_SYMBOL_GPL(ata_ratelimit);
 EXPORT_SYMBOL_GPL(ata_wait_register);
 EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
@@ -6844,7 +6711,6 @@ EXPORT_SYMBOL_GPL(ata_id_c_string);
 EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
 EXPORT_SYMBOL_GPL(ata_scsi_simulate);
 
-EXPORT_SYMBOL_GPL(ata_pio_queue_task);
 EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
 EXPORT_SYMBOL_GPL(ata_timing_find_mode);
 EXPORT_SYMBOL_GPL(ata_timing_compute);