Merge branch 'for-linus' of git://git.kernel.dk/data/git/linux-2.6-block
[sfrench/cifs-2.6.git] / drivers / message / fusion / mptscsih.c
index 3bd94f11e7d6ef417244f48036e24a9b696aebc0..626bb3c9af2b0d6614d2313753b4c9796e64bb5e 100644 (file)
@@ -1,10 +1,10 @@
 /*
  *  linux/drivers/message/fusion/mptscsih.c
- *      For use with LSI Logic PCI chip/adapter(s)
- *      running LSI Logic Fusion MPT (Message Passing Technology) firmware.
+ *      For use with LSI PCI chip/adapter(s)
+ *      running LSI Fusion MPT (Message Passing Technology) firmware.
  *
- *  Copyright (c) 1999-2007 LSI Logic Corporation
- *  (mailto:mpt_linux_developer@lsi.com)
+ *  Copyright (c) 1999-2007 LSI Corporation
+ *  (mailto:DL-MPTFusionLinux@lsi.com)
  *
  */
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -44,7 +44,6 @@
 */
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 
-#include "linux_compat.h"      /* linux-2.6 tweaks */
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -81,6 +80,10 @@ MODULE_VERSION(my_VERSION);
 /*
  *  Other private/forward protos...
  */
+static struct scsi_cmnd * mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i);
+static struct scsi_cmnd * mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i);
+static void    mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd);
+static int     SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *scmd);
 int            mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
 static void    mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
 int            mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
@@ -91,7 +94,6 @@ static void   mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
 static void    mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
 static int     mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
 static int     mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
-static int     SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
 
 static int     mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
 
@@ -192,8 +194,8 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
        int rc;
        int chain_idx;
 
-       dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer called\n",
-                       ioc->name));
+       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "getFreeChainBuffer called\n",
+           ioc->name));
        spin_lock_irqsave(&ioc->FreeQlock, flags);
        if (!list_empty(&ioc->FreeChainQ)) {
                int offset;
@@ -204,13 +206,14 @@ mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
                offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
                chain_idx = offset / ioc->req_sz;
                rc = SUCCESS;
-               dsgprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
-                       ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
+               dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "getFreeChainBuffer chainBuf=%p ChainBuffer=%p offset=%d chain_idx=%d\n",
+                   ioc->name, chainBuf, ioc->ChainBuffer, offset, chain_idx));
        } else {
                rc = FAILED;
                chain_idx = MPT_HOST_NO_CHAIN;
-               dfailprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer failed\n",
-                       ioc->name));
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
+                   ioc->name));
        }
        spin_unlock_irqrestore(&ioc->FreeQlock, flags);
 
@@ -260,30 +263,13 @@ mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
        /* Map the data portion, if any.
         * sges_left  = 0 if no data transfer.
         */
-       if ( (sges_left = SCpnt->use_sg) ) {
-               sges_left = pci_map_sg(ioc->pcidev,
-                              (struct scatterlist *) SCpnt->request_buffer,
-                              SCpnt->use_sg,
-                              SCpnt->sc_data_direction);
-               if (sges_left == 0)
-                       return FAILED;
-       } else if (SCpnt->request_bufflen) {
-               SCpnt->SCp.dma_handle = pci_map_single(ioc->pcidev,
-                                     SCpnt->request_buffer,
-                                     SCpnt->request_bufflen,
-                                     SCpnt->sc_data_direction);
-               dsgprintk((MYIOC_s_INFO_FMT "SG: non-SG for %p, len=%d\n",
-                               ioc->name, SCpnt, SCpnt->request_bufflen));
-               mptscsih_add_sge((char *) &pReq->SGL,
-                       0xD1000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|SCpnt->request_bufflen,
-                       SCpnt->SCp.dma_handle);
-
-               return SUCCESS;
-       }
+       sges_left = scsi_dma_map(SCpnt);
+       if (sges_left < 0)
+               return FAILED;
 
        /* Handle the SG case.
         */
-       sg = (struct scatterlist *) SCpnt->request_buffer;
+       sg = scsi_sglist(SCpnt);
        sg_done  = 0;
        sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
        chainSge = NULL;
@@ -307,7 +293,7 @@ nextSGEset:
        for (ii=0; ii < (numSgeThisFrame-1); ii++) {
                thisxfer = sg_dma_len(sg);
                if (thisxfer == 0) {
-                       sg ++; /* Get next SG element from the OS */
+                       sg = sg_next(sg); /* Get next SG element from the OS */
                        sg_done++;
                        continue;
                }
@@ -315,7 +301,7 @@ nextSGEset:
                v2 = sg_dma_address(sg);
                mptscsih_add_sge(psge, sgflags | thisxfer, v2);
 
-               sg++;           /* Get next SG element from the OS */
+               sg = sg_next(sg);       /* Get next SG element from the OS */
                psge += (sizeof(u32) + sizeof(dma_addr_t));
                sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
                sg_done++;
@@ -336,7 +322,7 @@ nextSGEset:
                v2 = sg_dma_address(sg);
                mptscsih_add_sge(psge, sgflags | thisxfer, v2);
                /*
-               sg++;
+               sg = sg_next(sg);
                psge += (sizeof(u32) + sizeof(dma_addr_t));
                */
                sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
@@ -355,7 +341,7 @@ nextSGEset:
                         */
                        pReq->ChainOffset = 0;
                        RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor)  + 1) & 0x03;
-                       dsgprintk((MYIOC_s_INFO_FMT
+                       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                            "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
                        ioc->RequestNB[req_idx] = RequestNB;
                }
@@ -371,7 +357,7 @@ nextSGEset:
                 * Loop until done.
                 */
 
-               dsgprintk((MYIOC_s_INFO_FMT "SG: Chain Required! sg done %d\n",
+               dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SG: Chain Required! sg done %d\n",
                                ioc->name, sg_done));
 
                /* Set LAST_ELEMENT flag for last non-chain element
@@ -404,7 +390,7 @@ nextSGEset:
                         */
                        pReq->ChainOffset = (u8) (sgeOffset >> 2);
                        RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor)  + 1) & 0x03;
-                       dsgprintk((MYIOC_s_ERR_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
+                       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
                        ioc->RequestNB[req_idx] = RequestNB;
                }
 
@@ -415,7 +401,7 @@ nextSGEset:
                 * in current buffer. Get a chain buffer.
                 */
                if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED) {
-                       dfailprintk((MYIOC_s_INFO_FMT
+                       dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                            "getFreeChainBuffer FAILED SCSI cmd=%02x (%p)\n",
                            ioc->name, pReq->CDB[0], SCpnt));
                        return FAILED;
@@ -437,8 +423,8 @@ nextSGEset:
                 *   out the Address and Flags fields.
                 */
                chainSge = (char *) psge;
-               dsgprintk((KERN_INFO "  Current buff @ %p (index 0x%x)",
-                               psge, req_idx));
+               dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "  Current buff @ %p (index 0x%x)",
+                   ioc->name, psge, req_idx));
 
                /* Start the SGE for the next buffer
                 */
@@ -446,8 +432,8 @@ nextSGEset:
                sgeOffset = 0;
                sg_done = 0;
 
-               dsgprintk((KERN_INFO "  Chain buff @ %p (index 0x%x)\n",
-                               psge, chain_idx));
+               dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "  Chain buff @ %p (index 0x%x)\n",
+                   ioc->name, psge, chain_idx));
 
                /* Start the SGE for the next buffer
                 */
@@ -465,11 +451,16 @@ mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
        MPT_FRAME_HDR *mf;
        SEPRequest_t     *SEPMsg;
 
-       if (ioc->bus_type == FC)
+       if (ioc->bus_type != SAS)
+               return;
+
+       /* Not supported for hidden raid components
+        */
+       if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
                return;
 
        if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
-               dfailprintk((MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: no msg frames!!\n",
                    ioc->name,__FUNCTION__));
                return;
        }
@@ -480,93 +471,156 @@ mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
        SEPMsg->TargetID = vtarget->id;
        SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
        SEPMsg->SlotStatus = SlotStatus;
-       devtverboseprintk((MYIOC_s_WARN_FMT
+       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
            "Sending SEP cmd=%x channel=%d id=%d\n",
            ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));
        mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
 }
 
-#ifdef MPT_DEBUG_REPLY
+#ifdef CONFIG_FUSION_LOGGING
 /**
- *     mptscsih_iocstatus_info_scsiio - IOCSTATUS information for SCSIIO
+ *     mptscsih_info_scsiio - debug print info on reply frame
  *     @ioc: Pointer to MPT_ADAPTER structure
- *     @ioc_status: U32 IOCStatus word from IOC
- *     @scsi_status: U8 sam status from target
- *     @scsi_state: U8 scsi state
  *     @sc: original scsi cmnd pointer
- *     @mf: Pointer to MPT request frame
+ *     @pScsiReply: Pointer to MPT reply frame
+ *
+ *     MPT_DEBUG_REPLY needs to be enabled to obtain this info
  *
  *     Refer to lsi/mpi.h.
  **/
 static void
