device create: ieee1394: convert device_create_drvdata to device_create
[safe/jmp/linux-2.6] / drivers / ieee1394 / sbp2.c
index 36d7b06..1d6ad34 100644 (file)
 #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>
 #include <linux/stringify.h>
 #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>
 
@@ -116,27 +119,30 @@ MODULE_PARM_DESC(max_speed, "Force max speed "
                 "(3 = 800Mb/s, 2 = 400Mb/s, 1 = 200Mb/s, 0 = 100Mb/s)");
 
 /*
- * Set serialize_io to 1 if you'd like only one scsi command sent
- * down to us at a time (debugging). This might be necessary for very
- * badly behaved sbp2 devices.
+ * Set serialize_io to 0 or N to use dynamically appended lists of command ORBs.
+ * This is and always has been buggy in multiple subtle ways. See above TODOs.
  */
 static int sbp2_serialize_io = 1;
-module_param_named(serialize_io, sbp2_serialize_io, int, 0444);
-MODULE_PARM_DESC(serialize_io, "Serialize I/O coming from scsi drivers "
-                "(default = 1, faster = 0)");
+module_param_named(serialize_io, sbp2_serialize_io, bool, 0444);
+MODULE_PARM_DESC(serialize_io, "Serialize requests coming from SCSI drivers "
+                "(default = Y, faster but buggy = N)");
 
 /*
- * Bump up max_sectors if you'd like to support very large sized
- * transfers. Please note that some older sbp2 bridge chips are broken for
- * transfers greater or equal to 128KB.  Default is a value of 255
- * sectors, or just under 128KB (at 512 byte sector size). I can note that
- * the Oxsemi sbp2 chipsets have no problems supporting very large
- * transfer sizes.
+ * Adjust max_sectors if you'd like to influence how many sectors each SCSI
+ * command can transfer at most. Please note that some older SBP-2 bridge
+ * chips are broken for transfers greater or equal to 128KB, therefore
+ * max_sectors used to be a safe 255 sectors for many years. We now have a
+ * default of 0 here which means that we let the SCSI stack choose a limit.
+ *
+ * The SBP2_WORKAROUND_128K_MAX_TRANS flag, if set either in the workarounds
+ * module parameter or in the sbp2_workarounds_table[], will override the
+ * value of max_sectors. We should use sbp2_workarounds_table[] to cover any
+ * bridge chip which becomes known to need the 255 sectors limit.
  */
-static int sbp2_max_sectors = SBP2_MAX_SECTORS;
+static int sbp2_max_sectors;
 module_param_named(max_sectors, sbp2_max_sectors, int, 0444);
 MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported "
-                "(default = " __stringify(SBP2_MAX_SECTORS) ")");
+                "(default = 0 = use SCSI stack's default)");
 
 /*
  * Exclusive login to sbp2 device? In most cases, the sbp2 driver should
@@ -152,9 +158,9 @@ MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported "
  * are possible on OXFW911 and newer Oxsemi bridges.
  */
 static int sbp2_exclusive_login = 1;
-module_param_named(exclusive_login, sbp2_exclusive_login, int, 0644);
+module_param_named(exclusive_login, sbp2_exclusive_login, bool, 0644);
 MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
