libata: improve AC_ERR_DEV handling for ->post_internal_cmd
[safe/jmp/linux-2.6] / drivers / ata / libata-core.c
index 2e8ca65..2f2884b 100644 (file)
@@ -59,7 +59,7 @@
 
 #include "libata.h"
 
-#define DRV_VERSION    "2.10"  /* must be exactly four chars */
+#define DRV_VERSION    "2.20"  /* must be exactly four chars */
 
 
 /* debounce timing parameters in msecs { interval, duration, timeout } */
@@ -72,7 +72,7 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
 static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
 static void ata_dev_xfermask(struct ata_device *dev);
 
-static unsigned int ata_unique_id = 1;
+static unsigned int ata_print_id = 1;
 static struct workqueue_struct *ata_wq;
 
 struct workqueue_struct *ata_aux_wq;
@@ -93,6 +93,10 @@ static int ata_probe_timeout = ATA_TMOUT_INTERNAL / HZ;
 module_param(ata_probe_timeout, int, 0444);
 MODULE_PARM_DESC(ata_probe_timeout, "Set ATA probing timeout (seconds)");
 
+int libata_noacpi = 1;
+module_param_named(noacpi, libata_noacpi, int, 0444);
+MODULE_PARM_DESC(noacpi, "Disables the use of ACPI in suspend/resume when set");
+
 MODULE_AUTHOR("Jeff Garzik");
 MODULE_DESCRIPTION("Library module for ATA devices");
 MODULE_LICENSE("GPL");
@@ -311,9 +315,7 @@ int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
        tf->flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
        tf->flags |= tf_flags;
 
-       if ((dev->flags & (ATA_DFLAG_PIO | ATA_DFLAG_NCQ_OFF |
-                          ATA_DFLAG_NCQ)) == ATA_DFLAG_NCQ &&
-           likely(tag != ATA_TAG_INTERNAL)) {
+       if (ata_ncq_enabled(dev) && likely(tag != ATA_TAG_INTERNAL)) {
                /* yay, NCQ */
                if (!lba_48_ok(block, n_block))
                        return -ERANGE;
@@ -596,6 +598,8 @@ void ata_dev_disable(struct ata_device *dev)
 {
        if (ata_dev_enabled(dev) && ata_msg_drv(dev->ap)) {
                ata_dev_printk(dev, KERN_WARNING, "disabled\n");
+               ata_down_xfermask_limit(dev, ATA_DNXFER_FORCE_PIO0 |
+                                            ATA_DNXFER_QUIET);
                dev->class++;
        }
 }
@@ -704,7 +708,7 @@ unsigned int ata_dev_classify(const struct ata_taskfile *tf)
  *     Device type - %ATA_DEV_ATA, %ATA_DEV_ATAPI or %ATA_DEV_NONE.
  */
 
-static unsigned int
+unsigned int
 ata_dev_try_classify(struct ata_port *ap, unsigned int device, u8 *r_err)
 {
        struct ata_taskfile tf;
@@ -820,6 +824,48 @@ static u64 ata_id_n_sectors(const u16 *id)
 }
 
 /**
+ *     ata_id_to_dma_mode      -       Identify DMA mode from id block
+ *     @dev: device to identify
+ *     @unknown: mode to assume if we cannot tell
+ *
+ *     Set up the timing values for the device based upon the identify
+ *     reported values for the DMA mode. This function is used by drivers
+ *     which rely upon firmware configured modes, but wish to report the
+ *     mode correctly when possible.
+ *
+ *     In addition we emit similarly formatted messages to the default
+ *     ata_dev_set_mode handler, in order to provide consistency of
+ *     presentation.
+ */
+
+void ata_id_to_dma_mode(struct ata_device *dev, u8 unknown)
+{
+       unsigned int mask;
+       u8 mode;
+
+       /* Pack the DMA modes */
+       mask = ((dev->id[63] >> 8) << ATA_SHIFT_MWDMA) & ATA_MASK_MWDMA;
+       if (dev->id[53] & 0x04)
+               mask |= ((dev->id[88] >> 8) << ATA_SHIFT_UDMA) & ATA_MASK_UDMA;
+
+       /* Select the mode in use */
+       mode = ata_xfer_mask2mode(mask);
+
+       if (mode != 0) {
+               ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
+                      ata_mode_string(mask));
+       } else {
+               /* SWDMA perhaps ? */
+               mode = unknown;
+               ata_dev_printk(dev, KERN_INFO, "configured for DMA\n");
+       }
+
+       /* Configure the device reporting */
+       dev->xfer_mode = mode;
+       dev->xfer_shift = ata_xfer_mode2shift(mode);
+}
+
+/**
  *     ata_noop_dev_select - Select device 0/1 on ATA bus
  *     @ap: ATA channel to manipulate
  *     @device: ATA device (numbered from zero) to select
@@ -887,8 +933,8 @@ void ata_dev_select(struct ata_port *ap, unsigned int device,
                           unsigned int wait, unsigned int can_sleep)
 {
        if (ata_msg_probe(ap))
-               ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, ata%u: "
-                               "device %u, wait %u\n", ap->id, device, wait);
+               ata_port_printk(ap, KERN_INFO, "ata_dev_select: ENTER, "
+                               "device %u, wait %u\n", device, wait);
 
        if (wait)
                ata_wait_idle(ap);
@@ -1224,12 +1270,16 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
        if (ap->ops->post_internal_cmd)
                ap->ops->post_internal_cmd(qc);
 
-       if ((qc->flags & ATA_QCFLAG_FAILED) && !qc->err_mask) {
-               if (ata_msg_warn(ap))
-                       ata_dev_printk(dev, KERN_WARNING,
-                               "zero err_mask for failed "
-                               "internal command, assuming AC_ERR_OTHER\n");
-               qc->err_mask |= AC_ERR_OTHER;
+       /* perform minimal error analysis */
+       if (qc->flags & ATA_QCFLAG_FAILED) {
+               if (qc->result_tf.command & (ATA_ERR | ATA_DF))
+                       qc->err_mask |= AC_ERR_DEV;
+
+               if (!qc->err_mask)
+                       qc->err_mask |= AC_ERR_OTHER;
+
+               if (qc->err_mask & ~AC_ERR_OTHER)
+                       qc->err_mask &= ~AC_ERR_OTHER;
        }
 
        /* finish up */
@@ -1333,30 +1383,44 @@ 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)
 {
-       int pio;
-       int speed = adev->pio_mode - XFER_PIO_0;
-
-       if (speed < 2)
+       /* Controller doesn't support  IORDY. Probably a pointless check
+          as the caller should know this */
+       if (adev->ap->flags & ATA_FLAG_NO_IORDY)
                return 0;
-       if (speed > 2)
+       /* PIO3 and higher it is mandatory */
+       if (adev->pio_mode > XFER_PIO_2)
                return 1;
+       /* We turn it on when possible */
+       if (ata_id_has_iordy(adev->id))
+               return 1;
+       return 0;
+}
 