-mptscsih_iocstatus_info_scsiio(MPT_ADAPTER *ioc, u32 ioc_status,
-    u8 scsi_status, u8 scsi_state, struct scsi_cmnd *sc)
+mptscsih_info_scsiio(MPT_ADAPTER *ioc, struct scsi_cmnd *sc, SCSIIOReply_t * pScsiReply)
 {
-       char extend_desc[EVENT_DESCR_STR_SZ];
-       char *desc = NULL;
+       char    *desc = NULL;
+       char    *desc1 = NULL;
+       u16     ioc_status;
+       u8      skey, asc, ascq;
+
+       ioc_status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
 
        switch (ioc_status) {
 
-       case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
-               desc = "SCSI Invalid Bus";
+       case MPI_IOCSTATUS_SUCCESS:
+               desc = "success";
                break;
-
-       case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
-               desc = "SCSI Invalid TargetID";
+       case MPI_IOCSTATUS_SCSI_INVALID_BUS:
+               desc = "invalid bus";
                break;
-
-       case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
-               /*
-                * Inquiry is issued for device scanning
-                */
-               if (sc->cmnd[0] != 0x12)
-                       desc = "SCSI Device Not There";
+       case MPI_IOCSTATUS_SCSI_INVALID_TARGETID:
+               desc = "invalid target_id";
                break;
-
-       case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
-               desc = "SCSI Data Overrun";
+       case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
+               desc = "device not there";
                break;
-
-       case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
-               desc = "SCSI I/O Data Error";
+       case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:
+               desc = "data overrun";
                break;
-
-       case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
-               desc = "SCSI Protocol Error";
+       case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:
+               desc = "data underrun";
                break;
-
-       case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
-               desc = "SCSI Task Terminated";
+       case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR:
+               desc = "I/O data error";
                break;
-
-       case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
-               desc = "SCSI Residual Mismatch";
+       case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR:
+               desc = "protocol error";
                break;
-
-       case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
-               desc = "SCSI Task Management Failed";
+       case MPI_IOCSTATUS_SCSI_TASK_TERMINATED:
+               desc = "task terminated";
                break;
-
-       case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
-               desc = "SCSI IOC Terminated";
+       case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
+               desc = "residual mismatch";
+               break;
+       case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
+               desc = "task management failed";
+               break;
+       case MPI_IOCSTATUS_SCSI_IOC_TERMINATED:
+               desc = "IOC terminated";
                break;
+       case MPI_IOCSTATUS_SCSI_EXT_TERMINATED:
+               desc = "ext terminated";
+               break;
+       default:
+               desc = "";
+               break;
+       }
 
-       case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
-               desc = "SCSI Ext Terminated";
+       switch (pScsiReply->SCSIStatus)
+       {
+
+       case MPI_SCSI_STATUS_SUCCESS:
+               desc1 = "success";
+               break;
+       case MPI_SCSI_STATUS_CHECK_CONDITION:
+               desc1 = "check condition";
+               break;
+       case MPI_SCSI_STATUS_CONDITION_MET:
+               desc1 = "condition met";
+               break;
+       case MPI_SCSI_STATUS_BUSY:
+               desc1 = "busy";
+               break;
+       case MPI_SCSI_STATUS_INTERMEDIATE:
+               desc1 = "intermediate";
+               break;
+       case MPI_SCSI_STATUS_INTERMEDIATE_CONDMET:
+               desc1 = "intermediate condmet";
+               break;
+       case MPI_SCSI_STATUS_RESERVATION_CONFLICT:
+               desc1 = "reservation conflict";
+               break;
+       case MPI_SCSI_STATUS_COMMAND_TERMINATED:
+               desc1 = "command terminated";
+               break;
+       case MPI_SCSI_STATUS_TASK_SET_FULL:
+               desc1 = "task set full";
+               break;
+       case MPI_SCSI_STATUS_ACA_ACTIVE:
+               desc1 = "aca active";
+               break;
+       case MPI_SCSI_STATUS_FCPEXT_DEVICE_LOGGED_OUT:
+               desc1 = "fcpext device logged out";
+               break;
+       case MPI_SCSI_STATUS_FCPEXT_NO_LINK:
+               desc1 = "fcpext no link";
+               break;
+       case MPI_SCSI_STATUS_FCPEXT_UNASSIGNED:
+               desc1 = "fcpext unassigned";
+               break;
+       default:
+               desc1 = "";
                break;
        }
 
-       if (!desc)
-               return;
+       scsi_print_command(sc);
+       printk(MYIOC_s_DEBUG_FMT "\tfw_channel = %d, fw_id = %d\n",
+           ioc->name, pScsiReply->Bus, pScsiReply->TargetID);
+       printk(MYIOC_s_DEBUG_FMT "\trequest_len = %d, underflow = %d, "
+           "resid = %d\n", ioc->name, scsi_bufflen(sc), sc->underflow,
+           scsi_get_resid(sc));
+       printk(MYIOC_s_DEBUG_FMT "\ttag = %d, transfer_count = %d, "
+           "sc->result = %08X\n", ioc->name, le16_to_cpu(pScsiReply->TaskTag),
+           le32_to_cpu(pScsiReply->TransferCount), sc->result);
+       printk(MYIOC_s_DEBUG_FMT "\tiocstatus = %s (0x%04x), "
+           "scsi_status = %s (0x%02x), scsi_state = (0x%02x)\n",
+           ioc->name, desc, ioc_status, desc1, pScsiReply->SCSIStatus,
+           pScsiReply->SCSIState);
 
-       snprintf(extend_desc, EVENT_DESCR_STR_SZ,
-           "[%d:%d:%d:%d] cmd=%02Xh, sam_status=%02Xh state=%02Xh",
-               sc->device->host->host_no,
-               sc->device->channel, sc->device->id, sc->device->lun,
-               sc->cmnd[0], scsi_status, scsi_state);
+       if (pScsiReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
+               skey = sc->sense_buffer[2] & 0x0F;
+               asc = sc->sense_buffer[12];
+               ascq = sc->sense_buffer[13];
 
-       printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s: %s\n",
-           ioc->name, ioc_status, desc, extend_desc);
+               printk(MYIOC_s_DEBUG_FMT "\t[sense_key,asc,ascq]: "
+                   "[0x%02x,0x%02x,0x%02x]\n", ioc->name, skey, asc, ascq);
+       }
+
+       /*
+        *  Look for + dump FCP ResponseInfo[]!
+        */
+       if (pScsiReply->SCSIState & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
+           pScsiReply->ResponseInfo)
+               printk(MYIOC_s_DEBUG_FMT "response_info = %08xh\n",
+                   ioc->name, le32_to_cpu(pScsiReply->ResponseInfo));
 }
 #endif
 
@@ -593,11 +647,10 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
        SCSIIORequest_t *pScsiReq;
        SCSIIOReply_t   *pScsiReply;
        u16              req_idx, req_idx_MR;
-       VirtDevice       *vdev;
+       VirtDevice       *vdevice;
        VirtTarget       *vtarget;
 
-       hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
-
+       hd = shost_priv(ioc->sh);
        req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
        req_idx_MR = (mr != NULL) ?
            le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx) : req_idx;
@@ -608,12 +661,11 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                printk (MYIOC_s_ERR_FMT
                    "req_idx=%x req_idx_MR=%x mf=%p mr=%p sc=%p\n",
                    ioc->name, req_idx, req_idx_MR, mf, mr,
-                   hd->ScsiLookup[req_idx_MR]);
+                   mptscsih_get_scsi_lookup(ioc, req_idx_MR));
                return 0;
        }
 
-       sc = hd->ScsiLookup[req_idx];
-       hd->ScsiLookup[req_idx] = NULL;
+       sc = mptscsih_getclear_scsi_lookup(ioc, req_idx);
        if (sc == NULL) {
                MPIHeader_t *hdr = (MPIHeader_t *)mf;
 
@@ -640,11 +692,11 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
        pScsiReply = (SCSIIOReply_t *) mr;
 
        if((ioc->facts.MsgVersion >= MPI_VERSION_01_05) && pScsiReply){
-               dmfprintk((MYIOC_s_INFO_FMT
+               dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                        "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d,task-tag=%d)\n",
                        ioc->name, mf, mr, sc, req_idx, pScsiReply->TaskTag));
        }else{
-               dmfprintk((MYIOC_s_INFO_FMT
+               dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                        "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
                        ioc->name, mf, mr, sc, req_idx));
        }
@@ -662,7 +714,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                scsi_state = pScsiReply->SCSIState;
                scsi_status = pScsiReply->SCSIStatus;
                xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
-               sc->resid = sc->request_bufflen - xfer_cnt;
+               scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
                log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
 
                /*
@@ -686,8 +738,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                 */
                if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
                    pScsiReply->ResponseInfo) {
-                       printk(KERN_NOTICE "[%d:%d:%d:%d] "
-                       "FCP_ResponseInfo=%08xh\n",
+                       printk(MYIOC_s_NOTE_FMT "[%d:%d:%d:%d] "
+                       "FCP_ResponseInfo=%08xh\n", ioc->name,
                        sc->device->host->host_no, sc->device->channel,
                        sc->device->id, sc->device->lun,
                        le32_to_cpu(pScsiReply->ResponseInfo));
@@ -719,10 +771,10 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                        if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
                                hd->sel_timeout[pScsiReq->TargetID]++;
 
-                       vdev = sc->device->hostdata;
-                       if (!vdev)
+                       vdevice = sc->device->hostdata;
+                       if (!vdevice)
                                break;
-                       vtarget = vdev->vtarget;
+                       vtarget = vdevice->vtarget;
                        if (vtarget->tflags & MPT_TARGET_FLAGS_LED_ON) {
                                mptscsih_issue_sep_command(ioc, vtarget,
                                    MPI_SEP_REQ_SLOTSTATUS_UNCONFIGURED);
@@ -767,14 +819,14 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                        break;
 
                case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:      /* 0x0049 */
-                       sc->resid = sc->request_bufflen - xfer_cnt;
+                       scsi_set_resid(sc, scsi_bufflen(sc) - xfer_cnt);
                        if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
                                sc->result=DID_SOFT_ERROR << 16;
                        else /* Sufficient data transfer occurred */
                                sc->result = (DID_OK << 16) | scsi_status;
-                       dreplyprintk((KERN_NOTICE
+                       dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                            "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
-                           sc->result, sc->device->channel, sc->device->id));
+                           ioc->name, sc->result, sc->device->channel, sc->device->id));
                        break;
 
                case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN:          /* 0x0045 */
@@ -805,9 +857,13 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                                }
                        }
 
-                       dreplyprintk((KERN_NOTICE "  sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
-                                       sc->underflow));
-                       dreplyprintk((KERN_NOTICE "  ActBytesXferd=%02xh\n", xfer_cnt));
+
+                       dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                           "  sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
+                           ioc->name, sc->underflow));
+                       dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                           "  ActBytesXferd=%02xh\n", ioc->name, xfer_cnt));
+
                        /* Report Queue Full
                         */
                        if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
@@ -816,7 +872,7 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                        break;
 
                case MPI_IOCSTATUS_SCSI_DATA_OVERRUN:           /* 0x0044 */
-                       sc->resid=0;
+                       scsi_set_resid(sc, 0);
                case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:        /* 0x0040 */
                case MPI_IOCSTATUS_SUCCESS:                     /* 0x0000 */
                        sc->result = (DID_OK << 16) | scsi_status;
@@ -884,38 +940,15 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 
                }       /* switch(status) */
 
