]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ata/libata-core.c
libata: eliminate the home grown dma padding in favour of
[linux-2.6-omap-h63xx.git] / drivers / ata / libata-core.c
index 865428a64de3fda68d5332bc0492d7b2399db4d5..3587ac3fe3f394bb2e9113672f1d165876ce6a6a 100644 (file)
@@ -950,8 +950,8 @@ unsigned int ata_dev_try_classify(struct ata_device *dev, int present,
        if (r_err)
                *r_err = err;
 
-       /* see if device passed diags: if master then continue and warn later */
-       if (err == 0 && dev->devno == 0)
+       /* see if device passed diags: continue and warn later */
+       if (err == 0)
                /* diagnostic fail : do nothing _YET_ */
                dev->horkage |= ATA_HORKAGE_DIAGNOSTIC;
        else if (err == 1)
@@ -1480,7 +1480,7 @@ unsigned long ata_id_xfermask(const u16 *id)
 }
 
 /**
- *     ata_port_queue_task - Queue port_task
+ *     ata_pio_queue_task - Queue port_task
  *     @ap: The ata_port to queue port_task for
  *     @fn: workqueue function to be scheduled
  *     @data: data for @fn to use
@@ -1492,16 +1492,15 @@ unsigned long ata_id_xfermask(const u16 *id)
  *     one task is active at any given time.
  *
  *     libata core layer takes care of synchronization between
- *     port_task and EH.  ata_port_queue_task() may be ignored for EH
+ *     port_task and EH.  ata_pio_queue_task() may be ignored for EH
  *     synchronization.
  *
  *     LOCKING:
  *     Inherited from caller.
  */
-void ata_port_queue_task(struct ata_port *ap, work_func_t fn, void *data,
-                        unsigned long delay)
+static void ata_pio_queue_task(struct ata_port *ap, void *data,
+                              unsigned long delay)
 {
-       PREPARE_DELAYED_WORK(&ap->port_task, fn);
        ap->port_task_data = data;
 
        /* may fail if ata_port_flush_task() in progress */
@@ -2262,19 +2261,8 @@ int ata_dev_configure(struct ata_device *dev)
                        dev->flags |= ATA_DFLAG_DIPM;
        }
 