+/**
+ *     ata_pio_mask_no_iordy   -       Return the non IORDY mask
+ *     @adev: ATA device
+ *
+ *     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 */
-
        if (adev->id[ATA_ID_FIELD_VALID] & 2) { /* EIDE */
-               pio = adev->id[ATA_ID_EIDE_PIO];
+               u16 pio = adev->id[ATA_ID_EIDE_PIO];
                /* Is the speed faster than the drive allows non IORDY ? */
                if (pio) {
                        /* This is cycle times not frequency - watch the logic! */
                        if (pio > 240)  /* PIO2 is 240nS per cycle */
-                               return 1;
-                       return 0;
+                               return 3 << ATA_SHIFT_PIO;
+                       return 7 << ATA_SHIFT_PIO;
                }
        }
-       return 0;
+       return 3 << ATA_SHIFT_PIO;
 }
 
 /**
@@ -1388,8 +1452,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        int rc;
 
        if (ata_msg_ctl(ap))
-               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n",
-                              __FUNCTION__, ap->id, dev->devno);
+               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
 
        ata_dev_select(ap, dev->devno, 1, 1); /* select device 0/1 */
 
@@ -1410,14 +1473,23 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
        }
 
        tf.protocol = ATA_PROT_PIO;
-       tf.flags |= ATA_TFLAG_POLLING; /* for polling presence detection */
+
+       /* Some devices choke if TF registers contain garbage.  Make
+        * sure those are properly initialized.
+        */
+       tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
+
+       /* Device presence detection is unreliable on some
+        * controllers.  Always poll IDENTIFY if available.
+        */
+       tf.flags |= ATA_TFLAG_POLLING;
 
        err_mask = ata_exec_internal(dev, &tf, NULL, DMA_FROM_DEVICE,
                                     id, sizeof(id[0]) * ATA_ID_WORDS);
        if (err_mask) {
                if (err_mask & AC_ERR_NODEV_HINT) {
                        DPRINTK("ata%u.%d: NODEV after polling detection\n",
-                               ap->id, dev->devno);
+                               ap->print_id, dev->devno);
                        return -ENOENT;
                }
 
@@ -1506,20 +1578,6 @@ static void ata_dev_config_ncq(struct ata_device *dev,
                snprintf(desc, desc_sz, "NCQ (depth %d/%d)", hdepth, ddepth);
 }
 
-static void ata_set_port_max_cmd_len(struct ata_port *ap)
-{
-       int i;
-
-       if (ap->scsi_host) {
-               unsigned int len = 0;
-
-               for (i = 0; i < ATA_MAX_DEVICES; i++)
-                       len = max(len, ap->device[i].cdb_len);
-
-               ap->scsi_host->max_cmd_len = len;
-       }
-}
-
 /**
  *     ata_dev_configure - Configure the specified ATA/ATAPI device
  *     @dev: Target device to configure
@@ -1540,18 +1598,28 @@ int ata_dev_configure(struct ata_device *dev)
        const u16 *id = dev->id;
        unsigned int xfer_mask;
        char revbuf[7];         /* XYZ-99\0 */
+       char fwrevbuf[ATA_ID_FW_REV_LEN+1];
+       char modelbuf[ATA_ID_PROD_LEN+1];
        int rc;
 
        if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
-               ata_dev_printk(dev, KERN_INFO,
-                              "%s: ENTER/EXIT (host %u, dev %u) -- nodev\n",
-                              __FUNCTION__, ap->id, dev->devno);
+               ata_dev_printk(dev, KERN_INFO, "%s: ENTER/EXIT -- nodev\n",
+                              __FUNCTION__);
                return 0;
        }
 
        if (ata_msg_probe(ap))
-               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER, host %u, dev %u\n",
-                              __FUNCTION__, ap->id, dev->devno);
+               ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
+
+       /* set _SDD */
+       rc = ata_acpi_push_id(ap, dev->devno);
+       if (rc) {
+               ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n",
+                       rc);
+       }
+
+       /* retrieve and execute the ATA task file of _GTF */
+       ata_acpi_exec_tfs(ap);
 
        /* print device capabilities */
        if (ata_msg_probe(ap))
@@ -1585,8 +1653,9 @@ int ata_dev_configure(struct ata_device *dev)
        if (dev->class == ATA_DEV_ATA) {
                if (ata_id_is_cfa(id)) {
                        if (id[162] & 1) /* CPRM may make this media unusable */
-                               ata_dev_printk(dev, KERN_WARNING, "ata%u: device %u  supports DRM functions and may not be fully accessable.\n",
-                                       ap->id, dev->devno);
+                               ata_dev_printk(dev, KERN_WARNING,
+                                              "supports DRM functions and may "
+                                              "not be fully accessable.\n");
                        snprintf(revbuf, 7, "CFA");
                }
                else
@@ -1594,6 +1663,16 @@ int ata_dev_configure(struct ata_device *dev)
 
                dev->n_sectors = ata_id_n_sectors(id);
 
+               /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
+               ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
+                               sizeof(fwrevbuf));
+
+               ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD,
+                               sizeof(modelbuf));
+
+               if (dev->id[59] & 0x100)
+                       dev->multi_count = dev->id[59] & 0xff;
+
                if (ata_id_has_lba(id)) {
                        const char *lba_desc;
                        char ncq_desc[20];
@@ -1613,13 +1692,16 @@ int ata_dev_configure(struct ata_device *dev)
                        ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
 
                        /* print device info to dmesg */
-                       if (ata_msg_drv(ap) && print_info)
-                               ata_dev_printk(dev, KERN_INFO, "%s, "
-                                       "max %s, %Lu sectors: %s %s\n",
-                                       revbuf,
-                                       ata_mode_string(xfer_mask),
+                       if (ata_msg_drv(ap) && print_info) {
+                               ata_dev_printk(dev, KERN_INFO,
+                                       "%s: %s, %s, max %s\n",
+                                       revbuf, modelbuf, fwrevbuf,
+                                       ata_mode_string(xfer_mask));
+                               ata_dev_printk(dev, KERN_INFO,
+                                       "%Lu sectors, multi %u: %s %s\n",
                                        (unsigned long long)dev->n_sectors,
-                                       lba_desc, ncq_desc);
+                                       dev->multi_count, lba_desc, ncq_desc);
+                       }
                } else {
                        /* CHS */
 
@@ -1636,22 +1718,17 @@ int ata_dev_configure(struct ata_device *dev)
                        }
 
                        /* print device info to dmesg */