-#ifdef MPT_DEBUG_REPLY
-               if (sc->result) {
-
-                       mptscsih_iocstatus_info_scsiio(ioc, status,
-                           scsi_status, scsi_state, sc);
-
-                       dreplyprintk(("%s: [%d:%d:%d:%d] cmd=0x%02x "
-                           "result=0x%08x\n\tiocstatus=0x%04X "
-                           "scsi_state=0x%02X scsi_status=0x%02X "
-                           "loginfo=0x%08X\n", __FUNCTION__,
-                           sc->device->host->host_no, sc->device->channel, sc->device->id,
-                           sc->device->lun, sc->cmnd[0], sc->result, status,
-                           scsi_state, scsi_status, log_info));
-
-                       dreplyprintk(("%s: [%d:%d:%d:%d] resid=%d "
-                           "bufflen=%d xfer_cnt=%d\n", __FUNCTION__,
-                           sc->device->host->host_no, sc->device->channel, sc->device->id,
-                           sc->device->lun, sc->resid, sc->request_bufflen,
-                           xfer_cnt));
-               }
+#ifdef CONFIG_FUSION_LOGGING
+               if (sc->result && (ioc->debug_level & MPT_DEBUG_REPLY))
+                       mptscsih_info_scsiio(ioc, sc, pScsiReply);
 #endif
 
        } /* end of address reply case */
 
        /* Unmap the DMA buffers, if any. */
-       if (sc->use_sg) {
-               pci_unmap_sg(ioc->pcidev, (struct scatterlist *) sc->request_buffer,
-                           sc->use_sg, sc->sc_data_direction);
-       } else if (sc->request_bufflen) {
-               pci_unmap_single(ioc->pcidev, sc->SCp.dma_handle,
-                               sc->request_bufflen, sc->sc_data_direction);
-       }
+       scsi_dma_unmap(sc);
 
        sc->scsi_done(sc);              /* Issue the command callback */
 
@@ -938,57 +971,32 @@ static void
 mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
 {
        MPT_ADAPTER *ioc = hd->ioc;
-       struct scsi_cmnd        *SCpnt;
-       MPT_FRAME_HDR   *mf;
+       struct scsi_cmnd *sc;
+       SCSIIORequest_t *mf = NULL;
        int              ii;
-       int              max = ioc->req_depth;
-
-       dprintk((KERN_INFO MYNAM ": flush_ScsiLookup called\n"));
-       for (ii= 0; ii < max; ii++) {
-               if ((SCpnt = hd->ScsiLookup[ii]) != NULL) {
-
-                       /* Command found.
-                        */
-
-                       /* Null ScsiLookup index
-                        */
-                       hd->ScsiLookup[ii] = NULL;
-
-                       mf = MPT_INDEX_2_MFPTR(ioc, ii);
-                       dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n",
-                                       mf, SCpnt));
-
-                       /* Free Chain buffers */
-                       mptscsih_freeChainBuffers(ioc, ii);
-
-                       /* Free Message frames */
-                       mpt_free_msg_frame(ioc, mf);
-
-                       if ((unsigned char *)mf != SCpnt->host_scribble)
-                               continue;
-
-                       /* Set status, free OS resources (SG DMA buffers)
-                        * Do OS callback
-                        */
-                       if (SCpnt->use_sg) {
-                               pci_unmap_sg(ioc->pcidev,
-                                       (struct scatterlist *) SCpnt->request_buffer,
-                                       SCpnt->use_sg,
-                                       SCpnt->sc_data_direction);
-                       } else if (SCpnt->request_bufflen) {
-                               pci_unmap_single(ioc->pcidev,
-                                       SCpnt->SCp.dma_handle,
-                                       SCpnt->request_bufflen,
-                                       SCpnt->sc_data_direction);
-                       }
-                       SCpnt->result = DID_RESET << 16;
-                       SCpnt->host_scribble = NULL;
+       int              channel, id;
 
-                       SCpnt->scsi_done(SCpnt);        /* Issue the command callback */
-               }
+       for (ii= 0; ii < ioc->req_depth; ii++) {
+               sc = mptscsih_getclear_scsi_lookup(ioc, ii);
+               if (!sc)
+                       continue;
+               mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
+               if (!mf)
+                       continue;
+               channel = mf->Bus;
+               id = mf->TargetID;
+               mptscsih_freeChainBuffers(ioc, ii);
+               mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
+               if ((unsigned char *)mf != sc->host_scribble)
+                       continue;
+               scsi_dma_unmap(sc);
+               sc->result = DID_RESET << 16;
+               sc->host_scribble = NULL;
+               sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT
+                   "completing cmds: fw_channel %d, fw_id %d, sc=%p,"
+                   " mf = %p, idx=%x\n", ioc->name, channel, id, sc, mf, ii);
+               sc->scsi_done(sc);
        }
-
-       return;
 }
 
 /*
@@ -1010,51 +1018,49 @@ mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
 {
        SCSIIORequest_t *mf = NULL;
        int              ii;
-       int              max = hd->ioc->req_depth;
        struct scsi_cmnd *sc;
        struct scsi_lun  lun;
+       MPT_ADAPTER *ioc = hd->ioc;
+       unsigned long   flags;
 
-       dsprintk((KERN_INFO MYNAM ": search_running channel %d id %d lun %d max %d\n",
-           vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun, max));
-
-       for (ii=0; ii < max; ii++) {
-               if ((sc = hd->ScsiLookup[ii]) != NULL) {
+       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+       for (ii = 0; ii < ioc->req_depth; ii++) {
+               if ((sc = ioc->ScsiLookup[ii]) != NULL) {
 
-                       mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
+                       mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(ioc, ii);
                        if (mf == NULL)
                                continue;
+                       /* If the device is a hidden raid component, then its
+                        * expected that the mf->function will be RAID_SCSI_IO
+                        */
+                       if (vdevice->vtarget->tflags &
+                           MPT_TARGET_FLAGS_RAID_COMPONENT && mf->Function !=
+                           MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
+                               continue;
+
                        int_to_scsilun(vdevice->lun, &lun);
                        if ((mf->Bus != vdevice->vtarget->channel) ||
                            (mf->TargetID != vdevice->vtarget->id) ||
                            memcmp(lun.scsi_lun, mf->LUN, 8))
                                continue;
-                       dsprintk(( "search_running: found (sc=%p, mf = %p) "
-                           "channel %d id %d, lun %d \n", hd->ScsiLookup[ii],
-                           mf, mf->Bus, mf->TargetID, vdevice->lun));
 
-                       /* Cleanup
-                        */
-                       hd->ScsiLookup[ii] = NULL;
-                       mptscsih_freeChainBuffers(hd->ioc, ii);
-                       mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf);
                        if ((unsigned char *)mf != sc->host_scribble)
                                continue;
-                       if (sc->use_sg) {
-                               pci_unmap_sg(hd->ioc->pcidev,
-                               (struct scatterlist *) sc->request_buffer,
-                                       sc->use_sg,
-                                       sc->sc_data_direction);
-                       } else if (sc->request_bufflen) {
-                               pci_unmap_single(hd->ioc->pcidev,
-                                       sc->SCp.dma_handle,
-                                       sc->request_bufflen,
-                                       sc->sc_data_direction);
-                       }
+                       ioc->ScsiLookup[ii] = NULL;
+                       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+                       mptscsih_freeChainBuffers(ioc, ii);
+                       mpt_free_msg_frame(ioc, (MPT_FRAME_HDR *)mf);
+                       scsi_dma_unmap(sc);
                        sc->host_scribble = NULL;
                        sc->result = DID_NO_CONNECT << 16;
+                       sdev_printk(KERN_INFO, sc->device, MYIOC_s_FMT "completing cmds: fw_channel %d,"
+                          "fw_id %d, sc=%p, mf = %p, idx=%x\n", ioc->name, vdevice->vtarget->channel,
+                          vdevice->vtarget->id, sc, mf, ii);
                        sc->scsi_done(sc);
+                       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
                }
        }
+       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
        return;
 }
 
@@ -1077,17 +1083,18 @@ mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSI
 {
        long time = jiffies;
        MPT_SCSI_HOST           *hd;
+       MPT_ADAPTER     *ioc;
 
        if (sc->device == NULL)
                return;
        if (sc->device->host == NULL)
                return;
-       if ((hd = (MPT_SCSI_HOST *)sc->device->host->hostdata) == NULL)
+       if ((hd = shost_priv(sc->device->host)) == NULL)
                return;
-
+       ioc = hd->ioc;
        if (time - hd->last_queue_full > 10 * HZ) {
-               dprintk((MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
-                               hd->ioc->name, 0, sc->device->id, sc->device->lun));
+               dprintk(ioc, printk(MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
+                               ioc->name, 0, sc->device->id, sc->device->lun));
                hd->last_queue_full = time;
        }
 }
@@ -1114,28 +1121,28 @@ mptscsih_remove(struct pci_dev *pdev)
 
        scsi_remove_host(host);
 
-       if((hd = (MPT_SCSI_HOST *)host->hostdata) == NULL)
+       if((hd = shost_priv(host)) == NULL)
                return;
 
        mptscsih_shutdown(pdev);
 
        sz1=0;
 
-       if (hd->ScsiLookup != NULL) {
-               sz1 = hd->ioc->req_depth * sizeof(void *);
-               kfree(hd->ScsiLookup);
-               hd->ScsiLookup = NULL;
+       if (ioc->ScsiLookup != NULL) {
+               sz1 = ioc->req_depth * sizeof(void *);
+               kfree(ioc->ScsiLookup);
+               ioc->ScsiLookup = NULL;
        }
 
-       dprintk((MYIOC_s_INFO_FMT
+       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
            "Free'd ScsiLookup (%d) memory\n",
-           hd->ioc->name, sz1));
+           ioc->name, sz1));
 
        kfree(hd->info_kbuf);
 
        /* NULL the Scsi_Host pointer
         */
-       hd->ioc->sh = NULL;
+       ioc->sh = NULL;
 
        scsi_host_put(host);
 
@@ -1151,15 +1158,6 @@ mptscsih_remove(struct pci_dev *pdev)
 void
 mptscsih_shutdown(struct pci_dev *pdev)
 {
-       MPT_ADAPTER             *ioc = pci_get_drvdata(pdev);
-       struct Scsi_Host        *host = ioc->sh;
-       MPT_SCSI_HOST           *hd;
-
-       if(!host)
-               return;
-
-       hd = (MPT_SCSI_HOST *)host->hostdata;
-
 }
 
 #ifdef CONFIG_PM