-                "(default = 1)");
+                "(default = Y, use N for concurrent initiators)");
 
 /*
  * If any of the following workarounds is required for your device to work,
@@ -177,6 +183,14 @@ MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device "
  *   Avoids access beyond actual disk limits on devices with an off-by-one bug.
  *   Don't use this with devices which don't have this bug.
  *
+ * - delay inquiry
+ *   Wait extra SBP2_INQUIRY_DELAY seconds after login before SCSI inquiry.
+ *
+ * - power condition
+ *   Set the power condition field in the START STOP UNIT commands sent by
+ *   sd_mod on suspend, resume, and shutdown (if manage_start_stop is on).
+ *   Some disks need this to spin down or to resume properly.
+ *
  * - override internal blacklist
  *   Instead of adding to the built-in blacklist, use only the workarounds
  *   specified in the module load parameter.
@@ -189,9 +203,33 @@ MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0"
        ", 36 byte inquiry = "    __stringify(SBP2_WORKAROUND_INQUIRY_36)
        ", skip mode page 8 = "   __stringify(SBP2_WORKAROUND_MODE_SENSE_8)
        ", fix capacity = "       __stringify(SBP2_WORKAROUND_FIX_CAPACITY)
+       ", delay inquiry = "      __stringify(SBP2_WORKAROUND_DELAY_INQUIRY)
+       ", set power condition in start stop unit = "
+                                 __stringify(SBP2_WORKAROUND_POWER_CONDITION)
        ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE)
        ", or a combination)");
 
+/*
+ * This influences the format of the sysfs attribute
+ * /sys/bus/scsi/devices/.../ieee1394_id.
+ *
+ * The default format is like in older kernels:  %016Lx:%d:%d
+ * It contains the target's EUI-64, a number given to the logical unit by
+ * the ieee1394 driver's nodemgr (starting at 0), and the LUN.
+ *
+ * The long format is:  %016Lx:%06x:%04x
+ * It contains the target's EUI-64, the unit directory's directory_ID as per
+ * IEEE 1212 clause 7.7.19, and the LUN.  This format comes closest to the
+ * format of SBP(-3) target port and logical unit identifier as per SAM (SCSI
+ * Architecture Model) rev.2 to 4 annex A.  Therefore and because it is
+ * independent of the implementation of the ieee1394 nodemgr, the longer format
+ * is recommended for future use.
+ */
+static int sbp2_long_sysfs_ieee1394_id;
+module_param_named(long_ieee1394_id, sbp2_long_sysfs_ieee1394_id, bool, 0644);
+MODULE_PARM_DESC(long_ieee1394_id, "8+3+2 bytes format of ieee1394_id in sysfs "
+                "(default = backwards-compatible = N, SAM-conforming = Y)");
+
 
 #define SBP2_INFO(fmt, args...)        HPSB_INFO("sbp2: "fmt, ## args)
 #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)
@@ -220,6 +258,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,
@@ -326,18 +366,35 @@ static const struct {
                .firmware_revision      = 0x002800,
                .model_id               = 0x001010,
                .workarounds            = SBP2_WORKAROUND_INQUIRY_36 |
-                                         SBP2_WORKAROUND_MODE_SENSE_8,
+                                         SBP2_WORKAROUND_MODE_SENSE_8 |
+                                         SBP2_WORKAROUND_POWER_CONDITION,
+       },
+       /* DViCO Momobay FX-3A with TSB42AA9A bridge */ {
+               .firmware_revision      = 0x002800,
+               .model_id               = 0x000000,
+               .workarounds            = SBP2_WORKAROUND_DELAY_INQUIRY |
+                                         SBP2_WORKAROUND_POWER_CONDITION,
        },
        /* Initio bridges, actually only needed for some older ones */ {
                .firmware_revision      = 0x000200,
                .model_id               = SBP2_ROM_VALUE_WILDCARD,
                .workarounds            = SBP2_WORKAROUND_INQUIRY_36,
        },
+       /* PL-3507 bridge with Prolific firmware */ {
+               .firmware_revision      = 0x012800,
+               .model_id               = SBP2_ROM_VALUE_WILDCARD,
+               .workarounds            = SBP2_WORKAROUND_POWER_CONDITION,
+       },
        /* Symbios bridge */ {
                .firmware_revision      = 0xa0b800,
                .model_id               = SBP2_ROM_VALUE_WILDCARD,
                .workarounds            = SBP2_WORKAROUND_128K_MAX_TRANS,
        },
+       /* Datafab MD2-FW2 with Symbios/LSILogic SYM13FW500 bridge */ {
+               .firmware_revision      = 0x002600,
+               .model_id               = SBP2_ROM_VALUE_WILDCARD,
+               .workarounds            = SBP2_WORKAROUND_128K_MAX_TRANS,
+       },
        /* iPod 4th generation */ {
                .firmware_revision      = 0x0a2700,
                .model_id               = 0x000021,
@@ -470,19 +527,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),
@@ -490,17 +541,16 @@ 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;
 }
 
-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;
@@ -515,7 +565,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);
@@ -579,7 +629,7 @@ static struct sbp2_command_info *sbp2util_allocate_command_orb(
                cmd->Current_SCpnt = Current_SCpnt;
                list_add_tail(&cmd->list, &lu->cmd_orb_inuse);
        } else
-               SBP2_ERR("%s: no orbs available", __FUNCTION__);
+               SBP2_ERR("%s: no orbs available", __func__);
        spin_unlock_irqrestore(&lu->cmd_orb_lock, flags);
        return cmd;
 }