-                       if (ata_msg_drv(ap) && print_info)
-                               ata_dev_printk(dev, KERN_INFO, "%s, "
-                                       "max %s, %Lu sectors: CHS %u/%u/%u\n",
-                                       revbuf,
-                                       ata_mode_string(xfer_mask),
-                                       (unsigned long long)dev->n_sectors,
-                                       dev->cylinders, dev->heads,
-                                       dev->sectors);
-               }
-
-               if (dev->id[59] & 0x100) {
-                       dev->multi_count = dev->id[59] & 0xff;
-                       if (ata_msg_drv(ap) && print_info)
+                       if (ata_msg_drv(ap) && print_info) {
                                ata_dev_printk(dev, KERN_INFO,
-                                       "ata%u: dev %u multi count %u\n",
-                                       ap->id, dev->devno, dev->multi_count);
+                                       "%s: %s, %s, max %s\n",
+                                       revbuf, modelbuf, fwrevbuf,
+                                       ata_mode_string(xfer_mask));
+                               ata_dev_printk(dev, KERN_INFO,
+                                       "%Lu sectors, multi %u, CHS %u/%u/%u\n",
+                                       (unsigned long long)dev->n_sectors,
+                                       dev->multi_count, dev->cylinders,
+                                       dev->heads, dev->sectors);
+                       }
                }
 
                dev->cdb_len = 16;
@@ -1700,8 +1777,6 @@ int ata_dev_configure(struct ata_device *dev)
                }
        }
 
-       ata_set_port_max_cmd_len(ap);
-
        /* limit bridge transfers to udma5, 200 sectors */
        if (ata_dev_knobble(dev)) {
                if (ata_msg_drv(ap) && print_info)
@@ -1711,8 +1786,15 @@ int ata_dev_configure(struct ata_device *dev)
                dev->max_sectors = ATA_MAX_SECTORS;
        }
 
+       if (ata_device_blacklisted(dev) & ATA_HORKAGE_MAX_SEC_128)
+               dev->max_sectors = min(ATA_MAX_SECTORS_128, dev->max_sectors);
+
+       /* limit ATAPI DMA to R/W commands only */
+       if (ata_device_blacklisted(dev) & ATA_HORKAGE_DMA_RW_ONLY)
+               dev->horkage |= ATA_HORKAGE_DMA_RW_ONLY;
+
        if (ap->ops->dev_config)
-               ap->ops->dev_config(ap, dev);
+               ap->ops->dev_config(dev);
 
        if (ata_msg_probe(ap))
                ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n",
@@ -1727,6 +1809,56 @@ err_out_nosup:
 }
 
 /**
+ *     ata_cable_40wire        -       return 40 wire cable type
+ *     @ap: port
+ *
+ *     Helper method for drivers which want to hardwire 40 wire cable
+ *     detection.
+ */
+
+int ata_cable_40wire(struct ata_port *ap)
+{
+       return ATA_CBL_PATA40;
+}
+
+/**
+ *     ata_cable_80wire        -       return 80 wire cable type
+ *     @ap: port
+ *
+ *     Helper method for drivers which want to hardwire 80 wire cable
+ *     detection.
+ */
+
+int ata_cable_80wire(struct ata_port *ap)
+{
+       return ATA_CBL_PATA80;
+}
+
+/**
+ *     ata_cable_unknown       -       return unknown PATA cable.
+ *     @ap: port
+ *
+ *     Helper method for drivers which have no PATA cable detection.
+ */
+
+int ata_cable_unknown(struct ata_port *ap)
+{
+       return ATA_CBL_PATA_UNK;
+}
+
+/**
+ *     ata_cable_sata  -       return SATA cable type
+ *     @ap: port
+ *
+ *     Helper method for drivers which have SATA cables
+ */
+
+int ata_cable_sata(struct ata_port *ap)
+{
+       return ATA_CBL_SATA;
+}
+
+/**
  *     ata_bus_probe - Reset and probe ATA bus
  *     @ap: Bus to probe
  *
@@ -1745,7 +1877,7 @@ int ata_bus_probe(struct ata_port *ap)
 {
        unsigned int classes[ATA_MAX_DEVICES];
        int tries[ATA_MAX_DEVICES];
-       int i, rc, down_xfermask;
+       int i, rc;
        struct ata_device *dev;
 
        ata_port_probe(ap);
@@ -1754,8 +1886,6 @@ int ata_bus_probe(struct ata_port *ap)
                tries[i] = ATA_PROBE_MAX_TRIES;
 
  retry:
-       down_xfermask = 0;
-
        /* reset and determine device classes */
        ap->ops->phy_reset(ap);
 
@@ -1779,8 +1909,11 @@ int ata_bus_probe(struct ata_port *ap)
        for (i = 0; i < ATA_MAX_DEVICES; i++)
                ap->device[i].pio_mode = XFER_PIO_0;
 
