IPoIB/cm: Fix performance regression on Mellanox
[safe/jmp/linux-2.6] / drivers / scsi / 53c700.c
index eb7a6a4..cb02656 100644 (file)
 #include <linux/delay.h>
 #include <linux/spinlock.h>
 #include <linux/completion.h>
-#include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/proc_fs.h>
 #include <linux/blkdev.h>
@@ -173,6 +172,7 @@ STATIC int NCR_700_bus_reset(struct scsi_cmnd * SCpnt);
 STATIC int NCR_700_host_reset(struct scsi_cmnd * SCpnt);
 STATIC void NCR_700_chip_setup(struct Scsi_Host *host);
 STATIC void NCR_700_chip_reset(struct Scsi_Host *host);
+STATIC int NCR_700_slave_alloc(struct scsi_device *SDpnt);
 STATIC int NCR_700_slave_configure(struct scsi_device *SDpnt);
 STATIC void NCR_700_slave_destroy(struct scsi_device *SDpnt);
 static int NCR_700_change_queue_depth(struct scsi_device *SDpnt, int depth);
@@ -182,10 +182,6 @@ STATIC struct device_attribute *NCR_700_dev_attrs[];
 
 STATIC struct scsi_transport_template *NCR_700_transport_template = NULL;
 
-struct NCR_700_sense {
-       unsigned char cmnd[MAX_COMMAND_SIZE];
-};
-
 static char *NCR_700_phase[] = {
        "",
        "after selection",
@@ -316,7 +312,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
        hostdata->status = memory + STATUS_OFFSET;
        /* all of these offsets are L1_CACHE_BYTES separated.  It is fatal
         * if this isn't sufficient separation to avoid dma flushing issues */
-       BUG_ON(!dma_is_consistent(pScript) && L1_CACHE_BYTES < dma_get_cache_alignment());
+       BUG_ON(!dma_is_consistent(hostdata->dev, pScript) && L1_CACHE_BYTES < dma_get_cache_alignment());
        hostdata->slots = (struct NCR_700_command_slot *)(memory + SLOTS_OFFSET);
        hostdata->dev = dev;
 
@@ -333,6 +329,7 @@ NCR_700_detect(struct scsi_host_template *tpnt,
        tpnt->use_clustering = ENABLE_CLUSTERING;
        tpnt->slave_configure = NCR_700_slave_configure;
        tpnt->slave_destroy = NCR_700_slave_destroy;
+       tpnt->slave_alloc = NCR_700_slave_alloc;
        tpnt->change_queue_depth = NCR_700_change_queue_depth;
        tpnt->change_queue_type = NCR_700_change_queue_type;
 
@@ -364,11 +361,11 @@ NCR_700_detect(struct scsi_host_template *tpnt,
        for (j = 0; j < PATCHES; j++)
                script[LABELPATCHES[j]] = bS_to_host(pScript + SCRIPT[LABELPATCHES[j]]);
        /* now patch up fixed addresses. */
-       script_patch_32(script, MessageLocation,
+       script_patch_32(hostdata->dev, script, MessageLocation,
                        pScript + MSGOUT_OFFSET);
-       script_patch_32(script, StatusAddress,
+       script_patch_32(hostdata->dev, script, StatusAddress,
                        pScript + STATUS_OFFSET);
-       script_patch_32(script, ReceiveMsgAddress,
+       script_patch_32(hostdata->dev, script, ReceiveMsgAddress,
                        pScript + MSGIN_OFFSET);
 
        hostdata->script = script;
@@ -611,9 +608,10 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
                struct NCR_700_command_slot *slot = 
                        (struct NCR_700_command_slot *)SCp->host_scribble;
                
-               NCR_700_unmap(hostdata, SCp, slot);
+               dma_unmap_single(hostdata->dev, slot->pCmd,
+                                sizeof(SCp->cmnd), DMA_TO_DEVICE);
                if (slot->flags == NCR_700_FLAG_AUTOSENSE) {
-                       struct NCR_700_sense *sense = SCp->device->hostdata;
+                       char *cmnd = NCR_700_get_sense_cmnd(SCp->device);
 #ifdef NCR_700_DEBUG
                        printk(" ORIGINAL CMD %p RETURNED %d, new return is %d sense is\n",
                               SCp, SCp->cmnd[7], result);
@@ -623,11 +621,12 @@ NCR_700_scsi_done(struct NCR_700_Host_Parameters *hostdata,
                        dma_unmap_single(hostdata->dev, slot->dma_handle, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
                        /* restore the old result if the request sense was
                         * successful */
-                       if(result == 0)
-                               result = sense->cmnd[7];
+                       if (result == 0)
+                               result = cmnd[7];
+                       /* restore the original length */
+                       SCp->cmd_len = cmnd[8];
                } else
-                       dma_unmap_single(hostdata->dev, slot->pCmd,
-                                        sizeof(SCp->cmnd), DMA_TO_DEVICE);
+                       NCR_700_unmap(hostdata, SCp, slot);
 
                free_slot(slot, hostdata);
 #ifdef NCR_700_DEBUG
@@ -667,12 +666,30 @@ NCR_700_chip_setup(struct Scsi_Host *host)
        __u8 min_xferp = (hostdata->chip710 ? NCR_710_MIN_XFERP : NCR_700_MIN_XFERP);
 
        if(hostdata->chip710) {
-               __u8 burst_disable = hostdata->burst_disable
-                       ? BURST_DISABLE : 0;
+               __u8 burst_disable = 0;
+               __u8 burst_length = 0;
+
+               switch (hostdata->burst_length) {
+                       case 1:
+                               burst_length = BURST_LENGTH_1;
+                               break;
+                       case 2:
+                               burst_length = BURST_LENGTH_2;
+                               break;
+                       case 4:
+                               burst_length = BURST_LENGTH_4;
+                               break;
+                       case 8:
+                               burst_length = BURST_LENGTH_8;
+                               break;
+                       default:
+                               burst_disable = BURST_DISABLE;
+                               break;
+               }
                dcntl_extra = COMPAT_700_MODE;
 
                NCR_700_writeb(dcntl_extra, host, DCNTL_REG);
-               NCR_700_writeb(BURST_LENGTH_8  | hostdata->dmode_extra,
+               NCR_700_writeb(burst_length | hostdata->dmode_extra,
                               host, DMODE_710_REG);
                NCR_700_writeb(burst_disable | (hostdata->differential ? 
                                                DIFF : 0), host, CTEST7_REG);
@@ -821,8 +838,9 @@ process_extended_message(struct Scsi_Host *host,
                        shost_printk(KERN_WARNING, host,
                                "Unexpected SDTR msg\n");
                        hostdata->msgout[0] = A_REJECT_MSG;
-                       dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
-                       script_patch_16(hostdata->script, MessageCount, 1);
+                       dma_cache_sync(hostdata->dev, hostdata->msgout, 1, DMA_TO_DEVICE);
+                       script_patch_16(hostdata->dev, hostdata->script,
+                                       MessageCount, 1);
                        /* SendMsgOut returns, so set up the return
                         * address */
                        resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
@@ -833,8 +851,9 @@ process_extended_message(struct Scsi_Host *host,
                printk(KERN_INFO "scsi%d: (%d:%d), Unsolicited WDTR after CMD, Rejecting\n",
                       host->host_no, pun, lun);
                hostdata->msgout[0] = A_REJECT_MSG;
-               dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
-               script_patch_16(hostdata->script, MessageCount, 1);
+               dma_cache_sync(hostdata->dev, hostdata->msgout, 1, DMA_TO_DEVICE);
+               script_patch_16(hostdata->dev, hostdata->script, MessageCount,
+                               1);
                resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
 
                break;
@@ -847,8 +866,9 @@ process_extended_message(struct Scsi_Host *host,
                printk("\n");
                /* just reject it */
                hostdata->msgout[0] = A_REJECT_MSG;
-               dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
-               script_patch_16(hostdata->script, MessageCount, 1);
+               dma_cache_sync(hostdata->dev, hostdata->msgout, 1, DMA_TO_DEVICE);
+               script_patch_16(hostdata->dev, hostdata->script, MessageCount,
+                               1);
                /* SendMsgOut returns, so set up the return
                 * address */
                resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
@@ -929,8 +949,9 @@ process_message(struct Scsi_Host *host,     struct NCR_700_Host_Parameters *hostdata
                printk("\n");
                /* just reject it */
                hostdata->msgout[0] = A_REJECT_MSG;
-               dma_cache_sync(hostdata->msgout, 1, DMA_TO_DEVICE);
-               script_patch_16(hostdata->script, MessageCount, 1);
+               dma_cache_sync(hostdata->dev, hostdata->msgout, 1, DMA_TO_DEVICE);
+               script_patch_16(hostdata->dev, hostdata->script, MessageCount,
+                               1);
                /* SendMsgOut returns, so set up the return
                 * address */
                resume_offset = hostdata->pScript + Ent_SendMessageWithATN;
@@ -939,7 +960,7 @@ process_message(struct Scsi_Host *host,     struct NCR_700_Host_Parameters *hostdata
        }
        NCR_700_writel(temp, host, TEMP_REG);
        /* set us up to receive another message */
-       dma_cache_sync(hostdata->msgin, MSG_ARRAY_SIZE, DMA_FROM_DEVICE);
+       dma_cache_sync(hostdata->dev, hostdata->msgin, MSG_ARRAY_SIZE, DMA_FROM_DEVICE);
        return resume_offset;
 }
 
@@ -969,14 +990,15 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
                   status_byte(hostdata->status[0]) == COMMAND_TERMINATED) {
                        struct NCR_700_command_slot *slot =
                                (struct NCR_700_command_slot *)SCp->host_scribble;
-                       if(SCp->cmnd[0] == REQUEST_SENSE) {
+                       if(slot->flags == NCR_700_FLAG_AUTOSENSE) {
                                /* OOPS: bad device, returning another
                                 * contingent allegiance condition */
                                scmd_printk(KERN_ERR, SCp,
                                        "broken device is looping in contingent allegiance: ignoring\n");
                                NCR_700_scsi_done(hostdata, SCp, hostdata->status[0]);
                        } else {
-                               struct NCR_700_sense *sense = SCp->device->hostdata;
+                               char *cmnd =
+                                       NCR_700_get_sense_cmnd(SCp->device);
 #ifdef NCR_DEBUG
                                scsi_print_command(SCp);
                                printk("  cmd %p has status %d, requesting sense\n",
@@ -994,30 +1016,33 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
                                                 sizeof(SCp->cmnd),
                                                 DMA_TO_DEVICE);
 
-                               sense->cmnd[0] = REQUEST_SENSE;
-                               sense->cmnd[1] = (SCp->device->lun & 0x7) << 5;
-                               sense->cmnd[2] = 0;
-                               sense->cmnd[3] = 0;
-                               sense->cmnd[4] = sizeof(SCp->sense_buffer);
-                               sense->cmnd[5] = 0;
+                               cmnd[0] = REQUEST_SENSE;
+                               cmnd[1] = (SCp->device->lun & 0x7) << 5;
+                               cmnd[2] = 0;
+                               cmnd[3] = 0;
+                               cmnd[4] = sizeof(SCp->sense_buffer);
+                               cmnd[5] = 0;
                                /* Here's a quiet hack: the
                                 * REQUEST_SENSE command is six bytes,
                                 * so store a flag indicating that
                                 * this was an internal sense request
                                 * and the original status at the end
                                 * of the command */
-                               sense->cmnd[6] = NCR_700_INTERNAL_SENSE_MAGIC;
-                               sense->cmnd[7] = hostdata->status[0];
-                               slot->pCmd = dma_map_single(hostdata->dev, sense->cmnd, sizeof(sense->cmnd), DMA_TO_DEVICE);
+                               cmnd[6] = NCR_700_INTERNAL_SENSE_MAGIC;
+                               cmnd[7] = hostdata->status[0];
+                               cmnd[8] = SCp->cmd_len;
+                               SCp->cmd_len = 6; /* command length for
+                                                  * REQUEST_SENSE */
+                               slot->pCmd = dma_map_single(hostdata->dev, cmnd, MAX_COMMAND_SIZE, DMA_TO_DEVICE);
                                slot->dma_handle = dma_map_single(hostdata->dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
                                slot->SG[0].ins = bS_to_host(SCRIPT_MOVE_DATA_IN | sizeof(SCp->sense_buffer));
                                slot->SG[0].pAddr = bS_to_host(slot->dma_handle);
                                slot->SG[1].ins = bS_to_host(SCRIPT_RETURN);
                                slot->SG[1].pAddr = 0;
                                slot->resume_offset = hostdata->pScript;
-                               dma_cache_sync(slot->SG, sizeof(slot->SG[0])*2, DMA_TO_DEVICE);
-                               dma_cache_sync(SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
-                               
+                               dma_cache_sync(hostdata->dev, slot->SG, sizeof(slot->SG[0])*2, DMA_TO_DEVICE);
+                               dma_cache_sync(hostdata->dev, SCp->sense_buffer, sizeof(SCp->sense_buffer), DMA_FROM_DEVICE);
+
                                /* queue the command for reissue */
                                slot->state = NCR_700_SLOT_QUEUED;
                                slot->flags = NCR_700_FLAG_AUTOSENSE;
@@ -1132,11 +1157,12 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
                        hostdata->cmd = slot->cmnd;
 
                        /* re-patch for this command */
-                       script_patch_32_abs(hostdata->script, CommandAddress, 
-                                           slot->pCmd);
-                       script_patch_16(hostdata->script,
+                       script_patch_32_abs(hostdata->dev, hostdata->script,
+                                           CommandAddress, slot->pCmd);
+                       script_patch_16(hostdata->dev, hostdata->script,
                                        CommandCount, slot->cmnd->cmd_len);
-                       script_patch_32_abs(hostdata->script, SGScriptStartAddress,
+                       script_patch_32_abs(hostdata->dev, hostdata->script,
+                                           SGScriptStartAddress,
                                            to32bit(&slot->pSG[0].ins));
 
                        /* Note: setting SXFER only works if we're
@@ -1146,13 +1172,13 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
                         * should therefore always clear ACK */
                        NCR_700_writeb(NCR_700_get_SXFER(hostdata->cmd->device),
                                       host, SXFER_REG);
-                       dma_cache_sync(hostdata->msgin,
+                       dma_cache_sync(hostdata->dev, hostdata->msgin,
                                       MSG_ARRAY_SIZE, DMA_FROM_DEVICE);
-                       dma_cache_sync(hostdata->msgout,
+                       dma_cache_sync(hostdata->dev, hostdata->msgout,
                                       MSG_ARRAY_SIZE, DMA_TO_DEVICE);
                        /* I'm just being paranoid here, the command should
                         * already have been flushed from the cache */
-                       dma_cache_sync(slot->cmnd->cmnd,
+                       dma_cache_sync(hostdata->dev, slot->cmnd->cmnd,
                                       slot->cmnd->cmd_len, DMA_TO_DEVICE);
 
 
@@ -1216,7 +1242,7 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp,
                hostdata->reselection_id = reselection_id;
                /* just in case we have a stale simple tag message, clear it */
                hostdata->msgin[1] = 0;
-               dma_cache_sync(hostdata->msgin,
+               dma_cache_sync(hostdata->dev, hostdata->msgin,
                               MSG_ARRAY_SIZE, DMA_BIDIRECTIONAL);
                if(hostdata->tag_negotiated & (1<<reselection_id)) {
                        resume_offset = hostdata->pScript + Ent_GetReselectionWithTag;
@@ -1332,7 +1358,7 @@ process_selection(struct Scsi_Host *host, __u32 dsp)
        hostdata->cmd = NULL;
        /* clear any stale simple tag message */
        hostdata->msgin[1] = 0;
-       dma_cache_sync(hostdata->msgin, MSG_ARRAY_SIZE,
+       dma_cache_sync(hostdata->dev, hostdata->msgin, MSG_ARRAY_SIZE,
                       DMA_BIDIRECTIONAL);
 
        if(id == 0xff) {
@@ -1429,29 +1455,30 @@ NCR_700_start_command(struct scsi_cmnd *SCp)
                NCR_700_set_flag(SCp->device, NCR_700_DEV_BEGIN_SYNC_NEGOTIATION);
        }
 
-       script_patch_16(hostdata->script, MessageCount, count);
+       script_patch_16(hostdata->dev, hostdata->script, MessageCount, count);
 
 
-       script_patch_ID(hostdata->script,
+       script_patch_ID(hostdata->dev, hostdata->script,
                        Device_ID, 1<<scmd_id(SCp));
 
-       script_patch_32_abs(hostdata->script, CommandAddress, 
+       script_patch_32_abs(hostdata->dev, hostdata->script, CommandAddress,
                            slot->pCmd);
-       script_patch_16(hostdata->script, CommandCount, SCp->cmd_len);
+       script_patch_16(hostdata->dev, hostdata->script, CommandCount,
+                       SCp->cmd_len);
        /* finally plumb the beginning of the SG list into the script
         * */
-       script_patch_32_abs(hostdata->script, SGScriptStartAddress,
-                           to32bit(&slot->pSG[0].ins));
+       script_patch_32_abs(hostdata->dev, hostdata->script,
+                           SGScriptStartAddress, to32bit(&slot->pSG[0].ins));
        NCR_700_clear_fifo(SCp->device->host);
 
        if(slot->resume_offset == 0)
                slot->resume_offset = hostdata->pScript;
        /* now perform all the writebacks and invalidates */
-       dma_cache_sync(hostdata->msgout, count, DMA_TO_DEVICE);
-       dma_cache_sync(hostdata->msgin, MSG_ARRAY_SIZE,
+       dma_cache_sync(hostdata->dev, hostdata->msgout, count, DMA_TO_DEVICE);
+       dma_cache_sync(hostdata->dev, hostdata->msgin, MSG_ARRAY_SIZE,
                       DMA_FROM_DEVICE);
-       dma_cache_sync(SCp->cmnd, SCp->cmd_len, DMA_TO_DEVICE);
-       dma_cache_sync(hostdata->status, 1, DMA_FROM_DEVICE);
+       dma_cache_sync(hostdata->dev, SCp->cmnd, SCp->cmd_len, DMA_TO_DEVICE);
+       dma_cache_sync(hostdata->dev, hostdata->status, 1, DMA_FROM_DEVICE);
 
        /* set the synchronous period/offset */
        NCR_700_writeb(NCR_700_get_SXFER(SCp->device),
@@ -1463,7 +1490,7 @@ NCR_700_start_command(struct scsi_cmnd *SCp)
 }
 
 irqreturn_t
-NCR_700_intr(int irq, void *dev_id, struct pt_regs *regs)
+NCR_700_intr(int irq, void *dev_id)
 {
        struct Scsi_Host *host = (struct Scsi_Host *)dev_id;
        struct NCR_700_Host_Parameters *hostdata =
@@ -1530,7 +1557,7 @@ NCR_700_intr(int irq, void *dev_id, struct pt_regs *regs)
 
                        /* clear all the negotiated parameters */
                        __shost_for_each_device(SDp, host)
-                               SDp->hostdata = NULL;
+                               NCR_700_clear_flag(SDp, ~0);
                        
                        /* clear all the slots and their pending commands */
                        for(i = 0; i < NCR_700_COMMAND_SLOTS_PER_HOST; i++) {
@@ -1627,7 +1654,7 @@ NCR_700_intr(int irq, void *dev_id, struct pt_regs *regs)
                                        slot->SG[i].ins = bS_to_host(SCRIPT_NOP);
                                        slot->SG[i].pAddr = 0;
                                }
-                               dma_cache_sync(slot->SG, sizeof(slot->SG), DMA_TO_DEVICE);
+                               dma_cache_sync(hostdata->dev, slot->SG, sizeof(slot->SG), DMA_TO_DEVICE);
                                /* and pretend we disconnected after
                                 * the command phase */
                                resume_offset = hostdata->pScript + Ent_MsgInDuringData;
@@ -1893,9 +1920,9 @@ NCR_700_queuecommand(struct scsi_cmnd *SCp, void (*done)(struct scsi_cmnd *))
                }
                slot->SG[i].ins = bS_to_host(SCRIPT_RETURN);
                slot->SG[i].pAddr = 0;
-               dma_cache_sync(slot->SG, sizeof(slot->SG), DMA_TO_DEVICE);
+               dma_cache_sync(hostdata->dev, slot->SG, sizeof(slot->SG), DMA_TO_DEVICE);
                DEBUG((" SETTING %08lx to %x\n",
-                      (&slot->pSG[i].ins), 
+                      (&slot->pSG[i].ins),
                       slot->SG[i].ins));
        }
        slot->resume_offset = 0;
@@ -1940,7 +1967,7 @@ NCR_700_abort(struct scsi_cmnd * SCp)
 STATIC int
 NCR_700_bus_reset(struct scsi_cmnd * SCp)
 {
-       DECLARE_COMPLETION(complete);
+       DECLARE_COMPLETION_ONSTACK(complete);
        struct NCR_700_Host_Parameters *hostdata = 
                (struct NCR_700_Host_Parameters *)SCp->device->host->hostdata[0];
 
@@ -2035,7 +2062,17 @@ NCR_700_set_offset(struct scsi_target *STp, int offset)
        spi_flags(STp) |= NCR_700_DEV_PRINT_SYNC_NEGOTIATION;
 }
 
+STATIC int
+NCR_700_slave_alloc(struct scsi_device *SDp)
+{
+       SDp->hostdata = kzalloc(sizeof(struct NCR_700_Device_Parameters),
+                               GFP_KERNEL);
+
+       if (!SDp->hostdata)
+               return -ENOMEM;
 
+       return 0;
+}
 
 STATIC int
 NCR_700_slave_configure(struct scsi_device *SDp)
@@ -2043,11 +2080,6 @@ NCR_700_slave_configure(struct scsi_device *SDp)
        struct NCR_700_Host_Parameters *hostdata = 
                (struct NCR_700_Host_Parameters *)SDp->host->hostdata[0];
 
-       SDp->hostdata = kmalloc(GFP_KERNEL, sizeof(struct NCR_700_sense));
-
-       if (!SDp->hostdata)
-               return -ENOMEM;
-
        /* to do here: allocate memory; build a queue_full list */
        if(SDp->tagged_supported) {
                scsi_set_tag_type(SDp, MSG_ORDERED_TAG);