@@ -1205,7 +1203,7 @@ mptscsih_info(struct Scsi_Host *SChost)
        MPT_SCSI_HOST *h;
        int size = 0;
 
-       h = (MPT_SCSI_HOST *)SChost->hostdata;
+       h = shost_priv(SChost);
 
        if (h) {
                if (h->info_kbuf == NULL)
@@ -1299,7 +1297,7 @@ int
 mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
                        int length, int func)
 {
-       MPT_SCSI_HOST   *hd = (MPT_SCSI_HOST *)host->hostdata;
+       MPT_SCSI_HOST   *hd = shost_priv(host);
        MPT_ADAPTER     *ioc = hd->ioc;
        int size = 0;
 
@@ -1338,7 +1336,7 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
        MPT_SCSI_HOST           *hd;
        MPT_FRAME_HDR           *mf;
        SCSIIORequest_t         *pScsiReq;
-       VirtDevice              *vdev = SCpnt->device->hostdata;
+       VirtDevice              *vdevice = SCpnt->device->hostdata;
        int      lun;
        u32      datalen;
        u32      scsictl;
@@ -1346,26 +1344,28 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
        u32      cmd_len;
        int      my_idx;
        int      ii;
+       MPT_ADAPTER *ioc;
 
-       hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
+       hd = shost_priv(SCpnt->device->host);
+       ioc = hd->ioc;
        lun = SCpnt->device->lun;
        SCpnt->scsi_done = done;
 
-       dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n",
-                       (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done));
+       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "qcmd: SCpnt=%p, done()=%p\n",
+               ioc->name, SCpnt, done));
 
        if (hd->resetPending) {
-               dtmprintk((MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
-                       (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt));
+               dtmprintk(ioc, printk(MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
+                       ioc->name, SCpnt));
                return SCSI_MLQUEUE_HOST_BUSY;
        }
 
        /*
         *  Put together a MPT SCSI request...
         */
-       if ((mf = mpt_get_msg_frame(hd->ioc->DoneCtx, hd->ioc)) == NULL) {
-               dprintk((MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
-                               hd->ioc->name));
+       if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
+               dprintk(ioc, printk(MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
+                               ioc->name));
                return SCSI_MLQUEUE_HOST_BUSY;
        }
 
@@ -1380,10 +1380,10 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
         *    will be no data transfer!  GRRRRR...
         */
        if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
-               datalen = SCpnt->request_bufflen;
+               datalen = scsi_bufflen(SCpnt);
                scsidir = MPI_SCSIIO_CONTROL_READ;      /* DATA IN  (host<--ioc<--dev) */
        } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
-               datalen = SCpnt->request_bufflen;
+               datalen = scsi_bufflen(SCpnt);
                scsidir = MPI_SCSIIO_CONTROL_WRITE;     /* DATA OUT (host-->ioc-->dev) */
        } else {
                datalen = 0;
@@ -1393,8 +1393,8 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
        /* Default to untagged. Once a target structure has been allocated,
         * use the Inquiry data to determine if device supports tagged.
         */
-       if (vdev
-           && (vdev->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
+       if (vdevice
+           && (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_Q_YES)
            && (SCpnt->device->tagged_supported)) {
                scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
        } else {
@@ -1403,10 +1403,10 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
 
        /* Use the above information to set up the message frame
         */
-       pScsiReq->TargetID = (u8) vdev->vtarget->id;
-       pScsiReq->Bus = vdev->vtarget->channel;
+       pScsiReq->TargetID = (u8) vdevice->vtarget->id;
+       pScsiReq->Bus = vdevice->vtarget->channel;
        pScsiReq->ChainOffset = 0;
-       if (vdev->vtarget->tflags &  MPT_TARGET_FLAGS_RAID_COMPONENT)
+       if (vdevice->vtarget->tflags &  MPT_TARGET_FLAGS_RAID_COMPONENT)
                pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
        else
                pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
@@ -1431,7 +1431,7 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
        pScsiReq->DataLength = cpu_to_le32(datalen);
 
        /* SenseBuffer low address */
-       pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
+       pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
                                           + (my_idx * MPT_SENSE_BUFFER_ALLOC));
 
        /* Now add the SG list
@@ -1443,23 +1443,22 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
                        (dma_addr_t) -1);
        } else {
                /* Add a 32 or 64 bit SGE */
-               if (mptscsih_AddSGE(hd->ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
+               if (mptscsih_AddSGE(ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
                        goto fail;
        }
 
        SCpnt->host_scribble = (unsigned char *)mf;
-       hd->ScsiLookup[my_idx] = SCpnt;
+       mptscsih_set_scsi_lookup(ioc, my_idx, SCpnt);
 
-       mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf);
-       dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
-                       hd->ioc->name, SCpnt, mf, my_idx));
-       DBG_DUMP_REQUEST_FRAME(mf)
+       mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
+       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
+                       ioc->name, SCpnt, mf, my_idx));
+       DBG_DUMP_REQUEST_FRAME(ioc, (u32 *)mf);
        return 0;
 
  fail:
-       hd->ScsiLookup[my_idx] = NULL;
-       mptscsih_freeChainBuffers(hd->ioc, my_idx);
-       mpt_free_msg_frame(hd->ioc, mf);
+       mptscsih_freeChainBuffers(ioc, my_idx);
+       mpt_free_msg_frame(ioc, mf);
        return SCSI_MLQUEUE_HOST_BUSY;
 }
 
@@ -1504,7 +1503,7 @@ mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
                list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
                spin_unlock_irqrestore(&ioc->FreeQlock, flags);
 
-               dmfprintk((MYIOC_s_INFO_FMT "FreeChainBuffers (index %d)\n",
+               dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FreeChainBuffers (index %d)\n",
                                ioc->name, chain_idx));
 
                /* handle next */
@@ -1548,7 +1547,7 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int c
        unsigned long    flags;
 
        ioc = hd->ioc;
-       dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name));
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler Entered!\n", ioc->name));
 
        // SJR - CHECKME - Can we avoid this here?
        // (mpt_HardResetHandler has this check...)
@@ -1568,38 +1567,38 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int c
         */
        if (mptscsih_tm_pending_wait(hd) == FAILED) {
                if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
-                       dtmprintk((KERN_INFO MYNAM ": %s: TMHandler abort: "
+                       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler abort: "
                           "Timed out waiting for last TM (%d) to complete! \n",
-                          hd->ioc->name, hd->tmPending));
+                          ioc->name, hd->tmPending));
                        return FAILED;
                } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
-                       dtmprintk((KERN_INFO MYNAM ": %s: TMHandler target "
+                       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler target "
                                "reset: Timed out waiting for last TM (%d) "
-                               "to complete! \n", hd->ioc->name,
+                               "to complete! \n", ioc->name,
                                hd->tmPending));
                        return FAILED;
                } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
-                       dtmprintk((KERN_INFO MYNAM ": %s: TMHandler bus reset: "
+                       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TMHandler bus reset: "
                           "Timed out waiting for last TM (%d) to complete! \n",
-                          hd->ioc->name, hd->tmPending));
+                         ioc->name, hd->tmPending));
                        return FAILED;
                }
        } else {
-               spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
+               spin_lock_irqsave(&ioc->FreeQlock, flags);
                hd->tmPending |=  (1 << type);
-               spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
+               spin_unlock_irqrestore(&ioc->FreeQlock, flags);
        }
 
-       ioc_raw_state = mpt_GetIocState(hd->ioc, 0);
+       ioc_raw_state = mpt_GetIocState(ioc, 0);
 
        if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
                printk(MYIOC_s_WARN_FMT
                        "TM Handler for type=%x: IOC Not operational (0x%x)!\n",
                        ioc->name, type, ioc_raw_state);
-               printk(KERN_WARNING " Issuing HardReset!!\n");
+               printk(MYIOC_s_WARN_FMT " Issuing HardReset!!\n", ioc->name);
                if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
-                       printk((KERN_WARNING "TMHandler: HardReset "
-                               "FAILED!!\n"));
+                       printk(MYIOC_s_WARN_FMT "TMHandler: HardReset "
+                           "FAILED!!\n", ioc->name);
                return FAILED;
        }
 
@@ -1620,12 +1619,13 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int c
            ctx2abort, timeout);
        if (rc)
                printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n",
-                      hd->ioc->name);
+                      ioc->name);
        else
-               dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n",
-                          hd->ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Issue of TaskMgmt Successful!\n",
+                          ioc->name));
 
-       dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                       "TMHandler rc = %d!\n", ioc->name, rc));
 
        return rc;
 }
@@ -1657,16 +1657,17 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, i
        SCSITaskMgmt_t  *pScsiTm;
        int              ii;
        int              retval;
+       MPT_ADAPTER     *ioc = hd->ioc;
 
        /* Return Fail to calling function if no message frames available.
         */
-       if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) {
-               dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
-                               hd->ioc->name));
+       if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
+                               ioc->name));
                return FAILED;
        }
-       dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
-                       hd->ioc->name, mf));
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt request @ %p\n",
+                       ioc->name, mf));
 
        /* Format the Request
         */
@@ -1689,28 +1690,34 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, i
 
        pScsiTm->TaskMsgContext = ctx2abort;
 
-       dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) "
-               "type=%d\n", hd->ioc->name, ctx2abort, type));
-
-       DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
-
-       if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc,
-               sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP)) != 0) {
-               dfailprintk((MYIOC_s_ERR_FMT "send_handshake FAILED!"
-                       " (hd %p, ioc %p, mf %p, rc=%d) \n", hd->ioc->name, hd,
-                       hd->ioc, mf, retval));
-               goto fail_out;
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IssueTaskMgmt: ctx2abort (0x%08x) "
+               "type=%d\n", ioc->name, ctx2abort, type));
+
+       DBG_DUMP_TM_REQUEST_FRAME(ioc, (u32 *)pScsiTm);
+
+       if ((ioc->facts.IOCCapabilities & MPI_IOCFACTS_CAPABILITY_HIGH_PRI_Q) &&
+           (ioc->facts.MsgVersion >= MPI_VERSION_01_05))
+               mpt_put_msg_frame_hi_pri(ioc->TaskCtx, ioc, mf);
+       else {
+               retval = mpt_send_handshake_request(ioc->TaskCtx, ioc,
+                       sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP);
+               if (retval) {
+                       dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "send_handshake FAILED!"
+                       " (hd %p, ioc %p, mf %p, rc=%d) \n", ioc->name, hd,
+                       ioc, mf, retval));
+                       goto fail_out;
+               }
        }
 
        if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