-       /* read IDENTIFY page and configure devices */
-       for (i = 0; i < ATA_MAX_DEVICES; i++) {
+       /* 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 */
+
+       for (i = ATA_MAX_DEVICES - 1; i >=  0; i--) {
                dev = &ap->device[i];
 
                if (tries[i])
@@ -1793,6 +1926,19 @@ int ata_bus_probe(struct ata_port *ap)
                                     dev->id);
                if (rc)
                        goto fail;
+       }
+
+       /* Now ask for the cable type as PDIAG- should have been released */
+       if (ap->ops->cable_detect)
+               ap->cbl = ap->ops->cable_detect(ap);
+
+       /* After the identify sequence we can now set up the devices. We do
+          this in the normal order so that the user doesn't get confused */
+
+       for(i = 0; i < ATA_MAX_DEVICES; i++) {
+               dev = &ap->device[i];
+               if (!ata_dev_enabled(dev))
+                       continue;
 
                ap->eh_context.i.flags |= ATA_EHI_PRINTINFO;
                rc = ata_dev_configure(dev);
@@ -1803,10 +1949,8 @@ int ata_bus_probe(struct ata_port *ap)
 
        /* configure transfer mode */
        rc = ata_set_mode(ap, &dev);
-       if (rc) {
-               down_xfermask = 1;
+       if (rc)
                goto fail;
-       }
 
        for (i = 0; i < ATA_MAX_DEVICES; i++)
                if (ata_dev_enabled(&ap->device[i]))
@@ -1818,25 +1962,29 @@ int ata_bus_probe(struct ata_port *ap)
        return -ENODEV;
 
  fail:
+       tries[dev->devno]--;
+
        switch (rc) {
        case -EINVAL:
-       case -ENODEV:
+               /* eeek, something went very wrong, give up */
                tries[dev->devno] = 0;
                break;
+
+       case -ENODEV:
+               /* give it just one more chance */
+               tries[dev->devno] = min(tries[dev->devno], 1);
        case -EIO:
-               sata_down_spd_limit(ap);
-               /* fall through */
-       default:
-               tries[dev->devno]--;
-               if (down_xfermask &&
-                   ata_down_xfermask_limit(dev, tries[dev->devno] == 1))
-                       tries[dev->devno] = 0;
+               if (tries[dev->devno] == 1) {
+                       /* This is the last chance, better to slow
+                        * down than lose it.
+                        */
+                       sata_down_spd_limit(ap);
+                       ata_down_xfermask_limit(dev, ATA_DNXFER_PIO);
+               }
        }
 
-       if (!tries[dev->devno]) {
-               ata_down_xfermask_limit(dev, 1);
+       if (!tries[dev->devno])
                ata_dev_disable(dev);
-       }
 
        goto retry;
 }
@@ -1866,7 +2014,7 @@ void ata_port_probe(struct ata_port *ap)
  *     LOCKING:
  *     None.
  */
-static void sata_print_link_status(struct ata_port *ap)
+void sata_print_link_status(struct ata_port *ap)
 {
        u32 sstatus, scontrol, tmp;
 
@@ -2267,7 +2415,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
 /**
  *     ata_down_xfermask_limit - adjust dev xfer masks downward
  *     @dev: Device to adjust xfer masks
- *     @force_pio0: Force PIO0
+ *     @sel: ATA_DNXFER_* selector
  *
  *     Adjust xfer masks of @dev downward.  Note that this function
  *     does not apply the change.  Invoking ata_set_mode() afterwards
@@ -2279,37 +2427,78 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
  *     RETURNS:
  *     0 on success, negative errno on failure
  */
-int ata_down_xfermask_limit(struct ata_device *dev, int force_pio0)
+int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel)
 {
-       unsigned long xfer_mask;
-       int highbit;
+       char buf[32];
+       unsigned int orig_mask, xfer_mask;
+       unsigned int pio_mask, mwdma_mask, udma_mask;
+       int quiet, highbit;
 
-       xfer_mask = ata_pack_xfermask(dev->pio_mask, dev->mwdma_mask,
-                                     dev->udma_mask);
+       quiet = !!(sel & ATA_DNXFER_QUIET);
+       sel &= ~ATA_DNXFER_QUIET;
 
-       if (!xfer_mask)
-               goto fail;
-       /* don't gear down to MWDMA from UDMA, go directly to PIO */
-       if (xfer_mask & ATA_MASK_UDMA)
-               xfer_mask &= ~ATA_MASK_MWDMA;
+       xfer_mask = orig_mask = ata_pack_xfermask(dev->pio_mask,
+                                                 dev->mwdma_mask,
+                                                 dev->udma_mask);
+       ata_unpack_xfermask(xfer_mask, &pio_mask, &mwdma_mask, &udma_mask);
 
-       highbit = fls(xfer_mask) - 1;
-       xfer_mask &= ~(1 << highbit);
-       if (force_pio0)
-               xfer_mask &= 1 << ATA_SHIFT_PIO;
-       if (!xfer_mask)
-               goto fail;
+       switch (sel) {
+       case ATA_DNXFER_PIO:
+               highbit = fls(pio_mask) - 1;
+               pio_mask &= ~(1 << highbit);
+               break;
+
+       case ATA_DNXFER_DMA:
+               if (udma_mask) {
+                       highbit = fls(udma_mask) - 1;
+                       udma_mask &= ~(1 << highbit);
+                       if (!udma_mask)
+                               return -ENOENT;
+               } else if (mwdma_mask) {
+                       highbit = fls(mwdma_mask) - 1;
+                       mwdma_mask &= ~(1 << highbit);
+                       if (!mwdma_mask)
+                               return -ENOENT;
+               }
+               break;
+
+       case ATA_DNXFER_40C:
+               udma_mask &= ATA_UDMA_MASK_40C;
+               break;
+
+       case ATA_DNXFER_FORCE_PIO0:
+               pio_mask &= 1;
+       case ATA_DNXFER_FORCE_PIO:
+               mwdma_mask = 0;
+               udma_mask = 0;
+               break;
+
+       default:
+               BUG();
+       }
+
+       xfer_mask &= ata_pack_xfermask(pio_mask, mwdma_mask, udma_mask);
+
+       if (!(xfer_mask & ATA_MASK_PIO) || xfer_mask == orig_mask)
+               return -ENOENT;
+
+       if (!quiet) {
+               if (xfer_mask & (ATA_MASK_MWDMA | ATA_MASK_UDMA))
+                       snprintf(buf, sizeof(buf), "%s:%s",
+                                ata_mode_string(xfer_mask),
+                                ata_mode_string(xfer_mask & ATA_MASK_PIO));
+               else
+                       snprintf(buf, sizeof(buf), "%s",
+                                ata_mode_string(xfer_mask));
+
+               ata_dev_printk(dev, KERN_WARNING,
+                              "limiting speed to %s\n", buf);
+       }
 
        ata_unpack_xfermask(xfer_mask, &dev->pio_mask, &dev->mwdma_mask,
                            &dev->udma_mask);
 
-       ata_dev_printk(dev, KERN_WARNING, "limiting speed to %s\n",
-                      ata_mode_string(xfer_mask));
-
        return 0;
-
- fail:
-       return -EINVAL;
 }
 
 static int ata_dev_set_mode(struct ata_device *dev)