-       if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) {
-               /* Let the user know. We don't want to disallow opens for
-                  rescue purposes, or in case the vendor is just a blithering
-                  idiot */
-               if (print_info) {
-                       ata_dev_printk(dev, KERN_WARNING,
-"Drive reports diagnostics failure. This may indicate a drive\n");
-                       ata_dev_printk(dev, KERN_WARNING,
-"fault or invalid emulation. Contact drive vendor for information.\n");
-               }
-       }
-
-       /* limit bridge transfers to udma5, 200 sectors */
+       /* Limit PATA drive on SATA cable bridge transfers to udma5,
+          200 sectors */
        if (ata_dev_knobble(dev)) {
                if (ata_msg_drv(ap) && print_info)
                        ata_dev_printk(dev, KERN_INFO,
@@ -2303,6 +2291,21 @@ int ata_dev_configure(struct ata_device *dev)
        if (ap->ops->dev_config)
                ap->ops->dev_config(dev);
 
+       if (dev->horkage & ATA_HORKAGE_DIAGNOSTIC) {
+               /* Let the user know. We don't want to disallow opens for
+                  rescue purposes, or in case the vendor is just a blithering
+                  idiot. Do this after the dev_config call as some controllers
+                  with buggy firmware may want to avoid reporting false device
+                  bugs */
+
+               if (print_info) {
+                       ata_dev_printk(dev, KERN_WARNING,
+"Drive reports diagnostics failure. This may indicate a drive\n");
+                       ata_dev_printk(dev, KERN_WARNING,
+"fault or invalid emulation. Contact drive vendor for information.\n");
+               }
+       }
+
        if (ata_msg_probe(ap))
                ata_dev_printk(dev, KERN_DEBUG, "%s: EXIT, drv_stat = 0x%x\n",
                        __FUNCTION__, ata_chk_status(ap));
@@ -3045,6 +3048,8 @@ int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel)
 static int ata_dev_set_mode(struct ata_device *dev)
 {
        struct ata_eh_context *ehc = &dev->link->eh_context;
+       const char *dev_err_whine = "";
+       int ign_dev_err = 0;
        unsigned int err_mask;
        int rc;
 
@@ -3054,47 +3059,63 @@ static int ata_dev_set_mode(struct ata_device *dev)
 
        err_mask = ata_dev_set_xfermode(dev);
 
+       if (err_mask & ~AC_ERR_DEV)
+               goto fail;
+
+       /* revalidate */
+       ehc->i.flags |= ATA_EHI_POST_SETMODE;
+       rc = ata_dev_revalidate(dev, ATA_DEV_UNKNOWN, 0);
+       ehc->i.flags &= ~ATA_EHI_POST_SETMODE;
+       if (rc)
+               return rc;
+
        /* 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;
+               ign_dev_err = 1;
 
        /* Some very old devices and some bad newer ones fail any kind of
           SET_XFERMODE request but support PIO0-2 timings and no IORDY */
        if (dev->xfer_shift == ATA_SHIFT_PIO && !ata_id_has_iordy(dev->id) &&
                        dev->pio_mode <= XFER_PIO_2)
-               err_mask &= ~AC_ERR_DEV;
+               ign_dev_err = 1;
 
        /* Early MWDMA devices do DMA but don't allow DMA mode setting.
           Don't fail an MWDMA0 set IFF the device indicates it is in MWDMA0 */
-       if (dev->xfer_shift == ATA_SHIFT_MWDMA && 
+       if (dev->xfer_shift == ATA_SHIFT_MWDMA &&
            dev->dma_mode == XFER_MW_DMA_0 &&
            (dev->id[63] >> 8) & 1)
-               err_mask &= ~AC_ERR_DEV;
+               ign_dev_err = 1;
 
-       if (err_mask) {
-               ata_dev_printk(dev, KERN_ERR, "failed to set xfermode "
-                              "(err_mask=0x%x)\n", err_mask);
-               return -EIO;
-       }
+       /* if the device is actually configured correctly, ignore dev err */
+       if (dev->xfer_mode == ata_xfer_mask2mode(ata_id_xfermask(dev->id)))
+               ign_dev_err = 1;
 
-       ehc->i.flags |= ATA_EHI_POST_SETMODE;
-       rc = ata_dev_revalidate(dev, ATA_DEV_UNKNOWN, 0);
-       ehc->i.flags &= ~ATA_EHI_POST_SETMODE;
-       if (rc)
-               return rc;
+       if (err_mask & AC_ERR_DEV) {
+               if (!ign_dev_err)
+                       goto fail;
+               else
+                       dev_err_whine = " (device error ignored)";
+       }
 
        DPRINTK("xfer_shift=%u, xfer_mode=0x%x\n",
                dev->xfer_shift, (int)dev->xfer_mode);
 
-       ata_dev_printk(dev, KERN_INFO, "configured for %s\n",
-                      ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)));
+       ata_dev_printk(dev, KERN_INFO, "configured for %s%s\n",
+                      ata_mode_string(ata_xfer_mode2mask(dev->xfer_mode)),
+                      dev_err_whine);
+
        return 0;
+
+ fail:
+       ata_dev_printk(dev, KERN_ERR, "failed to set xfermode "
+                      "(err_mask=0x%x)\n", err_mask);
+       return -EIO;
 }
 
 /**
  *     ata_do_set_mode - Program timings and issue SET FEATURES - XFER
  *     @link: link on which timings will be programmed
- *     @r_failed_dev: out paramter for failed device
+ *     @r_failed_dev: out parameter for failed device
  *
  *     Standard implementation of the function used to tune and set
  *     ATA device disk transfer mode (PIO3, UDMA6, etc.).  If
@@ -4151,8 +4172,6 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* NCQ is broken */
        { "Maxtor *",           "BANC*",        ATA_HORKAGE_NONCQ },
        { "Maxtor 7V300F0",     "VA111630",     ATA_HORKAGE_NONCQ },
-       { "HITACHI HDS7250SASUN500G*", NULL,    ATA_HORKAGE_NONCQ },
-       { "HITACHI HDS7225SBSUN250G*", NULL,    ATA_HORKAGE_NONCQ },
        { "ST380817AS",         "3.42",         ATA_HORKAGE_NONCQ },
        { "ST3160023AS",        "3.42",         ATA_HORKAGE_NONCQ },
 
