Merge branch 'master'
authorJeff Garzik <jgarzik@pobox.com>
Mon, 31 Oct 2005 01:24:34 +0000 (20:24 -0500)
committerJeff Garzik <jgarzik@pobox.com>
Mon, 31 Oct 2005 01:24:34 +0000 (20:24 -0500)
1  2 
drivers/scsi/ahci.c
drivers/scsi/libata-core.c
drivers/scsi/pdc_adma.c
drivers/scsi/sata_mv.c
drivers/scsi/sata_qstor.c
drivers/scsi/sata_sil24.c
drivers/scsi/sata_sx4.c

diff --combined drivers/scsi/ahci.c
index 25a47d7afa282753f775fc7ca22ddf0d55bfc97c,e2a5657d5fdb4887ae969158ac89ff95fcedb01a..8420204c2eaa50b7e999f657a1d6dadd59165e34
@@@ -41,6 -41,7 +41,7 @@@
  #include <linux/interrupt.h>
  #include <linux/sched.h>
  #include <linux/dma-mapping.h>
+ #include <linux/device.h>
  #include "scsi.h"
  #include <scsi/scsi_host.h>
  #include <linux/libata.h>
@@@ -312,15 -313,8 +313,15 @@@ static int ahci_port_start(struct ata_p
                return -ENOMEM;
        memset(pp, 0, sizeof(*pp));
  
 +      ap->pad = dma_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ, &ap->pad_dma, GFP_KERNEL);
 +      if (!ap->pad) {
 +              kfree(pp);
 +              return -ENOMEM;
 +      }
 +
        mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL);
        if (!mem) {
 +              dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma);
                kfree(pp);
                return -ENOMEM;
        }
@@@ -396,7 -390,6 +397,7 @@@ static void ahci_port_stop(struct ata_p
        ap->private_data = NULL;
        dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
                          pp->cmd_slot, pp->cmd_slot_dma);
 +      dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma);
        kfree(pp);
  }
  