@@ -681,15 +731,26 @@ static int sbp2_update(struct unit_directory *ud)
 {
        struct sbp2_lu *lu = ud->device.driver_data;
 
-       if (sbp2_reconnect_device(lu)) {
-               /* Reconnect has failed. Perhaps we didn't reconnect fast
-                * enough. Try a regular login, but first log out just in
-                * case of any weirdness. */
+       if (sbp2_reconnect_device(lu) != 0) {
+               /*
+                * Reconnect failed.  If another bus reset happened,
+                * let nodemgr proceed and call sbp2_update again later
+                * (or sbp2_remove if this node went away).
+                */
+               if (!hpsb_node_entry_valid(lu->ne))
+                       return 0;
+               /*
+                * Or the target rejected the reconnect because we weren't
+                * fast enough.  Try a regular login, but first log out
+                * just in case of any weirdness.
+                */
                sbp2_logout_device(lu);
 
-               if (sbp2_login_device(lu)) {
-                       /* Login failed too, just fail, and the backend
-                        * will call our sbp2_remove for us */
+               if (sbp2_login_device(lu) != 0) {
+                       if (!hpsb_node_entry_valid(lu->ne))
+                               return 0;
+
+                       /* Maybe another initiator won the login. */
                        SBP2_ERR("Failed to reconnect to sbp2 device!");
                        return -EBUSY;
                }
@@ -717,6 +778,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) {
@@ -769,7 +831,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
@@ -813,16 +877,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)
@@ -866,11 +934,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. */
@@ -888,6 +953,9 @@ static int sbp2_start_device(struct sbp2_lu *lu)
        sbp2_agent_reset(lu, 1);
        sbp2_max_speed_and_size(lu);
 
+       if (lu->workarounds & SBP2_WORKAROUND_DELAY_INQUIRY)
+               ssleep(SBP2_INQUIRY_DELAY);
+
        error = scsi_add_device(lu->shost, 0, lu->ud->id, 0);
        if (error) {
                SBP2_ERR("scsi_add_device failed");
@@ -907,20 +975,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,
@@ -959,9 +1031,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);
 }
 
@@ -1248,7 +1319,7 @@ static int sbp2_set_busy_timeout(struct sbp2_lu *lu)
 
        data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE);
        if (hpsb_node_write(lu->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4))
-               SBP2_ERR("%s error", __FUNCTION__);
+               SBP2_ERR("%s error", __func__);
        return 0;
 }
 
@@ -1427,7 +1498,7 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
                                     struct sbp2_fwhost_info *hi,
                                     struct sbp2_command_info *cmd,
                                     unsigned int scsi_use_sg,