@@ -4171,6 +4190,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
        /* Devices which report 1 sector over size HPA */
        { "ST340823A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
        { "ST320413A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
+       { "ST310211A",          NULL,           ATA_HORKAGE_HPA_SIZE, },
 
        /* Devices which get the IVB wrong */
        { "QUANTUM FIREBALLlct10 05", "A03.0900", ATA_HORKAGE_IVB, },
@@ -4471,34 +4491,18 @@ static unsigned int ata_dev_init_params(struct ata_device *dev,
 void ata_sg_clean(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
-       struct scatterlist *sg = qc->__sg;
+       struct scatterlist *sg = qc->sg;
        int dir = qc->dma_dir;
-       void *pad_buf = NULL;
 
        WARN_ON(sg == NULL);
 
        VPRINTK("unmapping %u sg elements\n", qc->n_elem);
 
-       /* if we padded the buffer out to 32-bit bound, and data
-        * xfer direction is from-device, we must copy from the
-        * pad buffer back into the supplied buffer
-        */
-       if (qc->pad_len && !(qc->tf.flags & ATA_TFLAG_WRITE))
-               pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);
-
        if (qc->n_elem)
                dma_unmap_sg(ap->dev, sg, qc->n_elem, dir);
-       /* restore last sg */
-       sg_last(sg, qc->orig_n_elem)->length += qc->pad_len;
-       if (pad_buf) {
-               struct scatterlist *psg = &qc->pad_sgent;
-               void *addr = kmap_atomic(sg_page(psg), KM_IRQ0);
-               memcpy(addr + psg->offset, pad_buf, qc->pad_len);
-               kunmap_atomic(addr, KM_IRQ0);
-       }
 
        qc->flags &= ~ATA_QCFLAG_DMAMAP;
-       qc->__sg = NULL;
+       qc->sg = NULL;
 }
 
 /**
@@ -4516,13 +4520,10 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
        struct scatterlist *sg;
-       unsigned int idx;
-
-       WARN_ON(qc->__sg == NULL);
-       WARN_ON(qc->n_elem == 0 && qc->pad_len == 0);
+       unsigned int si, pi;
 
-       idx = 0;
-       ata_for_each_sg(sg, qc) {
+       pi = 0;
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
                u32 addr, offset;
                u32 sg_len, len;
 
@@ -4539,18 +4540,17 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
                        if ((offset + sg_len) > 0x10000)
                                len = 0x10000 - offset;
 
-                       ap->prd[idx].addr = cpu_to_le32(addr);
-                       ap->prd[idx].flags_len = cpu_to_le32(len & 0xffff);
-                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
+                       ap->prd[pi].addr = cpu_to_le32(addr);
+                       ap->prd[pi].flags_len = cpu_to_le32(len & 0xffff);
+                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
 
-                       idx++;
+                       pi++;
                        sg_len -= len;
                        addr += len;
                }
        }
 
-       if (idx)
-               ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+       ap->prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
 }
 
 /**
@@ -4570,13 +4570,10 @@ static void ata_fill_sg_dumb(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
        struct scatterlist *sg;
-       unsigned int idx;
+       unsigned int si, pi;
 
-       WARN_ON(qc->__sg == NULL);
-       WARN_ON(qc->n_elem == 0 && qc->pad_len == 0);
-
-       idx = 0;
-       ata_for_each_sg(sg, qc) {
+       pi = 0;
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
                u32 addr, offset;
                u32 sg_len, len, blen;
 
@@ -4594,25 +4591,24 @@ static void ata_fill_sg_dumb(struct ata_queued_cmd *qc)
                                len = 0x10000 - offset;
 
                        blen = len & 0xffff;
-                       ap->prd[idx].addr = cpu_to_le32(addr);
+                       ap->prd[pi].addr = cpu_to_le32(addr);
                        if (blen == 0) {
                           /* Some PATA chipsets like the CS5530 can't
                              cope with 0x0000 meaning 64K as the spec says */
-                               ap->prd[idx].flags_len = cpu_to_le32(0x8000);
+                               ap->prd[pi].flags_len = cpu_to_le32(0x8000);
                                blen = 0x8000;
-                               ap->prd[++idx].addr = cpu_to_le32(addr + 0x8000);
+                               ap->prd[++pi].addr = cpu_to_le32(addr + 0x8000);
                        }
-                       ap->prd[idx].flags_len = cpu_to_le32(blen);
-                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", idx, addr, len);
+                       ap->prd[pi].flags_len = cpu_to_le32(blen);
+                       VPRINTK("PRD[%u] = (0x%X, 0x%X)\n", pi, addr, len);
 
-                       idx++;
+                       pi++;
                        sg_len -= len;
                        addr += len;
                }
        }
 
