]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ieee1394/sbp2.c
[SCSI] relax scsi dma alignment
[linux-2.6-omap-h63xx.git] / drivers / ieee1394 / sbp2.c
index e882cb951b474e06a11a861327f8dde7c73d316f..1eda11abeb1e0b3cb912cb7e0c9bcac196b79810 100644 (file)
 #include <linux/types.h>
 #include <linux/wait.h>
 #include <linux/workqueue.h>
+#include <linux/scatterlist.h>
 
 #include <asm/byteorder.h>
 #include <asm/errno.h>
 #include <asm/param.h>
-#include <asm/scatterlist.h>
 #include <asm/system.h>
 #include <asm/types.h>
 
@@ -242,6 +242,8 @@ static int sbp2_max_speed_and_size(struct sbp2_lu *);
 
 static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC };
 
+static DEFINE_RWLOCK(sbp2_hi_logical_units_lock);
+
 static struct hpsb_highlevel sbp2_highlevel = {
        .name           = SBP2_DEVICE_NAME,
        .host_reset     = sbp2_host_reset,
@@ -513,9 +515,9 @@ static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
        return 0;
 }
 
-static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu)
+static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu,
+                                            struct hpsb_host *host)
 {
-       struct hpsb_host *host = lu->hi->host;
        struct list_head *lh, *next;
        struct sbp2_command_info *cmd;
        unsigned long flags;
@@ -732,6 +734,7 @@ static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
        struct sbp2_fwhost_info *hi;
        struct Scsi_Host *shost = NULL;
        struct sbp2_lu *lu = NULL;
+       unsigned long flags;
 
        lu = kzalloc(sizeof(*lu), GFP_KERNEL);
        if (!lu) {
@@ -773,11 +776,6 @@ static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
                        SBP2_ERR("failed to register lower 4GB address range");
                        goto failed_alloc;
                }
-#else
-               if (dma_set_mask(hi->host->device.parent, DMA_32BIT_MASK)) {
-                       SBP2_ERR("failed to set 4GB DMA mask");
-                       goto failed_alloc;
-               }
 #endif
        }
 
@@ -789,7 +787,9 @@ static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
 
        lu->hi = hi;
 
+       write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
        list_add_tail(&lu->lu_list, &hi->logical_units);
+       write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
 
        /* Register the status FIFO address range. We could use the same FIFO
         * for targets at different nodes. However we need different FIFOs per
@@ -833,16 +833,20 @@ static void sbp2_host_reset(struct hpsb_host *host)
 {
        struct sbp2_fwhost_info *hi;
        struct sbp2_lu *lu;
+       unsigned long flags;
 
        hi = hpsb_get_hostinfo(&sbp2_highlevel, host);
        if (!hi)
                return;
+
+       read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
        list_for_each_entry(lu, &hi->logical_units, lu_list)
                if (likely(atomic_read(&lu->state) !=
                           SBP2LU_STATE_IN_SHUTDOWN)) {
                        atomic_set(&lu->state, SBP2LU_STATE_IN_RESET);
                        scsi_block_requests(lu->shost);
                }
+       read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
 }
 
 static int sbp2_start_device(struct sbp2_lu *lu)
@@ -924,20 +928,24 @@ alloc_fail:
 static void sbp2_remove_device(struct sbp2_lu *lu)
 {
        struct sbp2_fwhost_info *hi;
+       unsigned long flags;
 
        if (!lu)
                return;
-
        hi = lu->hi;
+       if (!hi)
+               goto no_hi;
 
        if (lu->shost) {
                scsi_remove_host(lu->shost);
                scsi_host_put(lu->shost);
        }
        flush_scheduled_work();
-       sbp2util_remove_command_orb_pool(lu);
+       sbp2util_remove_command_orb_pool(lu, hi->host);
 
+       write_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
        list_del(&lu->lu_list);
+       write_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
 
        if (lu->login_response)
                dma_free_coherent(hi->host->device.parent,
@@ -976,9 +984,8 @@ static void sbp2_remove_device(struct sbp2_lu *lu)
 
        lu->ud->device.driver_data = NULL;
 
-       if (hi)
-               module_put(hi->host->driver->owner);
-
+       module_put(hi->host->driver->owner);
+no_hi:
        kfree(lu);
 }
 
@@ -1459,7 +1466,7 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
                cmd->dma_size = sgpnt[0].length;
                cmd->dma_type = CMD_DMA_PAGE;
                cmd->cmd_dma = dma_map_page(hi->host->device.parent,
-                                           sgpnt[0].page, sgpnt[0].offset,
+                                           sg_page(&sgpnt[0]), sgpnt[0].offset,
                                            cmd->dma_size, cmd->dma_dir);
 
                orb->data_descriptor_lo = cmd->cmd_dma;
@@ -1712,6 +1719,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
        }
 
        /* Find the unit which wrote the status. */
+       read_lock_irqsave(&sbp2_hi_logical_units_lock, flags);
        list_for_each_entry(lu_tmp, &hi->logical_units, lu_list) {
                if (lu_tmp->ne->nodeid == nodeid &&
                    lu_tmp->status_fifo_addr == addr) {
@@ -1719,6 +1727,8 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
                        break;
                }
        }
+       read_unlock_irqrestore(&sbp2_hi_logical_units_lock, flags);
+
        if (unlikely(!lu)) {
                SBP2_ERR("lu is NULL - device is gone?");
                return RCODE_ADDRESS_ERROR;
@@ -1953,6 +1963,12 @@ static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
        lu->sdev = sdev;
        sdev->allow_restart = 1;
 
+       /*
+        * Update the dma alignment (minimum alignment requirements for
+        * start and end of DMA transfers) to be a sector
+        */
+       blk_queue_update_dma_alignment(sdev->request_queue, 511);
+
        if (lu->workarounds & SBP2_WORKAROUND_INQUIRY_36)
                sdev->inquiry_len = 36;
        return 0;