-                                    struct scatterlist *sgpnt,
+                                    struct scatterlist *sg,
                                     u32 orb_direction,
                                     enum dma_data_direction dma_dir)
 {
@@ -1436,13 +1507,12 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
        orb->misc |= ORB_SET_DIRECTION(orb_direction);
 
        /* special case if only one element (and less than 64KB in size) */
-       if ((scsi_use_sg == 1) &&
-           (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) {
+       if (scsi_use_sg == 1 && sg->length <= SBP2_MAX_SG_ELEMENT_LENGTH) {
 
-               cmd->dma_size = sgpnt[0].length;
+               cmd->dma_size = sg->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(sg), sg->offset,
                                            cmd->dma_size, cmd->dma_dir);
 
                orb->data_descriptor_lo = cmd->cmd_dma;
@@ -1453,11 +1523,11 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
                                                &cmd->scatter_gather_element[0];
                u32 sg_count, sg_len;
                dma_addr_t sg_addr;
-               int i, count = dma_map_sg(hi->host->device.parent, sgpnt,
+               int i, count = dma_map_sg(hi->host->device.parent, sg,
                                          scsi_use_sg, dma_dir);
 
                cmd->dma_size = scsi_use_sg;
-               cmd->sge_buffer = sgpnt;
+               cmd->sge_buffer = sg;
 
                /* use page tables (s/g) */
                orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
@@ -1465,9 +1535,9 @@ static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
 
                /* loop through and fill out our SBP-2 page tables
                 * (and split up anything too large) */
-               for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) {
-                       sg_len = sg_dma_len(sgpnt);
-                       sg_addr = sg_dma_address(sgpnt);
+               for (i = 0, sg_count = 0; i < count; i++, sg = sg_next(sg)) {
+                       sg_len = sg_dma_len(sg);
+                       sg_addr = sg_dma_address(sg);
                        while (sg_len) {
                                sg_element[sg_count].segment_base_lo = sg_addr;
                                if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
@@ -1492,81 +1562,15 @@ 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,
-                                   unsigned int scsi_use_sg,
-                                   unsigned int scsi_request_bufflen,
-                                   void *scsi_request_buffer,
-                                   enum dma_data_direction dma_dir)
+                                   struct scsi_cmnd *SCpnt)
 {
        struct sbp2_fwhost_info *hi = lu->hi;
-       struct scatterlist *sgpnt = (struct scatterlist *)scsi_request_buffer;
        struct sbp2_command_orb *orb = &cmd->command_orb;
        u32 orb_direction;
+       unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt);
+       enum dma_data_direction dma_dir = SCpnt->sc_data_direction;
 
        /*
         * Set-up our command ORB.
@@ -1598,18 +1602,15 @@ 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)
-               sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_use_sg, sgpnt,
+       } else
+               sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_sg_count(SCpnt),
+                                        scsi_sglist(SCpnt),
                                         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));
 
-       memset(orb->cdb, 0, 12);
-       memcpy(orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd));
+       memset(orb->cdb, 0, sizeof(orb->cdb));
+       memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);
 }
 
 static void sbp2_link_orb_command(struct sbp2_lu *lu,
@@ -1629,7 +1630,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);
@@ -1692,17 +1693,13 @@ static void sbp2_link_orb_command(struct sbp2_lu *lu,
 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;
        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,
-                               SCpnt->sc_data_direction);
+       sbp2_create_command_orb(lu, cmd, SCpnt);
        sbp2_link_orb_command(lu, cmd);
 
        return 0;
@@ -1762,6 +1759,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) {
@@ -1769,6 +1767,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;
@@ -1795,7 +1795,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
@@ -1927,7 +1927,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;
@@ -2000,9 +2000,15 @@ static int sbp2scsi_slave_alloc(struct scsi_device *sdev)
 {
        struct sbp2_lu *lu = (struct sbp2_lu *)sdev->host->hostdata[0];
 
+       if (sdev->lun != 0 || sdev->id != lu->ud->id || sdev->channel != 0)
+               return -ENODEV;
+
        lu->sdev = sdev;
        sdev->allow_restart = 1;
 
+       /* SBP-2 requires quadlet alignment of the data buffers. */
+       blk_queue_update_dma_alignment(sdev->request_queue, 4 - 1);
+
        if (lu->workarounds & SBP2_WORKAROUND_INQUIRY_36)
                sdev->inquiry_len = 36;
        return 0;
@@ -2012,9 +2018,10 @@ 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 (sbp2_exclusive_login)
+               sdev->manage_start_stop = 1;
        if (sdev->type == TYPE_ROM)
                sdev->use_10_for_ms = 1;
        if (sdev->type == TYPE_DISK &&
@@ -2022,6 +2029,10 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev)
                sdev->skip_ms_page_8 = 1;
        if (lu->workarounds & SBP2_WORKAROUND_FIX_CAPACITY)
                sdev->fix_capacity = 1;
+       if (lu->workarounds & SBP2_WORKAROUND_POWER_CONDITION)
+               sdev->start_stop_pwr_cond = 1;
+       if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
+               blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
        return 0;
 }
 
@@ -2059,7 +2070,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;
@@ -2104,8 +2115,14 @@ static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev,
        if (!(lu = (struct sbp2_lu *)sdev->host->hostdata[0]))
                return 0;
 
-       return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)lu->ne->guid,
-                      lu->ud->id, ORB_SET_LUN(lu->lun));
+       if (sbp2_long_sysfs_ieee1394_id)
+               return sprintf(buf, "%016Lx:%06x:%04x\n",
+                               (unsigned long long)lu->ne->guid,
+                               lu->ud->directory_id, ORB_SET_LUN(lu->lun));
+       else
+               return sprintf(buf, "%016Lx:%d:%d\n",
+                               (unsigned long long)lu->ne->guid,
+                               lu->ud->id, ORB_SET_LUN(lu->lun));
 }
 
 MODULE_AUTHOR("Ben Collins <bcollins@debian.org>");
@@ -2122,9 +2139,6 @@ static int sbp2_module_init(void)
                sbp2_shost_template.cmd_per_lun = 1;
        }
 
-       if (sbp2_default_workarounds & SBP2_WORKAROUND_128K_MAX_TRANS &&
-           (sbp2_max_sectors * 512) > (128 * 1024))
-               sbp2_max_sectors = 128 * 1024 / 512;
        sbp2_shost_template.max_sectors = sbp2_max_sectors;
 
        hpsb_register_highlevel(&sbp2_highlevel);