-       if (idx)
-               ap->prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+       ap->prd[pi - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
 }
 
 /**
@@ -4662,24 +4658,9 @@ int ata_check_atapi_dma(struct ata_queued_cmd *qc)
  */
 static int atapi_qc_may_overflow(struct ata_queued_cmd *qc)
 {
-       if (qc->tf.protocol != ATAPI_PROT_PIO &&
-           qc->tf.protocol != ATAPI_PROT_DMA)
-               return 0;
-
-       if (qc->tf.flags & ATA_TFLAG_WRITE)
-               return 0;
-
-       switch (qc->cdb[0]) {
-       case READ_10:
-       case READ_12:
-       case WRITE_10:
-       case WRITE_12:
-       case GPCMD_READ_CD:
-       case GPCMD_READ_CD_MSF:
-               return 0;
-       }
-
-       return 1;
+       return ata_is_atapi(qc->tf.protocol) && ata_is_data(qc->tf.protocol) &&
+               atapi_cmd_type(qc->cdb[0]) == ATAPI_MISC &&
+               !(qc->tf.flags & ATA_TFLAG_WRITE);
 }
 
 /**
@@ -4764,10 +4745,9 @@ void ata_noop_qc_prep(struct ata_queued_cmd *qc) { }
 void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
                 unsigned int n_elem)
 {
-       qc->__sg = sg;
+       qc->sg = sg;
        qc->n_elem = n_elem;
-       qc->orig_n_elem = n_elem;
-       qc->cursg = qc->__sg;
+       qc->cursg = qc->sg;
 }
 
 /**
@@ -4783,73 +4763,19 @@ void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg,
  *     Zero on success, negative on error.
  *
  */
-
 static int ata_sg_setup(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
-       struct scatterlist *sg = qc->__sg;
-       struct scatterlist *lsg = sg_last(qc->__sg, qc->n_elem);
-       int n_elem, pre_n_elem, dir, trim_sg = 0;
+       unsigned int n_elem;
 
        VPRINTK("ENTER, ata%u\n", ap->print_id);
 
-       /* we must lengthen transfers to end on a 32-bit boundary */
-       qc->pad_len = lsg->length & 3;
-       if (qc->pad_len) {
-               void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);
-               struct scatterlist *psg = &qc->pad_sgent;
-               unsigned int offset;
-
-               WARN_ON(qc->dev->class != ATA_DEV_ATAPI);
-
-               memset(pad_buf, 0, ATA_DMA_PAD_SZ);
-
-               /*
-                * psg->page/offset are used to copy to-be-written
-                * data in this function or read data in ata_sg_clean.
-                */
-               offset = lsg->offset + lsg->length - qc->pad_len;
-               sg_init_table(psg, 1);
-               sg_set_page(psg, nth_page(sg_page(lsg), offset >> PAGE_SHIFT),
-                               qc->pad_len, offset_in_page(offset));
-
-               if (qc->tf.flags & ATA_TFLAG_WRITE) {
-                       void *addr = kmap_atomic(sg_page(psg), KM_IRQ0);
-                       memcpy(pad_buf, addr + psg->offset, qc->pad_len);
-                       kunmap_atomic(addr, KM_IRQ0);
-               }
-
-               sg_dma_address(psg) = ap->pad_dma + (qc->tag * ATA_DMA_PAD_SZ);
-               sg_dma_len(psg) = ATA_DMA_PAD_SZ;
-               /* trim last sg */
-               lsg->length -= qc->pad_len;
-               if (lsg->length == 0)
-                       trim_sg = 1;
-
-               DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n",
-                       qc->n_elem - 1, lsg->length, qc->pad_len);
-       }
-
-       pre_n_elem = qc->n_elem;
-       if (trim_sg && pre_n_elem)
-               pre_n_elem--;
-
-       if (!pre_n_elem) {
-               n_elem = 0;
-               goto skip_map;
-       }
-
-       dir = qc->dma_dir;
-       n_elem = dma_map_sg(ap->dev, sg, pre_n_elem, dir);
-       if (n_elem < 1) {
-               /* restore last sg */
-               lsg->length += qc->pad_len;
+       n_elem = dma_map_sg(ap->dev, qc->sg, qc->n_elem, qc->dma_dir);
+       if (n_elem < 1)
                return -1;
-       }
 
        DPRINTK("%d sg elements mapped\n", n_elem);
 