@@@ -475,23 -468,23 +476,23 @@@ static void ahci_tf_read(struct ata_por
  static void ahci_fill_sg(struct ata_queued_cmd *qc)
  {
        struct ahci_port_priv *pp = qc->ap->private_data;
 -      unsigned int i;
 +      struct scatterlist *sg;
 +      struct ahci_sg *ahci_sg;
  
        VPRINTK("ENTER\n");
  
        /*
         * Next, the S/G list.
         */
 -      for (i = 0; i < qc->n_elem; i++) {
 -              u32 sg_len;
 -              dma_addr_t addr;
 -
 -              addr = sg_dma_address(&qc->sg[i]);
 -              sg_len = sg_dma_len(&qc->sg[i]);
 -
 -              pp->cmd_tbl_sg[i].addr = cpu_to_le32(addr & 0xffffffff);
 -              pp->cmd_tbl_sg[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
 -              pp->cmd_tbl_sg[i].flags_size = cpu_to_le32(sg_len - 1);
 +      ahci_sg = pp->cmd_tbl_sg;
 +      ata_for_each_sg(sg, qc) {
 +              dma_addr_t addr = sg_dma_address(sg);
 +              u32 sg_len = sg_dma_len(sg);
 +
 +              ahci_sg->addr = cpu_to_le32(addr & 0xffffffff);
 +              ahci_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16);
 +              ahci_sg->flags_size = cpu_to_le32(sg_len - 1);
 +              ahci_sg++;
        }
  }
  
@@@ -682,10 -675,10 +683,10 @@@ static irqreturn_t ahci_interrupt (int 
                        if (!ahci_host_intr(ap, qc))
                                if (ata_ratelimit()) {
                                        struct pci_dev *pdev =
-                                         to_pci_dev(ap->host_set->dev);
-                                       printk(KERN_WARNING
-                                         "ahci(%s): unhandled interrupt on port %u\n",
-                                         pci_name(pdev), i);
+                                               to_pci_dev(ap->host_set->dev);
+                                       dev_printk(KERN_WARNING, &pdev->dev,
+                                         "unhandled interrupt on port %u\n",
+                                         i);
                                }
  
                        VPRINTK("port %u\n", i);
                        VPRINTK("port %u (no irq)\n", i);
                        if (ata_ratelimit()) {
                                struct pci_dev *pdev =
-                                 to_pci_dev(ap->host_set->dev);
-                               printk(KERN_WARNING
-                                 "ahci(%s): interrupt on disabled port %u\n",
-                                 pci_name(pdev), i);
+                                       to_pci_dev(ap->host_set->dev);
+                               dev_printk(KERN_WARNING, &pdev->dev,
+                                       "interrupt on disabled port %u\n", i);
                        }
                }
  
@@@ -768,8 -760,8 +768,8 @@@ static int ahci_host_init(struct ata_pr
  
        tmp = readl(mmio + HOST_CTL);
        if (tmp & HOST_RESET) {
-               printk(KERN_ERR DRV_NAME "(%s): controller reset failed (0x%x)\n",
-                       pci_name(pdev), tmp);
+               dev_printk(KERN_ERR, &pdev->dev,
+                          "controller reset failed (0x%x)\n", tmp);
                return -EIO;
        }
  
                if (rc) {
                        rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
                        if (rc) {
-                               printk(KERN_ERR DRV_NAME "(%s): 64-bit DMA enable failed\n",
-                                       pci_name(pdev));
+                               dev_printk(KERN_ERR, &pdev->dev,
+                                          "64-bit DMA enable failed\n");
                                return rc;
                        }
                }
        } else {
                rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
                if (rc) {
-                       printk(KERN_ERR DRV_NAME "(%s): 32-bit DMA enable failed\n",
-                               pci_name(pdev));
+                       dev_printk(KERN_ERR, &pdev->dev,
+                                  "32-bit DMA enable failed\n");
                        return rc;
                }
                rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
                if (rc) {
-                       printk(KERN_ERR DRV_NAME "(%s): 32-bit consistent DMA enable failed\n",
-                               pci_name(pdev));
+                       dev_printk(KERN_ERR, &pdev->dev,
+                                  "32-bit consistent DMA enable failed\n");
                        return rc;
                }
        }
@@@ -915,10 -907,10 +915,10 @@@ static void ahci_print_info(struct ata_
        else
                scc_s = "unknown";
  
-       printk(KERN_INFO DRV_NAME "(%s) AHCI %02x%02x.%02x%02x "
+       dev_printk(KERN_INFO, &pdev->dev,
+               "AHCI %02x%02x.%02x%02x "
                "%u slots %u ports %s Gbps 0x%x impl %s mode\n"
                ,
-               pci_name(pdev),
  
                (vers >> 24) & 0xff,
                (vers >> 16) & 0xff,
                impl,
                scc_s);
  
-       printk(KERN_INFO DRV_NAME "(%s) flags: "
+       dev_printk(KERN_INFO, &pdev->dev,
+               "flags: "
                "%s%s%s%s%s%s"
                "%s%s%s%s%s%s%s\n"
                ,
-               pci_name(pdev),
  
                cap & (1 << 31) ? "64bit " : "",
                cap & (1 << 30) ? "ncq " : "",
@@@ -968,7 -960,7 +968,7 @@@ static int ahci_init_one (struct pci_de
        VPRINTK("ENTER\n");
  
        if (!printed_version++)
-               printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  
        rc = pci_enable_device(pdev);
        if (rc)
index 6cab14965cc89da85cb979ca6ffbde7c572483fe,8be7dc0b47b849858c8d5b37872e7112fb8e3b31..2e022240051eb6ff069435457dd5750d0e2bd942
@@@ -2427,9 -2427,8 +2427,9 @@@ static void ata_dev_init_params(struct 
  static 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;
  
        assert(qc->flags & ATA_QCFLAG_DMAMAP);
        assert(sg != NULL);
  
        DPRINTK("unmapping %u sg elements\n", qc->n_elem);
  
 -      if (qc->flags & ATA_QCFLAG_SG)
 +      /* 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->flags & ATA_QCFLAG_SG) {
                dma_unmap_sg(ap->host_set->dev, sg, qc->n_elem, dir);
 -      else
 +              /* restore last sg */
 +              sg[qc->orig_n_elem - 1].length += qc->pad_len;
 +              if (pad_buf) {
 +                      struct scatterlist *psg = &qc->pad_sgent;
 +                      void *addr = kmap_atomic(psg->page, KM_IRQ0);
 +                      memcpy(addr + psg->offset, pad_buf, qc->pad_len);
 +                      kunmap_atomic(psg->page, KM_IRQ0);
 +              }
 +      } else {
                dma_unmap_single(ap->host_set->dev, sg_dma_address(&sg[0]),
                                 sg_dma_len(&sg[0]), dir);
 +              /* restore sg */
 +              sg->length += qc->pad_len;
 +              if (pad_buf)
 +                      memcpy(qc->buf_virt + sg->length - qc->pad_len,
 +                             pad_buf, qc->pad_len);
 +      }
  
        qc->flags &= ~ATA_QCFLAG_DMAMAP;
 -      qc->sg = NULL;
 +      qc->__sg = NULL;
  }
  
  /**
   */
  static void ata_fill_sg(struct ata_queued_cmd *qc)
  {
 -      struct scatterlist *sg = qc->sg;
        struct ata_port *ap = qc->ap;
 -      unsigned int idx, nelem;
 +      struct scatterlist *sg;
 +      unsigned int idx;
  
 -      assert(sg != NULL);
 +      assert(qc->__sg != NULL);
        assert(qc->n_elem > 0);
  
        idx = 0;
 -      for (nelem = qc->n_elem; nelem; nelem--,sg++) {
 +      ata_for_each_sg(sg, qc) {
                u32 addr, offset;
                u32 sg_len, len;
  
@@@ -2577,18 -2555,12 +2577,18 @@@ void ata_qc_prep(struct ata_queued_cmd 
  
  void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen)
  {
 +      struct scatterlist *sg;
 +
        qc->flags |= ATA_QCFLAG_SINGLE;
  
 -      qc->sg = &qc->sgent;
 +      memset(&qc->sgent, 0, sizeof(qc->sgent));
 +      qc->__sg = &qc->sgent;
        qc->n_elem = 1;
 +      qc->orig_n_elem = 1;
        qc->buf_virt = buf;
 -      sg_init_one(qc->sg, buf, buflen);
 +
 +      sg = qc->__sg;
 +      sg_init_one(sg, buf, buflen);
  }
  
  /**
@@@ -2609,9 -2581,8 +2609,9 @@@ void ata_sg_init(struct ata_queued_cmd 
                 unsigned int n_elem)
  {
        qc->flags |= ATA_QCFLAG_SG;
 -      qc->sg = sg;
 +      qc->__sg = sg;
        qc->n_elem = n_elem;
 +      qc->orig_n_elem = n_elem;
  }
  
  /**
@@@ -2631,32 -2602,9 +2631,32 @@@ static int ata_sg_setup_one(struct ata_
  {
        struct ata_port *ap = qc->ap;
        int dir = qc->dma_dir;
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg = qc->__sg;
        dma_addr_t dma_address;
  
 +      /* we must lengthen transfers to end on a 32-bit boundary */
 +      qc->pad_len = sg->length & 3;
 +      if (qc->pad_len) {
 +              void *pad_buf = ap->pad + (qc->tag * ATA_DMA_PAD_SZ);
 +              struct scatterlist *psg = &qc->pad_sgent;
 +
 +              assert(qc->dev->class == ATA_DEV_ATAPI);
 +
 +              memset(pad_buf, 0, ATA_DMA_PAD_SZ);
 +
 +              if (qc->tf.flags & ATA_TFLAG_WRITE)
 +                      memcpy(pad_buf, qc->buf_virt + sg->length - qc->pad_len,
 +                             qc->pad_len);
 +
 +              sg_dma_address(psg) = ap->pad_dma + (qc->tag * ATA_DMA_PAD_SZ);
 +              sg_dma_len(psg) = ATA_DMA_PAD_SZ;
 +              /* trim sg */
 +              sg->length -= qc->pad_len;
 +
 +              DPRINTK("padding done, sg->length=%u pad_len=%u\n",
 +                      sg->length, qc->pad_len);
 +      }
 +
        dma_address = dma_map_single(ap->host_set->dev, qc->buf_virt,
                                     sg->length, dir);
        if (dma_mapping_error(dma_address))
  static int ata_sg_setup(struct ata_queued_cmd *qc)
  {
        struct ata_port *ap = qc->ap;
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg = qc->__sg;
 +      struct scatterlist *lsg = &sg[qc->n_elem - 1];
        int n_elem, dir;
  
        VPRINTK("ENTER, ata%u\n", ap->id);
        assert(qc->flags & ATA_QCFLAG_SG);
  
 +      /* 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;
 +
 +              assert(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;
 +              psg->page = nth_page(lsg->page, offset >> PAGE_SHIFT);
 +              psg->offset = offset_in_page(offset);
 +
 +              if (qc->tf.flags & ATA_TFLAG_WRITE) {
 +                      void *addr = kmap_atomic(psg->page, KM_IRQ0);
 +                      memcpy(pad_buf, addr + psg->offset, qc->pad_len);
 +                      kunmap_atomic(psg->page, 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;
 +
 +              DPRINTK("padding done, sg[%d].length=%u pad_len=%u\n",
 +                      qc->n_elem - 1, lsg->length, qc->pad_len);
 +      }
 +
        dir = qc->dma_dir;
        n_elem = dma_map_sg(ap->host_set->dev, sg, qc->n_elem, dir);
        if (n_elem < 1)
@@@ -3004,7 -2917,7 +3004,7 @@@ static void ata_data_xfer(struct ata_po
  static void ata_pio_sector(struct ata_queued_cmd *qc)
  {
        int do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg = qc->__sg;
        struct ata_port *ap = qc->ap;
        struct page *page;
        unsigned int offset;
  static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes)
  {
        int do_write = (qc->tf.flags & ATA_TFLAG_WRITE);
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg = qc->__sg;
        struct ata_port *ap = qc->ap;
        struct page *page;
        unsigned char *buf;
@@@ -3087,7 -3000,7 +3087,7 @@@ next_sg
                return;
        }
  
 -      sg = &qc->sg[qc->cursg];
 +      sg = &qc->__sg[qc->cursg];
  
        page = sg->page;
        offset = sg->offset + qc->cursg_ofs;
@@@ -3444,7 -3357,7 +3444,7 @@@ struct ata_queued_cmd *ata_qc_new_init(
  
        qc = ata_qc_new(ap);
        if (qc) {
 -              qc->sg = NULL;
 +              qc->__sg = NULL;
                qc->flags = 0;
                qc->scsicmd = NULL;
                qc->ap = ap;
@@@ -4133,12 -4046,6 +4133,12 @@@ int ata_port_start (struct ata_port *ap
        if (!ap->prd)
                return -ENOMEM;
  
 +      ap->pad = dma_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ, &ap->pad_dma, GFP_KERNEL);
 +      if (!ap->pad) {
 +              dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
 +              return -ENOMEM;
 +      }
 +
        DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd, (unsigned long long) ap->prd_dma);
  
        return 0;
@@@ -4162,7 -4069,6 +4162,7 @@@ void ata_port_stop (struct ata_port *ap
        struct device *dev = ap->host_set->dev;
  
        dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
 +      dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma);
  }
  
  void ata_host_stop (struct ata_host_set *host_set)
@@@ -4621,11 -4527,11 +4621,11 @@@ ata_pci_init_native_mode(struct pci_de
        return probe_ent;
  }
  
- static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info **port, int port_num)
+ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, struct ata_port_info *port, int port_num)
  {
        struct ata_probe_ent *probe_ent;
  
-       probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
+       probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port);
        if (!probe_ent)
                return NULL;
  
@@@ -4772,9 -4678,9 +4772,9 @@@ int ata_pci_init_one (struct pci_dev *p
  
        if (legacy_mode) {
                if (legacy_mode & (1 << 0))
-                       probe_ent = ata_pci_init_legacy_port(pdev, port, 0);
+                       probe_ent = ata_pci_init_legacy_port(pdev, port[0], 0);
                if (legacy_mode & (1 << 1))
-                       probe_ent2 = ata_pci_init_legacy_port(pdev, port, 1);
+                       probe_ent2 = ata_pci_init_legacy_port(pdev, port[1], 1);
        } else {
                if (n_ports == 2)
                        probe_ent = ata_pci_init_native_mode(pdev, port, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
diff --combined drivers/scsi/pdc_adma.c
index 988d0d70a2774d46c2b38c3ce4d2120873627de5,665017eda8a6596754b7f69bb6d6565597e3172f..a50588c60fabc62e256aaf7880d2ba453aab9f22
@@@ -40,6 -40,7 +40,7 @@@
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/sched.h>
+ #include <linux/device.h>
  #include "scsi.h"
  #include <scsi/scsi_host.h>
  #include <asm/io.h>
@@@ -292,14 -293,14 +293,14 @@@ static void adma_eng_timeout(struct ata
  
  static int adma_fill_sg(struct ata_queued_cmd *qc)
  {
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg;
        struct ata_port *ap = qc->ap;
        struct adma_port_priv *pp = ap->private_data;
        u8  *buf = pp->pkt;
 -      int nelem, i = (2 + buf[3]) * 8;
 +      int i = (2 + buf[3]) * 8;
        u8 pFLAGS = pORD | ((qc->tf.flags & ATA_TFLAG_WRITE) ? pDIRO : 0);
  
 -      for (nelem = 0; nelem < qc->n_elem; nelem++,sg++) {
 +      ata_for_each_sg(sg, qc) {
                u32 addr;
                u32 len;
  
                *(__le32 *)(buf + i) = cpu_to_le32(len);
                i += 4;
  
 -              if ((nelem + 1) == qc->n_elem)
 +              if (ata_sg_is_last(sg, qc))
                        pFLAGS |= pEND;
                buf[i++] = pFLAGS;
                buf[i++] = qc->dev->dma_mode & 0xf;
@@@ -626,16 -627,14 +627,14 @@@ static int adma_set_dma_masks(struct pc
  
        rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
        if (rc) {
-               printk(KERN_ERR DRV_NAME
-                       "(%s): 32-bit DMA enable failed\n",
-                       pci_name(pdev));
+               dev_printk(KERN_ERR, &pdev->dev,
+                       "32-bit DMA enable failed\n");
                return rc;
        }
        rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
        if (rc) {
-               printk(KERN_ERR DRV_NAME
-                       "(%s): 32-bit consistent DMA enable failed\n",
-                       pci_name(pdev));
+               dev_printk(KERN_ERR, &pdev->dev,
+                       "32-bit consistent DMA enable failed\n");
                return rc;
        }
        return 0;
@@@ -651,7 -650,7 +650,7 @@@ static int adma_ata_init_one(struct pci
        int rc, port_no;
  
        if (!printed_version++)
-               printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  
        rc = pci_enable_device(pdev);
        if (rc)
diff --combined drivers/scsi/sata_mv.c
index a3ab14c79cdd61d133ddfcbbbdecb055219cf342,46dbdee79f77af8d51ecbe334323bea22c2f641c..64af334e71f49daaad0622a384fc20e11e6015ef
@@@ -29,6 -29,7 +29,7 @@@
  #include <linux/interrupt.h>
  #include <linux/sched.h>
  #include <linux/dma-mapping.h>
+ #include <linux/device.h>
  #include "scsi.h"
  #include <scsi/scsi_host.h>
  #include <linux/libata.h>
@@@ -783,24 -784,23 +784,24 @@@ static void mv_port_stop(struct ata_por
  static void mv_fill_sg(struct ata_queued_cmd *qc)
  {
        struct mv_port_priv *pp = qc->ap->private_data;
 -      unsigned int i;
 +      unsigned int i = 0;
 +      struct scatterlist *sg;
  
 -      for (i = 0; i < qc->n_elem; i++) {
 +      ata_for_each_sg(sg, qc) {
                u32 sg_len;
                dma_addr_t addr;
  
 -              addr = sg_dma_address(&qc->sg[i]);
 -              sg_len = sg_dma_len(&qc->sg[i]);
 +              addr = sg_dma_address(sg);
 +              sg_len = sg_dma_len(sg);
  
                pp->sg_tbl[i].addr = cpu_to_le32(addr & 0xffffffff);
                pp->sg_tbl[i].addr_hi = cpu_to_le32((addr >> 16) >> 16);
                assert(0 == (sg_len & ~MV_DMA_BOUNDARY));
                pp->sg_tbl[i].flags_size = cpu_to_le32(sg_len);
 -      }
 -      if (0 < qc->n_elem) {
 -              pp->sg_tbl[qc->n_elem - 1].flags_size |= 
 -                      cpu_to_le32(EPRD_FLAG_END_OF_TBL);
 +              if (ata_sg_is_last(sg, qc))
 +                      pp->sg_tbl[i].flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
 +
 +              i++;
        }
  }
  
@@@ -1438,9 -1438,9 +1439,9 @@@ static void mv_print_info(struct ata_pr
        else
                scc_s = "unknown";
  
-       printk(KERN_INFO DRV_NAME 
-              "(%s) %u slots %u ports %s mode IRQ via %s\n",
-              pci_name(pdev), (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, 
+       dev_printk(KERN_INFO, &pdev->dev,
+              "%u slots %u ports %s mode IRQ via %s\n",
+              (unsigned)MV_MAX_Q_DEPTH, probe_ent->n_ports, 
               scc_s, (MV_HP_FLAG_MSI & hpriv->hp_flags) ? "MSI" : "INTx");
  }
  
@@@ -1461,9 -1461,8 +1462,8 @@@ static int mv_init_one(struct pci_dev *
        void __iomem *mmio_base;
        int pci_dev_busy = 0, rc;
  
-       if (!printed_version++) {
-               printk(KERN_INFO DRV_NAME " version " DRV_VERSION "\n");
-       }
+       if (!printed_version++)
+               dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
  
        rc = pci_enable_device(pdev);
        if (rc) {
index 8c20229b01b4a31b8841ef646da85445d24ae2e7,9938dae782b6b1b2ba6255e4ba67203a72fc650d..65502c157a5497c1112c0de5a523a037de1333ec
@@@ -35,6 -35,7 +35,7 @@@
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/sched.h>
+ #include <linux/device.h>
  #include "scsi.h"
  #include <scsi/scsi_host.h>
  #include <asm/io.h>
@@@ -270,17 -271,16 +271,17 @@@ static void qs_scr_write (struct ata_po
  
  static void qs_fill_sg(struct ata_queued_cmd *qc)
  {
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg;
        struct ata_port *ap = qc->ap;
        struct qs_port_priv *pp = ap->private_data;
        unsigned int nelem;
        u8 *prd = pp->pkt + QS_CPB_BYTES;
  
 -      assert(sg != NULL);
 +      assert(qc->__sg != NULL);
        assert(qc->n_elem > 0);
  
 -      for (nelem = 0; nelem < qc->n_elem; nelem++,sg++) {
 +      nelem = 0;
 +      ata_for_each_sg(sg, qc) {
                u64 addr;
                u32 len;
  
  
                VPRINTK("PRD[%u] = (0x%llX, 0x%X)\n", nelem,
                                        (unsigned long long)addr, len);
 +              nelem++;
        }
  }
  
@@@ -602,25 -601,22 +603,22 @@@ static int qs_set_dma_masks(struct pci_
                if (rc) {
                        rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
                        if (rc) {
-                               printk(KERN_ERR DRV_NAME
-                                       "(%s): 64-bit DMA enable failed\n",
-                                       pci_name(pdev));
+                               dev_printk(KERN_ERR, &pdev->dev,
+                                          "64-bit DMA enable failed\n");
                                return rc;
                        }
                }
        } else {
                rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
                if (rc) {
-                       printk(KERN_ERR DRV_NAME
-                               "(%s): 32-bit DMA enable failed\n",
-                               pci_name(pdev));
+                       dev_printk(KERN_ERR, &pdev->dev,
+                               "32-bit DMA enable failed\n");
                        return rc;
                }
                rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
                if (rc) {
-                       printk(KERN_ERR DRV_NAME
-                               "(%s): 32-bit consistent DMA enable failed\n",
-                               pci_name(pdev));
+                       dev_printk(KERN_ERR, &pdev->dev,
+                               "32-bit consistent DMA enable failed\n");
                        return rc;
                }
        }
@@@ -637,7 -633,7 +635,7 @@@ static int qs_ata_init_one(struct pci_d
        int rc, port_no;
  
        if (!printed_version++)
-               printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  
        rc = pci_enable_device(pdev);
        if (rc)
index 05ce84286aea34bac3957571e39bc04729838958,c66548025657e52339ab89d9f0a1914b8ff58111..211ec7eebc9c864ef2b0470cbd8d48d08b07d548
@@@ -35,6 -35,7 +35,7 @@@
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/dma-mapping.h>
+ #include <linux/device.h>
  #include <scsi/scsi_host.h>
  #include "scsi.h"
  #include <linux/libata.h>
@@@ -410,20 -411,15 +411,20 @@@ static void sil24_phy_reset(struct ata_
  static inline void sil24_fill_sg(struct ata_queued_cmd *qc,
                                 struct sil24_cmd_block *cb)
  {
 -      struct scatterlist *sg = qc->sg;
        struct sil24_sge *sge = cb->sge;
 -      unsigned i;
 +      struct scatterlist *sg;
 +      unsigned int idx = 0;
  
 -      for (i = 0; i < qc->n_elem; i++, sg++, sge++) {
 +      ata_for_each_sg(sg, qc) {
                sge->addr = cpu_to_le64(sg_dma_address(sg));
                sge->cnt = cpu_to_le32(sg_dma_len(sg));
 -              sge->flags = 0;
 -              sge->flags = i < qc->n_elem - 1 ? 0 : cpu_to_le32(SGE_TRM);
 +              if (ata_sg_is_last(sg, qc))
 +                      sge->flags = cpu_to_le32(SGE_TRM);
 +              else
 +                      sge->flags = 0;
 +
 +              sge++;
 +              idx++;
        }
  }
  
@@@ -695,7 -691,7 +696,7 @@@ static int sil24_init_one(struct pci_de
        int i, rc;
  
        if (!printed_version++)
-               printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  
        rc = pci_enable_device(pdev);
        if (rc)
         */
        rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
        if (rc) {
-               printk(KERN_ERR DRV_NAME "(%s): 32-bit DMA enable failed\n",
-                      pci_name(pdev));
+               dev_printk(KERN_ERR, &pdev->dev,
+                          "32-bit DMA enable failed\n");
                goto out_free;
        }
        rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
        if (rc) {
-               printk(KERN_ERR DRV_NAME "(%s): 32-bit consistent DMA enable failed\n",
-                      pci_name(pdev));
+               dev_printk(KERN_ERR, &pdev->dev,
+                          "32-bit consistent DMA enable failed\n");
                goto out_free;
        }
  
                                        break;
                        }
                        if (tmp & PORT_CS_PORT_RST)
-                               printk(KERN_ERR DRV_NAME
-                                      "(%s): failed to clear port RST\n",
-                                      pci_name(pdev));
+                               dev_printk(KERN_ERR, &pdev->dev,
+                                          "failed to clear port RST\n");
                }
  
                /* Zero error counters. */
  
                /* Reset itself */
                if (__sil24_reset_controller(port))
-                       printk(KERN_ERR DRV_NAME
-                              "(%s): failed to reset controller\n",
-                              pci_name(pdev));
+                       dev_printk(KERN_ERR, &pdev->dev,
+                                  "failed to reset controller\n");
        }
  
        /* Turn on interrupts */
diff --combined drivers/scsi/sata_sx4.c
index 8e2e7b8308c07a866af9a7e441af93dc6682f1ce,0ec21e09f5d84d04a20a0b32e0f58fbf205f8457..f859bbd681ed30721da8b3043c9805de12977637
@@@ -38,6 -38,7 +38,7 @@@
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/sched.h>
+ #include <linux/device.h>
  #include "scsi.h"
  #include <scsi/scsi_host.h>
  #include <linux/libata.h>
@@@ -449,14 -450,14 +450,14 @@@ static inline void pdc20621_host_pkt(st
  
  static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
  {
 -      struct scatterlist *sg = qc->sg;
 +      struct scatterlist *sg;
        struct ata_port *ap = qc->ap;
        struct pdc_port_priv *pp = ap->private_data;
        void __iomem *mmio = ap->host_set->mmio_base;
        struct pdc_host_priv *hpriv = ap->host_set->private_data;
        void __iomem *dimm_mmio = hpriv->dimm_mmio;
        unsigned int portno = ap->port_no;
 -      unsigned int i, last, idx, total_len = 0, sgt_len;
 +      unsigned int i, idx, total_len = 0, sgt_len;
        u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
  
        assert(qc->flags & ATA_QCFLAG_DMAMAP);
        /*
         * Build S/G table
         */
 -      last = qc->n_elem;
        idx = 0;
 -      for (i = 0; i < last; i++) {
 -              buf[idx++] = cpu_to_le32(sg_dma_address(&sg[i]));
 -              buf[idx++] = cpu_to_le32(sg_dma_len(&sg[i]));
 -              total_len += sg_dma_len(&sg[i]);
 +      ata_for_each_sg(sg, qc) {
 +              buf[idx++] = cpu_to_le32(sg_dma_address(sg));
 +              buf[idx++] = cpu_to_le32(sg_dma_len(sg));
 +              total_len += sg_dma_len(sg);
        }
        buf[idx - 1] |= cpu_to_le32(ATA_PRD_EOT);
        sgt_len = idx * 4;
@@@ -1384,7 -1386,7 +1385,7 @@@ static int pdc_sata_init_one (struct pc
        int rc;
  
        if (!printed_version++)
-               printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
+               dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
  
        /*
         * If this driver happens to only be useful on Apple's K2, then