@@ -2323,6 +2512,10 @@ static int ata_dev_set_mode(struct ata_device *dev)
                dev->flags |= ATA_DFLAG_PIO;
 
        err_mask = ata_dev_set_xfermode(dev);
+       /* Old CFA may refuse this command, which is just fine */
+       if (dev->xfer_shift == ATA_SHIFT_PIO && ata_id_is_cfa(dev->id))
+               err_mask &= ~AC_ERR_DEV;
+
        if (err_mask) {
                ata_dev_printk(dev, KERN_ERR, "failed to set xfermode "
                               "(err_mask=0x%x)\n", err_mask);
@@ -2344,12 +2537,13 @@ static int ata_dev_set_mode(struct ata_device *dev)
 }
 
 /**
- *     ata_set_mode - Program timings and issue SET FEATURES - XFER
+ *     ata_do_set_mode - Program timings and issue SET FEATURES - XFER
  *     @ap: port on which timings will be programmed
  *     @r_failed_dev: out paramter for failed device
  *
- *     Set ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
- *     ata_set_mode() fails, pointer to the failing device is
+ *     Standard implementation of the function used to tune and set
+ *     ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
+ *     ata_dev_set_mode() fails, pointer to the failing device is
  *     returned in @r_failed_dev.
  *
  *     LOCKING:
@@ -2358,14 +2552,12 @@ static int ata_dev_set_mode(struct ata_device *dev)
  *     RETURNS:
  *     0 on success, negative errno otherwise
  */
-int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
+
+int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
 {
        struct ata_device *dev;
        int i, rc = 0, used_dma = 0, found = 0;
 
-       /* has private set_mode? */
-       if (ap->ops->set_mode)
-               return ap->ops->set_mode(ap, r_failed_dev);
 
        /* step 1: calculate xfer_mask */
        for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -2438,12 +2630,11 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
         * host channels are not permitted to do so.
         */
        if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX))
-               ap->host->simplex_claimed = 1;
+               ap->host->simplex_claimed = ap;
 
        /* step5: chip specific finalisation */
        if (ap->ops->post_set_mode)
                ap->ops->post_set_mode(ap);
-
  out:
        if (rc)
                *r_failed_dev = dev;
@@ -2451,6 +2642,29 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
 }
 
 /**
+ *     ata_set_mode - Program timings and issue SET FEATURES - XFER
+ *     @ap: port on which timings will be programmed
+ *     @r_failed_dev: out paramter for failed device
+ *
+ *     Set ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
+ *     ata_set_mode() fails, pointer to the failing device is
+ *     returned in @r_failed_dev.
+ *
+ *     LOCKING:
+ *     PCI/etc. bus probe sem.
+ *
+ *     RETURNS:
+ *     0 on success, negative errno otherwise
+ */
+int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
+{
+       /* has private set_mode? */
+       if (ap->ops->set_mode)
+               return ap->ops->set_mode(ap, r_failed_dev);
+       return ata_do_set_mode(ap, r_failed_dev);
+}
+
+/**
  *     ata_tf_to_host - issue ATA taskfile to host controller
  *     @ap: port to which command is being issued
  *     @tf: ATA taskfile register set
@@ -2572,7 +2786,7 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
 {
        struct ata_ioports *ioaddr = &ap->ioaddr;
 
-       DPRINTK("ata%u: bus reset via SRST\n", ap->id);
+       DPRINTK("ata%u: bus reset via SRST\n", ap->print_id);
 
        /* software reset.  causes dev0 to be selected */
        iowrite8(ap->ctl, ioaddr->ctl_addr);
@@ -2632,7 +2846,7 @@ void ata_bus_reset(struct ata_port *ap)
        u8 err;
        unsigned int dev0, dev1 = 0, devmask = 0;
 
-       DPRINTK("ENTER, host %u, port %u\n", ap->id, ap->port_no);
+       DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no);
 
        /* determine if device 0/1 are present */
        if (ap->flags & ATA_FLAG_SATA_RESET)
@@ -3013,6 +3227,9 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
                return 0;
        }
 
+       /* wait a while before checking status, see SRST for more info */
+       msleep(150);
+
        if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
                ata_port_printk(ap, KERN_ERR,
                                "COMRESET failed (device not ready)\n");
@@ -3216,16 +3433,30 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        { "WPI CDD-820",        NULL,           ATA_HORKAGE_NODMA },
        { "SAMSUNG CD-ROM SC-148C", NULL,       ATA_HORKAGE_NODMA },
        { "SAMSUNG CD-ROM SC",  NULL,           ATA_HORKAGE_NODMA },