-               dfailprintk((MYIOC_s_ERR_FMT "task management request TIMED OUT!"
-                       " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
-                       hd->ioc, mf));
-               dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
-                        hd->ioc->name));
-               retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
-               dtmprintk((MYIOC_s_INFO_FMT "rc=%d \n",
-                        hd->ioc->name, retval));
+               dfailprintk(ioc, printk(MYIOC_s_ERR_FMT "task management request TIMED OUT!"
+                       " (hd %p, ioc %p, mf %p) \n", ioc->name, hd,
+                       ioc, mf));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling HardReset! \n",
+                        ioc->name));
+               retval = mpt_HardResetHandler(ioc, CAN_SLEEP);
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rc=%d \n",
+                        ioc->name, retval));
                goto fail_out;
        }
 
@@ -1731,7 +1738,7 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, i
        /*
         * Free task managment mf, and corresponding tm flags
         */
-       mpt_free_msg_frame(hd->ioc, mf);
+       mpt_free_msg_frame(ioc, mf);
        hd->tmPending = 0;
        hd->tmState = TM_STATE_NONE;
        return FAILED;
@@ -1768,43 +1775,69 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
        u32              ctx2abort;
        int              scpnt_idx;
        int              retval;
-       VirtDevice       *vdev;
+       VirtDevice       *vdevice;
        ulong            sn = SCpnt->serial_number;
+       MPT_ADAPTER     *ioc;
 
        /* If we can't locate our host adapter structure, return FAILED status.
         */
-       if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL) {
+       if ((hd = shost_priv(SCpnt->device->host)) == NULL) {
                SCpnt->result = DID_RESET << 16;
                SCpnt->scsi_done(SCpnt);
-               dfailprintk((KERN_INFO MYNAM ": mptscsih_abort: "
-                          "Can't locate host! (sc=%p)\n",
-                          SCpnt));
+               printk(KERN_ERR MYNAM ": task abort: "
+                   "can't locate host! (sc=%p)\n", SCpnt);
                return FAILED;
        }
 
+       ioc = hd->ioc;
+       printk(MYIOC_s_INFO_FMT "attempting task abort! (sc=%p)\n",
+              ioc->name, SCpnt);
+       scsi_print_command(SCpnt);
+
+       vdevice = SCpnt->device->hostdata;
+       if (!vdevice || !vdevice->vtarget) {
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "task abort: device has been deleted (sc=%p)\n",
+                   ioc->name, SCpnt));
+               SCpnt->result = DID_NO_CONNECT << 16;
+               SCpnt->scsi_done(SCpnt);
+               retval = 0;
+               goto out;
+       }
+
+       /* Task aborts are not supported for hidden raid components.
+        */
+       if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "task abort: hidden raid component (sc=%p)\n",
+                   ioc->name, SCpnt));
+               SCpnt->result = DID_RESET << 16;
+               retval = FAILED;
+               goto out;
+       }
+
        /* Find this command
         */
-       if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(SCpnt)) < 0) {
+       if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(ioc, SCpnt)) < 0) {
                /* Cmd not found in ScsiLookup.
                 * Do OS callback.
                 */
                SCpnt->result = DID_RESET << 16;
-               dtmprintk((KERN_INFO MYNAM ": %s: mptscsih_abort: "
-                          "Command not in the active list! (sc=%p)\n",
-                          hd->ioc->name, SCpnt));
-               return SUCCESS;
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "task abort: "
+                  "Command not in the active list! (sc=%p)\n", ioc->name,
+                  SCpnt));
+               retval = 0;
+               goto out;
        }
 
-       if (hd->resetPending)
-               return FAILED;
+       if (hd->resetPending) {
+               retval = FAILED;
+               goto out;
+       }
 
        if (hd->timeouts < -1)
                hd->timeouts++;
 
-       printk(KERN_WARNING MYNAM ": %s: attempting task abort! (sc=%p)\n",
-              hd->ioc->name, SCpnt);
-       scsi_print_command(SCpnt);
-
        /* Most important!  Set TaskMsgContext to SCpnt's MsgContext!
         * (the IO to be ABORT'd)
         *
@@ -1812,23 +1845,22 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
         *       swap it here either.  It is an opaque cookie to
         *       the controller, so it does not matter. -DaveM
         */
-       mf = MPT_INDEX_2_MFPTR(hd->ioc, scpnt_idx);
+       mf = MPT_INDEX_2_MFPTR(ioc, scpnt_idx);
        ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
 
        hd->abortSCpnt = SCpnt;
 
-       vdev = SCpnt->device->hostdata;
        retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
-               vdev->vtarget->channel, vdev->vtarget->id, vdev->lun,
-               ctx2abort, mptscsih_get_tm_timeout(hd->ioc));
+           vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun,
+           ctx2abort, mptscsih_get_tm_timeout(ioc));
 
-       if (SCPNT_TO_LOOKUP_IDX(SCpnt) == scpnt_idx &&
+       if (SCPNT_TO_LOOKUP_IDX(ioc, SCpnt) == scpnt_idx &&
            SCpnt->serial_number == sn)
                retval = FAILED;
 
-       printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n",
-               hd->ioc->name,
-               ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
+ out:
+       printk(MYIOC_s_INFO_FMT "task abort: %s (sc=%p)\n",
+           ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
 
        if (retval == 0)
                return SUCCESS;
@@ -1850,32 +1882,47 @@ mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
 {
        MPT_SCSI_HOST   *hd;
        int              retval;
-       VirtDevice       *vdev;
+       VirtDevice       *vdevice;
+       MPT_ADAPTER     *ioc;
 
        /* If we can't locate our host adapter structure, return FAILED status.
         */
-       if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
-               dtmprintk((KERN_INFO MYNAM ": mptscsih_dev_reset: "
-                          "Can't locate host! (sc=%p)\n",
-                          SCpnt));
+       if ((hd = shost_priv(SCpnt->device->host)) == NULL){
+               printk(KERN_ERR MYNAM ": target reset: "
+                  "Can't locate host! (sc=%p)\n", SCpnt);
                return FAILED;
        }
 
-       if (hd->resetPending)
-               return FAILED;
-
-       printk(KERN_WARNING MYNAM ": %s: attempting target reset! (sc=%p)\n",
-              hd->ioc->name, SCpnt);
+       ioc = hd->ioc;
+       printk(MYIOC_s_INFO_FMT "attempting target reset! (sc=%p)\n",
+              ioc->name, SCpnt);
        scsi_print_command(SCpnt);
 
-       vdev = SCpnt->device->hostdata;
+       if (hd->resetPending) {
+               retval = FAILED;
+               goto out;
+       }
+
+       vdevice = SCpnt->device->hostdata;
+       if (!vdevice || !vdevice->vtarget) {
+               retval = 0;
+               goto out;
+       }
+
+       /* Target reset to hidden raid component is not supported
+        */
+       if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
+               retval = FAILED;
+               goto out;
+       }
+
        retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
-               vdev->vtarget->channel, vdev->vtarget->id,
-               0, 0, mptscsih_get_tm_timeout(hd->ioc));
+           vdevice->vtarget->channel, vdevice->vtarget->id, 0, 0,
+           mptscsih_get_tm_timeout(ioc));
 
