]> err.no Git - linux-2.6/blobdiff - drivers/ata/sata_nv.c
[libata] Prefer SCSI_SENSE_BUFFERSIZE to sizeof()
[linux-2.6] / drivers / ata / sata_nv.c
index 8d55f7fb50af4e644ffd21aaa42d8c303ec8b161..a0f98fdab7a0c04da379acd19f72add501e69aa0 100644 (file)
@@ -291,7 +291,7 @@ struct nv_swncq_port_priv {
 };
 
 
-#define NV_ADMA_CHECK_INTR(GCTL, PORT) ((GCTL) & ( 1 << (19 + (12 * (PORT)))))
+#define NV_ADMA_CHECK_INTR(GCTL, PORT) ((GCTL) & (1 << (19 + (12 * (PORT)))))
 
 static int nv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
 #ifdef CONFIG_PM
@@ -791,11 +791,13 @@ static int nv_adma_check_atapi_dma(struct ata_queued_cmd *qc)
 
 static void nv_adma_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
 {
-       /* Since commands where a result TF is requested are not
-          executed in ADMA mode, the only time this function will be called
-          in ADMA mode will be if a command fails. In this case we
-          don't care about going into register mode with ADMA commands
-          pending, as the commands will all shortly be aborted anyway. */
+       /* Other than when internal or pass-through commands are executed,
+          the only time this function will be called in ADMA mode will be
+          if a command fails. In the failure case we don't care about going
+          into register mode with ADMA commands pending, as the commands will
+          all shortly be aborted anyway. We assume that NCQ commands are not
+          issued via passthrough, which is the only way that switching into
+          ADMA mode could abort outstanding commands. */
        nv_adma_register_mode(ap);
 
        ata_tf_read(ap, tf);
@@ -884,8 +886,9 @@ static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
                        /* Notifier bits set without a command may indicate the drive
                           is misbehaving. Raise host state machine violation on this
                           condition. */
-                       ata_port_printk(ap, KERN_ERR, "notifier for tag %d with no command?\n",
-                               cpb_num);
+                       ata_port_printk(ap, KERN_ERR,
+                                       "notifier for tag %d with no cmd?\n",
+                                       cpb_num);
                        ehi->err_mask |= AC_ERR_HSM;
                        ehi->action |= ATA_EH_SOFTRESET;
                        ata_port_freeze(ap);
@@ -1021,8 +1024,8 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
                                while ((pos = ffs(check_commands)) && !error) {
                                        pos--;
                                        error = nv_adma_check_cpb(ap, pos,
-                                               notifier_error & (1 << pos) );
-                                       check_commands &= ~(1 << pos );
+                                               notifier_error & (1 << pos));
+                                       check_commands &= ~(1 << pos);
                                }
                        }
                }
@@ -1061,7 +1064,7 @@ static void nv_adma_freeze(struct ata_port *ap)
        tmp = readw(mmio + NV_ADMA_CTL);
        writew(tmp & ~(NV_ADMA_CTL_AIEN | NV_ADMA_CTL_HOTPLUG_IEN),
                mmio + NV_ADMA_CTL);
-       readw(mmio + NV_ADMA_CTL );     /* flush posted write */
+       readw(mmio + NV_ADMA_CTL);      /* flush posted write */
 }
 
 static void nv_adma_thaw(struct ata_port *ap)
@@ -1079,7 +1082,7 @@ static void nv_adma_thaw(struct ata_port *ap)
        tmp = readw(mmio + NV_ADMA_CTL);
        writew(tmp | (NV_ADMA_CTL_AIEN | NV_ADMA_CTL_HOTPLUG_IEN),
                mmio + NV_ADMA_CTL);
-       readw(mmio + NV_ADMA_CTL );     /* flush posted write */
+       readw(mmio + NV_ADMA_CTL);      /* flush posted write */
 }
 
 static void nv_adma_irq_clear(struct ata_port *ap)
@@ -1165,7 +1168,7 @@ static int nv_adma_port_start(struct ata_port *ap)
        pp->cpb_dma = mem_dma;
 
        writel(mem_dma & 0xFFFFFFFF,    mmio + NV_ADMA_CPB_BASE_LOW);
-       writel((mem_dma >> 16 ) >> 16,  mmio + NV_ADMA_CPB_BASE_HIGH);
+       writel((mem_dma >> 16) >> 16,   mmio + NV_ADMA_CPB_BASE_HIGH);
 
        mem     += NV_ADMA_MAX_CPBS * NV_ADMA_CPB_SZ;
        mem_dma += NV_ADMA_MAX_CPBS * NV_ADMA_CPB_SZ;