-       { "SanDisk SDP3B-64",   NULL,           ATA_HORKAGE_NODMA },
        { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
        { "_NEC DV5800A",       NULL,           ATA_HORKAGE_NODMA },
        { "SAMSUNG CD-ROM SN-124","N001",       ATA_HORKAGE_NODMA },
 
+       /* Weird ATAPI devices */
+       { "TORiSAN DVD-ROM DRD-N216", NULL,     ATA_HORKAGE_MAX_SEC_128 |
+                                               ATA_HORKAGE_DMA_RW_ONLY },
+
        /* Devices we expect to fail diagnostics */
 
        /* Devices where NCQ should be avoided */
        /* NCQ is slow */
         { "WDC WD740ADFD-00",   NULL,          ATA_HORKAGE_NONCQ },
+       /* http://thread.gmane.org/gmane.linux.ide/14907 */
+       { "FUJITSU MHT2060BH",  NULL,           ATA_HORKAGE_NONCQ },
+       /* NCQ is broken */
+       { "Maxtor 6L250S0",     "BANC1G10",     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
+          Windows driver .inf file - also several Linux problem reports */
+       { "HTS541060G9SA00",    "MB3OC60D",     ATA_HORKAGE_NONCQ, },
+       { "HTS541080G9SA00",    "MB4OC60D",     ATA_HORKAGE_NONCQ, },
+       { "HTS541010G9SA00",    "MBZOC60D",     ATA_HORKAGE_NONCQ, },
 
        /* Devices with NCQ limits */
 
@@ -3288,19 +3519,7 @@ static void ata_dev_xfermask(struct ata_device *dev)
        xfer_mask = ata_pack_xfermask(ap->pio_mask,
                                      ap->mwdma_mask, ap->udma_mask);
 
-       /* Apply cable rule here.  Don't apply it early because when
-        * we handle hot plug the cable type can itself change.
-        */
-       if (ap->cbl == ATA_CBL_PATA40)
-               xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
-       /* Apply drive side cable rule. Unknown or 80 pin cables reported
-        * host side are checked drive side as well. Cases where we know a
-        * 40wire cable is used safely for 80 are not checked here.
-        */
-        if (ata_drive_40wire(dev->id) && (ap->cbl == ATA_CBL_PATA_UNK || ap->cbl == ATA_CBL_PATA80))
-               xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
-
-
+       /* drive modes available */
        xfer_mask &= ata_pack_xfermask(dev->pio_mask,
                                       dev->mwdma_mask, dev->udma_mask);
        xfer_mask &= ata_id_xfermask(dev->id);
@@ -3322,14 +3541,37 @@ static void ata_dev_xfermask(struct ata_device *dev)
                               "device is on DMA blacklist, disabling DMA\n");
        }
 
-       if ((host->flags & ATA_HOST_SIMPLEX) && host->simplex_claimed) {
+       if ((host->flags & ATA_HOST_SIMPLEX) &&
+            host->simplex_claimed && host->simplex_claimed != ap) {
                xfer_mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
                ata_dev_printk(dev, KERN_WARNING, "simplex DMA is claimed by "
                               "other device, disabling DMA\n");
        }
 
+       if (ap->flags & ATA_FLAG_NO_IORDY)
+               xfer_mask &= ata_pio_mask_no_iordy(dev);
+
        if (ap->ops->mode_filter)
-               xfer_mask = ap->ops->mode_filter(ap, dev, xfer_mask);
+               xfer_mask = ap->ops->mode_filter(dev, xfer_mask);
+
+       /* Apply cable rule here.  Don't apply it early because when
+        * we handle hot plug the cable type can itself change.
+        * Check this last so that we know if the transfer rate was
+        * solely limited by the cable.
+        * Unknown or 80 wire cables reported host side are checked
+        * drive side as well. Cases where we know a 40wire cable
+        * is used safely for 80 are not checked here.
+        */
+       if (xfer_mask & (0xF8 << ATA_SHIFT_UDMA))
+               /* UDMA/44 or higher would be available */
+               if((ap->cbl == ATA_CBL_PATA40) ||
+                   (ata_drive_40wire(dev->id) &&
+                    (ap->cbl == ATA_CBL_PATA_UNK ||
+                     ap->cbl == ATA_CBL_PATA80))) {
+                       ata_dev_printk(dev, KERN_WARNING,
+                                "limited to UDMA/33 due to 40-wire cable\n");
+                       xfer_mask &= ~(0xF8 << ATA_SHIFT_UDMA);
+               }
 
        ata_unpack_xfermask(xfer_mask, &dev->pio_mask,
                            &dev->mwdma_mask, &dev->udma_mask);
@@ -3536,6 +3778,26 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
        struct ata_port *ap = qc->ap;
        int rc = 0; /* Assume ATAPI DMA is OK by default */
 
+       /* some drives can only do ATAPI DMA on read/write */
+       if (unlikely(qc->dev->horkage & ATA_HORKAGE_DMA_RW_ONLY)) {
+               struct scsi_cmnd *cmd = qc->scsicmd;
+               u8 *scsicmd = cmd->cmnd;
+
+               switch (scsicmd[0]) {
+               case READ_10:
+               case WRITE_10:
+               case READ_12:
+               case WRITE_12:
+               case READ_6:
+               case WRITE_6:
+                       /* atapi dma maybe ok */
+                       break;
+               default:
+                       /* turn off atapi dma */
+                       return 1;
+               }
+       }
+
        if (ap->ops->check_atapi_dma)
                rc = ap->ops->check_atapi_dma(qc);
 
@@ -3699,7 +3961,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
        struct scatterlist *lsg = &sg[qc->n_elem - 1];
        int n_elem, pre_n_elem, dir, trim_sg = 0;
 
-       VPRINTK("ENTER, ata%u\n", ap->id);
+       VPRINTK("ENTER, ata%u\n", ap->print_id);
        WARN_ON(!(qc->flags & ATA_QCFLAG_SG));
 
        /* we must lengthen transfers to end on a 32-bit boundary */
@@ -3848,10 +4110,10 @@ void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
 
 
 /**
- *     ata_pio_sector - Transfer ATA_SECT_SIZE (512 bytes) of data.
+ *     ata_pio_sector - Transfer a sector of data.
  *     @qc: Command on going
  *
- *     Transfer ATA_SECT_SIZE of data from/to the ATA device.
+ *     Transfer qc->sect_size bytes of data from/to the ATA device.
  *
  *     LOCKING:
  *     Inherited from caller.
@@ -3866,7 +4128,7 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
        unsigned int offset;
        unsigned char *buf;
 
-       if (qc->curbytes == qc->nbytes - ATA_SECT_SIZE)
+       if (qc->curbytes == qc->nbytes - qc->sect_size)
                ap->hsm_task_state = HSM_ST_LAST;
 
        page = sg[qc->cursg].page;
@@ -3886,17 +4148,17 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
                buf = kmap_atomic(page, KM_IRQ0);
 
                /* do the actual data transfer */
-               ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write);
+               ap->ops->data_xfer(qc->dev, buf + offset, qc->sect_size, do_write);
 
                kunmap_atomic(buf, KM_IRQ0);
                local_irq_restore(flags);
        } else {
                buf = page_address(page);
-               ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write);
+               ap->ops->data_xfer(qc->dev, buf + offset, qc->sect_size, do_write);
        }
 