-       printk (KERN_WARNING MYNAM ": %s: target reset: %s (sc=%p)\n",
-               hd->ioc->name,
-               ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
+ out:
+       printk (MYIOC_s_INFO_FMT "target reset: %s (sc=%p)\n",
+           ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
 
        if (retval == 0)
                return SUCCESS;
@@ -1898,31 +1945,31 @@ mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
 {
        MPT_SCSI_HOST   *hd;
        int              retval;
-       VirtDevice       *vdev;
+       VirtDevice       *vdevice;
+       MPT_ADAPTER     *ioc;
 
        /* If we can't locate our host adapter structure, return FAILED status.
         */
-       if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
-               dtmprintk((KERN_INFO MYNAM ": mptscsih_bus_reset: "
-                          "Can't locate host! (sc=%p)\n",
-                          SCpnt ) );
+       if ((hd = shost_priv(SCpnt->device->host)) == NULL){
+               printk(KERN_ERR MYNAM ": bus reset: "
+                  "Can't locate host! (sc=%p)\n", SCpnt);
                return FAILED;
        }
 
-       printk(KERN_WARNING MYNAM ": %s: attempting bus reset! (sc=%p)\n",
-              hd->ioc->name, SCpnt);
+       ioc = hd->ioc;
+       printk(MYIOC_s_INFO_FMT "attempting bus reset! (sc=%p)\n",
+              ioc->name, SCpnt);
        scsi_print_command(SCpnt);
 
        if (hd->timeouts < -1)
                hd->timeouts++;
 
-       vdev = SCpnt->device->hostdata;
+       vdevice = SCpnt->device->hostdata;
        retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
-               vdev->vtarget->channel, 0, 0, 0, mptscsih_get_tm_timeout(hd->ioc));
+           vdevice->vtarget->channel, 0, 0, 0, mptscsih_get_tm_timeout(ioc));
 
-       printk (KERN_WARNING MYNAM ": %s: bus reset: %s (sc=%p)\n",
-               hd->ioc->name,
-               ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
+       printk(MYIOC_s_INFO_FMT "bus reset: %s (sc=%p)\n",
+           ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
 
        if (retval == 0)
                return SUCCESS;
@@ -1943,37 +1990,38 @@ int
 mptscsih_host_reset(struct scsi_cmnd *SCpnt)
 {
        MPT_SCSI_HOST *  hd;
-       int              status = SUCCESS;
+       int              retval;
+       MPT_ADAPTER     *ioc;
 
        /*  If we can't locate the host to reset, then we failed. */
-       if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
-               dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
-                            "Can't locate host! (sc=%p)\n",
-                            SCpnt ) );
+       if ((hd = shost_priv(SCpnt->device->host)) == NULL){
+               printk(KERN_ERR MYNAM ": host reset: "
+                   "Can't locate host! (sc=%p)\n", SCpnt);
                return FAILED;
        }
 
-       printk(KERN_WARNING MYNAM ": %s: Attempting host reset! (sc=%p)\n",
-              hd->ioc->name, SCpnt);
+       ioc = hd->ioc;
+       printk(MYIOC_s_INFO_FMT "attempting host reset! (sc=%p)\n",
+           ioc->name, SCpnt);
 
        /*  If our attempts to reset the host failed, then return a failed
         *  status.  The host will be taken off line by the SCSI mid-layer.
         */
-       if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0){
-               status = FAILED;
+       if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0) {
+               retval = FAILED;
        } else {
                /*  Make sure TM pending is cleared and TM state is set to
                 *  NONE.
                 */
+               retval = 0;
                hd->tmPending = 0;
                hd->tmState = TM_STATE_NONE;
        }
 
-       dtmprintk( ( KERN_INFO MYNAM ": mptscsih_host_reset: "
-                    "Status = %s\n",
-                    (status == SUCCESS) ? "SUCCESS" : "FAILED" ) );
+       printk(MYIOC_s_INFO_FMT "host reset: %s (sc=%p)\n",
+           ioc->name, ((retval == 0) ? "SUCCESS" : "FAILED" ), SCpnt);
 
-       return status;
+       return retval;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1989,17 +2037,18 @@ mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
        unsigned long  flags;
        int            loop_count = 4 * 10;  /* Wait 10 seconds */
        int            status = FAILED;
+       MPT_ADAPTER     *ioc = hd->ioc;
 
        do {
-               spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
+               spin_lock_irqsave(&ioc->FreeQlock, flags);
                if (hd->tmState == TM_STATE_NONE) {
                        hd->tmState = TM_STATE_IN_PROGRESS;
                        hd->tmPending = 1;
-                       spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
+                       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
                        status = SUCCESS;
                        break;
                }
-               spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
+               spin_unlock_irqrestore(&ioc->FreeQlock, flags);
                msleep(250);
        } while (--loop_count);
 
@@ -2020,15 +2069,16 @@ mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
        unsigned long  flags;
        int            loop_count = 4 * timeout;
        int            status = FAILED;
+       MPT_ADAPTER     *ioc = hd->ioc;
 
        do {
-               spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
+               spin_lock_irqsave(&ioc->FreeQlock, flags);
                if(hd->tmPending == 0) {
                        status = SUCCESS;
-                       spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
+                       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
                        break;
                }
-               spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
+               spin_unlock_irqrestore(&ioc->FreeQlock, flags);
                msleep(250);
        } while (--loop_count);
 
@@ -2096,21 +2146,21 @@ mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *m
        u8                       tmType;
        u32                      termination_count;
 
-       dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
            ioc->name, mf, mr));
        if (!ioc->sh) {
-               dtmprintk((MYIOC_s_WARN_FMT
+               dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
                    "TaskMgmt Complete: NULL Scsi Host Ptr\n", ioc->name));
                return 1;
        }
 
        if (mr == NULL) {
-               dtmprintk((MYIOC_s_WARN_FMT
+               dtmprintk(ioc, printk(MYIOC_s_WARN_FMT
                    "ERROR! TaskMgmt Reply: NULL Request %p\n", ioc->name, mf));
                return 1;
        }
 
-       hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
+       hd = shost_priv(ioc->sh);
        pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
        pScsiTmReq = (SCSITaskMgmt_t*)mf;
        tmType = pScsiTmReq->TaskType;
@@ -2121,19 +2171,21 @@ mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *m
            pScsiTmReply->ResponseCode)
                mptscsih_taskmgmt_response_code(ioc,
                    pScsiTmReply->ResponseCode);
-       DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
-
-#if defined(MPT_DEBUG_REPLY) || defined(MPT_DEBUG_TM)
-       printk("%s: ha=%d [%d:%d:0] task_type=0x%02X "
-           "iocstatus=0x%04X\n\tloginfo=0x%08X response_code=0x%02X "
-           "term_cmnds=%d\n", __FUNCTION__, ioc->id, pScsiTmReply->Bus,
-           pScsiTmReply->TargetID, pScsiTmReq->TaskType,
-           le16_to_cpu(pScsiTmReply->IOCStatus),
-           le32_to_cpu(pScsiTmReply->IOCLogInfo),pScsiTmReply->ResponseCode,
-           le32_to_cpu(pScsiTmReply->TerminationCount));
+       DBG_DUMP_TM_REPLY_FRAME(ioc, (u32 *)pScsiTmReply);
+
+#ifdef CONFIG_FUSION_LOGGING
+       if ((ioc->debug_level & MPT_DEBUG_REPLY) ||
+                               (ioc->debug_level & MPT_DEBUG_TM ))
+               printk("%s: ha=%d [%d:%d:0] task_type=0x%02X "
+                       "iocstatus=0x%04X\n\tloginfo=0x%08X response_code=0x%02X "
+                       "term_cmnds=%d\n", __FUNCTION__, ioc->id, pScsiTmReply->Bus,
+                        pScsiTmReply->TargetID, pScsiTmReq->TaskType,
+                       le16_to_cpu(pScsiTmReply->IOCStatus),
+                       le32_to_cpu(pScsiTmReply->IOCLogInfo),pScsiTmReply->ResponseCode,
+                       le32_to_cpu(pScsiTmReply->TerminationCount));
 #endif
        if (!iocstatus) {
-               dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT " TaskMgmt SUCCESS\n", ioc->name));
                        hd->abortSCpnt = NULL;
                goto out;
        }
@@ -2159,7 +2211,7 @@ mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *m
                if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED ||
                    hd->cmdPtr)
                        if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
-                               printk((KERN_WARNING " Firmware Reload FAILED!!\n"));
+                               printk(MYIOC_s_WARN_FMT " Firmware Reload FAILED!!\n", ioc->name);
                break;
 
        case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
@@ -2214,10 +2266,6 @@ mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
        geom[1] = sectors;
        geom[2] = cylinders;
 
-       dprintk((KERN_NOTICE
-               ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n",
-               sdev->id, sdev->lun, sdev->channel, (int)cylinders, heads, sectors));
-
        return 0;
 }
 