-skip_map:
        qc->n_elem = n_elem;
        qc->flags |= ATA_QCFLAG_DMAMAP;
 
@@ -4883,7 +4809,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
  *     @dev: device to target
  *     @buf: data buffer
  *     @buflen: buffer length
- *     @write_data: read/write
+ *     @rw: read/write
  *
  *     Transfer data from/to the device data register by PIO.
  *
@@ -4908,7 +4834,7 @@ unsigned int ata_data_xfer(struct ata_device *dev, unsigned char *buf,
 
        /* Transfer trailing 1 byte, if any. */
        if (unlikely(buflen & 0x01)) {
-               u16 align_buf[1] = { 0 };
+               __le16 align_buf[1] = { 0 };
                unsigned char *trailing_buf = buf + buflen - 1;
 
                if (rw == READ) {
@@ -4929,7 +4855,7 @@ unsigned int ata_data_xfer(struct ata_device *dev, unsigned char *buf,
  *     @dev: device to target
  *     @buf: data buffer
  *     @buflen: buffer length
- *     @write_data: read/write
+ *     @rw: read/write
  *
  *     Transfer data from/to the device data register by PIO. Do the
  *     transfer with interrupts disabled.
@@ -5088,13 +5014,14 @@ static void atapi_send_cdb(struct ata_port *ap, struct ata_queued_cmd *qc)
  */
 static int __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
 {
-       int do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
+       int rw = (qc->tf.flags & ATA_TFLAG_WRITE) ? WRITE : READ;
        struct ata_port *ap = qc->ap;
-       struct ata_eh_info *ehi = &qc->dev->link->eh_info;
+       struct ata_device *dev = qc->dev;
+       struct ata_eh_info *ehi = &dev->link->eh_info;
        struct scatterlist *sg;
        struct page *page;
        unsigned char *buf;
-       unsigned int offset, count;
+       unsigned int offset, count, consumed;
 
 next_sg:
        sg = qc->cursg;
@@ -5107,26 +5034,27 @@ next_sg:
                 *    - for write case, padding zero data to the device
                 */
                u16 pad_buf[1] = { 0 };
-               unsigned int i;
 
-               if (bytes > qc->curbytes - qc->nbytes + ATAPI_MAX_DRAIN) {
+               if (qc->curbytes + bytes > qc->nbytes + ATAPI_MAX_DRAIN) {
                        ata_ehi_push_desc(ehi, "too much trailing data "
                                          "buf=%u cur=%u bytes=%u",
                                          qc->nbytes, qc->curbytes, bytes);
                        return -1;
                }
 
-                /* overflow is exptected for misc ATAPI commands */
-               if (bytes && !atapi_qc_may_overflow(qc))
-                       ata_dev_printk(qc->dev, KERN_WARNING, "ATAPI %u bytes "
-                                      "trailing data (cdb=%02x nbytes=%u)\n",
-                                      bytes, qc->cdb[0], qc->nbytes);
+               /* allow overflow only for misc ATAPI commands */
+               if (!atapi_qc_may_overflow(qc)) {
+                       ata_ehi_push_desc(ehi, "unexpected trailing data "
+                                         "%u bytes", bytes);
+                       return -1;
+               }
 
-               for (i = 0; i < (bytes + 1) / 2; i++)
-                       ap->ops->data_xfer(qc->dev, (unsigned char *)pad_buf, 2, do_write);
+               consumed = 0;
+               while (consumed < bytes)
+                       consumed += ap->ops->data_xfer(dev,
+                                       (unsigned char *)pad_buf, 2, rw);
 
                qc->curbytes += bytes;
-
                return 0;
        }
 
@@ -5153,18 +5081,16 @@ next_sg:
                buf = kmap_atomic(page, KM_IRQ0);
 
                /* do the actual data transfer */
-               ap->ops->data_xfer(qc->dev,  buf + offset, count, do_write);
+               consumed = ap->ops->data_xfer(dev,  buf + offset, count, rw);
 
                kunmap_atomic(buf, KM_IRQ0);
                local_irq_restore(flags);
        } else {
                buf = page_address(page);
-               ap->ops->data_xfer(qc->dev,  buf + offset, count, do_write);
+               consumed = ap->ops->data_xfer(dev,  buf + offset, count, rw);
        }
 
-       bytes -= count;
-       if ((count & 1) && bytes)
-               bytes--;
+       bytes -= min(bytes, consumed);
        qc->curbytes += count;
        qc->cursg_ofs += count;
 
@@ -5173,9 +5099,11 @@ next_sg:
                qc->cursg_ofs = 0;
        }
 
+       /* consumed can be larger than count only for the last transfer */
+       WARN_ON(qc->cursg && count != consumed);
+
        if (bytes)
                goto next_sg;
-
        return 0;
 }
 
@@ -5193,6 +5121,7 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
        struct ata_device *dev = qc->dev;
+       struct ata_eh_info *ehi = &dev->link->eh_info;
        unsigned int ireason, bc_lo, bc_hi, bytes;
        int i_write, do_write = (qc->tf.flags & ATA_TFLAG_WRITE) ? 1 : 0;
 
@@ -5210,26 +5139,28 @@ static void atapi_pio_bytes(struct ata_queued_cmd *qc)
 
        /* shall be cleared to zero, indicating xfer of data */
        if (unlikely(ireason & (1 << 0)))
-               goto err_out;
+               goto atapi_check;
 
        /* make sure transfer direction matches expected */
        i_write = ((ireason & (1 << 1)) == 0) ? 1 : 0;
        if (unlikely(do_write != i_write))
-               goto err_out;
+               goto atapi_check;
 
        if (unlikely(!bytes))
-               goto err_out;
+               goto atapi_check;
 
        VPRINTK("ata%u: xfering %d bytes\n", ap->print_id, bytes);
 
-       if (__atapi_pio_bytes(qc, bytes))
+       if (unlikely(__atapi_pio_bytes(qc, bytes)))
                goto err_out;
        ata_altstatus(ap); /* flush */
 
        return;
 
-err_out:
-       ata_dev_printk(dev, KERN_INFO, "ATAPI check failed\n");
+ atapi_check:
+       ata_ehi_push_desc(ehi, "ATAPI check failed (ireason=0x%x bytes=%u)",
+                         ireason, bytes);
+ err_out:
        qc->err_mask |= AC_ERR_HSM;
        ap->hsm_task_state = HSM_ST_ERR;
 }
@@ -5576,7 +5507,7 @@ fsm_start:
                msleep(2);
                status = ata_busy_wait(ap, ATA_BUSY, 10);
                if (status & ATA_BUSY) {
-                       ata_port_queue_task(ap, ata_pio_task, qc, ATA_SHORT_PAUSE);
+                       ata_pio_queue_task(ap, qc, ATA_SHORT_PAUSE);
                        return;
                }
        }