-       qc->curbytes += ATA_SECT_SIZE;
-       qc->cursg_ofs += ATA_SECT_SIZE;
+       qc->curbytes += qc->sect_size;
+       qc->cursg_ofs += qc->sect_size;
 
        if (qc->cursg_ofs == (&sg[qc->cursg])->length) {
                qc->cursg++;
@@ -3905,10 +4167,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
 }
 
 /**
- *     ata_pio_sectors - Transfer one or many 512-byte sectors.
+ *     ata_pio_sectors - Transfer one or many sectors.
  *     @qc: Command on going
  *
- *     Transfer one or many ATA_SECT_SIZE of data from/to the
+ *     Transfer one or many sectors of data from/to the
  *     ATA device for the DRQ request.
  *
  *     LOCKING:
@@ -3923,7 +4185,7 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
 
                WARN_ON(qc->dev->multi_count == 0);
 
-               nsect = min((qc->nbytes - qc->curbytes) / ATA_SECT_SIZE,
+               nsect = min((qc->nbytes - qc->curbytes) / qc->sect_size,
                            qc->dev->multi_count);
                while (nsect--)
                        ata_pio_sector(qc);
@@ -4100,7 +4362,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
        if (do_write != i_write)
                goto err_out;
 
-       VPRINTK("ata%u: xfering %d bytes\n", ap->id, bytes);
+       VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes);
 
        __atapi_pio_bytes(qc, bytes);
 
@@ -4217,7 +4479,7 @@ int ata_hsm_move(struct ata_port *ap, struct ata_queued_cmd *qc,
 
 fsm_start:
        DPRINTK("ata%u: protocol %d task_state %d (dev_stat 0x%X)\n",
-               ap->id, qc->tf.protocol, ap->hsm_task_state, status);
+               ap->print_id, qc->tf.protocol, ap->hsm_task_state, status);
 
        switch (ap->hsm_task_state) {
        case HSM_ST_FIRST:
@@ -4250,8 +4512,8 @@ fsm_start:
                 * let the EH abort the command or reset the device.
                 */
                if (unlikely(status & (ATA_ERR | ATA_DF))) {
-                       printk(KERN_WARNING "ata%d: DRQ=1 with device error, dev_stat 0x%X\n",
-                              ap->id, status);
+                       ata_port_printk(ap, KERN_WARNING, "DRQ=1 with device "
+                                       "error, dev_stat 0x%X\n", status);
                        qc->err_mask |= AC_ERR_HSM;
                        ap->hsm_task_state = HSM_ST_ERR;
                        goto fsm_start;
@@ -4308,8 +4570,9 @@ fsm_start:
                         * let the EH abort the command or reset the device.
                         */
                        if (unlikely(status & (ATA_ERR | ATA_DF))) {
-                               printk(KERN_WARNING "ata%d: DRQ=1 with device error, dev_stat 0x%X\n",
-                                      ap->id, status);
+                               ata_port_printk(ap, KERN_WARNING, "DRQ=1 with "
+                                               "device error, dev_stat 0x%X\n",
+                                               status);
                                qc->err_mask |= AC_ERR_HSM;
                                ap->hsm_task_state = HSM_ST_ERR;
                                goto fsm_start;
@@ -4395,7 +4658,7 @@ fsm_start:
 
                /* no more data to transfer */
                DPRINTK("ata%u: dev %u command complete, drv_stat 0x%x\n",
-                       ap->id, qc->dev->devno, status);
+                       ap->print_id, qc->dev->devno, status);
 
                WARN_ON(qc->err_mask);
 
@@ -4578,8 +4841,8 @@ static void fill_result_tf(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
 
-       ap->ops->tf_read(ap, &qc->result_tf);
        qc->result_tf.flags = qc->tf.flags;
+       ap->ops->tf_read(ap, &qc->result_tf);
 }
 
 /**
@@ -4937,7 +5200,7 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
        u8 status, host_stat = 0;
 
        VPRINTK("ata%u: protocol %d task_state %d\n",
-               ap->id, qc->tf.protocol, ap->hsm_task_state);
+               ap->print_id, qc->tf.protocol, ap->hsm_task_state);
 
        /* Check whether we are expecting interrupt in this state */
        switch (ap->hsm_task_state) {
@@ -4958,7 +5221,8 @@ inline unsigned int ata_host_intr (struct ata_port *ap,
                    qc->tf.protocol == ATA_PROT_ATAPI_DMA) {
                        /* check status of DMA engine */
                        host_stat = ap->ops->bmdma_status(ap);
-                       VPRINTK("ata%u: host_stat 0x%X\n", ap->id, host_stat);
+                       VPRINTK("ata%u: host_stat 0x%X\n",
+                               ap->print_id, host_stat);
 
                        /* if it's not our irq... */
                        if (!(host_stat & ATA_DMA_INTR))
@@ -5219,6 +5483,7 @@ int ata_flush_cache(struct ata_device *dev)
        return 0;
 }
 
+#ifdef CONFIG_PM
 static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg,
                               unsigned int action, unsigned int ehi_flags,
                               int wait)
@@ -5334,6 +5599,7 @@ void ata_host_resume(struct ata_host *host)
                            ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET, 0);
        host->dev->power.power_state = PMSG_ON;
 }