@@ -2306,7 +2354,7 @@ void
 mptscsih_slave_destroy(struct scsi_device *sdev)
 {
        struct Scsi_Host        *host = sdev->host;
-       MPT_SCSI_HOST           *hd = (MPT_SCSI_HOST *)host->hostdata;
+       MPT_SCSI_HOST           *hd = shost_priv(host);
        VirtTarget              *vtarget;
        VirtDevice              *vdevice;
        struct scsi_target      *starget;
@@ -2333,16 +2381,17 @@ mptscsih_slave_destroy(struct scsi_device *sdev)
 int
 mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
 {
-       MPT_SCSI_HOST           *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
+       MPT_SCSI_HOST           *hd = shost_priv(sdev->host);
        VirtTarget              *vtarget;
        struct scsi_target      *starget;
        int                     max_depth;
        int                     tagged;
+       MPT_ADAPTER             *ioc = hd->ioc;
 
        starget = scsi_target(sdev);
        vtarget = starget->hostdata;
 
-       if (hd->ioc->bus_type == SPI) {
+       if (ioc->bus_type == SPI) {
                if (!(vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
                        max_depth = 1;
                else if (sdev->type == TYPE_DISK &&
@@ -2377,19 +2426,20 @@ mptscsih_slave_configure(struct scsi_device *sdev)
        VirtTarget              *vtarget;
        VirtDevice              *vdevice;
        struct scsi_target      *starget;
-       MPT_SCSI_HOST           *hd = (MPT_SCSI_HOST *)sh->hostdata;
+       MPT_SCSI_HOST           *hd = shost_priv(sh);
+       MPT_ADAPTER             *ioc = hd->ioc;
 
        starget = scsi_target(sdev);
        vtarget = starget->hostdata;
        vdevice = sdev->hostdata;
 
-       dsprintk((MYIOC_s_INFO_FMT
+       dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                "device @ %p, channel=%d, id=%d, lun=%d\n",
-               hd->ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
-       if (hd->ioc->bus_type == SPI)
-               dsprintk((MYIOC_s_INFO_FMT
+               ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
+       if (ioc->bus_type == SPI)
+               dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                    "sdtr %d wdtr %d ppr %d inq length=%d\n",
-                   hd->ioc->name, sdev->sdtr, sdev->wdtr,
+                   ioc->name, sdev->sdtr, sdev->wdtr,
                    sdev->ppr, sdev->inquiry_len));
 
        if (sdev->id > sh->max_id) {
@@ -2401,21 +2451,21 @@ mptscsih_slave_configure(struct scsi_device *sdev)
        vdevice->configured_lun = 1;
        mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
 
-       dsprintk((MYIOC_s_INFO_FMT
+       dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                "Queue depth=%d, tflags=%x\n",
-               hd->ioc->name, sdev->queue_depth, vtarget->tflags));
+               ioc->name, sdev->queue_depth, vtarget->tflags));
 
-       if (hd->ioc->bus_type == SPI)
-               dsprintk((MYIOC_s_INFO_FMT
+       if (ioc->bus_type == SPI)
+               dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                    "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
-                   hd->ioc->name, vtarget->negoFlags, vtarget->maxOffset,
+                   ioc->name, vtarget->negoFlags, vtarget->maxOffset,
                    vtarget->minSyncFactor));
 
 slave_configure_exit:
 
-       dsprintk((MYIOC_s_INFO_FMT
+       dsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
                "tagged %d, simple %d, ordered %d\n",
-               hd->ioc->name,sdev->tagged_supported, sdev->simple_tags,
+               ioc->name,sdev->tagged_supported, sdev->simple_tags,
                sdev->ordered_tags));
 
        return 0;
@@ -2434,14 +2484,15 @@ slave_configure_exit:
 static void
 mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
 {
-       VirtDevice      *vdev;
+       VirtDevice      *vdevice;
        SCSIIORequest_t *pReq;
        u32              sense_count = le32_to_cpu(pScsiReply->SenseCount);
+       MPT_ADAPTER     *ioc = hd->ioc;
 
        /* Get target structure
         */
        pReq = (SCSIIORequest_t *) mf;
-       vdev = sc->device->hostdata;
+       vdevice = sc->device->hostdata;
 
        if (sense_count) {
                u8 *sense_data;
@@ -2449,15 +2500,14 @@ mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR
 
                /* Copy the sense received into the scsi command block. */
                req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
-               sense_data = ((u8 *)hd->ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
+               sense_data = ((u8 *)ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
                memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
 
                /* Log SMART data (asc = 0x5D, non-IM case only) if required.
                 */
-               if ((hd->ioc->events) && (hd->ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
-                       if ((sense_data[12] == 0x5D) && (vdev->vtarget->raidVolume == 0)) {
+               if ((ioc->events) && (ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
+                       if ((sense_data[12] == 0x5D) && (vdevice->vtarget->raidVolume == 0)) {
                                int idx;
-                               MPT_ADAPTER *ioc = hd->ioc;
 
                                idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
                                ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
@@ -2470,36 +2520,112 @@ mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR
                                ioc->events[idx].data[1] = (sense_data[13] << 8) | sense_data[12];
 
                                ioc->eventContext++;
-                               if (hd->ioc->pcidev->vendor ==
+                               if (ioc->pcidev->vendor ==
                                    PCI_VENDOR_ID_IBM) {
-                                       mptscsih_issue_sep_command(hd->ioc,
-                                           vdev->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
-                                       vdev->vtarget->tflags |=
+                                       mptscsih_issue_sep_command(ioc,
+                                           vdevice->vtarget, MPI_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
+                                       vdevice->vtarget->tflags |=
                                            MPT_TARGET_FLAGS_LED_ON;
                                }
                        }
                }
        } else {
-               dprintk((MYIOC_s_INFO_FMT "Hmmm... SenseData len=0! (?)\n",
-                               hd->ioc->name));
+               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Hmmm... SenseData len=0! (?)\n",
+                               ioc->name));
        }
 }
 
-static int
-SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc)
+/**
+ * mptscsih_get_scsi_lookup
+ *
+ * retrieves scmd entry from ScsiLookup[] array list
+ *
+ * @ioc: Pointer to MPT_ADAPTER structure
+ * @i: index into the array
+ *
+ * Returns the scsi_cmd pointer
+ *
+ **/
+static struct scsi_cmnd *
+mptscsih_get_scsi_lookup(MPT_ADAPTER *ioc, int i)
 {
-       MPT_SCSI_HOST *hd;
-       int i;
+       unsigned long   flags;
+       struct scsi_cmnd *scmd;
 
-       hd = (MPT_SCSI_HOST *) sc->device->host->hostdata;
+       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+       scmd = ioc->ScsiLookup[i];
+       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+
+       return scmd;
+}
 
-       for (i = 0; i < hd->ioc->req_depth; i++) {
-               if (hd->ScsiLookup[i] == sc) {
-                       return i;
+/**
+ * mptscsih_getclear_scsi_lookup
+ *
+ * retrieves and clears scmd entry from ScsiLookup[] array list
+ *
+ * @ioc: Pointer to MPT_ADAPTER structure
+ * @i: index into the array
+ *
+ * Returns the scsi_cmd pointer
+ *
+ **/
+static struct scsi_cmnd *
+mptscsih_getclear_scsi_lookup(MPT_ADAPTER *ioc, int i)
+{
+       unsigned long   flags;
+       struct scsi_cmnd *scmd;
+
+       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+       scmd = ioc->ScsiLookup[i];
+       ioc->ScsiLookup[i] = NULL;
+       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+
+       return scmd;
+}
+
+/**
+ * mptscsih_set_scsi_lookup
+ *
+ * writes a scmd entry into the ScsiLookup[] array list
+ *
+ * @ioc: Pointer to MPT_ADAPTER structure
+ * @i: index into the array
+ * @scmd: scsi_cmnd pointer
+ *
+ **/
+static void
+mptscsih_set_scsi_lookup(MPT_ADAPTER *ioc, int i, struct scsi_cmnd *scmd)
+{
+       unsigned long   flags;
+
+       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+       ioc->ScsiLookup[i] = scmd;
+       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+}
+
+/**
+ * SCPNT_TO_LOOKUP_IDX - searches for a given scmd in the ScsiLookup[] array list
+ * @ioc: Pointer to MPT_ADAPTER structure
+ * @sc: scsi_cmnd pointer
+ */
+static int
+SCPNT_TO_LOOKUP_IDX(MPT_ADAPTER *ioc, struct scsi_cmnd *sc)
+{
+       unsigned long   flags;
+       int i, index=-1;
+
+       spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
+       for (i = 0; i < ioc->req_depth; i++) {
+               if (ioc->ScsiLookup[i] == sc) {
+                       index = i;
+                       goto out;
                }
        }
 
-       return -1;
+ out:
+       spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
+       return index;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -2508,24 +2634,23 @@ mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
 {
        MPT_SCSI_HOST   *hd;
        unsigned long    flags;
-       int             ii;
 
-       dtmprintk((KERN_WARNING MYNAM
-                       ": IOC %s_reset routed to SCSI host driver!\n",
-                       reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
-                       reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+           ": IOC %s_reset routed to SCSI host driver!\n",
+           ioc->name, reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
+           reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
 
        /* If a FW reload request arrives after base installed but
         * before all scsi hosts have been attached, then an alt_ioc
         * may have a NULL sh pointer.
         */
-       if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL))
+       if (ioc->sh == NULL || shost_priv(ioc->sh) == NULL)
                return 0;
        else
-               hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
+               hd = shost_priv(ioc->sh);
 
        if (reset_phase == MPT_IOC_SETUP_RESET) {
-               dtmprintk((MYIOC_s_WARN_FMT "Setup-Diag Reset\n", ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Setup-Diag Reset\n", ioc->name));
 
                /* Clean Up:
                 * 1. Set Hard Reset Pending Flag
@@ -2534,7 +2659,7 @@ mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
                hd->resetPending = 1;
 
        } else if (reset_phase == MPT_IOC_PRE_RESET) {
-               dtmprintk((MYIOC_s_WARN_FMT "Pre-Diag Reset\n", ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Pre-Diag Reset\n", ioc->name));
 
                /* 2. Flush running commands
                 *      Clean ScsiLookup (and associated memory)
@@ -2554,21 +2679,16 @@ mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
                        mpt_free_msg_frame(ioc, hd->cmdPtr);
                }
 
-               dtmprintk((MYIOC_s_WARN_FMT "Pre-Reset complete.\n", ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Pre-Reset complete.\n", ioc->name));
 
        } else {
-               dtmprintk((MYIOC_s_WARN_FMT "Post-Diag Reset\n", ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Post-Diag Reset\n", ioc->name));
 
                /* Once a FW reload begins, all new OS commands are
                 * redirected to the doneQ w/ a reset status.
                 * Init all control structures.
                 */
 
-               /* ScsiLookup initialization
-                */
-               for (ii=0; ii < hd->ioc->req_depth; ii++)
-                       hd->ScsiLookup[ii] = NULL;
-
                /* 2. Chain Buffer initialization
                 */
 
@@ -2597,7 +2717,7 @@ mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
                        hd->cmdPtr = NULL;
                }
 
-               dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Post-Reset complete.\n", ioc->name));
 
        }
 
@@ -2611,11 +2731,11 @@ mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
        MPT_SCSI_HOST *hd;
        u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
 
-       devtverboseprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
+       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
                        ioc->name, event));
 
        if (ioc->sh == NULL ||
-               ((hd = (MPT_SCSI_HOST *)ioc->sh->hostdata) == NULL))
+               ((hd = shost_priv(ioc->sh)) == NULL))
                return 1;
 
        switch (event) {
@@ -2653,7 +2773,8 @@ mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
        case MPI_EVENT_STATE_CHANGE:                    /* 02 */
        case MPI_EVENT_EVENT_CHANGE:                    /* 0A */
        default:
-               dprintk((KERN_INFO "  Ignoring event (=%02Xh)\n", event));
+               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": Ignoring event (=%02Xh)\n",
+                   ioc->name, event));
                break;
        }
 
@@ -2693,7 +2814,7 @@ mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
        int              completionCode;
        u16              req_idx;
 
-       hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
+       hd = shost_priv(ioc->sh);
 
        if ((mf == NULL) ||
            (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
@@ -2705,17 +2826,17 @@ mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 
        del_timer(&hd->timer);
        req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
-       hd->ScsiLookup[req_idx] = NULL;
+       mptscsih_set_scsi_lookup(ioc, req_idx, NULL);
        pReq = (SCSIIORequest_t *) mf;
 
        if (mf != hd->cmdPtr) {
                printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
-                               hd->ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
+                               ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
        }
        hd->cmdPtr = NULL;
 
-       ddvprintk((MYIOC_s_INFO_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
-                       hd->ioc->name, mf, mr, req_idx));
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
+                       ioc->name, mf, mr, req_idx));
 
        hd->pLocal = &hd->localReply;
        hd->pLocal->scsiStatus = 0;
@@ -2734,9 +2855,6 @@ mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
                scsi_status = pReply->SCSIStatus;
 
-               ddvtprintk((KERN_NOTICE "  IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
-                            status, pReply->SCSIState, scsi_status,
-                            le32_to_cpu(pReply->IOCLogInfo)));
 
                switch(status) {
 
@@ -2782,15 +2900,15 @@ mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
                                 */
                                completionCode = MPT_SCANDV_SENSE;
                                hd->pLocal->scsiStatus = scsi_status;
-                               sense_data = ((u8 *)hd->ioc->sense_buf_pool +
+                               sense_data = ((u8 *)ioc->sense_buf_pool +
                                        (req_idx * MPT_SENSE_BUFFER_ALLOC));
 
                                sz = min_t(int, pReq->SenseBufferLength,
                                                        SCSI_STD_SENSE_BYTES);
                                memcpy(hd->pLocal->sense, sense_data, sz);
 
-                               ddvprintk((KERN_NOTICE "  Check Condition, sense ptr %p\n",
-                                               sense_data));
+                               ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "  Check Condition, sense ptr %p\n",
+                                   ioc->name, sense_data));
                        } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
                                if (pReq->CDB[0] == INQUIRY)
                                        completionCode = MPT_SCANDV_ISSUE_SENSE;
@@ -2820,8 +2938,6 @@ mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 
                }       /* switch(status) */
 
-               ddvtprintk((KERN_NOTICE "  completionCode set to %08xh\n",
-                               completionCode));
        } /* end of address reply case */
 
        hd->pLocal->completion = completionCode;
@@ -2851,8 +2967,9 @@ void
 mptscsih_timer_expired(unsigned long data)
 {
        MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
+       MPT_ADAPTER     *ioc = hd->ioc;
 
-       ddvprintk((MYIOC_s_WARN_FMT "Timer Expired! Cmd %p\n", hd->ioc->name, hd->cmdPtr));
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Timer Expired! Cmd %p\n", ioc->name, hd->cmdPtr));
 
        if (hd->cmdPtr) {
                MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
@@ -2864,16 +2981,15 @@ mptscsih_timer_expired(unsigned long data)
                         * If new eh code, do nothing. Wait for OS cmd timeout
                         *      for bus reset.
                         */
-                       ddvtprintk((MYIOC_s_NOTE_FMT "DV Cmd Timeout: NoOp\n", hd->ioc->name));
                } else {
                        /* Perform a FW reload */
-                       if (mpt_HardResetHandler(hd->ioc, NO_SLEEP) < 0) {
-                               printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", hd->ioc->name);
+                       if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
+                               printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
                        }
                }
        } else {
                /* This should NEVER happen */
-               printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", hd->ioc->name);
+               printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", ioc->name);
        }
 
        /* No more processing.
@@ -2881,7 +2997,7 @@ mptscsih_timer_expired(unsigned long data)
         * The FW will reply to all outstanding commands, callback will finish cleanup.
         * Hard reset clean-up will free all resources.
         */
-       ddvprintk((MYIOC_s_WARN_FMT "Timer Expired Complete!\n", hd->ioc->name));
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Timer Expired Complete!\n", ioc->name));
 
        return;
 }
@@ -2919,11 +3035,12 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
        char             cmdLen;
        char             CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        char             cmd = io->cmd;
+       MPT_ADAPTER     *ioc = hd->ioc;
 
        in_isr = in_interrupt();
        if (in_isr) {
-               dprintk((MYIOC_s_WARN_FMT "Internal SCSI IO request not allowed in ISR context!\n",
-                                       hd->ioc->name));
+               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Internal SCSI IO request not allowed in ISR context!\n",
+                                       ioc->name));
                return -EPERM;
        }
 
@@ -3024,9 +3141,9 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
 
        /* Get and Populate a free Frame
         */
-       if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
-               ddvprintk((MYIOC_s_WARN_FMT "No msg frames!\n",
-                                       hd->ioc->name));
+       if ((mf = mpt_get_msg_frame(ioc->InternalCtx, ioc)) == NULL) {
+               dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "No msg frames!\n",
+                   ioc->name));
                return -EBUSY;
        }
 
@@ -3065,19 +3182,19 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
 
        if (cmd == REQUEST_SENSE) {
                pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
-               ddvprintk((MYIOC_s_INFO_FMT "Untagged! 0x%2x\n",
-                       hd->ioc->name, cmd));
+               ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Untagged! 0x%2x\n",
+                       ioc->name, cmd));
        }
 
        for (ii=0; ii < 16; ii++)
                pScsiReq->CDB[ii] = CDB[ii];
 
        pScsiReq->DataLength = cpu_to_le32(io->size);
-       pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
+       pScsiReq->SenseBufferLowAddr = cpu_to_le32(ioc->sense_buf_low_dma
                                           + (my_idx * MPT_SENSE_BUFFER_ALLOC));
 
-       ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
-                       hd->ioc->name, cmd, io->channel, io->id, io->lun));
+       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
+                       ioc->name, cmd, io->channel, io->id, io->lun));
 
        if (dir == MPI_SCSIIO_CONTROL_READ) {
                mpt_add_sge((char *) &pScsiReq->SGL,
@@ -3112,7 +3229,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
        hd->cmdPtr = mf;
 
        add_timer(&hd->timer);
-       mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
+       mpt_put_msg_frame(ioc->InternalCtx, ioc, mf);
        wait_event(hd->scandv_waitq, hd->scandv_wait_done);
 
        if (hd->pLocal) {
@@ -3128,8 +3245,8 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
        } else {
                rc = -EFAULT;
                /* This should never happen. */
-               ddvprintk((MYIOC_s_INFO_FMT "_do_cmd: Null pLocal!!!\n",
-                               hd->ioc->name));
+               ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT "_do_cmd: Null pLocal!!!\n",
+                               ioc->name));
        }
 
        return rc;
