include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / ata / libata-core.c
index d4a7b8a..3f6771e 100644 (file)
@@ -57,6 +57,8 @@
 #include <linux/scatterlist.h>
 #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>
@@ -124,19 +126,19 @@ MODULE_PARM_DESC(force, "Force ATA configurations including cable type, link spe
 
 static int atapi_enabled = 1;
 module_param(atapi_enabled, int, 0444);
-MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on)");
+MODULE_PARM_DESC(atapi_enabled, "Enable discovery of ATAPI devices (0=off, 1=on [default])");
 
 static int atapi_dmadir = 0;
 module_param(atapi_dmadir, int, 0444);
-MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off, 1=on)");
+MODULE_PARM_DESC(atapi_dmadir, "Enable ATAPI DMADIR bridge support (0=off [default], 1=on)");
 
 int atapi_passthru16 = 1;
 module_param(atapi_passthru16, int, 0444);
-MODULE_PARM_DESC(atapi_passthru16, "Enable ATA_16 passthru for ATAPI devices; on by default (0=off, 1=on)");
+MODULE_PARM_DESC(atapi_passthru16, "Enable ATA_16 passthru for ATAPI devices (0=off, 1=on [default])");
 
 int libata_fua = 0;
 module_param_named(fua, libata_fua, int, 0444);
-MODULE_PARM_DESC(fua, "FUA support (0=off, 1=on)");
+MODULE_PARM_DESC(fua, "FUA support (0=off [default], 1=on)");
 
 static int ata_ignore_hpa;
 module_param_named(ignore_hpa, ata_ignore_hpa, int, 0644);
@@ -152,11 +154,11 @@ MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
 
 int libata_noacpi = 0;
 module_param_named(noacpi, libata_noacpi, int, 0444);
-MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in probe/suspend/resume when set");
+MODULE_PARM_DESC(noacpi, "Disable the use of ACPI in probe/suspend/resume (0=off [default], 1=on)");
 
 int libata_allow_tpm = 0;
 module_param_named(allow_tpm, libata_allow_tpm, int, 0444);
-MODULE_PARM_DESC(allow_tpm, "Permit the use of TPM commands");
+MODULE_PARM_DESC(allow_tpm, "Permit the use of TPM commands (0=off [default], 1=on)");
 
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Library module for ATA devices");
@@ -708,7 +710,13 @@ u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev)
                head = tf->device & 0xf;
                sect = tf->lbal;
 
-               block = (cyl * dev->heads + head) * dev->sectors + sect;
+               if (!sect) {
+                       ata_dev_printk(dev, KERN_WARNING, "device reported "
+                                      "invalid CHS sector 0\n");
+                       sect = 1; /* oh well */
+               }
+
+               block = (cyl * dev->heads + head) * dev->sectors + sect - 1;
        }
 
        return block;
@@ -1230,6 +1238,9 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
         *
         * We follow the current spec and consider that 0x69/0x96
         * identifies a port multiplier and 0x3c/0xc3 a SEMB device.
+        * Unfortunately, WDC WD1600JS-62MHB5 (a hard drive) reports
+        * SEMB signature.  This is worked around in
+        * ata_dev_read_id().
         */
        if ((tf->lbam == 0) && (tf->lbah == 0)) {
                DPRINTK("found ATA device by sig\n");
@@ -1247,8 +1258,8 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
        }
 
        if ((tf->lbam == 0x3c) && (tf->lbah == 0xc3)) {
-               printk(KERN_INFO "ata: SEMB device ignored\n");
-               return ATA_DEV_SEMB_UNSUP; /* not yet */
+               DPRINTK("found SEMB device by sig (could be ATA device)\n");
+               return ATA_DEV_SEMB;
        }
 
        DPRINTK("unknown device\n");
@@ -1511,6 +1522,7 @@ static int ata_hpa_resize(struct ata_device *dev)
 
                return rc;
        }