@@ -5912,7 +5843,7 @@ void ata_qc_issue(struct ata_queued_cmd *qc)
        /* We guarantee to LLDs that they will have at least one
         * non-zero sg if the command is a data command.
         */
-       BUG_ON(ata_is_data(prot) && (!qc->__sg || !qc->n_elem || !qc->nbytes));
+       BUG_ON(ata_is_data(prot) && (!qc->sg || !qc->n_elem || !qc->nbytes));
 
        if (ata_is_dma(prot) || (ata_is_pio(prot) &&
                                 (ap->flags & ATA_FLAG_PIO_DMA)))
@@ -5996,7 +5927,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
                ap->hsm_task_state = HSM_ST_LAST;
 
                if (qc->tf.flags & ATA_TFLAG_POLLING)
-                       ata_port_queue_task(ap, ata_pio_task, qc, 0);
+                       ata_pio_queue_task(ap, qc, 0);
 
                break;
 
@@ -6018,7 +5949,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
                if (qc->tf.flags & ATA_TFLAG_WRITE) {
                        /* PIO data out protocol */
                        ap->hsm_task_state = HSM_ST_FIRST;
-                       ata_port_queue_task(ap, ata_pio_task, qc, 0);
+                       ata_pio_queue_task(ap, qc, 0);
 
                        /* always send first data block using
                         * the ata_pio_task() codepath.
@@ -6028,7 +5959,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
                        ap->hsm_task_state = HSM_ST;
 
                        if (qc->tf.flags & ATA_TFLAG_POLLING)
-                               ata_port_queue_task(ap, ata_pio_task, qc, 0);
+                               ata_pio_queue_task(ap, qc, 0);
 
                        /* if polling, ata_pio_task() handles the rest.
                         * otherwise, interrupt handler takes over from here.
@@ -6049,7 +5980,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
                /* send cdb by polling if no cdb interrupt */
                if ((!(qc->dev->flags & ATA_DFLAG_CDB_INTR)) ||
                    (qc->tf.flags & ATA_TFLAG_POLLING))
-                       ata_port_queue_task(ap, ata_pio_task, qc, 0);
+                       ata_pio_queue_task(ap, qc, 0);
                break;
 
        case ATAPI_PROT_DMA:
@@ -6061,7 +5992,7 @@ unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc)
 
                /* send cdb by polling if no cdb interrupt */
                if (!(qc->dev->flags & ATA_DFLAG_CDB_INTR))
