]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ieee1394/sbp2.c
[SCSI] Merge up to linux-2.6 head
[linux-2.6-omap-h63xx.git] / drivers / ieee1394 / sbp2.c
index 4325aac7733d090f4708e5a0adf947d537d1e531..ce86ff226a283c2e185c7bcbe93c6261c906914c 100644 (file)
@@ -51,7 +51,6 @@
  * Grep for inline FIXME comments below.
  */
 
-#include <linux/blkdev.h>
 #include <linux/compiler.h>
 #include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
 #include <linux/list.h>
+#include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/stat.h>
@@ -69,6 +70,7 @@
 #include <linux/stringify.h>
 #include <linux/types.h>
 #include <linux/wait.h>
+#include <linux/workqueue.h>
 
 #include <asm/byteorder.h>
 #include <asm/errno.h>
@@ -304,10 +306,11 @@ static struct scsi_host_template sbp2_shost_template = {
        .use_clustering          = ENABLE_CLUSTERING,
        .cmd_per_lun             = SBP2_MAX_CMDS,
        .can_queue               = SBP2_MAX_CMDS,
-       .emulated                = 1,
        .sdev_attrs              = sbp2_sysfs_sdev_attrs,
 };
 
+/* for match-all entries in sbp2_workarounds_table */
+#define SBP2_ROM_VALUE_WILDCARD 0x1000000
 
 /*
  * List of devices with known bugs.
@@ -329,22 +332,14 @@ static const struct {
        },
        /* Initio bridges, actually only needed for some older ones */ {
                .firmware_revision      = 0x000200,
+               .model_id               = SBP2_ROM_VALUE_WILDCARD,
                .workarounds            = SBP2_WORKAROUND_INQUIRY_36,
        },
        /* Symbios bridge */ {
                .firmware_revision      = 0xa0b800,
+               .model_id               = SBP2_ROM_VALUE_WILDCARD,
                .workarounds            = SBP2_WORKAROUND_128K_MAX_TRANS,
        },
-       /*
-        * Note about the following Apple iPod blacklist entries:
-        *
-        * There are iPods (2nd gen, 3rd gen) with model_id==0.  Since our
-        * matching logic treats 0 as a wildcard, we cannot match this ID
-        * without rewriting the matching routine.  Fortunately these iPods
-        * do not feature the read_capacity bug according to one report.
-        * Read_capacity behaviour as well as model_id could change due to
-        * Apple-supplied firmware updates though.
-        */
        /* iPod 4th generation */ {
                .firmware_revision      = 0x0a2700,
                .model_id               = 0x000021,
@@ -477,19 +472,13 @@ static void sbp2util_write_doorbell(struct work_struct *work)
 static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
 {
        struct sbp2_fwhost_info *hi = lu->hi;
-       int i;
-       unsigned long flags, orbs;
        struct sbp2_command_info *cmd;
+       int i, orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS;
 
-       orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS;
-
-       spin_lock_irqsave(&lu->cmd_orb_lock, flags);
        for (i = 0; i < orbs; i++) {
-               cmd = kzalloc(sizeof(*cmd), GFP_ATOMIC);
-               if (!cmd) {
-                       spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
+               cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
+               if (!cmd)
                        return -ENOMEM;
-               }
                cmd->command_orb_dma = dma_map_single(hi->host->device.parent,
                                                &cmd->command_orb,
                                                sizeof(struct sbp2_command_orb),
@@ -497,11 +486,10 @@ static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
                cmd->sge_dma = dma_map_single(hi->host->device.parent,
                                        &cmd->scatter_gather_element,
                                        sizeof(cmd->scatter_gather_element),
-                                       DMA_BIDIRECTIONAL);
+                                       DMA_TO_DEVICE);
                INIT_LIST_HEAD(&cmd->list);
                list_add_tail(&cmd->list, &lu->cmd_orb_completed);
        }
-       spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
        return 0;
 }
 
@@ -522,7 +510,7 @@ static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu)
                                         DMA_TO_DEVICE);
                        dma_unmap_single(host->device.parent, cmd->sge_dma,
                                         sizeof(cmd->scatter_gather_element),
-                                        DMA_BIDIRECTIONAL);
+                                        DMA_TO_DEVICE);
                        kfree(cmd);
                }
        spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