@@ -3150,6 +3267,16 @@ mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
 {
        INTERNAL_CMD             iocmd;
 
+       /* Ignore hidden raid components, this is handled when the command
+        * is sent to the volume
+        */
+       if (vdevice->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
+               return;
+
+       if (vdevice->vtarget->type != TYPE_DISK || vdevice->vtarget->deleted ||
+           !vdevice->configured_lun)
+               return;
+
        /* Following parameters will not change
         * in this routine.
         */
@@ -3164,10 +3291,191 @@ mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
        iocmd.id = vdevice->vtarget->id;
        iocmd.lun = vdevice->lun;
 
-       if ((vdevice->vtarget->type == TYPE_DISK) &&
-           (vdevice->configured_lun))
-               mptscsih_do_cmd(hd, &iocmd);
+       mptscsih_do_cmd(hd, &iocmd);
+}
+
+static ssize_t
+mptscsih_version_fw_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%02d.%02d.%02d.%02d\n",
+           (ioc->facts.FWVersion.Word & 0xFF000000) >> 24,
+           (ioc->facts.FWVersion.Word & 0x00FF0000) >> 16,
+           (ioc->facts.FWVersion.Word & 0x0000FF00) >> 8,
+           ioc->facts.FWVersion.Word & 0x000000FF);
+}
+static CLASS_DEVICE_ATTR(version_fw, S_IRUGO, mptscsih_version_fw_show, NULL);
+
+static ssize_t
+mptscsih_version_bios_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x\n",
+           (ioc->biosVersion & 0xFF000000) >> 24,
+           (ioc->biosVersion & 0x00FF0000) >> 16,
+           (ioc->biosVersion & 0x0000FF00) >> 8,
+           ioc->biosVersion & 0x000000FF);
+}
+static CLASS_DEVICE_ATTR(version_bios, S_IRUGO, mptscsih_version_bios_show, NULL);
+
+static ssize_t
+mptscsih_version_mpi_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%03x\n", ioc->facts.MsgVersion);
+}
+static CLASS_DEVICE_ATTR(version_mpi, S_IRUGO, mptscsih_version_mpi_show, NULL);
+
+static ssize_t
+mptscsih_version_product_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", ioc->prod_name);
+}
+static CLASS_DEVICE_ATTR(version_product, S_IRUGO,
+    mptscsih_version_product_show, NULL);
+
+static ssize_t
+mptscsih_version_nvdata_persistent_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%02xh\n",
+           ioc->nvdata_version_persistent);
+}
+static CLASS_DEVICE_ATTR(version_nvdata_persistent, S_IRUGO,
+    mptscsih_version_nvdata_persistent_show, NULL);
+
+static ssize_t
+mptscsih_version_nvdata_default_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%02xh\n",ioc->nvdata_version_default);
+}
+static CLASS_DEVICE_ATTR(version_nvdata_default, S_IRUGO,
+    mptscsih_version_nvdata_default_show, NULL);
+
+static ssize_t
+mptscsih_board_name_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_name);
+}
+static CLASS_DEVICE_ATTR(board_name, S_IRUGO, mptscsih_board_name_show, NULL);
+
+static ssize_t
+mptscsih_board_assembly_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_assembly);
+}
+static CLASS_DEVICE_ATTR(board_assembly, S_IRUGO,
+    mptscsih_board_assembly_show, NULL);
+
+static ssize_t
+mptscsih_board_tracer_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%s\n", ioc->board_tracer);
+}
+static CLASS_DEVICE_ATTR(board_tracer, S_IRUGO,
+    mptscsih_board_tracer_show, NULL);
+
+static ssize_t
+mptscsih_io_delay_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->io_missing_delay);
 }
+static CLASS_DEVICE_ATTR(io_delay, S_IRUGO,
+    mptscsih_io_delay_show, NULL);
+
+static ssize_t
+mptscsih_device_delay_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%02d\n", ioc->device_missing_delay);
+}
+static CLASS_DEVICE_ATTR(device_delay, S_IRUGO,
+    mptscsih_device_delay_show, NULL);
+
+static ssize_t
+mptscsih_debug_level_show(struct class_device *cdev, char *buf)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+
+       return snprintf(buf, PAGE_SIZE, "%08xh\n", ioc->debug_level);
+}
+static ssize_t
+mptscsih_debug_level_store(struct class_device *cdev, const char *buf,
+                                                               size_t count)
+{
+       struct Scsi_Host *host = class_to_shost(cdev);
+       MPT_SCSI_HOST   *hd = shost_priv(host);
+       MPT_ADAPTER *ioc = hd->ioc;
+       int val = 0;
+
+       if (sscanf(buf, "%x", &val) != 1)
+               return -EINVAL;
+
+       ioc->debug_level = val;
+       printk(MYIOC_s_INFO_FMT "debug_level=%08xh\n",
+                               ioc->name, ioc->debug_level);
+       return strlen(buf);
+}
+static CLASS_DEVICE_ATTR(debug_level, S_IRUGO | S_IWUSR,
+    mptscsih_debug_level_show, mptscsih_debug_level_store);
+
+struct class_device_attribute *mptscsih_host_attrs[] = {
+       &class_device_attr_version_fw,
+       &class_device_attr_version_bios,
+       &class_device_attr_version_mpi,
+       &class_device_attr_version_product,
+       &class_device_attr_version_nvdata_persistent,
+       &class_device_attr_version_nvdata_default,
+       &class_device_attr_board_name,
+       &class_device_attr_board_assembly,
+       &class_device_attr_board_tracer,
+       &class_device_attr_io_delay,
+       &class_device_attr_device_delay,
+       &class_device_attr_debug_level,
+       NULL,
+};
+EXPORT_SYMBOL(mptscsih_host_attrs);
 
 EXPORT_SYMBOL(mptscsih_remove);
 EXPORT_SYMBOL(mptscsih_shutdown);