]> err.no Git - linux-2.6/blobdiff - drivers/scsi/sata_sil24.c
Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6] / drivers / scsi / sata_sil24.c
index 4afe2b15b80326ac2fed0a30ba44864b1fc86c29..cb1933a3bd55e03ca88ccfe9e5e6af74dd9a07e6 100644 (file)
@@ -35,8 +35,9 @@
 #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 <scsi/scsi_cmnd.h>
 #include <linux/libata.h>
 #include <asm/io.h>
 
@@ -138,6 +139,7 @@ enum {
        PORT_CS_DEV_RST         = (1 << 1), /* device reset */
        PORT_CS_INIT            = (1 << 2), /* port initialize */
        PORT_CS_IRQ_WOC         = (1 << 3), /* interrupt write one to clear */
+       PORT_CS_CDB16           = (1 << 5), /* 0=12b cdb, 1=16b cdb */
        PORT_CS_RESUME          = (1 << 6), /* port resume */
        PORT_CS_32BIT_ACTV      = (1 << 10), /* 32-bit activation */
        PORT_CS_PM_EN           = (1 << 13), /* port multiplier enable */
@@ -187,11 +189,29 @@ enum {
        PORT_CERR_XFR_PCIPERR   = 35, /* PSD ecode 11 - PCI prity err during transfer */
        PORT_CERR_SENDSERVICE   = 36, /* FIS received while sending service */
 
+       /* bits of PRB control field */
+       PRB_CTRL_PROTOCOL       = (1 << 0), /* override def. ATA protocol */
+       PRB_CTRL_PACKET_READ    = (1 << 4), /* PACKET cmd read */
+       PRB_CTRL_PACKET_WRITE   = (1 << 5), /* PACKET cmd write */
+       PRB_CTRL_NIEN           = (1 << 6), /* Mask completion irq */
+       PRB_CTRL_SRST           = (1 << 7), /* Soft reset request (ign BSY?) */
+
+       /* PRB protocol field */
+       PRB_PROT_PACKET         = (1 << 0),
+       PRB_PROT_TCQ            = (1 << 1),
+       PRB_PROT_NCQ            = (1 << 2),
+       PRB_PROT_READ           = (1 << 3),
+       PRB_PROT_WRITE          = (1 << 4),
+       PRB_PROT_TRANSPARENT    = (1 << 5),
+
        /*
         * Other constants
         */
        SGE_TRM                 = (1 << 31), /* Last SGE in chain */
-       PRB_SOFT_RST            = (1 << 7),  /* Soft reset request (ign BSY?) */
+       SGE_LNK                 = (1 << 30), /* linked list
+                                               Points to SGT, not SGE */
+       SGE_DRD                 = (1 << 29), /* discard data read (/dev/null)
+                                               data address ignored */
 
        /* board id */
        BID_SIL3124             = 0,
@@ -239,7 +259,7 @@ static void sil24_port_stop(struct ata_port *ap);
 static void sil24_host_stop(struct ata_host_set *host_set);
 static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
 
-static struct pci_device_id sil24_pci_tbl[] = {
+static const struct pci_device_id sil24_pci_tbl[] = {
        { 0x1095, 0x3124, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3124 },
        { 0x1095, 0x3132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3132 },
        { 0x1095, 0x3131, PCI_ANY_ID, PCI_ANY_ID, 0, 0, BID_SIL3131 },
@@ -254,7 +274,7 @@ static struct pci_driver sil24_pci_driver = {
        .remove                 = ata_pci_remove_one, /* safe? */
 };
 
-static Scsi_Host_Template sil24_sht = {
+static struct scsi_host_template sil24_sht = {
        .module                 = THIS_MODULE,
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
@@ -410,15 +430,20 @@ static void sil24_phy_reset(struct ata_port *ap)
 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++;
        }
 }
 
@@ -629,6 +654,13 @@ static irqreturn_t sil24_interrupt(int irq, void *dev_instance, struct pt_regs *
        return IRQ_RETVAL(handled);
 }
 
+static inline void sil24_cblk_free(struct sil24_port_priv *pp, struct device *dev)
+{
+       const size_t cb_size = sizeof(*pp->cmd_block);
+
+       dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma);
+}
+
 static int sil24_port_start(struct ata_port *ap)
 {
        struct device *dev = ap->host_set->dev;
@@ -636,36 +668,45 @@ static int sil24_port_start(struct ata_port *ap)
        struct sil24_cmd_block *cb;
        size_t cb_size = sizeof(*cb);
        dma_addr_t cb_dma;
+       int rc = -ENOMEM;
 
-       pp = kmalloc(sizeof(*pp), GFP_KERNEL);
+       pp = kzalloc(sizeof(*pp), GFP_KERNEL);
        if (!pp)
-               return -ENOMEM;
-       memset(pp, 0, sizeof(*pp));
+               goto err_out;
 
        pp->tf.command = ATA_DRDY;
 
        cb = dma_alloc_coherent(dev, cb_size, &cb_dma, GFP_KERNEL);
-       if (!cb) {
-               kfree(pp);
-               return -ENOMEM;
-       }
+       if (!cb)
+               goto err_out_pp;
        memset(cb, 0, cb_size);
 
+       rc = ata_pad_alloc(ap, dev);
+       if (rc)
+               goto err_out_pad;
+
        pp->cmd_block = cb;
        pp->cmd_block_dma = cb_dma;
 
        ap->private_data = pp;
 
        return 0;
+
+err_out_pad:
+       sil24_cblk_free(pp, dev);
+err_out_pp:
+       kfree(pp);
+err_out:
+       return rc;
 }
 
 static void sil24_port_stop(struct ata_port *ap)
 {
        struct device *dev = ap->host_set->dev;
        struct sil24_port_priv *pp = ap->private_data;
-       size_t cb_size = sizeof(*pp->cmd_block);
 
-       dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma);
+       sil24_cblk_free(pp, dev);
+       ata_pad_free(ap, dev);
        kfree(pp);
 }
 
@@ -690,7 +731,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
        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)
@@ -750,14 +791,14 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
         */
        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;
        }
 
@@ -793,9 +834,8 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
                                        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. */
@@ -824,9 +864,8 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 
                /* 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 */