@@ -765,6 +753,11 @@ 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
        }
 
@@ -873,11 +866,8 @@ static int sbp2_start_device(struct sbp2_lu *lu)
        if (!lu->login_orb)
                goto alloc_fail;
 
-       if (sbp2util_create_command_orb_pool(lu)) {
-               SBP2_ERR("sbp2util_create_command_orb_pool failed!");
-               sbp2_remove_device(lu);
-               return -ENOMEM;
-       }
+       if (sbp2util_create_command_orb_pool(lu))
+               goto alloc_fail;
 
        /* Wait a second before trying to log in. Previously logged in
         * initiators need a chance to reconnect. */
@@ -1307,11 +1297,13 @@ static void sbp2_parse_unit_directory(struct sbp2_lu *lu,
 
        if (!(workarounds & SBP2_WORKAROUND_OVERRIDE))
                for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
-                       if (sbp2_workarounds_table[i].firmware_revision &&
+                       if (sbp2_workarounds_table[i].firmware_revision !=
+                           SBP2_ROM_VALUE_WILDCARD &&
                            sbp2_workarounds_table[i].firmware_revision !=
                            (firmware_revision & 0xffff00))
                                continue;
-                       if (sbp2_workarounds_table[i].model_id &&
+                       if (sbp2_workarounds_table[i].model_id !=
+                           SBP2_ROM_VALUE_WILDCARD &&
                            sbp2_workarounds_table[i].model_id != ud->model_id)
                                continue;
                        workarounds |= sbp2_workarounds_table[i].workarounds;
@@ -1497,69 +1489,6 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
        }
 }
 
-static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb,
-                                       struct sbp2_fwhost_info *hi,
-                                       struct sbp2_command_info *cmd,
-                                       struct scatterlist *sgpnt,
-                                       u32 orb_direction,
-                                       unsigned int scsi_request_bufflen,
-                                       void *scsi_request_buffer,
-                                       enum dma_data_direction dma_dir)
-{
-       cmd->dma_dir = dma_dir;
-       cmd->dma_size = scsi_request_bufflen;
-       cmd->dma_type = CMD_DMA_SINGLE;
-       cmd->cmd_dma = dma_map_single(hi->host->device.parent,
-                                     scsi_request_buffer,
-                                     cmd->dma_size, cmd->dma_dir);
-       orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
-       orb->misc |= ORB_SET_DIRECTION(orb_direction);
-
-       /* handle case where we get a command w/o s/g enabled
-        * (but check for transfers larger than 64K) */
-       if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) {
-
-               orb->data_descriptor_lo = cmd->cmd_dma;
-               orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen);
-
-       } else {
-               /* The buffer is too large. Turn this into page tables. */
-
-               struct sbp2_unrestricted_page_table *sg_element =
-                                               &cmd->scatter_gather_element[0];
-               u32 sg_count, sg_len;
-               dma_addr_t sg_addr;
-
-               orb->data_descriptor_lo = cmd->sge_dma;
-               orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
-
-               /* fill out our SBP-2 page tables; split up the large buffer */
-               sg_count = 0;
-               sg_len = scsi_request_bufflen;
-               sg_addr = cmd->cmd_dma;
-               while (sg_len) {
-                       sg_element[sg_count].segment_base_lo = sg_addr;
-                       if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
-                               sg_element[sg_count].length_segment_base_hi =
-                                       PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
-                               sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
-                               sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
-                       } else {
-                               sg_element[sg_count].length_segment_base_hi =
-                                       PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
-                               sg_len = 0;
-                       }
-                       sg_count++;
-               }
-
-               orb->misc |= ORB_SET_DATA_SIZE(sg_count);
-
-               sbp2util_cpu_to_be32_buffer(sg_element,
-                               (sizeof(struct sbp2_unrestricted_page_table)) *
-                               sg_count);
-       }
-}
-
 static void sbp2_create_command_orb(struct sbp2_lu *lu,
                                    struct sbp2_command_info *cmd,
                                    unchar *scsi_cmd,
@@ -1603,13 +1532,9 @@ static void sbp2_create_command_orb(struct sbp2_lu *lu,
                orb->data_descriptor_hi = 0x0;
                orb->data_descriptor_lo = 0x0;
                orb->misc |= ORB_SET_DIRECTION(1);
-       } else if (scsi_use_sg)
+       } else
                sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_use_sg, sgpnt,
                                         orb_direction, dma_dir);