@@ -1189,15 +1192,15 @@ static int nv_adma_port_start(struct ata_port *ap)
 
        /* clear GO for register mode, enable interrupt */
        tmp = readw(mmio + NV_ADMA_CTL);
-       writew( (tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN |
-                NV_ADMA_CTL_HOTPLUG_IEN, mmio + NV_ADMA_CTL);
+       writew((tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN |
+               NV_ADMA_CTL_HOTPLUG_IEN, mmio + NV_ADMA_CTL);
 
        tmp = readw(mmio + NV_ADMA_CTL);
        writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
-       readw(mmio + NV_ADMA_CTL );     /* flush posted write */
+       readw(mmio + NV_ADMA_CTL);      /* flush posted write */
        udelay(1);
        writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
-       readw(mmio + NV_ADMA_CTL );     /* flush posted write */
+       readw(mmio + NV_ADMA_CTL);      /* flush posted write */
 
        return 0;
 }
@@ -1237,7 +1240,7 @@ static int nv_adma_port_resume(struct ata_port *ap)
 
        /* set CPB block location */
        writel(pp->cpb_dma & 0xFFFFFFFF,        mmio + NV_ADMA_CPB_BASE_LOW);
-       writel((pp->cpb_dma >> 16 ) >> 16,      mmio + NV_ADMA_CPB_BASE_HIGH);
+       writel((pp->cpb_dma >> 16) >> 16,       mmio + NV_ADMA_CPB_BASE_HIGH);
 
        /* clear any outstanding interrupt conditions */
        writew(0xffff, mmio + NV_ADMA_STAT);
@@ -1250,15 +1253,15 @@ static int nv_adma_port_resume(struct ata_port *ap)
 
        /* clear GO for register mode, enable interrupt */
        tmp = readw(mmio + NV_ADMA_CTL);
-       writew( (tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN |
-                NV_ADMA_CTL_HOTPLUG_IEN, mmio + NV_ADMA_CTL);
+       writew((tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN |
+               NV_ADMA_CTL_HOTPLUG_IEN, mmio + NV_ADMA_CTL);
 
        tmp = readw(mmio + NV_ADMA_CTL);
        writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
-       readw(mmio + NV_ADMA_CTL );     /* flush posted write */
+       readw(mmio + NV_ADMA_CTL);      /* flush posted write */
        udelay(1);
        writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
-       readw(mmio + NV_ADMA_CTL );     /* flush posted write */
+       readw(mmio + NV_ADMA_CTL);      /* flush posted write */
 
        return 0;
 }
@@ -1333,20 +1336,18 @@ static void nv_adma_fill_aprd(struct ata_queued_cmd *qc,
 static void nv_adma_fill_sg(struct ata_queued_cmd *qc, struct nv_adma_cpb *cpb)
 {
        struct nv_adma_port_priv *pp = qc->ap->private_data;
-       unsigned int idx;
        struct nv_adma_prd *aprd;
        struct scatterlist *sg;
+       unsigned int si;
 
        VPRINTK("ENTER\n");
 
-       idx = 0;
-
-       ata_for_each_sg(sg, qc) {
-               aprd = (idx < 5) ? &cpb->aprd[idx] : &pp->aprd[NV_ADMA_SGTBL_LEN * qc->tag + (idx-5)];
-               nv_adma_fill_aprd(qc, sg, idx, aprd);
-               idx++;
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
+               aprd = (si < 5) ? &cpb->aprd[si] :
+                              &pp->aprd[NV_ADMA_SGTBL_LEN * qc->tag + (si-5)];
+               nv_adma_fill_aprd(qc, sg, si, aprd);
        }
-       if (idx > 5)
+       if (si > 5)
                cpb->next_aprd = cpu_to_le64(((u64)(pp->aprd_dma + NV_ADMA_SGTBL_SZ * qc->tag)));
        else
                cpb->next_aprd = cpu_to_le64(0);
@@ -1357,11 +1358,9 @@ static int nv_adma_use_reg_mode(struct ata_queued_cmd *qc)
        struct nv_adma_port_priv *pp = qc->ap->private_data;
 
        /* ADMA engine can only be used for non-ATAPI DMA commands,
-          or interrupt-driven no-data commands, where a result taskfile
-          is not required. */
+          or interrupt-driven no-data commands. */
        if ((pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) ||
-          (qc->tf.flags & ATA_TFLAG_POLLING) ||
-          (qc->flags & ATA_QCFLAG_RESULT_TF))
+          (qc->tf.flags & ATA_TFLAG_POLLING))
                return 1;
 
        if ((qc->flags & ATA_QCFLAG_DMAMAP) ||
@@ -1379,6 +1378,8 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
                       NV_CPB_CTL_IEN;
 
        if (nv_adma_use_reg_mode(qc)) {
+               BUG_ON(!(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) &&
+                       (qc->flags & ATA_QCFLAG_DMAMAP));
                nv_adma_register_mode(qc->ap);
                ata_qc_prep(qc);
                return;
@@ -1407,8 +1408,8 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
        } else
                memset(&cpb->aprd[0], 0, sizeof(struct nv_adma_prd) * 5);
 
-       /* Be paranoid and don't let the device see NV_CPB_CTL_CPB_VALID until we are
-          finished filling in all of the contents */
+       /* Be paranoid and don't let the device see NV_CPB_CTL_CPB_VALID
+          until we are finished filling in all of the contents */
        wmb();
        cpb->ctl_flags = ctl_flags;
        wmb();
@@ -1423,9 +1424,21 @@ static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
 
        VPRINTK("ENTER\n");
 
+       /* We can't handle result taskfile with NCQ commands, since
+          retrieving the taskfile switches us out of ADMA mode and would abort
+          existing commands. */
+       if (unlikely(qc->tf.protocol == ATA_PROT_NCQ &&
+                    (qc->flags & ATA_QCFLAG_RESULT_TF))) {
+               ata_dev_printk(qc->dev, KERN_ERR,
+                       "NCQ w/ RESULT_TF not allowed\n");
+               return AC_ERR_SYSTEM;
+       }
+
        if (nv_adma_use_reg_mode(qc)) {
                /* use ATA register mode */
                VPRINTK("using ATA register mode: 0x%lx\n", qc->flags);
+               BUG_ON(!(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) &&
+                       (qc->flags & ATA_QCFLAG_DMAMAP));
                nv_adma_register_mode(qc->ap);
                return ata_qc_issue_prot(qc);
        } else
@@ -1436,15 +1449,15 @@ static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
        wmb();
 
        if (curr_ncq != pp->last_issue_ncq) {
-               /* Seems to need some delay before switching between NCQ and non-NCQ
-                  commands, else we get command timeouts and such. */
+               /* Seems to need some delay before switching between NCQ and
+                  non-NCQ commands, else we get command timeouts and such. */
                udelay(20);
                pp->last_issue_ncq = curr_ncq;
        }
 
        writew(qc->tag, mmio + NV_ADMA_APPEND);
 
-       DPRINTK("Issued tag %u\n",qc->tag);
+       DPRINTK("Issued tag %u\n", qc->tag);
 
        return 0;
 }
@@ -1627,7 +1640,7 @@ static int nv_hardreset(struct ata_link *link, unsigned int *class,
 
        /* SATA hardreset fails to retrieve proper device signature on
         * some controllers.  Don't classify on hardreset.  For more
-        * info, see http://bugme.osdl.org/show_bug.cgi?id=3352
+        * info, see http://bugzilla.kernel.org/show_bug.cgi?id=3352
         */
        return sata_std_hardreset(link, &dummy, deadline);
 }
@@ -1654,7 +1667,8 @@ static void nv_adma_error_handler(struct ata_port *ap)
                        u8 cpb_count = readb(mmio + NV_ADMA_CPB_COUNT);
                        u8 next_cpb_idx = readb(mmio + NV_ADMA_NEXT_CPB_IDX);
 
-                       ata_port_printk(ap, KERN_ERR, "EH in ADMA mode, notifier 0x%X "
+                       ata_port_printk(ap, KERN_ERR,
+                               "EH in ADMA mode, notifier 0x%X "
                                "notifier_error 0x%X gen_ctl 0x%X status 0x%X "
                                "next cpb count 0x%X next cpb idx 0x%x\n",
                                notifier, notifier_error, gen_ctl, status,
@@ -1663,7 +1677,7 @@ static void nv_adma_error_handler(struct ata_port *ap)
                        for (i = 0; i < NV_ADMA_MAX_CPBS; i++) {
                                struct nv_adma_cpb *cpb = &pp->cpb[i];
                                if ((ata_tag_valid(ap->link.active_tag) && i == ap->link.active_tag) ||
-                                   ap->link.sactive & (1 << i) )
+                                   ap->link.sactive & (1 << i))
                                        ata_port_printk(ap, KERN_ERR,
                                                "CPB %d: ctl_flags 0x%x, resp_flags 0x%x\n",
                                                i, cpb->ctl_flags, cpb->resp_flags);
@@ -1673,7 +1687,8 @@ static void nv_adma_error_handler(struct ata_port *ap)
                /* Push us back into port register mode for error handling. */
                nv_adma_register_mode(ap);
 
-               /* Mark all of the CPBs as invalid to prevent them from being executed */
+               /* Mark all of the CPBs as invalid to prevent them from
+                  being executed */
                for (i = 0; i < NV_ADMA_MAX_CPBS; i++)
                        pp->cpb[i].ctl_flags &= ~NV_CPB_CTL_CPB_VALID;
 
@@ -1977,17 +1992,14 @@ static void nv_swncq_fill_sg(struct ata_queued_cmd *qc)
 {
        struct ata_port *ap = qc->ap;
        struct scatterlist *sg;
-       unsigned int idx;
        struct nv_swncq_port_priv *pp = ap->private_data;
        struct ata_prd *prd;
-
-       WARN_ON(qc->__sg == NULL);
-       WARN_ON(qc->n_elem == 0 && qc->pad_len == 0);
+       unsigned int si, idx;
 
        prd = pp->prd + ATA_MAX_PRD * qc->tag;
 
        idx = 0;
-       ata_for_each_sg(sg, qc) {
+       for_each_sg(qc->sg, sg, qc->n_elem, si) {
                u32 addr, offset;
                u32 sg_len, len;
 
@@ -2009,8 +2021,7 @@ static void nv_swncq_fill_sg(struct ata_queued_cmd *qc)
                }
        }
 
-       if (idx)
-               prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
+       prd[idx - 1].flags_len |= cpu_to_le32(ATA_PRD_EOT);
 }
 
 static unsigned int nv_swncq_issue_atacmd(struct ata_port *ap,
@@ -2350,9 +2361,9 @@ static irqreturn_t nv_swncq_interrupt(int irq, void *dev_instance)
        return IRQ_RETVAL(handled);
 }
 
-static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
+static int nv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
-       static int printed_version = 0;
+       static int printed_version;
        const struct ata_port_info *ppi[] = { NULL, NULL };
        struct ata_host *host;
        struct nv_host_priv *hpriv;
@@ -2364,7 +2375,7 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
         // Make sure this is a SATA controller by counting the number of bars
         // (NVIDIA SATA controllers will always have six bars).  Otherwise,
         // it's an IDE controller and we ignore it.
-       for (bar=0; bar<6; bar++)
+       for (bar = 0; bar < 6; bar++)
                if (pci_resource_start(pdev, bar) == 0)
                        return -ENODEV;
 
@@ -2381,6 +2392,14 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
                type = ADMA;
        }
 
+       if (type == SWNCQ) {
+               if (swncq_enabled)
+                       dev_printk(KERN_NOTICE, &pdev->dev,
+                                  "Using SWNCQ mode\n");
+               else
+                       type = GENERIC;
+       }
+
        ppi[0] = &nv_port_info[type];
        rc = ata_pci_prepare_sff_host(pdev, ppi, &host);
        if (rc)
@@ -2422,10 +2441,8 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
                rc = nv_adma_host_init(host);
                if (rc)
                        return rc;
-       } else if (type == SWNCQ && swncq_enabled) {
-               dev_printk(KERN_NOTICE, &pdev->dev, "Using SWNCQ mode\n");
+       } else if (type == SWNCQ)
                nv_swncq_host_init(host);
-       }
 
        pci_set_master(pdev);
        return ata_host_activate(host, pdev->irq, ppi[0]->irq_handler,
@@ -2460,17 +2477,17 @@ static int nv_pci_device_resume(struct pci_dev *pdev)
                        pp = host->ports[0]->private_data;
                        if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)
                                tmp32 &= ~(NV_MCP_SATA_CFG_20_PORT0_EN |
-                                          NV_MCP_SATA_CFG_20_PORT0_PWB_EN);
+                                          NV_MCP_SATA_CFG_20_PORT0_PWB_EN);
                        else
                                tmp32 |=  (NV_MCP_SATA_CFG_20_PORT0_EN |
-                                          NV_MCP_SATA_CFG_20_PORT0_PWB_EN);
+                                          NV_MCP_SATA_CFG_20_PORT0_PWB_EN);
                        pp = host->ports[1]->private_data;
                        if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)
                                tmp32 &= ~(NV_MCP_SATA_CFG_20_PORT1_EN |
-                                          NV_MCP_SATA_CFG_20_PORT1_PWB_EN);
+                                          NV_MCP_SATA_CFG_20_PORT1_PWB_EN);
                        else
                                tmp32 |=  (NV_MCP_SATA_CFG_20_PORT1_EN |
-                                          NV_MCP_SATA_CFG_20_PORT1_PWB_EN);
+                                          NV_MCP_SATA_CFG_20_PORT1_PWB_EN);
 
                        pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, tmp32);
                }