-                       ata_port_queue_task(ap, ata_pio_task, qc, 0);
+                       ata_pio_queue_task(ap, qc, 0);
                break;
 
        default:
@@ -6522,19 +6453,12 @@ void ata_host_resume(struct ata_host *host)
 int ata_port_start(struct ata_port *ap)
 {
        struct device *dev = ap->dev;
-       int rc;
 
        ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma,
                                      GFP_KERNEL);
        if (!ap->prd)
                return -ENOMEM;
 
-       rc = ata_pad_alloc(ap, dev);
-       if (rc)
-               return rc;
-
-       DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd,
-               (unsigned long long)ap->prd_dma);
        return 0;
 }
 
@@ -6677,7 +6601,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
        ap->msg_enable = ATA_MSG_DRV | ATA_MSG_ERR | ATA_MSG_WARN;
 #endif
 
-       INIT_DELAYED_WORK(&ap->port_task, NULL);
+       INIT_DELAYED_WORK(&ap->port_task, ata_pio_task);
        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);
@@ -7026,7 +6950,6 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
        DPRINTK("probe begin\n");
        for (i = 0; i < host->n_ports; i++) {
                struct ata_port *ap = host->ports[i];
-               int rc;
 
                /* probe */
                if (ap->ops->error_handler) {
@@ -7554,7 +7477,6 @@ EXPORT_SYMBOL_GPL(ata_wait_register);
 EXPORT_SYMBOL_GPL(ata_busy_sleep);
 EXPORT_SYMBOL_GPL(ata_wait_after_reset);
 EXPORT_SYMBOL_GPL(ata_wait_ready);
-EXPORT_SYMBOL_GPL(ata_port_queue_task);
 EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
 EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
 EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
@@ -7586,6 +7508,7 @@ EXPORT_SYMBOL_GPL(pci_test_config_bits);
 EXPORT_SYMBOL_GPL(ata_pci_init_sff_host);
 EXPORT_SYMBOL_GPL(ata_pci_init_bmdma);
 EXPORT_SYMBOL_GPL(ata_pci_prepare_sff_host);
+EXPORT_SYMBOL_GPL(ata_pci_activate_sff_host);
 EXPORT_SYMBOL_GPL(ata_pci_init_one);
 EXPORT_SYMBOL_GPL(ata_pci_remove_one);
 #ifdef CONFIG_PM