-       else
-               sbp2_prep_command_orb_no_sg(orb, hi, cmd, sgpnt, orb_direction,
-                                           scsi_request_bufflen,
-                                           scsi_request_buffer, dma_dir);
 
        sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb));
 
@@ -1634,7 +1559,7 @@ static void sbp2_link_orb_command(struct sbp2_lu *lu,
                                   DMA_TO_DEVICE);
        dma_sync_single_for_device(hi->host->device.parent, cmd->sge_dma,
                                   sizeof(cmd->scatter_gather_element),
-                                  DMA_BIDIRECTIONAL);
+                                  DMA_TO_DEVICE);
 
        /* check to see if there are any previous orbs to use */
        spin_lock_irqsave(&lu->cmd_orb_lock, flags);
@@ -1698,15 +1623,15 @@ static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt,
                             void (*done)(struct scsi_cmnd *))
 {
        unchar *scsi_cmd = (unchar *)SCpnt->cmnd;
-       unsigned int request_bufflen = SCpnt->request_bufflen;
+       unsigned int request_bufflen = scsi_bufflen(SCpnt);
        struct sbp2_command_info *cmd;
 
        cmd = sbp2util_allocate_command_orb(lu, SCpnt, done);
        if (!cmd)
                return -EIO;
 
-       sbp2_create_command_orb(lu, cmd, scsi_cmd, SCpnt->use_sg,
-                               request_bufflen, SCpnt->request_buffer,
+       sbp2_create_command_orb(lu, cmd, scsi_cmd, scsi_sg_count(SCpnt),
+                               request_bufflen, scsi_sglist(SCpnt),
                                SCpnt->sc_data_direction);
        sbp2_link_orb_command(lu, cmd);
 
@@ -1800,7 +1725,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
                                        DMA_TO_DEVICE);
                dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
                                        sizeof(cmd->scatter_gather_element),
-                                       DMA_BIDIRECTIONAL);
+                                       DMA_TO_DEVICE);
                /* Grab SCSI command pointers and check status. */
                /*
                 * FIXME: If the src field in the status is 1, the ORB DMA must
@@ -1932,7 +1857,7 @@ static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
                                        DMA_TO_DEVICE);
                dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
                                        sizeof(cmd->scatter_gather_element),
-                                       DMA_BIDIRECTIONAL);
+                                       DMA_TO_DEVICE);
                sbp2util_mark_command_completed(lu, cmd);
                if (cmd->Current_SCpnt) {
                        cmd->Current_SCpnt->result = status << 16;
@@ -2017,7 +1942,6 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev)
 {
        struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
 
-       blk_queue_dma_alignment(sdev->request_queue, (512 - 1));
        sdev->use_10_for_rw = 1;
 
        if (sdev->type == TYPE_ROM)
@@ -2064,7 +1988,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
                        dma_sync_single_for_cpu(hi->host->device.parent,
                                        cmd->sge_dma,
                                        sizeof(cmd->scatter_gather_element),
-                                       DMA_BIDIRECTIONAL);
+                                       DMA_TO_DEVICE);
                        sbp2util_mark_command_completed(lu, cmd);
                        if (cmd->Current_SCpnt) {
                                cmd->Current_SCpnt->result = DID_ABORT << 16;