+#endif
 
 /**
  *     ata_port_start - Set port up for dma.
@@ -5417,7 +5683,7 @@ void ata_port_init(struct ata_port *ap, struct ata_host *host,
 
        ap->lock = &host->lock;
        ap->flags = ATA_FLAG_DISABLED;
-       ap->id = ata_unique_id++;
+       ap->print_id = ata_print_id++;
        ap->ctl = ATA_DEVCTL_OBS;
        ap->host = host;
        ap->dev = ent->dev;
@@ -5488,11 +5754,11 @@ static void ata_port_init_shost(struct ata_port *ap, struct Scsi_Host *shost)
 {
        ap->scsi_host = shost;
 
-       shost->unique_id = ap->id;
+       shost->unique_id = ap->print_id;
        shost->max_id = 16;
        shost->max_lun = 1;
        shost->max_channel = 1;
-       shost->max_cmd_len = 12;
+       shost->max_cmd_len = 16;
 }
 
 /**
@@ -5547,17 +5813,23 @@ static void ata_host_release(struct device *gendev, void *res)
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
 
-               if (!ap)
-                       continue;
-
-               if (ap->ops->port_stop)
+               if (ap && ap->ops->port_stop)
                        ap->ops->port_stop(ap);
-
-               scsi_host_put(ap->scsi_host);
        }
 
        if (host->ops->host_stop)
                host->ops->host_stop(host);
+
+       for (i = 0; i < host->n_ports; i++) {
+               struct ata_port *ap = host->ports[i];
+
+               if (ap)
+                       scsi_host_put(ap->scsi_host);
+
+               host->ports[i] = NULL;
+       }
+
+       dev_set_drvdata(gendev, NULL);
 }
 
 /**
@@ -5752,9 +6024,9 @@ int ata_device_add(const struct ata_probe_ent *ent)
                        /* wait for EH to finish */
                        ata_port_wait_eh(ap);
                } else {
-                       DPRINTK("ata%u: bus probe begin\n", ap->id);
+                       DPRINTK("ata%u: bus probe begin\n", ap->print_id);
                        rc = ata_bus_probe(ap);
-                       DPRINTK("ata%u: bus probe end\n", ap->id);
+                       DPRINTK("ata%u: bus probe end\n", ap->print_id);
 
                        if (rc) {
                                /* FIXME: do something useful here?
@@ -5780,7 +6052,6 @@ int ata_device_add(const struct ata_probe_ent *ent)
 
  err_out:
        devres_release_group(dev, ata_device_add);
-       dev_set_drvdata(dev, NULL);
        VPRINTK("EXIT, returning %d\n", rc);
        return 0;
 }
@@ -5865,11 +6136,7 @@ ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
 {
        struct ata_probe_ent *probe_ent;
 
-       /* XXX - the following if can go away once all LLDs are managed */
-       if (!list_empty(&dev->devres_head))
-               probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
-       else
-               probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
+       probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
        if (!probe_ent) {
                printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
                       kobject_name(&(dev->kobj)));
@@ -5972,14 +6239,14 @@ int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits)
        return (tmp == bits->val) ? 1 : 0;
 }
 
+#ifdef CONFIG_PM
 void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
        pci_save_state(pdev);
+       pci_disable_device(pdev);
 
-       if (mesg.event == PM_EVENT_SUSPEND) {
-               pci_disable_device(pdev);
+       if (mesg.event == PM_EVENT_SUSPEND)
                pci_set_power_state(pdev, PCI_D3hot);
-       }
 }
 
 int ata_pci_device_do_resume(struct pci_dev *pdev)
@@ -6024,6 +6291,8 @@ int ata_pci_device_resume(struct pci_dev *pdev)
                ata_host_resume(host);
        return rc;
 }
+#endif /* CONFIG_PM */
+
 #endif /* CONFIG_PCI */
 
 
@@ -6179,6 +6448,7 @@ EXPORT_SYMBOL_GPL(ata_tf_load);
 EXPORT_SYMBOL_GPL(ata_tf_read);
 EXPORT_SYMBOL_GPL(ata_noop_dev_select);
 EXPORT_SYMBOL_GPL(ata_std_dev_select);
+EXPORT_SYMBOL_GPL(sata_print_link_status);
 EXPORT_SYMBOL_GPL(ata_tf_to_fis);
 EXPORT_SYMBOL_GPL(ata_tf_from_fis);
 EXPORT_SYMBOL_GPL(ata_check_status);
@@ -6186,6 +6456,7 @@ EXPORT_SYMBOL_GPL(ata_altstatus);
 EXPORT_SYMBOL_GPL(ata_exec_command);
 EXPORT_SYMBOL_GPL(ata_port_start);
 EXPORT_SYMBOL_GPL(ata_interrupt);
+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);
@@ -6201,6 +6472,7 @@ EXPORT_SYMBOL_GPL(ata_bmdma_drive_eh);
 EXPORT_SYMBOL_GPL(ata_bmdma_error_handler);
 EXPORT_SYMBOL_GPL(ata_bmdma_post_internal_cmd);
 EXPORT_SYMBOL_GPL(ata_port_probe);
+EXPORT_SYMBOL_GPL(ata_dev_disable);
 EXPORT_SYMBOL_GPL(sata_set_spd);
 EXPORT_SYMBOL_GPL(sata_phy_debounce);
 EXPORT_SYMBOL_GPL(sata_phy_resume);
@@ -6231,10 +6503,13 @@ EXPORT_SYMBOL_GPL(sata_scr_write);
 EXPORT_SYMBOL_GPL(sata_scr_write_flush);
 EXPORT_SYMBOL_GPL(ata_port_online);
 EXPORT_SYMBOL_GPL(ata_port_offline);
+#ifdef CONFIG_PM
 EXPORT_SYMBOL_GPL(ata_host_suspend);
 EXPORT_SYMBOL_GPL(ata_host_resume);
+#endif /* CONFIG_PM */
 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);
 
@@ -6247,16 +6522,20 @@ EXPORT_SYMBOL_GPL(pci_test_config_bits);
 EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
 EXPORT_SYMBOL_GPL(ata_pci_init_one);
 EXPORT_SYMBOL_GPL(ata_pci_remove_one);
+#ifdef CONFIG_PM
 EXPORT_SYMBOL_GPL(ata_pci_device_do_suspend);
 EXPORT_SYMBOL_GPL(ata_pci_device_do_resume);
 EXPORT_SYMBOL_GPL(ata_pci_device_suspend);
 EXPORT_SYMBOL_GPL(ata_pci_device_resume);
+#endif /* CONFIG_PM */
 EXPORT_SYMBOL_GPL(ata_pci_default_filter);
 EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
 #endif /* CONFIG_PCI */
 
+#ifdef CONFIG_PM
 EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
 EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
+#endif /* CONFIG_PM */
 
 EXPORT_SYMBOL_GPL(ata_eng_timeout);
 EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
@@ -6271,3 +6550,9 @@ EXPORT_SYMBOL_GPL(ata_irq_on);
 EXPORT_SYMBOL_GPL(ata_dummy_irq_on);
 EXPORT_SYMBOL_GPL(ata_irq_ack);
 EXPORT_SYMBOL_GPL(ata_dummy_irq_ack);
+EXPORT_SYMBOL_GPL(ata_dev_try_classify);
+
+EXPORT_SYMBOL_GPL(ata_cable_40wire);
+EXPORT_SYMBOL_GPL(ata_cable_80wire);
+EXPORT_SYMBOL_GPL(ata_cable_unknown);
+EXPORT_SYMBOL_GPL(ata_cable_sata);