]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[SCSI] libsas, aic94xx: fix dma mapping cockups with ATA
authorJames Bottomley <James.Bottomley@steeleye.com>
Mon, 16 Jul 2007 18:41:04 +0000 (13:41 -0500)
committerJames Bottomley <jejb@mulgrave.localdomain>
Wed, 18 Jul 2007 16:16:14 +0000 (11:16 -0500)
This one was noticed by Gilbert Wu of Adaptec:

The libata core actually does the DMA mapping for you, so there has to
be an exception in the device drivers that *don't* do dma mapping for
ATA commands.  However, since we've already done this, libsas must now
dma map any ATA commands that it wishes to issue ... and yes, this is a
horrible mess.

Additionally, the test in aic94xx for ATA protocols isn't quite right.

Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
drivers/scsi/aic94xx/aic94xx_task.c
drivers/scsi/libsas/sas_discover.c
include/scsi/scsi_transport_sas.h

index 6c12c0f19f394ae0c87e0fac907dcb5785482aa4..d5d8caba35605f3643b165211d84aa583f29bbd4 100644 (file)
@@ -76,7 +76,7 @@ static inline int asd_map_scatterlist(struct sas_task *task,
 
        /* STP tasks come from libata which has already mapped
         * the SG list */
-       if (task->task_proto == SAS_PROTOCOL_STP)
+       if (sas_protocol_ata(task->task_proto))
                num_sg = task->num_scatter;
        else
                num_sg = pci_map_sg(asd_ha->pcidev, task->scatter,
@@ -125,7 +125,7 @@ static inline int asd_map_scatterlist(struct sas_task *task,
 
        return 0;
 err_unmap:
-       if (task->task_proto != SAS_PROTOCOL_STP)
+       if (sas_protocol_ata(task->task_proto))
                pci_unmap_sg(asd_ha->pcidev, task->scatter, task->num_scatter,
                             task->data_dir);
        return res;
index a18c0f6d66682aa612e4357736503cdd92b96f56..4d768db1b5674ae0e50b0c8d4f0574ccda9ebd48 100644 (file)
@@ -110,6 +110,13 @@ static int sas_execute_task(struct sas_task *task, void *buffer, int size,
        task->total_xfer_len = size;
        task->data_dir = pci_dma_dir;
        task->task_done = sas_disc_task_done;
+       if (pci_dma_dir != PCI_DMA_NONE &&
+           sas_protocol_ata(task->task_proto)) {
+               task->num_scatter = pci_map_sg(task->dev->port->ha->pcidev,
+                                              task->scatter,
+                                              task->num_scatter,
+                                              task->data_dir);
+       }
 
        for (retries = 0; retries < 5; retries++) {
                task->task_state_flags = SAS_TASK_STATE_PENDING;
@@ -192,8 +199,13 @@ static int sas_execute_task(struct sas_task *task, void *buffer, int size,
                }
        }
 ex_err:
-       if (pci_dma_dir != PCI_DMA_NONE)
+       if (pci_dma_dir != PCI_DMA_NONE) {
+               if (sas_protocol_ata(task->task_proto))
+                       pci_unmap_sg(task->dev->port->ha->pcidev,
+                                    task->scatter, task->num_scatter,
+                                    task->data_dir);
                kfree(scatter);
+       }
 out:
        return res;
 }
index 9aedc19820b0df1d007b0d8e7150de5e3c07e5fd..97eeb5b59ea5c286ca8f10a5ad1fa436e7a9662f 100644 (file)
@@ -23,6 +23,12 @@ enum sas_protocol {
        SAS_PROTOCOL_SSP                = 0x08,
 };
 
+static inline int sas_protocol_ata(enum sas_protocol proto)
+{
+       return ((proto & SAS_PROTOCOL_SATA) ||
+               (proto & SAS_PROTOCOL_STP))? 1 : 0;
+}
+
 enum sas_linkrate {
        /* These Values are defined in the SAS standard */
        SAS_LINK_RATE_UNKNOWN = 0,