+       dev->n_native_sectors = native_sectors;
 
        /* nothing to do? */
        if (native_sectors <= sectors || !ata_ignore_hpa) {
@@ -1652,8 +1664,8 @@ unsigned long ata_id_xfermask(const u16 *id)
                /*
                 *      Process compact flash extended modes
                 */
-               int pio = id[163] & 0x7;
-               int dma = (id[163] >> 3) & 7;
+               int pio = (id[ATA_ID_CFA_MODES] >> 0) & 0x7;
+               int dma = (id[ATA_ID_CFA_MODES] >> 3) & 0x7;
 
                if (pio)
                        pio_mask |= (1 << 5);
@@ -1989,11 +2001,17 @@ unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
  *     Check if the current speed of the device requires IORDY. Used
  *     by various controllers for chip configuration.
  */
-
 unsigned int ata_pio_need_iordy(const struct ata_device *adev)
 {
-       /* Controller doesn't support  IORDY. Probably a pointless check
-          as the caller should know this */
+       /* Don't set IORDY if we're preparing for reset.  IORDY may
+        * lead to controller lock up on certain controllers if the
+        * port is not occupied.  See bko#11703 for details.
+        */
+       if (adev->link->ap->pflags & ATA_PFLAG_RESETTING)
+               return 0;
+       /* Controller doesn't support IORDY.  Probably a pointless
+        * check as the caller should know this.
+        */
        if (adev->link->ap->flags & ATA_FLAG_NO_IORDY)
                return 0;
        /* CF spec. r4.1 Table 22 says no iordy on PIO5 and PIO6.  */
@@ -2016,7 +2034,6 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
  *     Compute the highest mode possible if we are not using iordy. Return
  *     -1 if no iordy mode is available.
  */
-
 static u32 ata_pio_mask_no_iordy(const struct ata_device *adev)
 {
        /* If we have no drive specific rule, then PIO 2 is non IORDY */
@@ -2079,6 +2096,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        struct ata_taskfile tf;
        unsigned int err_mask = 0;
        const char *reason;
+       bool is_semb = class == ATA_DEV_SEMB;
        int may_fallback = 1, tried_spinup = 0;
        int rc;
 
@@ -2089,6 +2107,8 @@ retry:
        ata_tf_init(dev, &tf);
 
        switch (class) {
+       case ATA_DEV_SEMB:
+               class = ATA_DEV_ATA;    /* some hard drives report SEMB sig */
        case ATA_DEV_ATA:
                tf.command = ATA_CMD_ID_ATA;
                break;
@@ -2125,6 +2145,14 @@ retry:
                        return -ENOENT;
                }
 
+               if (is_semb) {
+                       ata_dev_printk(dev, KERN_INFO, "IDENTIFY failed on "
+                                      "device w/ SEMB sig, disabled\n");
+                       /* SEMB is not supported yet */
+                       *p_class = ATA_DEV_SEMB_UNSUP;
+                       return 0;
+               }
+
                if ((err_mask == AC_ERR_DEV) && (tf.feature & ATA_ABORTED)) {
                        /* Device or controller might have reported
                         * the wrong device class.  Give a shot at the
@@ -2205,7 +2233,7 @@ retry:
                 * Some drives were very specific about that exact sequence.
                 *
                 * Note that ATA4 says lba is mandatory so the second check
-                * shoud never trigger.
+                * should never trigger.
                 */
                if (ata_id_major_version(id) < 4 || !ata_id_has_lba(id)) {
                        err_mask = ata_dev_init_params(dev, id[3], id[6]);
@@ -2278,29 +2306,49 @@ static inline u8 ata_dev_knobble(struct ata_device *dev)
        return ((ap->cbl == ATA_CBL_SATA) && (!ata_id_is_sata(dev->id)));
 }
 
-static void ata_dev_config_ncq(struct ata_device *dev,
+static int ata_dev_config_ncq(struct ata_device *dev,
                               char *desc, size_t desc_sz)
 {
        struct ata_port *ap = dev->link->ap;
        int hdepth = 0, ddepth = ata_id_queue_depth(dev->id);
+       unsigned int err_mask;
+       char *aa_desc = "";
 
        if (!ata_id_has_ncq(dev->id)) {
                desc[0] = '\0';
-               return;
+               return 0;
        }
        if (dev->horkage & ATA_HORKAGE_NONCQ) {
                snprintf(desc, desc_sz, "NCQ (not used)");
-               return;
+               return 0;
        }
        if (ap->flags & ATA_FLAG_NCQ) {
                hdepth = min(ap->scsi_host->can_queue, ATA_MAX_QUEUE - 1);
                dev->flags |= ATA_DFLAG_NCQ;
        }
 
+       if (!(dev->horkage & ATA_HORKAGE_BROKEN_FPDMA_AA) &&
+               (ap->flags & ATA_FLAG_FPDMA_AA) &&
+               ata_id_has_fpdma_aa(dev->id)) {
+               err_mask = ata_dev_set_feature(dev, SETFEATURES_SATA_ENABLE,
+                       SATA_FPDMA_AA);
+               if (err_mask) {
+                       ata_dev_printk(dev, KERN_ERR, "failed to enable AA"
+                               "(error_mask=0x%x)\n", err_mask);
+                       if (err_mask != AC_ERR_DEV) {
+                               dev->horkage |= ATA_HORKAGE_BROKEN_FPDMA_AA;
+                               return -EIO;
+                       }
+               } else
+                       aa_desc = ", AA";
+       }
+
        if (hdepth >= ddepth)
-               snprintf(desc, desc_sz, "NCQ (depth %d)", ddepth);
+               snprintf(desc, desc_sz, "NCQ (depth %d)%s", ddepth, aa_desc);
        else
-               snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth);
+               snprintf(desc, desc_sz, "NCQ (depth %d/%d)%s", hdepth,
+                       ddepth, aa_desc);
+       return 0;
 }
 
 /**
@@ -2389,6 +2437,7 @@ int ata_dev_configure(struct ata_device *dev)
        dev->cylinders = 0;
        dev->heads = 0;
        dev->sectors = 0;
+       dev->multi_count = 0;
 
        /*
         * common ATA, ATAPI feature tests
@@ -2410,7 +2459,8 @@ int ata_dev_configure(struct ata_device *dev)
        /* ATA-specific feature tests */
        if (dev->class == ATA_DEV_ATA) {
                if (ata_id_is_cfa(id)) {
-                       if (id[162] & 1) /* CPRM may make this media unusable */
+                       /* CPRM may make this media unusable */
+                       if (id[ATA_ID_CFA_KEY_MGMT] & 1)
                                ata_dev_printk(dev, KERN_WARNING,
                                               "supports DRM functions and may "
                                               "not be fully accessable.\n");
@@ -2426,12 +2476,19 @@ int ata_dev_configure(struct ata_device *dev)
 
                dev->n_sectors = ata_id_n_sectors(id);
 
-               if (dev->id[59] & 0x100)
-                       dev->multi_count = dev->id[59] & 0xff;
+               /* get current R/W Multiple count setting */
+               if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
+                       unsigned int max = dev->id[47] & 0xff;
+                       unsigned int cnt = dev->id[59] & 0xff;
+                       /* only recognize/allow powers of two here */
+                       if (is_power_of_2(max) && is_power_of_2(cnt))
+                               if (cnt <= max)
+                                       dev->multi_count = cnt;
+               }
 
                if (ata_id_has_lba(id)) {
                        const char *lba_desc;
-                       char ncq_desc[20];
+                       char ncq_desc[24];
 
                        lba_desc = "LBA";
                        dev->flags |= ATA_DFLAG_LBA;
@@ -2445,7 +2502,9 @@ int ata_dev_configure(struct ata_device *dev)
                        }
 
                        /* config NCQ */
-                       ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
+                       rc = ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
+                       if (rc)
+                               return rc;
 
                        /* print device info to dmesg */
                        if (ata_msg_drv(ap) && print_info) {
@@ -3153,6 +3212,7 @@ const struct ata_timing *ata_timing_find_mode(u8 xfer_mode)
 int ata_timing_compute(struct ata_device *adev, unsigned short speed,
                       struct ata_timing *t, int T, int UT)
 {
+       const u16 *id = adev->id;
        const struct ata_timing *s;
        struct ata_timing p;
 
@@ -3170,14 +3230,18 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
         * PIO/MW_DMA cycle timing.
         */
 
-       if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE drive */
+       if (id[ATA_ID_FIELD_VALID] & 2) {       /* EIDE drive */
                memset(&p, 0, sizeof(p));
+
                if (speed >= XFER_PIO_0 && speed <= XFER_SW_DMA_0) {
-                       if (speed <= XFER_PIO_2) p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO];
-                                           else p.cycle = p.cyc8b = adev->id[ATA_ID_EIDE_PIO_IORDY];
-               } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2) {
-                       p.cycle = adev->id[ATA_ID_EIDE_DMA_MIN];
-               }
+                       if (speed <= XFER_PIO_2)
+                               p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO];
+                       else if ((speed <= XFER_PIO_4) ||
+                                (speed == XFER_PIO_5 && !ata_id_is_cfa(id)))
+                               p.cycle = p.cyc8b = id[ATA_ID_EIDE_PIO_IORDY];
+               } else if (speed >= XFER_MW_DMA_0 && speed <= XFER_MW_DMA_2)
+                       p.cycle = id[ATA_ID_EIDE_DMA_MIN];
+
                ata_timing_merge(&p, t, t, ATA_TIMING_CYCLE | ATA_TIMING_CYC8B);
        }
 
@@ -3363,17 +3427,27 @@ int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel)
 
 static int ata_dev_set_mode(struct ata_device *dev)
 {
+       struct ata_port *ap = dev->link->ap;
        struct ata_eh_context *ehc = &dev->link->eh_context;
+       const bool nosetxfer = dev->horkage & ATA_HORKAGE_NOSETXFER;
        const char *dev_err_whine = "";
        int ign_dev_err = 0;
-       unsigned int err_mask;
+       unsigned int err_mask = 0;
        int rc;
 
        dev->flags &= ~ATA_DFLAG_PIO;
        if (dev->xfer_shift == ATA_SHIFT_PIO)
                dev->flags |= ATA_DFLAG_PIO;
 
-       err_mask = ata_dev_set_xfermode(dev);
+       if (nosetxfer && ap->flags & ATA_FLAG_SATA && ata_id_is_sata(dev->id))
+               dev_err_whine = " (SET_XFERMODE skipped)";
+       else {
+               if (nosetxfer)
+                       ata_dev_printk(dev, KERN_WARNING,
+                                      "NOSETXFER but PATA detected - can't "
+                                      "skip SETXFER, might malfunction\n");
+               err_mask = ata_dev_set_xfermode(dev);
+       }
 
        if (err_mask & ~AC_ERR_DEV)
                goto fail;
@@ -3722,21 +3796,45 @@ int sata_link_debounce(struct ata_link *link, const unsigned long *params,
 int sata_link_resume(struct ata_link *link, const unsigned long *params,
                     unsigned long deadline)
 {
+       int tries = ATA_LINK_RESUME_TRIES;
        u32 scontrol, serror;
        int rc;
 
        if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
                return rc;
 
-       scontrol = (scontrol & 0x0f0) | 0x300;
+       /*
+        * Writes to SControl sometimes get ignored under certain
+        * controllers (ata_piix SIDPR).  Make sure DET actually is
+        * cleared.
+        */
+       do {
+               scontrol = (scontrol & 0x0f0) | 0x300;
+               if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
+                       return rc;
+               /*
+                * Some PHYs react badly if SStatus is pounded
+                * immediately after resuming.  Delay 200ms before
+                * debouncing.
+                */
+               msleep(200);
 
-       if ((rc = sata_scr_write(link, SCR_CONTROL, scontrol)))
-               return rc;
+               /* is SControl restored correctly? */
+               if ((rc = sata_scr_read(link, SCR_CONTROL, &scontrol)))
+                       return rc;
+       } while ((scontrol & 0xf0f) != 0x300 && --tries);
 
-       /* Some PHYs react badly if SStatus is pounded immediately
-        * after resuming.  Delay 200ms before debouncing.
-        */
-       msleep(200);
+       if ((scontrol & 0xf0f) != 0x300) {
+               ata_link_printk(link, KERN_ERR,
+                               "failed to resume link (SControl %X)\n",
+                               scontrol);
+               return 0;
+       }
+
+       if (tries < ATA_LINK_RESUME_TRIES)
+               ata_link_printk(link, KERN_WARNING,
+                               "link resume succeeded after %d retries\n",
+                               ATA_LINK_RESUME_TRIES - tries);
 
        if ((rc = sata_link_debounce(link, params, deadline)))
                return rc;
@@ -4060,6 +4158,7 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
                       unsigned int readid_flags)
 {
        u64 n_sectors = dev->n_sectors;
+       u64 n_native_sectors = dev->n_native_sectors;
        int rc;
 
        if (!ata_dev_enabled(dev))
@@ -4067,7 +4166,9 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
 
        /* fail early if !ATA && !ATAPI to avoid issuing [P]IDENTIFY to PMP */
        if (ata_class_enabled(new_class) &&
-           new_class != ATA_DEV_ATA && new_class != ATA_DEV_ATAPI) {
+           new_class != ATA_DEV_ATA &&
+           new_class != ATA_DEV_ATAPI &&
+           new_class != ATA_DEV_SEMB) {
                ata_dev_printk(dev, KERN_INFO, "class mismatch %u != %u\n",
                               dev->class, new_class);
                rc = -ENODEV;
@@ -4087,16 +4188,30 @@ int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
        /* verify n_sectors hasn't changed */
        if (dev->class == ATA_DEV_ATA && n_sectors &&
            dev->n_sectors != n_sectors) {
-               ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch "
+               ata_dev_printk(dev, KERN_WARNING, "n_sectors mismatch "
                               "%llu != %llu\n",
                               (unsigned long long)n_sectors,
                               (unsigned long long)dev->n_sectors);
-
-               /* restore original n_sectors */
-               dev->n_sectors = n_sectors;
-
-               rc = -ENODEV;
-               goto fail;
+               /*
+                * 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;
+               }
        }
 
        return 0;
@@ -4245,6 +4360,9 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "WDC WD2500JD-00HBB0", "WD-WMAL71490727", ATA_HORKAGE_BROKEN_HPA },
        { "MAXTOR 6L080L4",     "A93.0500",     ATA_HORKAGE_BROKEN_HPA },
 
+       /* this one allows HPA unlocking but fails IOs on the area */
+       { "OCZ-VERTEX",             "1.30",     ATA_HORKAGE_BROKEN_HPA },
+
        /* Devices which report 1 sector over size HPA */
        { "ST340823A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
        { "ST320413A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
@@ -4266,6 +4384,12 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* Devices which aren't very happy with higher link speeds */
        { "WD My Book",                 NULL,   ATA_HORKAGE_1_5_GBPS, },
 
+       /*
+        * Devices which choke on SETXFER.  Applies only if both the
+        * device and controller are SATA.
+        */
+       { "PIONEER DVD-RW  DVRTD08",    "1.00", ATA_HORKAGE_NOSETXFER },
+
        /* End Marker */
        { }
 };
@@ -4825,10 +4949,11 @@ struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev)
  */
 void ata_qc_free(struct ata_queued_cmd *qc)
 {
-       struct ata_port *ap = qc->ap;
+       struct ata_port *ap;
        unsigned int tag;
 
        WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
+       ap = qc->ap;
 
        qc->flags = 0;
        tag = qc->tag;
@@ -4840,11 +4965,13 @@ void ata_qc_free(struct ata_queued_cmd *qc)
 
 void __ata_qc_complete(struct ata_queued_cmd *qc)
 {
-       struct ata_port *ap = qc->ap;
-       struct ata_link *link = qc->dev->link;
+       struct ata_port *ap;
+       struct ata_link *link;
 
        WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
        WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
+       ap = qc->ap;
+       link = qc->dev->link;
 
        if (likely(qc->flags & ATA_QCFLAG_DMAMAP))
                ata_sg_clean(qc);
@@ -4930,20 +5057,22 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
                struct ata_device *dev = qc->dev;
                struct ata_eh_info *ehi = &dev->link->eh_info;
 
-               WARN_ON_ONCE(ap->pflags & ATA_PFLAG_FROZEN);
-
                if (unlikely(qc->err_mask))
                        qc->flags |= ATA_QCFLAG_FAILED;
 
                if (unlikely(qc->flags & ATA_QCFLAG_FAILED)) {
-                       if (!ata_tag_internal(qc->tag)) {
-                               /* always fill result TF for failed qc */
-                               fill_result_tf(qc);
+                       /* always fill result TF for failed qc */
+                       fill_result_tf(qc);
+
+                       if (!ata_tag_internal(qc->tag))
                                ata_qc_schedule_eh(qc);
-                               return;
-                       }
+                       else
+                               __ata_qc_complete(qc);
+                       return;
                }
 
+               WARN_ON_ONCE(ap->pflags & ATA_PFLAG_FROZEN);
+
                /* read result TF if requested */
                if (qc->flags & ATA_QCFLAG_RESULT_TF)
                        fill_result_tf(qc);
@@ -5005,7 +5134,6 @@ int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active)
 {
        int nr_done = 0;
        u32 done_mask;
-       int i;
 
        done_mask = ap->qc_active ^ qc_active;
 
@@ -5015,16 +5143,16 @@ int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active)
                return -EINVAL;
        }
 
-       for (i = 0; i < ATA_MAX_QUEUE; i++) {
+       while (done_mask) {
                struct ata_queued_cmd *qc;
+               unsigned int tag = __ffs(done_mask);
 
-               if (!(done_mask & (1 << i)))
-                       continue;
-
-               if ((qc = ata_qc_from_tag(ap, i))) {
+               qc = ata_qc_from_tag(ap, tag);
+               if (qc) {
                        ata_qc_complete(qc);
                        nr_done++;
                }
+               done_mask &= ~(1 << tag);
        }
 
        return nr_done;
@@ -5498,6 +5626,9 @@ void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp)
 
                dev->link = link;
                dev->devno = dev - link->device;
+#ifdef CONFIG_ATA_ACPI
+               dev->gtf_filter = ata_acpi_gtf_filter;
+#endif
                ata_dev_init(dev);
        }
 }
@@ -6101,13 +6232,11 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
                        ata_port_printk(ap, KERN_INFO, "DUMMY\n");
        }
 
-       /* perform each probe synchronously */
-       DPRINTK("probe begin\n");
+       /* perform each probe asynchronously */
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
                async_schedule(async_port_probe, ap);
        }
-       DPRINTK("probe end\n");
 
        return 0;
 }
@@ -6517,6 +6646,13 @@ static int __init ata_init(void)
 {
        ata_parse_force_param();
 
+       /*
+        * 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;