tree-wide: fix comment/printk typos
[linux-flexiantxendom0-natty.git] / drivers / message / fusion / mptbase.c
index e866dac..3358c0a 100644 (file)
@@ -2,10 +2,10 @@
  *  linux/drivers/message/fusion/mptbase.c
  *      This is the Fusion MPT base driver which supports multiple
  *      (SCSI + LAN) specialized protocol drivers.
- *      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
+ *  Copyright (c) 1999-2008 LSI Corporation
  *  (mailto:DL-MPTFusionLinux@lsi.com)
  *
  */
@@ -50,6 +50,7 @@
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/init.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/pci.h>
@@ -79,17 +80,42 @@ MODULE_VERSION(my_VERSION);
 /*
  *  cmd line parameters
  */
-static int mpt_msi_enable;
-module_param(mpt_msi_enable, int, 0);
-MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
+
+static int mpt_msi_enable_spi;
+module_param(mpt_msi_enable_spi, int, 0);
+MODULE_PARM_DESC(mpt_msi_enable_spi, " Enable MSI Support for SPI \
+               controllers (default=0)");
+
+static int mpt_msi_enable_fc;
+module_param(mpt_msi_enable_fc, int, 0);
+MODULE_PARM_DESC(mpt_msi_enable_fc, " Enable MSI Support for FC \
+               controllers (default=0)");
+
+static int mpt_msi_enable_sas;
+module_param(mpt_msi_enable_sas, int, 0);
+MODULE_PARM_DESC(mpt_msi_enable_sas, " Enable MSI Support for SAS \
+               controllers (default=0)");
+
 
 static int mpt_channel_mapping;
 module_param(mpt_channel_mapping, int, 0);
 MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
 
 static int mpt_debug_level;
-module_param(mpt_debug_level, int, 0);
-MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h - (default=0)");
+static int mpt_set_debug_level(const char *val, struct kernel_param *kp);
+module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
+                 &mpt_debug_level, 0600);
+MODULE_PARM_DESC(mpt_debug_level, " debug level - refer to mptdebug.h \
+       - (default=0)");
+
+int mpt_fwfault_debug;
+EXPORT_SYMBOL(mpt_fwfault_debug);
+module_param(mpt_fwfault_debug, int, 0600);
+MODULE_PARM_DESC(mpt_fwfault_debug, "Enable detection of Firmware fault"
+       " and halt Firmware on fault - (default=0)");
+
+
+static char    MptCallbacksName[MPT_MAX_PROTOCOL_DRIVERS][50];
 
 #ifdef MFCNT
 static int mfcounter = 0;
@@ -100,10 +126,6 @@ static int mfcounter = 0;
 /*
  *  Public data...
  */
-int mpt_lan_index = -1;
-int mpt_stm_index = -1;
-
-struct proc_dir_entry *mpt_proc_root_dir;
 
 #define WHOINIT_UNKNOWN                0xAA
 
@@ -123,17 +145,23 @@ static MPT_EVHANDLER               MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
 static MPT_RESETHANDLER                 MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
 static struct mpt_pci_driver   *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
 
-static int     mpt_base_index = -1;
-static int     last_drv_idx = -1;
+#ifdef CONFIG_PROC_FS
+static struct proc_dir_entry   *mpt_proc_root_dir;
+#endif
 
-static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
+/*
+ *  Driver Callback Index's
+ */
+static u8 mpt_base_index = MPT_MAX_PROTOCOL_DRIVERS;
+static u8 last_drv_idx;
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /*
  *  Forward protos...
  */
 static irqreturn_t mpt_interrupt(int irq, void *bus_id);
-static int     mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
+static int     mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
+               MPT_FRAME_HDR *reply);
 static int     mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
                        u32 *req, int replyBytes, u16 *u16reply, int maxwait,
                        int sleepFlag);
@@ -164,29 +192,26 @@ static int        mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
 static int     mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
 static void    mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
 static void    mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
-static void    mpt_timer_expired(unsigned long data);
 static void    mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
-static int     SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
+static int     SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch,
+       int sleepFlag);
 static int     SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
 static int     mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
 static int     mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
 
 #ifdef CONFIG_PROC_FS
-static int     procmpt_summary_read(char *buf, char **start, off_t offset,
-                               int request, int *eof, void *data);
-static int     procmpt_version_read(char *buf, char **start, off_t offset,
-                               int request, int *eof, void *data);
-static int     procmpt_iocinfo_read(char *buf, char **start, off_t offset,
-                               int request, int *eof, void *data);
+static const struct file_operations mpt_summary_proc_fops;
+static const struct file_operations mpt_version_proc_fops;
+static const struct file_operations mpt_iocinfo_proc_fops;
 #endif
 static void    mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
 
-//int          mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
-static int     ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
+static int     ProcessEventNotification(MPT_ADAPTER *ioc,
+               EventNotificationReply_t *evReply, int *evHandlers);
 static void    mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
 static void    mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
 static void    mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
-static void    mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info);
+static void    mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info , u8 cb_idx);
 static int     mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
 static void    mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
 
@@ -220,6 +245,141 @@ pci_enable_io_access(struct pci_dev *pdev)
        pci_write_config_word(pdev, PCI_COMMAND, command_reg);
 }
 
+static int mpt_set_debug_level(const char *val, struct kernel_param *kp)
+{
+       int ret = param_set_int(val, kp);
+       MPT_ADAPTER *ioc;
+
+       if (ret)
+               return ret;
+
+       list_for_each_entry(ioc, &ioc_list, list)
+               ioc->debug_level = mpt_debug_level;
+       return 0;
+}
+
+/**
+ *     mpt_get_cb_idx - obtain cb_idx for registered driver
+ *     @dclass: class driver enum
+ *
+ *     Returns cb_idx, or zero means it wasn't found
+ **/
+static u8
+mpt_get_cb_idx(MPT_DRIVER_CLASS dclass)
+{
+       u8 cb_idx;
+
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--)
+               if (MptDriverClass[cb_idx] == dclass)
+                       return cb_idx;
+       return 0;
+}
+
+/**
+ * mpt_is_discovery_complete - determine if discovery has completed
+ * @ioc: per adatper instance
+ *
+ * Returns 1 when discovery completed, else zero.
+ */
+static int
+mpt_is_discovery_complete(MPT_ADAPTER *ioc)
+{
+       ConfigExtendedPageHeader_t hdr;
+       CONFIGPARMS cfg;
+       SasIOUnitPage0_t *buffer;
+       dma_addr_t dma_handle;
+       int rc = 0;
+
+       memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
+       memset(&cfg, 0, sizeof(CONFIGPARMS));
+       hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
+       hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
+       hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
+       cfg.cfghdr.ehdr = &hdr;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
+
+       if ((mpt_config(ioc, &cfg)))
+               goto out;
+       if (!hdr.ExtPageLength)
+               goto out;
+
+       buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
+           &dma_handle);
+       if (!buffer)
+               goto out;
+
+       cfg.physAddr = dma_handle;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+
+       if ((mpt_config(ioc, &cfg)))
+               goto out_free_consistent;
+
+       if (!(buffer->PhyData[0].PortFlags &
+           MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS))
+               rc = 1;
+
+ out_free_consistent:
+       pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
+           buffer, dma_handle);
+ out:
+       return rc;
+}
+
+/**
+ *     mpt_fault_reset_work - work performed on workq after ioc fault
+ *     @work: input argument, used to derive ioc
+ *
+**/
+static void
+mpt_fault_reset_work(struct work_struct *work)
+{
+       MPT_ADAPTER     *ioc =
+           container_of(work, MPT_ADAPTER, fault_reset_work.work);
+       u32              ioc_raw_state;
+       int              rc;
+       unsigned long    flags;
+
+       if (ioc->ioc_reset_in_progress || !ioc->active)
+               goto out;
+
+       ioc_raw_state = mpt_GetIocState(ioc, 0);
+       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
+               printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
+                      ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
+               printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
+                      ioc->name, __func__);
+               rc = mpt_HardResetHandler(ioc, CAN_SLEEP);
+               printk(MYIOC_s_WARN_FMT "%s: HardReset: %s\n", ioc->name,
+                      __func__, (rc == 0) ? "success" : "failed");
+               ioc_raw_state = mpt_GetIocState(ioc, 0);
+               if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT)
+                       printk(MYIOC_s_WARN_FMT "IOC is in FAULT state after "
+                           "reset (%04xh)\n", ioc->name, ioc_raw_state &
+                           MPI_DOORBELL_DATA_MASK);
+       } else if (ioc->bus_type == SAS && ioc->sas_discovery_quiesce_io) {
+               if ((mpt_is_discovery_complete(ioc))) {
+                       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "clearing "
+                           "discovery_quiesce_io flag\n", ioc->name));
+                       ioc->sas_discovery_quiesce_io = 0;
+               }
+       }
+
+ out:
+       /*
+        * Take turns polling alternate controller
+        */
+       if (ioc->alt_ioc)
+               ioc = ioc->alt_ioc;
+
+       /* rearm the timer */
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->reset_work_q)
+               queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
+                       msecs_to_jiffies(MPT_POLLING_INTERVAL));
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+}
+
+
 /*
  *  Process turbo (context) reply...
  */
@@ -228,8 +388,8 @@ mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
 {
        MPT_FRAME_HDR *mf = NULL;
        MPT_FRAME_HDR *mr = NULL;
-       int req_idx = 0;
-       int cb_idx;
+       u16 req_idx = 0;
+       u8 cb_idx;
 
        dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got TURBO reply req_idx=%08x\n",
                                ioc->name, pa));
@@ -241,7 +401,7 @@ mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
                mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
                break;
        case MPI_CONTEXT_REPLY_TYPE_LAN:
-               cb_idx = mpt_lan_index;
+               cb_idx = mpt_get_cb_idx(MPTLAN_DRIVER);
                /*
                 *  Blind set of mf to NULL here was fatal
                 *  after lan_reply says "freeme"
@@ -262,7 +422,7 @@ mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
                mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
                break;
        case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
-               cb_idx = mpt_stm_index;
+               cb_idx = mpt_get_cb_idx(MPTSTM_DRIVER);
                mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
                break;
        default:
@@ -271,10 +431,10 @@ mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
        }
 
        /*  Check for (valid) IO callback!  */
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
-                       MptCallbacks[cb_idx] == NULL) {
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
+               MptCallbacks[cb_idx] == NULL) {
                printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
-                               __FUNCTION__, ioc->name, cb_idx);
+                               __func__, ioc->name, cb_idx);
                goto out;
        }
 
@@ -289,8 +449,8 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
 {
        MPT_FRAME_HDR   *mf;
        MPT_FRAME_HDR   *mr;
-       int              req_idx;
-       int              cb_idx;
+       u16              req_idx;
+       u8               cb_idx;
        int              freeme;
 
        u32 reply_dma_low;
@@ -316,7 +476,7 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
 
        dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
                        ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
-       DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr)
+       DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr);
 
         /*  Check/log IOC log info
         */
@@ -328,17 +488,17 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
                else if (ioc->bus_type == SPI)
                        mpt_spi_log_info(ioc, log_info);
                else if (ioc->bus_type == SAS)
-                       mpt_sas_log_info(ioc, log_info);
+                       mpt_sas_log_info(ioc, log_info, cb_idx);
        }
 
        if (ioc_stat & MPI_IOCSTATUS_MASK)
                mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
 
        /*  Check for (valid) IO callback!  */
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
-                       MptCallbacks[cb_idx] == NULL) {
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
+               MptCallbacks[cb_idx] == NULL) {
                printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
-                               __FUNCTION__, ioc->name, cb_idx);
+                               __func__, ioc->name, cb_idx);
                freeme = 0;
                goto out;
        }
@@ -396,9 +556,9 @@ mpt_interrupt(int irq, void *bus_id)
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
- *     mpt_base_reply - MPT base driver's callback routine
+ *     mptbase_reply - MPT base driver's callback routine
  *     @ioc: Pointer to MPT_ADAPTER structure
- *     @mf: Pointer to original MPT request frame
+ *     @req: Pointer to original MPT request frame
  *     @reply: Pointer to MPT reply frame (NULL if TurboReply)
  *
  *     MPT base driver's callback routine; all base driver
@@ -409,121 +569,49 @@ mpt_interrupt(int irq, void *bus_id)
  *     should be freed, or 0 if it shouldn't.
  */
 static int
-mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
+mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
 {
+       EventNotificationReply_t *pEventReply;
+       u8 event;
+       int evHandlers;
        int freereq = 1;
-       u8 func;
-
-       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply() called\n", ioc->name));
-#ifdef CONFIG_FUSION_LOGGING
-       if ((ioc->debug_level & MPT_DEBUG_MSG_FRAME) &&
-                       !(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
-               dmfprintk(ioc, printk(KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
-               DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)mf)
-       }
-#endif
-
-       func = reply->u.hdr.Function;
-       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply, Function=%02Xh\n",
-                       ioc->name, func));
-
-       if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
-               EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
-               int evHandlers = 0;
-               int results;
-
-               results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
-               if (results != evHandlers) {
-                       /* CHECKME! Any special handling needed here? */
-                       devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
-                                       ioc->name, evHandlers, results));
-               }
 
-               /*
-                *      Hmmm...  It seems that EventNotificationReply is an exception
-                *      to the rule of one reply per request.
-                */
-               if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
+       switch (reply->u.hdr.Function) {
+       case MPI_FUNCTION_EVENT_NOTIFICATION:
+               pEventReply = (EventNotificationReply_t *)reply;
+               evHandlers = 0;
+               ProcessEventNotification(ioc, pEventReply, &evHandlers);
+               event = le32_to_cpu(pEventReply->Event) & 0xFF;
+               if (pEventReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
                        freereq = 0;
-               } else {
-                       devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
-                               ioc->name, pEvReply));
-               }
-
-#ifdef CONFIG_PROC_FS
-//             LogEvent(ioc, pEvReply);
-#endif
-
-       } else if (func == MPI_FUNCTION_EVENT_ACK) {
-               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_base_reply, EventAck reply received\n",
-                               ioc->name));
-       } else if (func == MPI_FUNCTION_CONFIG) {
-               CONFIGPARMS *pCfg;
-               unsigned long flags;
-
-               dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "config_complete (mf=%p,mr=%p)\n",
-                               ioc->name, mf, reply));
-
-               pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
-
-               if (pCfg) {
-                       /* disable timer and remove from linked list */
-                       del_timer(&pCfg->timer);
-
-                       spin_lock_irqsave(&ioc->FreeQlock, flags);
-                       list_del(&pCfg->linkage);
-                       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
-
-                       /*
-                        *      If IOC Status is SUCCESS, save the header
-                        *      and set the status code to GOOD.
-                        */
-                       pCfg->status = MPT_CONFIG_ERROR;
-                       if (reply) {
-                               ConfigReply_t   *pReply = (ConfigReply_t *)reply;
-                               u16              status;
-
-                               status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
-                               dcprintk(ioc, printk(KERN_NOTICE "  IOCStatus=%04xh, IOCLogInfo=%08xh\n",
-                                    status, le32_to_cpu(pReply->IOCLogInfo)));
-
-                               pCfg->status = status;
-                               if (status == MPI_IOCSTATUS_SUCCESS) {
-                                       if ((pReply->Header.PageType &
-                                           MPI_CONFIG_PAGETYPE_MASK) ==
-                                           MPI_CONFIG_PAGETYPE_EXTENDED) {
-                                               pCfg->cfghdr.ehdr->ExtPageLength =
-                                                   le16_to_cpu(pReply->ExtPageLength);
-                                               pCfg->cfghdr.ehdr->ExtPageType =
-                                                   pReply->ExtPageType;
-                                       }
-                                       pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
-
-                                       /* If this is a regular header, save PageLength. */
-                                       /* LMP Do this better so not using a reserved field! */
-                                       pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
-                                       pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
-                                       pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
-                               }
-                       }
-
-                       /*
-                        *      Wake up the original calling thread
-                        */
-                       pCfg->wait_done = 1;
-                       wake_up(&mpt_waitq);
+               if (event != MPI_EVENT_EVENT_CHANGE)
+                       break;
+       case MPI_FUNCTION_CONFIG:
+       case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
+               ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
+               if (reply) {
+                       ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
+                       memcpy(ioc->mptbase_cmds.reply, reply,
+                           min(MPT_DEFAULT_FRAME_SIZE,
+                               4 * reply->u.reply.MsgLength));
                }
-       } else if (func == MPI_FUNCTION_SAS_IO_UNIT_CONTROL) {
-               /* we should be always getting a reply frame */
-               memcpy(ioc->persist_reply_frame, reply,
-                   min(MPT_DEFAULT_FRAME_SIZE,
-                   4*reply->u.reply.MsgLength));
-               del_timer(&ioc->persist_timer);
-               ioc->persist_wait_done = 1;
-               wake_up(&mpt_waitq);
-       } else {
-               printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
-                               ioc->name, func);
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
+                       ioc->mptbase_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
+                       complete(&ioc->mptbase_cmds.done);
+               } else
+                       freereq = 0;
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_FREE_MF)
+                       freereq = 1;
+               break;
+       case MPI_FUNCTION_EVENT_ACK:
+               devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "EventAck reply received\n", ioc->name));
+               break;
+       default:
+               printk(MYIOC_s_ERR_FMT
+                   "Unexpected msg function (=%02Xh) reply received!\n",
+                   ioc->name, reply->u.hdr.Function);
+               break;
        }
 
        /*
@@ -538,6 +626,7 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
  *     mpt_register - Register protocol-specific main callback handler.
  *     @cbfunc: callback function pointer
  *     @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
+ *     @func_name: call function's name
  *
  *     This routine is called by a protocol-specific driver (SCSI host,
  *     LAN, SCSI target) to register its reply callback routine.  Each
@@ -548,28 +637,29 @@ mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
  *     in order to register separate callbacks; one for "normal" SCSI IO;
  *     one for MptScsiTaskMgmt requests; one for Scan/DV requests.
  *
- *     Returns a positive integer valued "handle" in the
- *     range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
- *     Any non-positive return value (including zero!) should be considered
- *     an error by the caller.
+ *     Returns u8 valued "handle" in the range (and S.O.D. order)
+ *     {N,...,7,6,5,...,1} if successful.
+ *     A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
+ *     considered an error by the caller.
  */
-int
-mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
+u8
+mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass, char *func_name)
 {
-       int i;
-
-       last_drv_idx = -1;
+       u8 cb_idx;
+       last_drv_idx = MPT_MAX_PROTOCOL_DRIVERS;
 
        /*
         *  Search for empty callback slot in this order: {N,...,7,6,5,...,1}
         *  (slot/handle 0 is reserved!)
         */
-       for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
-               if (MptCallbacks[i] == NULL) {
-                       MptCallbacks[i] = cbfunc;
-                       MptDriverClass[i] = dclass;
-                       MptEvHandlers[i] = NULL;
-                       last_drv_idx = i;
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptCallbacks[cb_idx] == NULL) {
+                       MptCallbacks[cb_idx] = cbfunc;
+                       MptDriverClass[cb_idx] = dclass;
+                       MptEvHandlers[cb_idx] = NULL;
+                       last_drv_idx = cb_idx;
+                       memcpy(MptCallbacksName[cb_idx], func_name,
+                           strlen(func_name) > 50 ? 50 : strlen(func_name));
                        break;
                }
        }
@@ -586,9 +676,9 @@ mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
  *     module is unloaded.
  */
 void
-mpt_deregister(int cb_idx)
+mpt_deregister(u8 cb_idx)
 {
-       if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
+       if (cb_idx && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
                MptCallbacks[cb_idx] = NULL;
                MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
                MptEvHandlers[cb_idx] = NULL;
@@ -599,8 +689,7 @@ mpt_deregister(int cb_idx)
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
- *     mpt_event_register - Register protocol-specific event callback
- *     handler.
+ *     mpt_event_register - Register protocol-specific event callback handler.
  *     @cb_idx: previously registered (via mpt_register) callback handle
  *     @ev_cbfunc: callback function
  *
@@ -610,9 +699,9 @@ mpt_deregister(int cb_idx)
  *     Returns 0 for success.
  */
 int
-mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
+mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc)
 {
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
                return -1;
 
        MptEvHandlers[cb_idx] = ev_cbfunc;
@@ -621,8 +710,7 @@ mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
- *     mpt_event_deregister - Deregister protocol-specific event callback
- *     handler.
+ *     mpt_event_deregister - Deregister protocol-specific event callback handler
  *     @cb_idx: previously registered callback handle
  *
  *     Each protocol-specific driver should call this routine
@@ -630,9 +718,9 @@ mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
  *     or when its module is unloaded.
  */
 void
-mpt_event_deregister(int cb_idx)
+mpt_event_deregister(u8 cb_idx)
 {
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
                return;
 
        MptEvHandlers[cb_idx] = NULL;
@@ -650,9 +738,9 @@ mpt_event_deregister(int cb_idx)
  *     Returns 0 for success.
  */
 int
-mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
+mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func)
 {
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
                return -1;
 
        MptResetHandlers[cb_idx] = reset_func;
@@ -669,9 +757,9 @@ mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
  *     or when its module is unloaded.
  */
 void
-mpt_reset_deregister(int cb_idx)
+mpt_reset_deregister(u8 cb_idx)
 {
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
                return;
 
        MptResetHandlers[cb_idx] = NULL;
@@ -684,12 +772,12 @@ mpt_reset_deregister(int cb_idx)
  *     @cb_idx: MPT protocol driver index
  */
 int
-mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
+mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
 {
        MPT_ADAPTER     *ioc;
        const struct pci_device_id *id;
 
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
                return -EINVAL;
 
        MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
@@ -711,12 +799,12 @@ mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
  *     @cb_idx: MPT protocol driver index
  */
 void
-mpt_device_driver_deregister(int cb_idx)
+mpt_device_driver_deregister(u8 cb_idx)
 {
        struct mpt_pci_driver *dd_cbfunc;
        MPT_ADAPTER     *ioc;
 
-       if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
+       if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
                return;
 
        dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
@@ -732,16 +820,18 @@ mpt_device_driver_deregister(int cb_idx)
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
- *     mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
- *     allocated per MPT adapter.
- *     @handle: Handle of registered MPT protocol driver
+ *     mpt_get_msg_frame - Obtain an MPT request frame from the pool
+ *     @cb_idx: Handle of registered MPT protocol driver
  *     @ioc: Pointer to MPT adapter structure
  *
+ *     Obtain an MPT request frame from the pool (of 1024) that are
+ *     allocated per MPT adapter.
+ *
  *     Returns pointer to a MPT request frame or %NULL if none are available
  *     or IOC is not active.
  */
 MPT_FRAME_HDR*
-mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
+mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc)
 {
        MPT_FRAME_HDR *mf;
        unsigned long flags;
@@ -751,7 +841,8 @@ mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
 
 #ifdef MFCNT
        if (!ioc->active)
-               printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
+               printk(MYIOC_s_WARN_FMT "IOC Not Active! mpt_get_msg_frame "
+                   "returning NULL!\n", ioc->name);
 #endif
 
        /* If interrupts are not attached, do not return a request frame */
@@ -766,13 +857,14 @@ mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
                                u.frame.linkage.list);
                list_del(&mf->u.frame.linkage.list);
                mf->u.frame.linkage.arg1 = 0;
-               mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;  /* byte */
+               mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;  /* byte */
                req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
                                                                /* u16! */
                req_idx = req_offset / ioc->req_sz;
                mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
                mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
-               ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
+               /* Default, will be changed if necessary in SG generation */
+               ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame;
 #ifdef MFCNT
                ioc->mfcnt++;
 #endif
@@ -783,37 +875,39 @@ mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
 
 #ifdef MFCNT
        if (mf == NULL)
-               printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
+               printk(MYIOC_s_WARN_FMT "IOC Active. No free Msg Frames! "
+                   "Count 0x%x Max 0x%x\n", ioc->name, ioc->mfcnt,
+                   ioc->req_depth);
        mfcounter++;
        if (mfcounter == PRINT_MF_COUNT)
-               printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
+               printk(MYIOC_s_INFO_FMT "MF Count 0x%x Max 0x%x \n", ioc->name,
+                   ioc->mfcnt, ioc->req_depth);
 #endif
 
-       dmfprintk(ioc, printk(KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
-                       ioc->name, handle, ioc->id, mf));
+       dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_get_msg_frame(%d,%d), got mf=%p\n",
+           ioc->name, cb_idx, ioc->id, mf));
        return mf;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
- *     mpt_put_msg_frame - Send a protocol specific MPT request frame
- *     to a IOC.
- *     @handle: Handle of registered MPT protocol driver
+ *     mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
+ *     @cb_idx: Handle of registered MPT protocol driver
  *     @ioc: Pointer to MPT adapter structure
  *     @mf: Pointer to MPT request frame
  *
- *     This routine posts a MPT request frame to the request post FIFO of a
+ *     This routine posts an MPT request frame to the request post FIFO of a
  *     specific MPT adapter.
  */
 void
-mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
+mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
 {
        u32 mf_dma_addr;
        int req_offset;
        u16      req_idx;       /* Request index */
 
        /* ensure values are reset properly! */
-       mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;          /* byte */
+       mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;          /* byte */
        req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
                                                                /* u16! */
        req_idx = req_offset / ioc->req_sz;
@@ -823,14 +917,49 @@ mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
        DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
 
        mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
-       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
+       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d "
+           "RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx,
+           ioc->RequestNB[req_idx]));
        CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
 }
 
+/**
+ *     mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
+ *     @cb_idx: Handle of registered MPT protocol driver
+ *     @ioc: Pointer to MPT adapter structure
+ *     @mf: Pointer to MPT request frame
+ *
+ *     Send a protocol-specific MPT request frame to an IOC using
+ *     hi-priority request queue.
+ *
+ *     This routine posts an MPT request frame to the request post FIFO of a
+ *     specific MPT adapter.
+ **/
+void
+mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
+{
+       u32 mf_dma_addr;
+       int req_offset;
+       u16      req_idx;       /* Request index */
+
+       /* ensure values are reset properly! */
+       mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
+       req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
+       req_idx = req_offset / ioc->req_sz;
+       mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
+       mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
+
+       DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
+
+       mf_dma_addr = (ioc->req_frames_low_dma + req_offset);
+       dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d\n",
+               ioc->name, mf_dma_addr, req_idx));
+       CHIPREG_WRITE32(&ioc->chip->RequestHiPriFifo, mf_dma_addr);
+}
+
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
  *     mpt_free_msg_frame - Place MPT request frame back on FreeQ.
- *     @handle: Handle of registered MPT protocol driver
  *     @ioc: Pointer to MPT adapter structure
  *     @mf: Pointer to MPT request frame
  *
@@ -844,17 +973,21 @@ mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
 
        /*  Put Request back on FreeQ!  */
        spin_lock_irqsave(&ioc->FreeQlock, flags);
-       mf->u.frame.linkage.arg1 = 0xdeadbeaf; /* signature to know if this mf is freed */
+       if (cpu_to_le32(mf->u.frame.linkage.arg1) == 0xdeadbeaf)
+               goto out;
+       /* signature to know if this mf is freed */
+       mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf);
        list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
 #ifdef MFCNT
        ioc->mfcnt--;
 #endif
+ out:
        spin_unlock_irqrestore(&ioc->FreeQlock, flags);
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
- *     mpt_add_sge - Place a simple SGE at address pAddr.
+ *     mpt_add_sge - Place a simple 32 bit SGE at address pAddr.
  *     @pAddr: virtual address for SGE
  *     @flagslength: SGE flags and data transfer length
  *     @dma_addr: Physical address
@@ -862,29 +995,122 @@ mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  *     This routine places a MPT request frame back on the MPT adapter's
  *     FreeQ.
  */
-void
-mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
+static void
+mpt_add_sge(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
+{
+       SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
+       pSge->FlagsLength = cpu_to_le32(flagslength);
+       pSge->Address = cpu_to_le32(dma_addr);
+}
+
+/**
+ *     mpt_add_sge_64bit - Place a simple 64 bit SGE at address pAddr.
+ *     @pAddr: virtual address for SGE
+ *     @flagslength: SGE flags and data transfer length
+ *     @dma_addr: Physical address
+ *
+ *     This routine places a MPT request frame back on the MPT adapter's
+ *     FreeQ.
+ **/
+static void
+mpt_add_sge_64bit(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
+{
+       SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
+       pSge->Address.Low = cpu_to_le32
+                       (lower_32_bits(dma_addr));
+       pSge->Address.High = cpu_to_le32
+                       (upper_32_bits(dma_addr));
+       pSge->FlagsLength = cpu_to_le32
+                       ((flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
+}
+
+/**
+ *     mpt_add_sge_64bit_1078 - Place a simple 64 bit SGE at address pAddr (1078 workaround).
+ *     @pAddr: virtual address for SGE
+ *     @flagslength: SGE flags and data transfer length
+ *     @dma_addr: Physical address
+ *
+ *     This routine places a MPT request frame back on the MPT adapter's
+ *     FreeQ.
+ **/
+static void
+mpt_add_sge_64bit_1078(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
+{
+       SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
+       u32 tmp;
+
+       pSge->Address.Low = cpu_to_le32
+                       (lower_32_bits(dma_addr));
+       tmp = (u32)(upper_32_bits(dma_addr));
+
+       /*
+        * 1078 errata workaround for the 36GB limitation
+        */
+       if ((((u64)dma_addr + MPI_SGE_LENGTH(flagslength)) >> 32)  == 9) {
+               flagslength |=
+                   MPI_SGE_SET_FLAGS(MPI_SGE_FLAGS_LOCAL_ADDRESS);
+               tmp |= (1<<31);
+               if (mpt_debug_level & MPT_DEBUG_36GB_MEM)
+                       printk(KERN_DEBUG "1078 P0M2 addressing for "
+                           "addr = 0x%llx len = %d\n",
+                           (unsigned long long)dma_addr,
+                           MPI_SGE_LENGTH(flagslength));
+       }
+
+       pSge->Address.High = cpu_to_le32(tmp);
+       pSge->FlagsLength = cpu_to_le32(
+               (flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
+}
+
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/**
+ *     mpt_add_chain - Place a 32 bit chain SGE at address pAddr.
+ *     @pAddr: virtual address for SGE
+ *     @next: nextChainOffset value (u32's)
+ *     @length: length of next SGL segment
+ *     @dma_addr: Physical address
+ *
+ */
+static void
+mpt_add_chain(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
+{
+               SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
+               pChain->Length = cpu_to_le16(length);
+               pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
+               pChain->NextChainOffset = next;
+               pChain->Address = cpu_to_le32(dma_addr);
+}
+
+/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+/**
+ *     mpt_add_chain_64bit - Place a 64 bit chain SGE at address pAddr.
+ *     @pAddr: virtual address for SGE
+ *     @next: nextChainOffset value (u32's)
+ *     @length: length of next SGL segment
+ *     @dma_addr: Physical address
+ *
+ */
+static void
+mpt_add_chain_64bit(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
 {
-       if (sizeof(dma_addr_t) == sizeof(u64)) {
-               SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
+               SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
                u32 tmp = dma_addr & 0xFFFFFFFF;
 
-               pSge->FlagsLength = cpu_to_le32(flagslength);
-               pSge->Address.Low = cpu_to_le32(tmp);
-               tmp = (u32) ((u64)dma_addr >> 32);
-               pSge->Address.High = cpu_to_le32(tmp);
+               pChain->Length = cpu_to_le16(length);
+               pChain->Flags = (MPI_SGE_FLAGS_CHAIN_ELEMENT |
+                                MPI_SGE_FLAGS_64_BIT_ADDRESSING);
 
-       } else {
-               SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
-               pSge->FlagsLength = cpu_to_le32(flagslength);
-               pSge->Address = cpu_to_le32(dma_addr);
-       }
+               pChain->NextChainOffset = next;
+
+               pChain->Address.Low = cpu_to_le32(tmp);
+               tmp = (u32)(upper_32_bits(dma_addr));
+               pChain->Address.High = cpu_to_le32(tmp);
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
  *     mpt_send_handshake_request - Send MPT request via doorbell handshake method.
- *     @handle: Handle of registered MPT protocol driver
+ *     @cb_idx: Handle of registered MPT protocol driver
  *     @ioc: Pointer to MPT adapter structure
  *     @reqBytes: Size of the request in bytes
  *     @req: Pointer to MPT request frame
@@ -899,7 +1125,7 @@ mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  *     Returns 0 for success, non-zero for failure.
  */
 int
-mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
+mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
 {
        int     r = 0;
        u8      *req_as_bytes;
@@ -919,7 +1145,7 @@ mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req,
        if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
                MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
                mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
-               mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
+               mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
        }
 
        /* Make sure there are no doorbells */
@@ -938,7 +1164,7 @@ mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req,
        if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
                return -5;
 
-       dhsprintk(ioc, printk(KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
+       dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_send_handshake_request start, WaitCnt=%d\n",
                ioc->name, ii));
 
        CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
@@ -1073,15 +1299,11 @@ mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
        psge = (char *)&ioc_init->HostPageBufferSGE;
        flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
            MPI_SGE_FLAGS_SYSTEM_ADDRESS |
-           MPI_SGE_FLAGS_32_BIT_ADDRESSING |
            MPI_SGE_FLAGS_HOST_TO_IOC |
            MPI_SGE_FLAGS_END_OF_BUFFER;
-       if (sizeof(dma_addr_t) == sizeof(u64)) {
-           flags_length |= MPI_SGE_FLAGS_64_BIT_ADDRESSING;
-       }
        flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
        flags_length |= ioc->HostPageBuffer_sz;
-       mpt_add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
+       ioc->add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
        ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
 
 return 0;
@@ -1357,6 +1579,122 @@ mpt_get_product_name(u16 vendor, u16 device, u8 revision, char *prod_name)
                sprintf(prod_name, "%s", product_str);
 }
 
+/**
+ *     mpt_mapresources - map in memory mapped io
+ *     @ioc: Pointer to pointer to IOC adapter
+ *
+ **/
+static int
+mpt_mapresources(MPT_ADAPTER *ioc)
+{
+       u8              __iomem *mem;
+       int              ii;
+       resource_size_t  mem_phys;
+       unsigned long    port;
+       u32              msize;
+       u32              psize;
+       u8               revision;
+       int              r = -ENODEV;
+       struct pci_dev *pdev;
+
+       pdev = ioc->pcidev;
+       ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
+       if (pci_enable_device_mem(pdev)) {
+               printk(MYIOC_s_ERR_FMT "pci_enable_device_mem() "
+                   "failed\n", ioc->name);
+               return r;
+       }
+       if (pci_request_selected_regions(pdev, ioc->bars, "mpt")) {
+               printk(MYIOC_s_ERR_FMT "pci_request_selected_regions() with "
+                   "MEM failed\n", ioc->name);
+               return r;
+       }
+
+       pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
+
+       if (sizeof(dma_addr_t) > 4) {
+               const uint64_t required_mask = dma_get_required_mask
+                   (&pdev->dev);
+               if (required_mask > DMA_BIT_MASK(32)
+                       && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
+                       && !pci_set_consistent_dma_mask(pdev,
+                                                DMA_BIT_MASK(64))) {
+                       ioc->dma_mask = DMA_BIT_MASK(64);
+                       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                               ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
+                               ioc->name));
+               } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
+                       && !pci_set_consistent_dma_mask(pdev,
+                                               DMA_BIT_MASK(32))) {
+                       ioc->dma_mask = DMA_BIT_MASK(32);
+                       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                               ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
+                               ioc->name));
+               } else {
+                       printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
+                           ioc->name, pci_name(pdev));
+                       pci_release_selected_regions(pdev, ioc->bars);
+                       return r;
+               }
+       } else {
+               if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
+                       && !pci_set_consistent_dma_mask(pdev,
+                                               DMA_BIT_MASK(32))) {
+                       ioc->dma_mask = DMA_BIT_MASK(32);
+                       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                               ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
+                               ioc->name));
+               } else {
+                       printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
+                           ioc->name, pci_name(pdev));
+                       pci_release_selected_regions(pdev, ioc->bars);
+                       return r;
+               }
+       }
+
+       mem_phys = msize = 0;
+       port = psize = 0;
+       for (ii = 0; ii < DEVICE_COUNT_RESOURCE; ii++) {
+               if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
+                       if (psize)
+                               continue;
+                       /* Get I/O space! */
+                       port = pci_resource_start(pdev, ii);
+                       psize = pci_resource_len(pdev, ii);
+               } else {
+                       if (msize)
+                               continue;
+                       /* Get memmap */
+                       mem_phys = pci_resource_start(pdev, ii);
+                       msize = pci_resource_len(pdev, ii);
+               }
+       }
+       ioc->mem_size = msize;
+
+       mem = NULL;
+       /* Get logical ptr for PciMem0 space */
+       /*mem = ioremap(mem_phys, msize);*/
+       mem = ioremap(mem_phys, msize);
+       if (mem == NULL) {
+               printk(MYIOC_s_ERR_FMT ": ERROR - Unable to map adapter"
+                       " memory!\n", ioc->name);
+               pci_release_selected_regions(pdev, ioc->bars);
+               return -EINVAL;
+       }
+       ioc->memmap = mem;
+       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "mem = %p, mem_phys = %llx\n",
+           ioc->name, mem, (unsigned long long)mem_phys));
+
+       ioc->mem_phys = mem_phys;
+       ioc->chip = (SYSIF_REGS __iomem *)mem;
+
+       /* Save Port IO values in case we need to do downloadboot */
+       ioc->pio_mem_phys = port;
+       ioc->pio_chip = (SYSIF_REGS __iomem *)port;
+
+       return 0;
+}
+
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
  *     mpt_attach - Install a PCI intelligent MPT adapter.
@@ -1379,18 +1717,13 @@ int
 mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
 {
        MPT_ADAPTER     *ioc;
-       u8              __iomem *mem;
-       unsigned long    mem_phys;
-       unsigned long    port;
-       u32              msize;
-       u32              psize;
-       int              ii;
+       u8               cb_idx;
        int              r = -ENODEV;
        u8               revision;
        u8               pcixcmd;
        static int       mpt_ids = 0;
 #ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *dent, *ent;
+       struct proc_dir_entry *dent;
 #endif
 
        ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
@@ -1399,39 +1732,56 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
                return -ENOMEM;
        }
 
+       ioc->id = mpt_ids++;
+       sprintf(ioc->name, "ioc%d", ioc->id);
+       dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
+
+       /*
+        * set initial debug level
+        * (refer to mptdebug.h)
+        *
+        */
        ioc->debug_level = mpt_debug_level;
        if (mpt_debug_level)
-               printk(KERN_INFO MYNAM ": mpt_debug_level=%xh\n", mpt_debug_level);
+               printk(KERN_INFO "mpt_debug_level=%xh\n", mpt_debug_level);
 
-       if (pci_enable_device(pdev))
-               return r;
+       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": mpt_adapter_install\n", ioc->name));
 
-       dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
-
-       if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
-               dprintk(ioc, printk(KERN_INFO MYNAM
-                       ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
-       } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
-               printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
+       ioc->pcidev = pdev;
+       if (mpt_mapresources(ioc)) {
+               kfree(ioc);
                return r;
        }
 
-       if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) {
-               dprintk(ioc, printk(KERN_INFO MYNAM
-                       ": Using 64 bit consistent mask\n"));
+       /*
+        * Setting up proper handlers for scatter gather handling
+        */
+       if (ioc->dma_mask == DMA_BIT_MASK(64)) {
+               if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
+                       ioc->add_sge = &mpt_add_sge_64bit_1078;
+               else
+                       ioc->add_sge = &mpt_add_sge_64bit;
+               ioc->add_chain = &mpt_add_chain_64bit;
+               ioc->sg_addr_size = 8;
        } else {
-               dprintk(ioc, printk(KERN_INFO MYNAM
-                       ": Not using 64 bit consistent mask\n"));
+               ioc->add_sge = &mpt_add_sge;
+               ioc->add_chain = &mpt_add_chain;
+               ioc->sg_addr_size = 4;
        }
+       ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
 
        ioc->alloc_total = sizeof(MPT_ADAPTER);
        ioc->req_sz = MPT_DEFAULT_FRAME_SIZE;           /* avoid div by zero! */
        ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
 
-       ioc->pcidev = pdev;
-       ioc->diagPending = 0;
-       spin_lock_init(&ioc->diagLock);
-       spin_lock_init(&ioc->initializing_hba_lock);
+
+       spin_lock_init(&ioc->taskmgmt_lock);
+       mutex_init(&ioc->internal_cmds.mutex);
+       init_completion(&ioc->internal_cmds.done);
+       mutex_init(&ioc->mptbase_cmds.mutex);
+       init_completion(&ioc->mptbase_cmds.done);
+       mutex_init(&ioc->taskmgmt_cmds.mutex);
+       init_completion(&ioc->taskmgmt_cmds.done);
 
        /* Initialize the event logging.
         */
@@ -1444,67 +1794,38 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        ioc->mfcnt = 0;
 #endif
 
+       ioc->sh = NULL;
        ioc->cached_fw = NULL;
 
-       /* Initilize SCSI Config Data structure
+       /* Initialize SCSI Config Data structure
         */
        memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
 
-       /* Initialize the running configQ head.
-        */
-       INIT_LIST_HEAD(&ioc->configQ);
-
        /* Initialize the fc rport list head.
         */
        INIT_LIST_HEAD(&ioc->fc_rports);
 
        /* Find lookup slot. */
        INIT_LIST_HEAD(&ioc->list);
-       ioc->id = mpt_ids++;
 
-       mem_phys = msize = 0;
-       port = psize = 0;
-       for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
-               if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
-                       if (psize)
-                               continue;
-                       /* Get I/O space! */
-                       port = pci_resource_start(pdev, ii);
-                       psize = pci_resource_len(pdev,ii);
-               } else {
-                       if (msize)
-                               continue;
-                       /* Get memmap */
-                       mem_phys = pci_resource_start(pdev, ii);
-                       msize = pci_resource_len(pdev,ii);
-               }
-       }
-       ioc->mem_size = msize;
 
-       mem = NULL;
-       /* Get logical ptr for PciMem0 space */
-       /*mem = ioremap(mem_phys, msize);*/
-       mem = ioremap(mem_phys, msize);
-       if (mem == NULL) {
-               printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
+       /* Initialize workqueue */
+       INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
+
+       snprintf(ioc->reset_work_q_name, MPT_KOBJ_NAME_LEN,
+                "mpt_poll_%d", ioc->id);
+       ioc->reset_work_q =
+               create_singlethread_workqueue(ioc->reset_work_q_name);
+       if (!ioc->reset_work_q) {
+               printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
+                   ioc->name);
+               pci_release_selected_regions(pdev, ioc->bars);
                kfree(ioc);
-               return -EINVAL;
+               return -ENOMEM;
        }
-       ioc->memmap = mem;
-       dinitprintk(ioc, printk(KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
-
-       dinitprintk(ioc, printk(KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
-                       &ioc->facts, &ioc->pfacts[0]));
-
-       ioc->mem_phys = mem_phys;
-       ioc->chip = (SYSIF_REGS __iomem *)mem;
 
-       /* Save Port IO values in case we need to do downloadboot */
-       {
-               u8 *pmem = (u8*)port;
-               ioc->pio_mem_phys = port;
-               ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
-       }
+       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n",
+           ioc->name, &ioc->facts, &ioc->pfacts[0]));
 
        pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
        mpt_get_product_name(pdev->vendor, pdev->device, revision, ioc->prod_name);
@@ -1566,18 +1887,41 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        case MPI_MANUFACTPAGE_DEVID_SAS1064:
        case MPI_MANUFACTPAGE_DEVID_SAS1068:
                ioc->errata_flag_1064 = 1;
+               ioc->bus_type = SAS;
+               break;
 
        case MPI_MANUFACTPAGE_DEVID_SAS1064E:
        case MPI_MANUFACTPAGE_DEVID_SAS1068E:
        case MPI_MANUFACTPAGE_DEVID_SAS1078:
                ioc->bus_type = SAS;
+               break;
        }
 
+
+       switch (ioc->bus_type) {
+
+       case SAS:
+               ioc->msi_enable = mpt_msi_enable_sas;
+               break;
+
+       case SPI:
+               ioc->msi_enable = mpt_msi_enable_spi;
+               break;
+
+       case FC:
+               ioc->msi_enable = mpt_msi_enable_fc;
+               break;
+
+       default:
+               ioc->msi_enable = 0;
+               break;
+       }
+
+       ioc->fw_events_off = 1;
+
        if (ioc->errata_flag_1064)
                pci_disable_io_access(pdev);
 
-       sprintf(ioc->name, "ioc%d", ioc->id);
-
        spin_lock_init(&ioc->FreeQlock);
 
        /* Disable all! */
@@ -1585,6 +1929,9 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        ioc->active = 0;
        CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
 
+       /* Set IOC ptr in the pcidev's driver data. */
+       pci_set_drvdata(ioc->pcidev, ioc);
+
        /* Set lookup ptr. */
        list_add_tail(&ioc->list, &ioc_list);
 
@@ -1592,26 +1939,36 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
         */
        mpt_detect_bound_ports(ioc, pdev);
 
+       INIT_LIST_HEAD(&ioc->fw_event_list);
+       spin_lock_init(&ioc->fw_event_lock);
+       snprintf(ioc->fw_event_q_name, MPT_KOBJ_NAME_LEN, "mpt/%d", ioc->id);
+       ioc->fw_event_q = create_singlethread_workqueue(ioc->fw_event_q_name);
+
        if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
            CAN_SLEEP)) != 0){
-               printk(KERN_WARNING MYNAM
-                 ": WARNING - %s did not initialize properly! (%d)\n",
-                 ioc->name, r);
+               printk(MYIOC_s_ERR_FMT "didn't initialize properly! (%d)\n",
+                   ioc->name, r);
 
                list_del(&ioc->list);
                if (ioc->alt_ioc)
                        ioc->alt_ioc->alt_ioc = NULL;
-               iounmap(mem);
+               iounmap(ioc->memmap);
+               if (r != -5)
+                       pci_release_selected_regions(pdev, ioc->bars);
+
+               destroy_workqueue(ioc->reset_work_q);
+               ioc->reset_work_q = NULL;
+
                kfree(ioc);
                pci_set_drvdata(pdev, NULL);
                return r;
        }
 
        /* call per device driver probe entry point */
-       for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
-               if(MptDeviceDriverHandlers[ii] &&
-                 MptDeviceDriverHandlers[ii]->probe) {
-                       MptDeviceDriverHandlers[ii]->probe(pdev,id);
+       for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
+               if(MptDeviceDriverHandlers[cb_idx] &&
+                 MptDeviceDriverHandlers[cb_idx]->probe) {
+                       MptDeviceDriverHandlers[cb_idx]->probe(pdev,id);
                }
        }
 
@@ -1621,19 +1978,15 @@ mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
         */
        dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
        if (dent) {
-               ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
-               if (ent) {
-                       ent->read_proc = procmpt_iocinfo_read;
-                       ent->data = ioc;
-               }
-               ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
-               if (ent) {
-                       ent->read_proc = procmpt_summary_read;
-                       ent->data = ioc;
-               }
+               proc_create_data("info", S_IRUGO, dent, &mpt_iocinfo_proc_fops, ioc);
+               proc_create_data("summary", S_IRUGO, dent, &mpt_summary_proc_fops, ioc);
        }
 #endif
 
+       if (!ioc->alt_ioc)
+               queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
+                       msecs_to_jiffies(MPT_POLLING_INTERVAL));
+
        return 0;
 }
 
@@ -1648,7 +2001,25 @@ mpt_detach(struct pci_dev *pdev)
 {
        MPT_ADAPTER     *ioc = pci_get_drvdata(pdev);
        char pname[32];
-       int ii;
+       u8 cb_idx;
+       unsigned long flags;
+       struct workqueue_struct *wq;
+
+       /*
+        * Stop polling ioc for fault condition
+        */
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       wq = ioc->reset_work_q;
+       ioc->reset_work_q = NULL;
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+       cancel_delayed_work(&ioc->fault_reset_work);
+       destroy_workqueue(wq);
+
+       spin_lock_irqsave(&ioc->fw_event_lock, flags);
+       wq = ioc->fw_event_q;
+       ioc->fw_event_q = NULL;
+       spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
+       destroy_workqueue(wq);
 
        sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
        remove_proc_entry(pname, NULL);
@@ -1658,10 +2029,10 @@ mpt_detach(struct pci_dev *pdev)
        remove_proc_entry(pname, NULL);
 
        /* call per device driver remove entry point */
-       for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
-               if(MptDeviceDriverHandlers[ii] &&
-                 MptDeviceDriverHandlers[ii]->remove) {
-                       MptDeviceDriverHandlers[ii]->remove(pdev);
+       for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
+               if(MptDeviceDriverHandlers[cb_idx] &&
+                 MptDeviceDriverHandlers[cb_idx]->remove) {
+                       MptDeviceDriverHandlers[cb_idx]->remove(pdev);
                }
        }
 
@@ -1678,7 +2049,6 @@ mpt_detach(struct pci_dev *pdev)
 
        mpt_adapter_dispose(ioc);
 
-       pci_set_drvdata(pdev, NULL);
 }
 
 /**************************************************************************
@@ -1697,13 +2067,10 @@ mpt_suspend(struct pci_dev *pdev, pm_message_t state)
        u32 device_state;
        MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
 
-       device_state=pci_choose_state(pdev, state);
-
-       printk(MYIOC_s_INFO_FMT
-       "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
-               ioc->name, pdev, pci_name(pdev), device_state);
-
-       pci_save_state(pdev);
+       device_state = pci_choose_state(pdev, state);
+       printk(MYIOC_s_INFO_FMT "pci-suspend: pdev=0x%p, slot=%s, Entering "
+           "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
+           device_state);
 
        /* put ioc into READY_STATE */
        if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
@@ -1718,9 +2085,14 @@ mpt_suspend(struct pci_dev *pdev, pm_message_t state)
        /* Clear any lingering interrupt */
        CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
 
+       free_irq(ioc->pci_irq, ioc);
+       if (ioc->msi_enable)
+               pci_disable_msi(ioc->pcidev);
+       ioc->pci_irq = -1;
+       pci_save_state(pdev);
        pci_disable_device(pdev);
+       pci_release_selected_regions(pdev, ioc->bars);
        pci_set_power_state(pdev, device_state);
-
        return 0;
 }
 
@@ -1737,43 +2109,72 @@ mpt_resume(struct pci_dev *pdev)
        int recovery_state;
        int err;
 
-       printk(MYIOC_s_INFO_FMT
-       "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
-               ioc->name, pdev, pci_name(pdev), device_state);
+       printk(MYIOC_s_INFO_FMT "pci-resume: pdev=0x%p, slot=%s, Previous "
+           "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
+           device_state);
 
-       pci_set_power_state(pdev, 0);
+       pci_set_power_state(pdev, PCI_D0);
+       pci_enable_wake(pdev, PCI_D0, 0);
        pci_restore_state(pdev);
-       err = pci_enable_device(pdev);
+       ioc->pcidev = pdev;
+       err = mpt_mapresources(ioc);
        if (err)
                return err;
 
-       /* enable interrupts */
-       CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
-       ioc->active = 1;
+       if (ioc->dma_mask == DMA_BIT_MASK(64)) {
+               if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
+                       ioc->add_sge = &mpt_add_sge_64bit_1078;
+               else
+                       ioc->add_sge = &mpt_add_sge_64bit;
+               ioc->add_chain = &mpt_add_chain_64bit;
+               ioc->sg_addr_size = 8;
+       } else {
 
-       printk(MYIOC_s_INFO_FMT
-               "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
-               ioc->name,
-               (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
-               CHIPREG_READ32(&ioc->chip->Doorbell));
+               ioc->add_sge = &mpt_add_sge;
+               ioc->add_chain = &mpt_add_chain;
+               ioc->sg_addr_size = 4;
+       }
+       ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
 
-       /* bring ioc to operational state */
-       if ((recovery_state = mpt_do_ioc_recovery(ioc,
-           MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
-               printk(MYIOC_s_INFO_FMT
-                       "pci-resume: Cannot recover, error:[%x]\n",
-                       ioc->name, recovery_state);
-       } else {
-               printk(MYIOC_s_INFO_FMT
-                       "pci-resume: success\n", ioc->name);
+       printk(MYIOC_s_INFO_FMT "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
+           ioc->name, (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
+           CHIPREG_READ32(&ioc->chip->Doorbell));
+
+       /*
+        * Errata workaround for SAS pci express:
+        * Upon returning to the D0 state, the contents of the doorbell will be
+        * stale data, and this will incorrectly signal to the host driver that
+        * the firmware is ready to process mpt commands.   The workaround is
+        * to issue a diagnostic reset.
+        */
+       if (ioc->bus_type == SAS && (pdev->device ==
+           MPI_MANUFACTPAGE_DEVID_SAS1068E || pdev->device ==
+           MPI_MANUFACTPAGE_DEVID_SAS1064E)) {
+               if (KickStart(ioc, 1, CAN_SLEEP) < 0) {
+                       printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover\n",
+                           ioc->name);
+                       goto out;
+               }
        }
 
+       /* bring ioc to operational state */
+       printk(MYIOC_s_INFO_FMT "Sending mpt_do_ioc_recovery\n", ioc->name);
+       recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
+                                                CAN_SLEEP);
+       if (recovery_state != 0)
+               printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover, "
+                   "error:[%x]\n", ioc->name, recovery_state);
+       else
+               printk(MYIOC_s_INFO_FMT
+                   "pci-resume: success\n", ioc->name);
+ out:
        return 0;
+
 }
 #endif
 
 static int
-mpt_signal_reset(int index, MPT_ADAPTER *ioc, int reset_phase)
+mpt_signal_reset(u8 index, MPT_ADAPTER *ioc, int reset_phase)
 {
        if ((MptDriverClass[index] == MPTSPI_DRIVER &&
             ioc->bus_type != SPI) ||
@@ -1806,6 +2207,8 @@ mpt_signal_reset(int index, MPT_ADAPTER *ioc, int reset_phase)
  *             -2 if READY but IOCFacts Failed
  *             -3 if READY but PrimeIOCFifos Failed
  *             -4 if READY but IOCInit Failed
+ *             -5 if failed to enable_device and/or request_selected_regions
+ *             -6 if failed to upload firmware
  */
 static int
 mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
@@ -1815,26 +2218,29 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
        int      hard;
        int      rc=0;
        int      ii;
-       int      handlers;
        int      ret = 0;
        int      reset_alt_ioc_active = 0;
        int      irq_allocated = 0;
        u8      *a;
 
-       printk(KERN_INFO MYNAM ": Initiating %s %s\n",
-                       ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
+       printk(MYIOC_s_INFO_FMT "Initiating %s\n", ioc->name,
+           reason == MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
 
        /* Disable reply interrupts (also blocks FreeQ) */
        CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
        ioc->active = 0;
 
        if (ioc->alt_ioc) {
-               if (ioc->alt_ioc->active)
+               if (ioc->alt_ioc->active ||
+                   reason == MPT_HOSTEVENT_IOC_RECOVER) {
                        reset_alt_ioc_active = 1;
-
-               /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
-               CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
-               ioc->alt_ioc->active = 0;
+                       /* Disable alt-IOC's reply interrupts
+                        *  (and FreeQ) for a bit
+                        **/
+                       CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
+                               0xFFFFFFFF);
+                       ioc->alt_ioc->active = 0;
+               }
        }
 
        hard = 1;
@@ -1843,23 +2249,23 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
 
        if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
                if (hard_reset_done == -4) {
-                       printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
-                                       ioc->name);
+                       printk(MYIOC_s_WARN_FMT "Owned by PEER..skipping!\n",
+                           ioc->name);
 
                        if (reset_alt_ioc_active && ioc->alt_ioc) {
                                /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
-                               dprintk(ioc, printk(KERN_INFO MYNAM
-                                       ": alt-%s reply irq re-enabled\n",
-                                               ioc->alt_ioc->name));
+                               dprintk(ioc, printk(MYIOC_s_INFO_FMT
+                                   "alt_ioc reply irq re-enabled\n", ioc->alt_ioc->name));
                                CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
                                ioc->alt_ioc->active = 1;
                        }
 
                } else {
-                       printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
-                                       ioc->name);
+                       printk(MYIOC_s_WARN_FMT
+                           "NOT READY WARNING!\n", ioc->name);
                }
-               return -1;
+               ret = -1;
+               goto out;
        }
 
        /* hard_reset_done = 0 if a soft reset was performed
@@ -1869,9 +2275,9 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
                        alt_ioc_ready = 1;
                else
-                       printk(KERN_WARNING MYNAM
-                                       ": alt-%s: Not ready WARNING!\n",
-                                       ioc->alt_ioc->name);
+                       printk(MYIOC_s_WARN_FMT
+                           ": alt-ioc Not ready WARNING!\n",
+                           ioc->alt_ioc->name);
        }
 
        for (ii=0; ii<5; ii++) {
@@ -1882,7 +2288,8 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
 
 
        if (ii == 5) {
-               dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
+               dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "Retry IocFacts failed rc=%x\n", ioc->name, rc));
                ret = -2;
        } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
                MptDisplayIocCapabilities(ioc);
@@ -1891,14 +2298,15 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
        if (alt_ioc_ready) {
                if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
                        dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                               "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
+                           "Initial Alt IocFacts failed rc=%x\n",
+                           ioc->name, rc));
                        /* Retry - alt IOC was initialized once
                         */
                        rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
                }
                if (rc) {
                        dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                               "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
+                           "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
                        alt_ioc_ready = 0;
                        reset_alt_ioc_active = 0;
                } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
@@ -1906,6 +2314,18 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                }
        }
 
+       if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP) &&
+           (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)) {
+               pci_release_selected_regions(ioc->pcidev, ioc->bars);
+               ioc->bars = pci_select_bars(ioc->pcidev, IORESOURCE_MEM |
+                   IORESOURCE_IO);
+               if (pci_enable_device(ioc->pcidev))
+                       return -5;
+               if (pci_request_selected_regions(ioc->pcidev, ioc->bars,
+                       "mpt"))
+                       return -5;
+       }
+
        /*
         * Device is reset now. It must have de-asserted the interrupt line
         * (if it was asserted) and it should be safe to register for the
@@ -1914,25 +2334,29 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
        if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
                ioc->pci_irq = -1;
                if (ioc->pcidev->irq) {
-                       if (mpt_msi_enable && !pci_enable_msi(ioc->pcidev))
+                       if (ioc->msi_enable && !pci_enable_msi(ioc->pcidev))
                                printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
-                                       ioc->name);
+                                   ioc->name);
+                       else
+                               ioc->msi_enable = 0;
                        rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
-                                       IRQF_SHARED, ioc->name, ioc);
+                           IRQF_SHARED, ioc->name, ioc);
                        if (rc < 0) {
                                printk(MYIOC_s_ERR_FMT "Unable to allocate "
-                                       "interrupt %d!\n", ioc->name,
-                                       ioc->pcidev->irq);
-                               if (mpt_msi_enable)
+                                   "interrupt %d!\n",
+                                   ioc->name, ioc->pcidev->irq);
+                               if (ioc->msi_enable)
                                        pci_disable_msi(ioc->pcidev);
-                               return -EBUSY;
+                               ret = -EBUSY;
+                               goto out;
                        }
                        irq_allocated = 1;
                        ioc->pci_irq = ioc->pcidev->irq;
                        pci_set_master(ioc->pcidev);            /* ?? */
                        pci_set_drvdata(ioc->pcidev, ioc);
-                       dprintk(ioc, printk(KERN_INFO MYNAM ": %s installed at interrupt "
-                               "%d\n", ioc->name, ioc->pcidev->irq));
+                       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                           "installed at interrupt %d\n", ioc->name,
+                           ioc->pcidev->irq));
                }
        }
 
@@ -1941,18 +2365,23 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
         * init as upper addresses are needed for init.
         * If fails, continue with alt-ioc processing
         */
+       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "PrimeIocFifos\n",
+           ioc->name));
        if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
                ret = -3;
 
        /* May need to check/upload firmware & data here!
         * If fails, continue with alt-ioc processing
         */
+       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendIocInit\n",
+           ioc->name));
        if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
                ret = -4;
 // NEW!
        if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
-               printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
-                               ioc->alt_ioc->name, rc);
+               printk(MYIOC_s_WARN_FMT
+                   ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
+                   ioc->alt_ioc->name, rc);
                alt_ioc_ready = 0;
                reset_alt_ioc_active = 0;
        }
@@ -1961,8 +2390,8 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
                        alt_ioc_ready = 0;
                        reset_alt_ioc_active = 0;
-                       printk(KERN_WARNING MYNAM
-                               ": alt-%s: (%d) init failure WARNING!\n",
+                       printk(MYIOC_s_WARN_FMT
+                               ": alt-ioc: (%d) init failure WARNING!\n",
                                        ioc->alt_ioc->name, rc);
                }
        }
@@ -1970,7 +2399,7 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
        if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
                if (ioc->upload_fw) {
                        ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                               "firmware upload required!\n", ioc->name));
+                           "firmware upload required!\n", ioc->name));
 
                        /* Controller is not operational, cannot do upload
                         */
@@ -1986,40 +2415,49 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                                                 * mpt_diag_reset)
                                                 */
                                                ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                                                       ": mpt_upload:  alt_%s has cached_fw=%p \n",
-                                                       ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
-                                               ioc->alt_ioc->cached_fw = NULL;
+                                                   "mpt_upload:  alt_%s has cached_fw=%p \n",
+                                                   ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
+                                               ioc->cached_fw = NULL;
                                        }
                                } else {
-                                       printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
-                                       ret = -5;
+                                       printk(MYIOC_s_WARN_FMT
+                                           "firmware upload failure!\n", ioc->name);
+                                       ret = -6;
                                }
                        }
                }
        }
 
+       /*  Enable MPT base driver management of EventNotification
+        *  and EventAck handling.
+        */
+       if ((ret == 0) && (!ioc->facts.EventState)) {
+               dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                       "SendEventNotification\n",
+                   ioc->name));
+               ret = SendEventNotification(ioc, 1, sleepFlag); /* 1=Enable */
+       }
+
+       if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
+               rc = SendEventNotification(ioc->alt_ioc, 1, sleepFlag);
+
        if (ret == 0) {
                /* Enable! (reply interrupt) */
                CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
                ioc->active = 1;
        }
-
-       if (reset_alt_ioc_active && ioc->alt_ioc) {
-               /* (re)Enable alt-IOC! (reply interrupt) */
-               dinitprintk(ioc, printk(KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
+       if (rc == 0) {  /* alt ioc */
+               if (reset_alt_ioc_active && ioc->alt_ioc) {
+                       /* (re)Enable alt-IOC! (reply interrupt) */
+                       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "alt-ioc"
+                               "reply irq re-enabled\n",
                                ioc->alt_ioc->name));
-               CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
-               ioc->alt_ioc->active = 1;
+                       CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
+                               MPI_HIM_DIM);
+                       ioc->alt_ioc->active = 1;
+               }
        }
 
-       /*  Enable MPT base driver management of EventNotification
-        *  and EventAck handling.
-        */
-       if ((ret == 0) && (!ioc->facts.EventState))
-               (void) SendEventNotification(ioc, 1);   /* 1=Enable EventNotification */
-
-       if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
-               (void) SendEventNotification(ioc->alt_ioc, 1);  /* 1=Enable EventNotification */
 
        /*      Add additional "reason" check before call to GetLanConfigPages
         *      (combined with GetIoUnitPage2 call).  This prevents a somewhat
@@ -2030,13 +2468,14 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
        if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
 
                /*
-                * Initalize link list for inactive raid volumes.
+                * Initialize link list for inactive raid volumes.
                 */
-               init_MUTEX(&ioc->raid_data.inactive_list_mutex);
+               mutex_init(&ioc->raid_data.inactive_list_mutex);
                INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
 
-               if (ioc->bus_type == SAS) {
+               switch (ioc->bus_type) {
 
+               case SAS:
                        /* clear persistency table */
                        if(ioc->facts.IOCExceptions &
                            MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
@@ -2050,8 +2489,15 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                         */
                        mpt_findImVolumes(ioc);
 
-               } else if (ioc->bus_type == FC) {
-                       if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
+                       /* Check, and possibly reset, the coalescing value
+                        */
+                       mpt_read_ioc_pg_1(ioc);
+
+                       break;
+
+               case FC:
+                       if ((ioc->pfacts[0].ProtocolFlags &
+                               MPI_PORTFACTS_PROTOCOL_LAN) &&
                            (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
                                /*
                                 *  Pre-fetch the ports LAN MAC address!
@@ -2060,13 +2506,14 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                                (void) GetLanConfigPages(ioc);
                                a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
                                dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                                       "LanAddr = %02X:%02X:%02X:"
-                                       "%02X:%02X:%02X\n",
+                                       "LanAddr = %02X:%02X:%02X"
+                                       ":%02X:%02X:%02X\n",
                                        ioc->name, a[5], a[4],
-                                       a[3], a[2], a[1], a[0] ));
-
+                                       a[3], a[2], a[1], a[0]));
                        }
-               } else {
+                       break;
+
+               case SPI:
                        /* Get NVRAM and adapter maximums from SPP 0 and 2
                         */
                        mpt_GetScsiPortSettings(ioc, 0);
@@ -2085,44 +2532,18 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
                        mpt_read_ioc_pg_1(ioc);
 
                        mpt_read_ioc_pg_4(ioc);
+
+                       break;
                }
 
                GetIoUnitPage2(ioc);
                mpt_get_manufacturing_pg_0(ioc);
        }
 
-       /*
-        * Call each currently registered protocol IOC reset handler
-        * with post-reset indication.
-        * NOTE: If we're doing _IOC_BRINGUP, there can be no
-        * MptResetHandlers[] registered yet.
-        */
-       if (hard_reset_done) {
-               rc = handlers = 0;
-               for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
-                       if ((ret == 0) && MptResetHandlers[ii]) {
-                               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                                       "Calling IOC post_reset handler #%d\n",
-                                       ioc->name, ii));
-                               rc += mpt_signal_reset(ii, ioc, MPT_IOC_POST_RESET);
-                               handlers++;
-                       }
-
-                       if (alt_ioc_ready && MptResetHandlers[ii]) {
-                               drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                                       "Calling alt-%s post_reset handler #%d\n",
-                                       ioc->name, ioc->alt_ioc->name, ii));
-                               rc += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_POST_RESET);
-                               handlers++;
-                       }
-               }
-               /* FIXME?  Examine results here? */
-       }
-
  out:
        if ((ret != 0) && irq_allocated) {
                free_irq(ioc->pci_irq, ioc);
-               if (mpt_msi_enable)
+               if (ioc->msi_enable)
                        pci_disable_msi(ioc->pcidev);
        }
        return ret;
@@ -2151,8 +2572,8 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
 
        dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PCI device %s devfn=%x/%x,"
            " searching for devfn match on %x or %x\n",
-               ioc->name, pci_name(pdev), pdev->bus->number,
-               pdev->devfn, func-1, func+1));
+           ioc->name, pci_name(pdev), pdev->bus->number,
+           pdev->devfn, func-1, func+1));
 
        peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
        if (!peer) {
@@ -2166,16 +2587,20 @@ mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
                if (_pcidev == peer) {
                        /* Paranoia checks */
                        if (ioc->alt_ioc != NULL) {
-                               printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
-                                       ioc->name, ioc->alt_ioc->name);
+                               printk(MYIOC_s_WARN_FMT
+                                   "Oops, already bound (%s <==> %s)!\n",
+                                   ioc->name, ioc->name, ioc->alt_ioc->name);
                                break;
                        } else if (ioc_srch->alt_ioc != NULL) {
-                               printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
-                                       ioc_srch->name, ioc_srch->alt_ioc->name);
+                               printk(MYIOC_s_WARN_FMT
+                                   "Oops, already bound (%s <==> %s)!\n",
+                                   ioc_srch->name, ioc_srch->name,
+                                   ioc_srch->alt_ioc->name);
                                break;
                        }
-                       dprintk(ioc, printk(KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
-                               ioc->name, ioc_srch->name));
+                       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                               "FOUND! binding %s <==> %s\n",
+                               ioc->name, ioc->name, ioc_srch->name));
                        ioc_srch->alt_ioc = ioc;
                        ioc->alt_ioc = ioc_srch;
                }
@@ -2195,23 +2620,45 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
        int ret;
 
        if (ioc->cached_fw != NULL) {
-               ddlprintk(ioc, printk(KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
-               if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)ioc->cached_fw, NO_SLEEP)) < 0) {
-                       printk(KERN_WARNING MYNAM
-                               ": firmware downloadboot failure (%d)!\n", ret);
+               ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                       "%s: Pushing FW onto adapter\n", __func__, ioc->name));
+               if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)
+                   ioc->cached_fw, CAN_SLEEP)) < 0) {
+                       printk(MYIOC_s_WARN_FMT
+                           ": firmware downloadboot failure (%d)!\n",
+                           ioc->name, ret);
                }
        }
 
+       /*
+        * Put the controller into ready state (if its not already)
+        */
+       if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY) {
+               if (!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
+                   CAN_SLEEP)) {
+                       if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY)
+                               printk(MYIOC_s_ERR_FMT "%s:  IOC msg unit "
+                                   "reset failed to put ioc in ready state!\n",
+                                   ioc->name, __func__);
+               } else
+                       printk(MYIOC_s_ERR_FMT "%s:  IOC msg unit reset "
+                           "failed!\n", ioc->name, __func__);
+       }
+
+
        /* Disable adapter interrupts! */
+       synchronize_irq(ioc->pcidev->irq);
        CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
        ioc->active = 0;
+
        /* Clear any lingering interrupt */
        CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
+       CHIPREG_READ32(&ioc->chip->IntStatus);
 
        if (ioc->alloc != NULL) {
                sz = ioc->alloc_sz;
-               dexitprintk(ioc, printk(KERN_INFO MYNAM ": %s.free  @ %p, sz=%d bytes\n",
-                       ioc->name, ioc->alloc, ioc->alloc_sz));
+               dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "free  @ %p, sz=%d bytes\n",
+                   ioc->name, ioc->alloc, ioc->alloc_sz));
                pci_free_consistent(ioc->pcidev, sz,
                                ioc->alloc, ioc->alloc_dma);
                ioc->reply_frames = NULL;
@@ -2235,13 +2682,7 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
                ioc->alloc_total -= sz;
        }
 
-       if (ioc->cached_fw != NULL) {
-               sz = ioc->facts.FWImageSize;
-               pci_free_consistent(ioc->pcidev, sz,
-                       ioc->cached_fw, ioc->cached_fw_dma);
-               ioc->cached_fw = NULL;
-               ioc->alloc_total -= sz;
-       }
+       mpt_free_fw_memory(ioc);
 
        kfree(ioc->spi_data.nvram);
        mpt_inactive_raid_list_free(ioc);
@@ -2271,21 +2712,23 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
        if (ioc->HostPageBuffer != NULL) {
                if((ret = mpt_host_page_access_control(ioc,
                    MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
-                       printk(KERN_ERR MYNAM
+                       printk(MYIOC_s_ERR_FMT
                           ": %s: host page buffers free failed (%d)!\n",
-                           __FUNCTION__, ret);
+                           ioc->name, __func__, ret);
                }
-               dexitprintk(ioc, printk(KERN_INFO MYNAM ": %s HostPageBuffer free  @ %p, sz=%d bytes\n",
-                       ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
+               dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                       "HostPageBuffer free  @ %p, sz=%d bytes\n",
+                       ioc->name, ioc->HostPageBuffer,
+                       ioc->HostPageBuffer_sz));
                pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
-                               ioc->HostPageBuffer,
-                               ioc->HostPageBuffer_dma);
+                   ioc->HostPageBuffer, ioc->HostPageBuffer_dma);
                ioc->HostPageBuffer = NULL;
                ioc->HostPageBuffer_sz = 0;
                ioc->alloc_total -= ioc->HostPageBuffer_sz;
        }
-}
 
+       pci_set_drvdata(ioc->pcidev, NULL);
+}
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
  *     mpt_adapter_dispose - Free all resources associated with an MPT adapter
@@ -2308,7 +2751,7 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
 
        if (ioc->pci_irq != -1) {
                free_irq(ioc->pci_irq, ioc);
-               if (mpt_msi_enable)
+               if (ioc->msi_enable)
                        pci_disable_msi(ioc->pcidev);
                ioc->pci_irq = -1;
        }
@@ -2318,10 +2761,13 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
                ioc->memmap = NULL;
        }
 
+       pci_disable_device(ioc->pcidev);
+       pci_release_selected_regions(ioc->pcidev, ioc->bars);
+
 #if defined(CONFIG_MTRR) && 0
        if (ioc->mtrr_reg > 0) {
                mtrr_del(ioc->mtrr_reg, 0, 0);
-               dprintk(ioc, printk(KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
+               dprintk(ioc, printk(MYIOC_s_INFO_FMT "MTRR region de-registered\n", ioc->name));
        }
 #endif
 
@@ -2329,8 +2775,8 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)
        list_del(&ioc->list);
 
        sz_last = ioc->alloc_total;
-       dprintk(ioc, printk(KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
-                       ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
+       dprintk(ioc, printk(MYIOC_s_INFO_FMT "free'd %d of %d bytes\n",
+           ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
 
        if (ioc->alt_ioc)
                ioc->alt_ioc->alt_ioc = NULL;
@@ -2409,7 +2855,7 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
 
        /* Get current [raw] IOC state  */
        ioc_state = mpt_GetIocState(ioc, 0);
-       dhsprintk(ioc, printk(KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
+       dhsprintk(ioc, printk(MYIOC_s_INFO_FMT "MakeIocReady [raw] state=%08x\n", ioc->name, ioc_state));
 
        /*
         *      Check to see if IOC got left/stuck in doorbell handshake
@@ -2422,8 +2868,12 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
        }
 
        /* Is it already READY? */
-       if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
+       if (!statefault &&
+           ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)) {
+               dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                   "IOC is in READY state\n", ioc->name));
                return 0;
+       }
 
        /*
         *      Check to see if IOC is in FAULT state.
@@ -2431,9 +2881,9 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
        if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
                statefault = 2;
                printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
-                               ioc->name);
-               printk(KERN_WARNING "           FAULT code = %04xh\n",
-                               ioc_state & MPI_DOORBELL_DATA_MASK);
+                   ioc->name);
+               printk(MYIOC_s_WARN_FMT "           FAULT code = %04xh\n",
+                   ioc->name, ioc_state & MPI_DOORBELL_DATA_MASK);
        }
 
        /*
@@ -2449,9 +2899,9 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
                 * Else, fall through to KickStart case
                 */
                whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
-               dinitprintk(ioc, printk(KERN_INFO MYNAM
-                       ": whoinit 0x%x statefault %d force %d\n",
-                       whoinit, statefault, force));
+               dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
+                       "whoinit 0x%x statefault %d force %d\n",
+                       ioc->name, whoinit, statefault, force));
                if (whoinit == MPI_WHOINIT_PCI_PEER)
                        return -4;
                else {
@@ -2496,8 +2946,9 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
 
                ii++; cntdn--;
                if (!cntdn) {
-                       printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
-                                       ioc->name, (int)((ii+5)/HZ));
+                       printk(MYIOC_s_ERR_FMT
+                               "Wait IOC_READY state (0x%x) timeout(%d)!\n",
+                               ioc->name, ioc_state, (int)((ii+5)/HZ));
                        return -ETIME;
                }
 
@@ -2510,9 +2961,8 @@ MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
        }
 
        if (statefault < 3) {
-               printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
-                               ioc->name,
-                               statefault==1 ? "stuck handshake" : "IOC FAULT");
+               printk(MYIOC_s_INFO_FMT "Recovered from %s\n", ioc->name,
+                       statefault == 1 ? "stuck handshake" : "IOC FAULT");
        }
 
        return hard_reset_done;
@@ -2534,7 +2984,6 @@ mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
 
        /*  Get!  */
        s = CHIPREG_READ32(&ioc->chip->Doorbell);
-//     dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
        sc = s & MPI_IOC_STATE_MASK;
 
        /*  Save!  */
@@ -2566,9 +3015,9 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
 
        /* IOC *must* NOT be in RESET state! */
        if (ioc->last_state == MPI_IOC_STATE_RESET) {
-               printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
-                               ioc->name,
-                               ioc->last_state );
+               printk(KERN_ERR MYNAM
+                   ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
+                   ioc->name, ioc->last_state);
                return -44;
        }
 
@@ -2630,7 +3079,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
                 *      Old: u16{Major(4),Minor(4),SubMinor(8)}
                 *      New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
                 */
-               if (facts->MsgVersion < 0x0102) {
+               if (facts->MsgVersion < MPI_VERSION_01_02) {
                        /*
                         *      Handle old FC f/w style, convert to new...
                         */
@@ -2642,9 +3091,11 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
                        facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
 
                facts->ProductID = le16_to_cpu(facts->ProductID);
+
                if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
                    > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
                        ioc->ir_firmware = 1;
+
                facts->CurrentHostMfaHighAddr =
                                le32_to_cpu(facts->CurrentHostMfaHighAddr);
                facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
@@ -2660,7 +3111,7 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
                 * to 14 in MPI-1.01.0x.
                 */
                if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
-                   facts->MsgVersion > 0x0100) {
+                   facts->MsgVersion > MPI_VERSION_01_00) {
                        facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
                }
 
@@ -2688,8 +3139,8 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
                }
                ioc->NBShiftFactor  = shiftFactor;
                dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                       "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
-                       ioc->name, vv, shiftFactor, r));
+                   "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
+                   ioc->name, vv, shiftFactor, r));
 
                if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
                        /*
@@ -2742,9 +3193,8 @@ GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
 
        /* IOC *must* NOT be in RESET state! */
        if (ioc->last_state == MPI_IOC_STATE_RESET) {
-               printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
-                               ioc->name,
-                               ioc->last_state );
+               printk(MYIOC_s_ERR_FMT "Can't get PortFacts NOT READY! (%08x)\n",
+                   ioc->name, ioc->last_state );
                return -4;
        }
 
@@ -2843,6 +3293,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
 
        ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
        ioc_init.MaxBuses = (U8)ioc->number_of_buses;
+
        dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts.MsgVersion=%x\n",
                   ioc->name, ioc->facts.MsgVersion));
        if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
@@ -2857,7 +3308,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
        }
        ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz);   /* in BYTES */
 
-       if (sizeof(dma_addr_t) == sizeof(u64)) {
+       if (ioc->sg_addr_size == sizeof(u64)) {
                /* Save the upper 32-bits of the request
                 * (reply) and sense buffers.
                 */
@@ -2919,7 +3370,7 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
                state = mpt_GetIocState(ioc, 1);
                count++;
        }
-       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wait IOC_OPERATIONAL state (cnt=%d)\n",
                        ioc->name, count));
 
        ioc->aen_event_read_flag=0;
@@ -2983,45 +3434,62 @@ SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  *
  *     If memory has already been allocated, the same (cached) value
  *     is returned.
- */
-void
+ *
+ *     Return 0 if successfull, or non-zero for failure
+ **/
+int
 mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
 {
-       if (ioc->cached_fw)
-               return;  /* use already allocated memory */
-       if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
+       int rc;
+
+       if (ioc->cached_fw) {
+               rc = 0;  /* use already allocated memory */
+               goto out;
+       }
+       else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
                ioc->cached_fw = ioc->alt_ioc->cached_fw;  /* use alt_ioc's memory */
                ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
-               ioc->alloc_total += size;
-               ioc->alt_ioc->alloc_total -= size;
+               rc = 0;
+               goto out;
+       }
+       ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma);
+       if (!ioc->cached_fw) {
+               printk(MYIOC_s_ERR_FMT "Unable to allocate memory for the cached firmware image!\n",
+                   ioc->name);
+               rc = -1;
        } else {
-               if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
-                       ioc->alloc_total += size;
+               dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Image  @ %p[%p], sz=%d[%x] bytes\n",
+                   ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, size, size));
+               ioc->alloc_total += size;
+               rc = 0;
        }
+ out:
+       return rc;
 }
+
 /**
  *     mpt_free_fw_memory - free firmware memory
  *     @ioc: Pointer to MPT_ADAPTER structure
  *
  *     If alt_img is NULL, delete from ioc structure.
  *     Else, delete a secondary image in same format.
- */
+ **/
 void
 mpt_free_fw_memory(MPT_ADAPTER *ioc)
 {
        int sz;
 
+       if (!ioc->cached_fw)
+               return;
+
        sz = ioc->facts.FWImageSize;
-       dinitprintk(ioc, printk(KERN_INFO MYNAM "free_fw_memory: FW Image  @ %p[%p], sz=%d[%x] bytes\n",
-                ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
-       pci_free_consistent(ioc->pcidev, sz,
-                       ioc->cached_fw, ioc->cached_fw_dma);
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free_fw_memory: FW Image  @ %p[%p], sz=%d[%x] bytes\n",
+                ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
+       pci_free_consistent(ioc->pcidev, sz, ioc->cached_fw, ioc->cached_fw_dma);
+       ioc->alloc_total -= sz;
        ioc->cached_fw = NULL;
-
-       return;
 }
 
-
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
  *     mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
@@ -3039,38 +3507,36 @@ mpt_free_fw_memory(MPT_ADAPTER *ioc)
 static int
 mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
 {
-       u8                       request[ioc->req_sz];
        u8                       reply[sizeof(FWUploadReply_t)];
        FWUpload_t              *prequest;
        FWUploadReply_t         *preply;
        FWUploadTCSGE_t         *ptcsge;
-       int                      sgeoffset;
        u32                      flagsLength;
        int                      ii, sz, reply_sz;
        int                      cmdStatus;
-
+       int                     request_size;
        /* If the image size is 0, we are done.
         */
        if ((sz = ioc->facts.FWImageSize) == 0)
                return 0;
 
-       mpt_alloc_fw_memory(ioc, sz);
+       if (mpt_alloc_fw_memory(ioc, ioc->facts.FWImageSize) != 0)
+               return -ENOMEM;
 
-       dinitprintk(ioc, printk(KERN_INFO MYNAM ": FW Image  @ %p[%p], sz=%d[%x] bytes\n",
-                ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
+       dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": FW Image  @ %p[%p], sz=%d[%x] bytes\n",
+           ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
 
-       if (ioc->cached_fw == NULL) {
-               /* Major Failure.
-                */
+       prequest = (sleepFlag == NO_SLEEP) ? kzalloc(ioc->req_sz, GFP_ATOMIC) :
+           kzalloc(ioc->req_sz, GFP_KERNEL);
+       if (!prequest) {
+               dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed "
+                   "while allocating memory \n", ioc->name));
+               mpt_free_fw_memory(ioc);
                return -ENOMEM;
        }
 
-       prequest = (FWUpload_t *)&request;
        preply = (FWUploadReply_t *)&reply;
 
-       /*  Destination...  */
-       memset(prequest, 0, ioc->req_sz);
-
        reply_sz = sizeof(reply);
        memset(preply, 0, reply_sz);
 
@@ -3081,45 +3547,46 @@ mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
        ptcsge->DetailsLength = 12;
        ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
        ptcsge->ImageSize = cpu_to_le32(sz);
-
-       sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
+       ptcsge++;
 
        flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
-       mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
-
-       sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
-       dinitprintk(ioc, printk(KERN_INFO MYNAM ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
-                       prequest, sgeoffset));
-       DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest)
+       ioc->add_sge((char *)ptcsge, flagsLength, ioc->cached_fw_dma);
+       request_size = offsetof(FWUpload_t, SGL) + sizeof(FWUploadTCSGE_t) +
+           ioc->SGE_size;
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending FW Upload "
+           " (req @ %p) fw_size=%d mf_request_size=%d\n", ioc->name, prequest,
+           ioc->facts.FWImageSize, request_size));
+       DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest);
 
-       ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
-                               reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
+       ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32 *)prequest,
+           reply_sz, (u16 *)preply, 65 /*seconds*/, sleepFlag);
 
-       dinitprintk(ioc, printk(KERN_INFO MYNAM ": FW Upload completed rc=%x \n", ii));
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Upload completed "
+           "rc=%x \n", ioc->name, ii));
 
        cmdStatus = -EFAULT;
        if (ii == 0) {
                /* Handshake transfer was complete and successful.
                 * Check the Reply Frame.
                 */
-               int status, transfer_sz;
-               status = le16_to_cpu(preply->IOCStatus);
-               if (status == MPI_IOCSTATUS_SUCCESS) {
-                       transfer_sz = le32_to_cpu(preply->ActualImageSize);
-                       if (transfer_sz == sz)
+               int status;
+               status = le16_to_cpu(preply->IOCStatus) &
+                               MPI_IOCSTATUS_MASK;
+               if (status == MPI_IOCSTATUS_SUCCESS &&
+                   ioc->facts.FWImageSize ==
+                   le32_to_cpu(preply->ActualImageSize))
                                cmdStatus = 0;
-               }
        }
        dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": do_upload cmdStatus=%d \n",
                        ioc->name, cmdStatus));
 
 
        if (cmdStatus) {
-
-               ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": fw upload failed, freeing image \n",
-                       ioc->name));
+               ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed, "
+                   "freeing image \n", ioc->name));
                mpt_free_fw_memory(ioc);
        }
+       kfree(prequest);
 
        return cmdStatus;
 }
@@ -3366,7 +3833,7 @@ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
        u32 ioc_state=0;
        int cnt,cntdn;
 
-       dinitprintk(ioc, printk(KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
+       dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStarting!\n", ioc->name));
        if (ioc->bus_type == SPI) {
                /* Always issue a Msg Unit Reset first. This will clear some
                 * SCSI bus hang conditions.
@@ -3385,7 +3852,7 @@ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
                return hard_reset_done;
 
        dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset successful!\n",
-                       ioc->name));
+               ioc->name));
 
        cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2;     /* 2 seconds */
        for (cnt=0; cnt<cntdn; cnt++) {
@@ -3402,8 +3869,8 @@ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
                }
        }
 
-       printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
-                       ioc->name, ioc_state);
+       dinitprintk(ioc, printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
+               ioc->name, mpt_GetIocState(ioc, 0)));
        return -1;
 }
 
@@ -3429,19 +3896,24 @@ KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
 static int
 mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
 {
-       MPT_ADAPTER     *iocp=NULL;
        u32 diag0val;
        u32 doorbell;
        int hard_reset_done = 0;
        int count = 0;
        u32 diag1val = 0;
+       MpiFwHeader_t *cached_fw;       /* Pointer to FW */
+       u8       cb_idx;
 
        /* Clear any existing interrupts */
        CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
 
        if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
+
+               if (!ignore)
+                       return 0;
+
                drsprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
-                       "address=%p\n",  ioc->name, __FUNCTION__,
+                       "address=%p\n",  ioc->name, __func__,
                        &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
                CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
                if (sleepFlag == CAN_SLEEP)
@@ -3449,6 +3921,18 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
                else
                        mdelay(1);
 
+               /*
+                * Call each currently registered protocol IOC reset handler
+                * with pre-reset indication.
+                * NOTE: If we're doing _IOC_BRINGUP, there can be no
+                * MptResetHandlers[] registered yet.
+                */
+               for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+                       if (MptResetHandlers[cb_idx])
+                               (*(MptResetHandlers[cb_idx]))(ioc,
+                                               MPT_IOC_PRE_RESET);
+               }
+
                for (count = 0; count < 60; count ++) {
                        doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
                        doorbell &= MPI_IOC_STATE_MASK;
@@ -3457,6 +3941,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
                                "looking for READY STATE: doorbell=%x"
                                " count=%d\n",
                                ioc->name, doorbell, count));
+
                        if (doorbell == MPI_IOC_STATE_READY) {
                                return 1;
                        }
@@ -3543,45 +4028,37 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
                 * with pre-reset indication.
                 * NOTE: If we're doing _IOC_BRINGUP, there can be no
                 * MptResetHandlers[] registered yet.
-                */
-               {
-                       int      ii;
-                       int      r = 0;
-
-                       for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
-                               if (MptResetHandlers[ii]) {
-                                       dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                                               "Calling IOC pre_reset handler #%d\n",
-                                               ioc->name, ii));
-                                       r += mpt_signal_reset(ii, ioc, MPT_IOC_PRE_RESET);
-                                       if (ioc->alt_ioc) {
-                                               dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
-                                                       "Calling alt-%s pre_reset handler #%d\n",
-                                                       ioc->name, ioc->alt_ioc->name, ii));
-                                               r += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_PRE_RESET);
-                                       }
+                */
+               for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+                       if (MptResetHandlers[cb_idx]) {
+                               mpt_signal_reset(cb_idx,
+                                       ioc, MPT_IOC_PRE_RESET);
+                               if (ioc->alt_ioc) {
+                                       mpt_signal_reset(cb_idx,
+                                       ioc->alt_ioc, MPT_IOC_PRE_RESET);
                                }
                        }
-                       /* FIXME?  Examine results here? */
                }
 
                if (ioc->cached_fw)
-                       iocp = ioc;
+                       cached_fw = (MpiFwHeader_t *)ioc->cached_fw;
                else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
-                       iocp = ioc->alt_ioc;
-               if (iocp) {
+                       cached_fw = (MpiFwHeader_t *)ioc->alt_ioc->cached_fw;
+               else
+                       cached_fw = NULL;
+               if (cached_fw) {
                        /* If the DownloadBoot operation fails, the
                         * IOC will be left unusable. This is a fatal error
                         * case.  _diag_reset will return < 0
                         */
                        for (count = 0; count < 30; count ++) {
-                               diag0val = CHIPREG_READ32(&iocp->chip->Diagnostic);
+                               diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
                                if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
                                        break;
                                }
 
                                dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
-                                       iocp->name, diag0val, count));
+                                       ioc->name, diag0val, count));
                                /* wait 1 sec */
                                if (sleepFlag == CAN_SLEEP) {
                                        msleep (1000);
@@ -3589,10 +4066,9 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
                                        mdelay (1000);
                                }
                        }
-                       if ((count = mpt_downloadboot(ioc,
-                               (MpiFwHeader_t *)iocp->cached_fw, sleepFlag)) < 0) {
-                               printk(KERN_WARNING MYNAM
-                                       ": firmware downloadboot failure (%d)!\n", count);
+                       if ((count = mpt_downloadboot(ioc, cached_fw, sleepFlag)) < 0) {
+                               printk(MYIOC_s_WARN_FMT
+                                       "firmware downloadboot failure (%d)!\n", ioc->name, count);
                        }
 
                } else {
@@ -3606,6 +4082,10 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
                                doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
                                doorbell &= MPI_IOC_STATE_MASK;
 
+                               drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                                   "looking for READY STATE: doorbell=%x"
+                                   " count=%d\n", ioc->name, doorbell, count));
+
                                if (doorbell == MPI_IOC_STATE_READY) {
                                        break;
                                }
@@ -3617,6 +4097,11 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
                                        mdelay (1000);
                                }
                        }
+
+                       if (doorbell != MPI_IOC_STATE_READY)
+                               printk(MYIOC_s_ERR_FMT "Failed to come READY "
+                                   "after reset! IocState=%x", ioc->name,
+                                   doorbell);
                }
        }
 
@@ -3735,8 +4220,9 @@ SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
                        if (sleepFlag != CAN_SLEEP)
                                count *= 10;
 
-                       printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
-                                       ioc->name, (int)((count+5)/HZ));
+                       printk(MYIOC_s_ERR_FMT
+                           "Wait IOC_READY state (0x%x) timeout(%d)!\n",
+                           ioc->name, state, (int)((count+5)/HZ));
                        return -ETIME;
                }
 
@@ -3806,24 +4292,29 @@ initChainBuffers(MPT_ADAPTER *ioc)
         * num_sge = num sge in request frame + last chain buffer
         * scale = num sge per chain buffer if no chain element
         */
-       scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
-       if (sizeof(dma_addr_t) == sizeof(u64))
-               num_sge =  scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
+       scale = ioc->req_sz / ioc->SGE_size;
+       if (ioc->sg_addr_size == sizeof(u64))
+               num_sge =  scale + (ioc->req_sz - 60) / ioc->SGE_size;
        else
-               num_sge =  1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
+               num_sge =  1 + scale + (ioc->req_sz - 64) / ioc->SGE_size;
 
-       if (sizeof(dma_addr_t) == sizeof(u64)) {
+       if (ioc->sg_addr_size == sizeof(u64)) {
                numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
-                       (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
+                       (ioc->req_sz - 60) / ioc->SGE_size;
        } else {
-               numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
-                       (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
+               numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) +
+                   scale + (ioc->req_sz - 64) / ioc->SGE_size;
        }
        dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "num_sge=%d numSGE=%d\n",
                ioc->name, num_sge, numSGE));
 
-       if ( numSGE > MPT_SCSI_SG_DEPTH )
-               numSGE = MPT_SCSI_SG_DEPTH;
+       if (ioc->bus_type == FC) {
+               if (numSGE > MPT_SCSI_FC_SG_DEPTH)
+                       numSGE = MPT_SCSI_FC_SG_DEPTH;
+       } else {
+               if (numSGE > MPT_SCSI_SG_DEPTH)
+                       numSGE = MPT_SCSI_SG_DEPTH;
+       }
 
        num_chain = 1;
        while (numSGE - num_sge > 0) {
@@ -3837,6 +4328,8 @@ initChainBuffers(MPT_ADAPTER *ioc)
 
        if (ioc->bus_type == SPI)
                num_chain *= MPT_SCSI_CAN_QUEUE;
+       else if (ioc->bus_type == SAS)
+               num_chain *= MPT_SAS_CAN_QUEUE;
        else
                num_chain *= MPT_FC_CAN_QUEUE;
 
@@ -3877,12 +4370,42 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
        dma_addr_t alloc_dma;
        u8 *mem;
        int i, reply_sz, sz, total_size, num_chain;
+       u64     dma_mask;
+
+       dma_mask = 0;
 
        /*  Prime reply FIFO...  */
 
        if (ioc->reply_frames == NULL) {
                if ( (num_chain = initChainBuffers(ioc)) < 0)
                        return -1;
+               /*
+                * 1078 errata workaround for the 36GB limitation
+                */
+               if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078 &&
+                   ioc->dma_mask > DMA_BIT_MASK(35)) {
+                       if (!pci_set_dma_mask(ioc->pcidev, DMA_BIT_MASK(32))
+                           && !pci_set_consistent_dma_mask(ioc->pcidev,
+                           DMA_BIT_MASK(32))) {
+                               dma_mask = DMA_BIT_MASK(35);
+                               d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                                   "setting 35 bit addressing for "
+                                   "Request/Reply/Chain and Sense Buffers\n",
+                                   ioc->name));
+                       } else {
+                               /*Reseting DMA mask to 64 bit*/
+                               pci_set_dma_mask(ioc->pcidev,
+                                       DMA_BIT_MASK(64));
+                               pci_set_consistent_dma_mask(ioc->pcidev,
+                                       DMA_BIT_MASK(64));
+
+                               printk(MYIOC_s_ERR_FMT
+                                   "failed setting 35 bit addressing for "
+                                   "Request/Reply/Chain and Sense Buffers\n",
+                                   ioc->name);
+                               return -1;
+                       }
+               }
 
                total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
                dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
@@ -4021,9 +4544,16 @@ PrimeIocFifos(MPT_ADAPTER *ioc)
                alloc_dma += ioc->reply_sz;
        }
 
+       if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
+           ioc->dma_mask) && !pci_set_consistent_dma_mask(ioc->pcidev,
+           ioc->dma_mask))
+               d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "restoring 64 bit addressing\n", ioc->name));
+
        return 0;
 
 out_fail:
+
        if (ioc->alloc != NULL) {
                sz = ioc->alloc_sz;
                pci_free_consistent(ioc->pcidev,
@@ -4040,6 +4570,13 @@ out_fail:
                                ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
                ioc->sense_buf_pool = NULL;
        }
+
+       if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
+           DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(ioc->pcidev,
+           DMA_BIT_MASK(64)))
+               d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "restoring 64 bit addressing\n", ioc->name));
+
        return -1;
 }
 
@@ -4129,7 +4666,7 @@ mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
                }
 
                dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handshake request frame (@%p) header\n", ioc->name, req));
-               DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)req)
+               DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)req);
 
                dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request post done, WaitCnt=%d%s\n",
                                ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
@@ -4310,7 +4847,7 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
                        failcnt++;
                hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
                /* don't overflow our IOC hs_reply[] buffer! */
-               if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
+               if (u16cnt < ARRAY_SIZE(ioc->hs_reply))
                        hs_reply[u16cnt] = hword;
                CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
        }
@@ -4334,7 +4871,7 @@ WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
 #endif
 
        dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got Handshake reply:\n", ioc->name));
-       DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mptReply)
+       DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mptReply);
 
        dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
                        ioc->name, t, u16cnt/2));
@@ -4475,7 +5012,14 @@ mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
        SasIoUnitControlReply_t         *sasIoUnitCntrReply;
        MPT_FRAME_HDR                   *mf = NULL;
        MPIHeader_t                     *mpi_hdr;
+       int                             ret = 0;
+       unsigned long                   timeleft;
+
+       mutex_lock(&ioc->mptbase_cmds.mutex);
 
+       /* init the internal cmd struct */
+       memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
+       INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
 
        /* insure garbage is not sent to fw */
        switch(persist_opcode) {
@@ -4485,17 +5029,19 @@ mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
                break;
 
        default:
-               return -1;
-               break;
+               ret = -1;
+               goto out;
        }
 
-       printk("%s: persist_opcode=%x\n",__FUNCTION__, persist_opcode);
+       printk(KERN_DEBUG  "%s: persist_opcode=%x\n",
+               __func__, persist_opcode);
 
        /* Get a MF for this command.
         */
        if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
-               printk("%s: no msg frames!\n",__FUNCTION__);
-               return -1;
+               printk(KERN_DEBUG "%s: no msg frames!\n", __func__);
+               ret = -1;
+               goto out;
         }
 
        mpi_hdr = (MPIHeader_t *) mf;
@@ -4505,27 +5051,43 @@ mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
        sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
        sasIoUnitCntrReq->Operation = persist_opcode;
 
-       init_timer(&ioc->persist_timer);
-       ioc->persist_timer.data = (unsigned long) ioc;
-       ioc->persist_timer.function = mpt_timer_expired;
-       ioc->persist_timer.expires = jiffies + HZ*10 /* 10 sec */;
-       ioc->persist_wait_done=0;
-       add_timer(&ioc->persist_timer);
        mpt_put_msg_frame(mpt_base_index, ioc, mf);
-       wait_event(mpt_waitq, ioc->persist_wait_done);
+       timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, 10*HZ);
+       if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = -ETIME;
+               printk(KERN_DEBUG "%s: failed\n", __func__);
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
+                       goto out;
+               if (!timeleft) {
+                       printk(MYIOC_s_WARN_FMT
+                              "Issuing Reset from %s!!, doorbell=0x%08x\n",
+                              ioc->name, __func__, mpt_GetIocState(ioc, 0));
+                       mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
+                       mpt_free_msg_frame(ioc, mf);
+               }
+               goto out;
+       }
+
+       if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
+               ret = -1;
+               goto out;
+       }
 
        sasIoUnitCntrReply =
-           (SasIoUnitControlReply_t *)ioc->persist_reply_frame;
+           (SasIoUnitControlReply_t *)ioc->mptbase_cmds.reply;
        if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
-               printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
-                   __FUNCTION__,
-                   sasIoUnitCntrReply->IOCStatus,
+               printk(KERN_DEBUG "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
+                   __func__, sasIoUnitCntrReply->IOCStatus,
                    sasIoUnitCntrReply->IOCLogInfo);
-               return -1;
-       }
+               printk(KERN_DEBUG "%s: failed\n", __func__);
+               ret = -1;
+       } else
+               printk(KERN_DEBUG "%s: success\n", __func__);
+ out:
 
-       printk("%s: success\n",__FUNCTION__);
-       return 0;
+       CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
+       mutex_unlock(&ioc->mptbase_cmds.mutex);
+       return ret;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -4809,8 +5371,8 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
 
                                if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
                                        ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
-                                       ddvprintk(ioc, printk(KERN_INFO MYNAM
-                                               " :%s noQas due to Capabilities=%x\n",
+                                       ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                                               "noQas due to Capabilities=%x\n",
                                                ioc->name, pPP0->Capabilities));
                                }
                                ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
@@ -4873,6 +5435,38 @@ mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
                                /* Nvram data is left with INVALID mark
                                 */
                                rc = 1;
+                       } else if (ioc->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
+
+                               /* This is an ATTO adapter, read Page2 accordingly
+                               */
+                               ATTO_SCSIPortPage2_t *pPP2 = (ATTO_SCSIPortPage2_t  *) pbuf;
+                               ATTODeviceInfo_t *pdevice = NULL;
+                               u16 ATTOFlags;
+
+                               /* Save the Port Page 2 data
+                                * (reformat into a 32bit quantity)
+                                */
+                               for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
+                                 pdevice = &pPP2->DeviceSettings[ii];
+                                 ATTOFlags = le16_to_cpu(pdevice->ATTOFlags);
+                                 data = 0;
+
+                                 /* Translate ATTO device flags to LSI format
+                                  */
+                                 if (ATTOFlags & ATTOFLAG_DISC)
+                                   data |= (MPI_SCSIPORTPAGE2_DEVICE_DISCONNECT_ENABLE);
+                                 if (ATTOFlags & ATTOFLAG_ID_ENB)
+                                   data |= (MPI_SCSIPORTPAGE2_DEVICE_ID_SCAN_ENABLE);
+                                 if (ATTOFlags & ATTOFLAG_LUN_ENB)
+                                   data |= (MPI_SCSIPORTPAGE2_DEVICE_LUN_SCAN_ENABLE);
+                                 if (ATTOFlags & ATTOFLAG_TAGGED)
+                                   data |= (MPI_SCSIPORTPAGE2_DEVICE_TAG_QUEUE_ENABLE);
+                                 if (!(ATTOFlags & ATTOFLAG_WIDE_ENB))
+                                   data |= (MPI_SCSIPORTPAGE2_DEVICE_WIDE_DISABLE);
+
+                                 data = (data << 16) | (pdevice->Period << 8) | 10;
+                                 ioc->spi_data.nvram[ii] = data;
+                               }
                        } else {
                                SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t  *) pbuf;
                                MpiDeviceInfo_t *pdevice = NULL;
@@ -4973,13 +5567,13 @@ mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
        if (list_empty(&ioc->raid_data.inactive_list))
                return;
 
-       down(&ioc->raid_data.inactive_list_mutex);
+       mutex_lock(&ioc->raid_data.inactive_list_mutex);
        list_for_each_entry_safe(component_info, pNext,
            &ioc->raid_data.inactive_list, list) {
                list_del(&component_info->list);
                kfree(component_info);
        }
-       up(&ioc->raid_data.inactive_list_mutex);
+       mutex_unlock(&ioc->raid_data.inactive_list_mutex);
 }
 
 /**
@@ -5038,7 +5632,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
        if (!handle_inactive_volumes)
                goto out;
 
-       down(&ioc->raid_data.inactive_list_mutex);
+       mutex_lock(&ioc->raid_data.inactive_list_mutex);
        for (i = 0; i < buffer->NumPhysDisks; i++) {
                if(mpt_raid_phys_disk_pg0(ioc,
                    buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
@@ -5058,7 +5652,7 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
                list_add_tail(&component_info->list,
                    &ioc->raid_data.inactive_list);
        }
-       up(&ioc->raid_data.inactive_list_mutex);
+       mutex_unlock(&ioc->raid_data.inactive_list_mutex);
 
  out:
        if (buffer)
@@ -5078,17 +5672,20 @@ mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
  *     -ENOMEM if pci_alloc failed
  **/
 int
-mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk)
+mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num,
+                       RaidPhysDiskPage0_t *phys_disk)
 {
-       CONFIGPARMS                     cfg;
-       ConfigPageHeader_t              hdr;
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              hdr;
        dma_addr_t                      dma_handle;
        pRaidPhysDiskPage0_t            buffer = NULL;
        int                             rc;
 
        memset(&cfg, 0 , sizeof(CONFIGPARMS));
        memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
+       memset(phys_disk, 0, sizeof(RaidPhysDiskPage0_t));
 
+       hdr.PageVersion = MPI_RAIDPHYSDISKPAGE0_PAGEVERSION;
        hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
        cfg.cfghdr.hdr = &hdr;
        cfg.physAddr = -1;
@@ -5135,9 +5732,163 @@ mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t
 }
 
 /**
+ *     mpt_raid_phys_disk_get_num_paths - returns number paths associated to this phys_num
+ *     @ioc: Pointer to a Adapter Structure
+ *     @phys_disk_num: io unit unique phys disk num generated by the ioc
+ *
+ *     Return:
+ *     returns number paths
+ **/
+int
+mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num)
+{
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              hdr;
+       dma_addr_t                      dma_handle;
+       pRaidPhysDiskPage1_t            buffer = NULL;
+       int                             rc;
+
+       memset(&cfg, 0 , sizeof(CONFIGPARMS));
+       memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
+
+       hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
+       hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
+       hdr.PageNumber = 1;
+       cfg.cfghdr.hdr = &hdr;
+       cfg.physAddr = -1;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
+
+       if (mpt_config(ioc, &cfg) != 0) {
+               rc = 0;
+               goto out;
+       }
+
+       if (!hdr.PageLength) {
+               rc = 0;
+               goto out;
+       }
+
+       buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
+           &dma_handle);
+
+       if (!buffer) {
+               rc = 0;
+               goto out;
+       }
+
+       cfg.physAddr = dma_handle;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+       cfg.pageAddr = phys_disk_num;
+
+       if (mpt_config(ioc, &cfg) != 0) {
+               rc = 0;
+               goto out;
+       }
+
+       rc = buffer->NumPhysDiskPaths;
+ out:
+
+       if (buffer)
+               pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
+                   dma_handle);
+
+       return rc;
+}
+EXPORT_SYMBOL(mpt_raid_phys_disk_get_num_paths);
+
+/**
+ *     mpt_raid_phys_disk_pg1 - returns phys disk page 1
+ *     @ioc: Pointer to a Adapter Structure
+ *     @phys_disk_num: io unit unique phys disk num generated by the ioc
+ *     @phys_disk: requested payload data returned
+ *
+ *     Return:
+ *     0 on success
+ *     -EFAULT if read of config page header fails or data pointer not NULL
+ *     -ENOMEM if pci_alloc failed
+ **/
+int
+mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num,
+               RaidPhysDiskPage1_t *phys_disk)
+{
+       CONFIGPARMS                     cfg;
+       ConfigPageHeader_t              hdr;
+       dma_addr_t                      dma_handle;
+       pRaidPhysDiskPage1_t            buffer = NULL;
+       int                             rc;
+       int                             i;
+       __le64                          sas_address;
+
+       memset(&cfg, 0 , sizeof(CONFIGPARMS));
+       memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
+       rc = 0;
+
+       hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
+       hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
+       hdr.PageNumber = 1;
+       cfg.cfghdr.hdr = &hdr;
+       cfg.physAddr = -1;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
+
+       if (mpt_config(ioc, &cfg) != 0) {
+               rc = -EFAULT;
+               goto out;
+       }
+
+       if (!hdr.PageLength) {
+               rc = -EFAULT;
+               goto out;
+       }
+
+       buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
+           &dma_handle);
+
+       if (!buffer) {
+               rc = -ENOMEM;
+               goto out;
+       }
+
+       cfg.physAddr = dma_handle;
+       cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
+       cfg.pageAddr = phys_disk_num;
+
+       if (mpt_config(ioc, &cfg) != 0) {
+               rc = -EFAULT;
+               goto out;
+       }
+
+       phys_disk->NumPhysDiskPaths = buffer->NumPhysDiskPaths;
+       phys_disk->PhysDiskNum = phys_disk_num;
+       for (i = 0; i < phys_disk->NumPhysDiskPaths; i++) {
+               phys_disk->Path[i].PhysDiskID = buffer->Path[i].PhysDiskID;
+               phys_disk->Path[i].PhysDiskBus = buffer->Path[i].PhysDiskBus;
+               phys_disk->Path[i].OwnerIdentifier =
+                               buffer->Path[i].OwnerIdentifier;
+               phys_disk->Path[i].Flags = le16_to_cpu(buffer->Path[i].Flags);
+               memcpy(&sas_address, &buffer->Path[i].WWID, sizeof(__le64));
+               sas_address = le64_to_cpu(sas_address);
+               memcpy(&phys_disk->Path[i].WWID, &sas_address, sizeof(__le64));
+               memcpy(&sas_address,
+                               &buffer->Path[i].OwnerWWID, sizeof(__le64));
+               sas_address = le64_to_cpu(sas_address);
+               memcpy(&phys_disk->Path[i].OwnerWWID,
+                               &sas_address, sizeof(__le64));
+       }
+
+ out:
+
+       if (buffer)
+               pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
+                   dma_handle);
+
+       return rc;
+}
+EXPORT_SYMBOL(mpt_raid_phys_disk_pg1);
+
+
+/**
  *     mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  *     @ioc: Pointer to a Adapter Strucutre
- *     @portnum: IOC port number
  *
  *     Return:
  *     0 on success
@@ -5194,8 +5945,10 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
                goto out;
 
        mem = kmalloc(iocpage2sz, GFP_KERNEL);
-       if (!mem)
+       if (!mem) {
+               rc = -ENOMEM;
                goto out;
+       }
 
        memcpy(mem, (u8 *)pIoc2, iocpage2sz);
        ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
@@ -5460,30 +6213,28 @@ mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc)
  *     SendEventNotification - Send EventNotification (on or off) request to adapter
  *     @ioc: Pointer to MPT_ADAPTER structure
  *     @EvSwitch: Event switch flags
+ *     @sleepFlag: Specifies whether the process can sleep
  */
 static int
-SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
+SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag)
 {
-       EventNotification_t     *evnp;
-
-       evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
-       if (evnp == NULL) {
-               devtverboseprintk(ioc, printk(MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
-                               ioc->name));
-               return 0;
-       }
-       memset(evnp, 0, sizeof(*evnp));
+       EventNotification_t     evn;
+       MPIDefaultReply_t       reply_buf;
 
-       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending EventNotification (%d) request %p\n", ioc->name, EvSwitch, evnp));
+       memset(&evn, 0, sizeof(EventNotification_t));
+       memset(&reply_buf, 0, sizeof(MPIDefaultReply_t));
 
-       evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
-       evnp->ChainOffset = 0;
-       evnp->MsgFlags = 0;
-       evnp->Switch = EvSwitch;
+       evn.Function = MPI_FUNCTION_EVENT_NOTIFICATION;
+       evn.Switch = EvSwitch;
+       evn.MsgContext = cpu_to_le32(mpt_base_index << 16);
 
-       mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
+       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+           "Sending EventNotification (%d) request %p\n",
+           ioc->name, EvSwitch, &evn));
 
-       return 0;
+       return mpt_handshake_req_reply_wait(ioc, sizeof(EventNotification_t),
+           (u32 *)&evn, sizeof(MPIDefaultReply_t), (u16 *)&reply_buf, 30,
+           sleepFlag);
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -5499,7 +6250,7 @@ SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
 
        if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
                dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
-                   ioc->name,__FUNCTION__));
+                   ioc->name, __func__));
                return -1;
        }
 
@@ -5536,12 +6287,19 @@ int
 mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
 {
        Config_t        *pReq;
+       ConfigReply_t   *pReply;
        ConfigExtendedPageHeader_t  *pExtHdr = NULL;
        MPT_FRAME_HDR   *mf;
-       unsigned long    flags;
-       int              ii, rc;
+       int              ii;
        int              flagsLength;
-       int              in_isr;
+       long             timeout;
+       int              ret;
+       u8               page_type = 0, extend_page;
+       unsigned long    timeleft;
+       unsigned long    flags;
+    int                 in_isr;
+       u8               issue_hard_reset = 0;
+       u8               retry_count = 0;
 
        /*      Prevent calling wait_event() (below), if caller happens
         *      to be in ISR context, because that is fatal!
@@ -5551,15 +6309,43 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
                dcprintk(ioc, printk(MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
                                ioc->name));
                return -EPERM;
+    }
+
+       /* don't send a config page during diag reset */
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->ioc_reset_in_progress) {
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: busy with host reset\n", ioc->name, __func__));
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+               return -EBUSY;
+       }
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+
+       /* don't send if no chance of success */
+       if (!ioc->active ||
+           mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_OPERATIONAL) {
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: ioc not operational, %d, %xh\n",
+                   ioc->name, __func__, ioc->active,
+                   mpt_GetIocState(ioc, 0)));
+               return -EFAULT;
        }
 
+ retry_config:
+       mutex_lock(&ioc->mptbase_cmds.mutex);
+       /* init the internal cmd struct */
+       memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
+       INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
+
        /* Get and Populate a free Frame
         */
        if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
-               dcprintk(ioc, printk(MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
-                               ioc->name));
-               return -EAGAIN;
+               dcprintk(ioc, printk(MYIOC_s_WARN_FMT
+               "mpt_config: no msg frames!\n", ioc->name));
+               ret = -EAGAIN;
+               goto out;
        }
+
        pReq = (Config_t *)mf;
        pReq->Action = pCfg->action;
        pReq->Reserved = 0;
@@ -5585,7 +6371,9 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
                pReq->ExtPageType = pExtHdr->ExtPageType;
                pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
 
-               /* Page Length must be treated as a reserved field for the extended header. */
+               /* Page Length must be treated as a reserved field for the
+                * extended header.
+                */
                pReq->Header.PageLength = 0;
        }
 
@@ -5598,78 +6386,97 @@ mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
        else
                flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
 
-       if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
+       if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
+           MPI_CONFIG_PAGETYPE_EXTENDED) {
                flagsLength |= pExtHdr->ExtPageLength * 4;
-
-               dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Config request type %d, page %d and action %d\n",
-                       ioc->name, pReq->ExtPageType, pReq->Header.PageNumber, pReq->Action));
-       }
-       else {
+               page_type = pReq->ExtPageType;
+               extend_page = 1;
+       } else {
                flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
-
-               dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Config request type %d, page %d and action %d\n",
-                       ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
+               page_type = pReq->Header.PageType;
+               extend_page = 0;
        }
 
-       mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
-
-       /* Append pCfg pointer to end of mf
-        */
-       *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) =  (void *) pCfg;
-
-       /* Initalize the timer
-        */
-       init_timer(&pCfg->timer);
-       pCfg->timer.data = (unsigned long) ioc;
-       pCfg->timer.function = mpt_timer_expired;
-       pCfg->wait_done = 0;
-
-       /* Set the timer; ensure 10 second minimum */
-       if (pCfg->timeout < 10)
-               pCfg->timer.expires = jiffies + HZ*10;
-       else
-               pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
-
-       /* Add to end of Q, set timer and then issue this command */
-       spin_lock_irqsave(&ioc->FreeQlock, flags);
-       list_add_tail(&pCfg->linkage, &ioc->configQ);
-       spin_unlock_irqrestore(&ioc->FreeQlock, flags);
+       dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+           "Sending Config request type 0x%x, page 0x%x and action %d\n",
+           ioc->name, page_type, pReq->Header.PageNumber, pReq->Action));
 
-       add_timer(&pCfg->timer);
+       ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
+       timeout = (pCfg->timeout < 15) ? HZ*15 : HZ*pCfg->timeout;
        mpt_put_msg_frame(mpt_base_index, ioc, mf);
-       wait_event(mpt_waitq, pCfg->wait_done);
+       timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done,
+               timeout);
+       if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
+               ret = -ETIME;
+               dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "Failed Sending Config request type 0x%x, page 0x%x,"
+                   " action %d, status %xh, time left %ld\n\n",
+                       ioc->name, page_type, pReq->Header.PageNumber,
+                       pReq->Action, ioc->mptbase_cmds.status, timeleft));
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
+                       goto out;
+               if (!timeleft)
+                       issue_hard_reset = 1;
+               goto out;
+       }
 
-       /* mf has been freed - do not access */
+       if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
+               ret = -1;
+               goto out;
+       }
+       pReply = (ConfigReply_t *)ioc->mptbase_cmds.reply;
+       ret = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
+       if (ret == MPI_IOCSTATUS_SUCCESS) {
+               if (extend_page) {
+                       pCfg->cfghdr.ehdr->ExtPageLength =
+                           le16_to_cpu(pReply->ExtPageLength);
+                       pCfg->cfghdr.ehdr->ExtPageType =
+                           pReply->ExtPageType;
+               }
+               pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
+               pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
+               pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
+               pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
 
-       rc = pCfg->status;
+       }
 
-       return rc;
-}
+       if (retry_count)
+               printk(MYIOC_s_INFO_FMT "Retry completed "
+                   "ret=0x%x timeleft=%ld\n",
+                   ioc->name, ret, timeleft);
 
-/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-/**
- *     mpt_timer_expired - Callback for timer process.
- *     Used only internal config functionality.
- *     @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
- */
-static void
-mpt_timer_expired(unsigned long data)
-{
-       MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
+       dcprintk(ioc, printk(KERN_DEBUG "IOCStatus=%04xh, IOCLogInfo=%08xh\n",
+            ret, le32_to_cpu(pReply->IOCLogInfo)));
 
-       dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_timer_expired! \n", ioc->name));
+out:
 
-       /* Perform a FW reload */
-       if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
-               printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
+       CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
+       mutex_unlock(&ioc->mptbase_cmds.mutex);
+       if (issue_hard_reset) {
+               issue_hard_reset = 0;
+               printk(MYIOC_s_WARN_FMT
+                      "Issuing Reset from %s!!, doorbell=0x%08x\n",
+                      ioc->name, __func__, mpt_GetIocState(ioc, 0));
+               if (retry_count == 0) {
+                       if (mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP) != 0)
+                               retry_count++;
+               } else
+                       mpt_HardResetHandler(ioc, CAN_SLEEP);
 
-       /* No more processing.
-        * Hard reset clean-up will wake up
-        * process and free all resources.
-        */
-       dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_timer_expired complete!\n", ioc->name));
+               mpt_free_msg_frame(ioc, mf);
+               /* attempt one retry for a timed out command */
+               if (retry_count < 2) {
+                       printk(MYIOC_s_INFO_FMT
+                           "Attempting Retry Config request"
+                           " type 0x%x, page 0x%x,"
+                           " action %d\n", ioc->name, page_type,
+                           pCfg->cfghdr.hdr->PageNumber, pCfg->action);
+                       retry_count++;
+                       goto retry_config;
+               }
+       }
+       return ret;
 
-       return;
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -5683,41 +6490,34 @@ mpt_timer_expired(unsigned long data)
 static int
 mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
 {
-       CONFIGPARMS *pCfg;
-       unsigned long flags;
-
-       dprintk(ioc, printk(KERN_DEBUG MYNAM
-                       ": IOC %s_reset routed to MPT base driver!\n",
-                       reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
-                       reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
-
-       if (reset_phase == MPT_IOC_SETUP_RESET) {
-               ;
-       } else if (reset_phase == MPT_IOC_PRE_RESET) {
-               /* If the internal config Q is not empty -
-                * delete timer. MF resources will be freed when
-                * the FIFO's are primed.
-                */
-               spin_lock_irqsave(&ioc->FreeQlock, flags);
-               list_for_each_entry(pCfg, &ioc->configQ, linkage)
-                       del_timer(&pCfg->timer);
-               spin_unlock_irqrestore(&ioc->FreeQlock, flags);
-
-       } else {
-               CONFIGPARMS *pNext;
-
-               /* Search the configQ for internal commands.
-                * Flush the Q, and wake up all suspended threads.
-                */
-               spin_lock_irqsave(&ioc->FreeQlock, flags);
-               list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
-                       list_del(&pCfg->linkage);
-
-                       pCfg->status = MPT_CONFIG_ERROR;
-                       pCfg->wait_done = 1;
-                       wake_up(&mpt_waitq);
+       switch (reset_phase) {
+       case MPT_IOC_SETUP_RESET:
+               ioc->taskmgmt_quiesce_io = 1;
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
+               break;
+       case MPT_IOC_PRE_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
+               break;
+       case MPT_IOC_POST_RESET:
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "%s: MPT_IOC_POST_RESET\n",  ioc->name, __func__));
+/* wake up mptbase_cmds */
+               if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
+                       ioc->mptbase_cmds.status |=
+                           MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->mptbase_cmds.done);
                }
-               spin_unlock_irqrestore(&ioc->FreeQlock, flags);
+/* wake up taskmgmt_cmds */
+               if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
+                       ioc->taskmgmt_cmds.status |=
+                               MPT_MGMT_STATUS_DID_IOCRESET;
+                       complete(&ioc->taskmgmt_cmds.done);
+               }
+               break;
+       default:
+               break;
        }
 
        return 1;               /* currently means nothing really */
@@ -5738,20 +6538,12 @@ mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
 static int
 procmpt_create(void)
 {
-       struct proc_dir_entry   *ent;
-
        mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
        if (mpt_proc_root_dir == NULL)
                return -ENOTDIR;
 
-       ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
-       if (ent)
-               ent->read_proc = procmpt_summary_read;
-
-       ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
-       if (ent)
-               ent->read_proc = procmpt_version_read;
-
+       proc_create("summary", S_IRUGO, mpt_proc_root_dir, &mpt_summary_proc_fops);
+       proc_create("version", S_IRUGO, mpt_proc_root_dir, &mpt_version_proc_fops);
        return 0;
 }
 
@@ -5770,77 +6562,53 @@ procmpt_destroy(void)
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-/**
- *     procmpt_summary_read - Handle read request of a summary file
- *     @buf: Pointer to area to write information
- *     @start: Pointer to start pointer
- *     @offset: Offset to start writing
- *     @request: Amount of read data requested
- *     @eof: Pointer to EOF integer
- *     @data: Pointer
- *
+/*
  *     Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
- *     Returns number of characters written to process performing the read.
  */
-static int
-procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
-{
-       MPT_ADAPTER *ioc;
-       char *out = buf;
-       int len;
+static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan);
 
-       if (data) {
-               int more = 0;
-
-               ioc = data;
-               mpt_print_ioc_summary(ioc, out, &more, 0, 1);
+static int mpt_summary_proc_show(struct seq_file *m, void *v)
+{
+       MPT_ADAPTER *ioc = m->private;
 
-               out += more;
+       if (ioc) {
+               seq_mpt_print_ioc_summary(ioc, m, 1);
        } else {
                list_for_each_entry(ioc, &ioc_list, list) {
-                       int     more = 0;
-
-                       mpt_print_ioc_summary(ioc, out, &more, 0, 1);
-
-                       out += more;
-                       if ((out-buf) >= request)
-                               break;
+                       seq_mpt_print_ioc_summary(ioc, m, 1);
                }
        }
 
-       len = out - buf;
+       return 0;
+}
 
-       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+static int mpt_summary_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mpt_summary_proc_show, PDE(inode)->data);
 }
 
-/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-/**
- *     procmpt_version_read - Handle read request from /proc/mpt/version.
- *     @buf: Pointer to area to write information
- *     @start: Pointer to start pointer
- *     @offset: Offset to start writing
- *     @request: Amount of read data requested
- *     @eof: Pointer to EOF integer
- *     @data: Pointer
- *
- *     Returns number of characters written to process performing the read.
- */
-static int
-procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
+static const struct file_operations mpt_summary_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mpt_summary_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int mpt_version_proc_show(struct seq_file *m, void *v)
 {
-       int      ii;
+       u8       cb_idx;
        int      scsi, fc, sas, lan, ctl, targ, dmp;
        char    *drvname;
-       int      len;
 
-       len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
-       len += sprintf(buf+len, "  Fusion MPT base driver\n");
+       seq_printf(m, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
+       seq_printf(m, "  Fusion MPT base driver\n");
 
        scsi = fc = sas = lan = ctl = targ = dmp = 0;
-       for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
                drvname = NULL;
-               if (MptCallbacks[ii]) {
-                       switch (MptDriverClass[ii]) {
+               if (MptCallbacks[cb_idx]) {
+                       switch (MptDriverClass[cb_idx]) {
                        case MPTSPI_DRIVER:
                                if (!scsi++) drvname = "SPI host";
                                break;
@@ -5862,98 +6630,97 @@ procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eo
                        }
 
                        if (drvname)
-                               len += sprintf(buf+len, "  Fusion MPT %s driver\n", drvname);
+                               seq_printf(m, "  Fusion MPT %s driver\n", drvname);
                }
        }
 
-       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+       return 0;
 }
 
-/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
-/**
- *     procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
- *     @buf: Pointer to area to write information
- *     @start: Pointer to start pointer
- *     @offset: Offset to start writing
- *     @request: Amount of read data requested
- *     @eof: Pointer to EOF integer
- *     @data: Pointer
- *
- *     Returns number of characters written to process performing the read.
- */
-static int
-procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
+static int mpt_version_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mpt_version_proc_show, NULL);
+}
+
+static const struct file_operations mpt_version_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mpt_version_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
+static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
 {
-       MPT_ADAPTER     *ioc = data;
-       int              len;
+       MPT_ADAPTER     *ioc = m->private;
        char             expVer[32];
        int              sz;
        int              p;
 
        mpt_get_fw_exp_ver(expVer, ioc);
 
-       len = sprintf(buf, "%s:", ioc->name);
+       seq_printf(m, "%s:", ioc->name);
        if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
-               len += sprintf(buf+len, "  (f/w download boot flag set)");
+               seq_printf(m, "  (f/w download boot flag set)");
 //     if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
-//             len += sprintf(buf+len, "  CONFIG_CHECKSUM_FAIL!");
+//             seq_printf(m, "  CONFIG_CHECKSUM_FAIL!");
 
-       len += sprintf(buf+len, "\n  ProductID = 0x%04x (%s)\n",
+       seq_printf(m, "\n  ProductID = 0x%04x (%s)\n",
                        ioc->facts.ProductID,
                        ioc->prod_name);
-       len += sprintf(buf+len, "  FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
+       seq_printf(m, "  FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
        if (ioc->facts.FWImageSize)
-               len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
-       len += sprintf(buf+len, "\n  MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
-       len += sprintf(buf+len, "  FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
-       len += sprintf(buf+len, "  EventState = 0x%02x\n", ioc->facts.EventState);
+               seq_printf(m, " (fw_size=%d)", ioc->facts.FWImageSize);
+       seq_printf(m, "\n  MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
+       seq_printf(m, "  FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
+       seq_printf(m, "  EventState = 0x%02x\n", ioc->facts.EventState);
 
-       len += sprintf(buf+len, "  CurrentHostMfaHighAddr = 0x%08x\n",
+       seq_printf(m, "  CurrentHostMfaHighAddr = 0x%08x\n",
                        ioc->facts.CurrentHostMfaHighAddr);
-       len += sprintf(buf+len, "  CurrentSenseBufferHighAddr = 0x%08x\n",
+       seq_printf(m, "  CurrentSenseBufferHighAddr = 0x%08x\n",
                        ioc->facts.CurrentSenseBufferHighAddr);
 
-       len += sprintf(buf+len, "  MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
-       len += sprintf(buf+len, "  MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
+       seq_printf(m, "  MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
+       seq_printf(m, "  MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
 
-       len += sprintf(buf+len, "  RequestFrames @ 0x%p (Dma @ 0x%p)\n",
+       seq_printf(m, "  RequestFrames @ 0x%p (Dma @ 0x%p)\n",
                                        (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
        /*
         *  Rounding UP to nearest 4-kB boundary here...
         */
        sz = (ioc->req_sz * ioc->req_depth) + 128;
        sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
-       len += sprintf(buf+len, "    {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
+       seq_printf(m, "    {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
                                        ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
-       len += sprintf(buf+len, "    {MaxReqSz=%d}   {MaxReqDepth=%d}\n",
+       seq_printf(m, "    {MaxReqSz=%d}   {MaxReqDepth=%d}\n",
                                        4*ioc->facts.RequestFrameSize,
                                        ioc->facts.GlobalCredits);
 
-       len += sprintf(buf+len, "  Frames   @ 0x%p (Dma @ 0x%p)\n",
+       seq_printf(m, "  Frames   @ 0x%p (Dma @ 0x%p)\n",
                                        (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
        sz = (ioc->reply_sz * ioc->reply_depth) + 128;
-       len += sprintf(buf+len, "    {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
+       seq_printf(m, "    {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
                                        ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
-       len += sprintf(buf+len, "    {MaxRepSz=%d}   {MaxRepDepth=%d}\n",
+       seq_printf(m, "    {MaxRepSz=%d}   {MaxRepDepth=%d}\n",
                                        ioc->facts.CurReplyFrameSize,
                                        ioc->facts.ReplyQueueDepth);
 
-       len += sprintf(buf+len, "  MaxDevices = %d\n",
+       seq_printf(m, "  MaxDevices = %d\n",
                        (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
-       len += sprintf(buf+len, "  MaxBuses = %d\n", ioc->facts.MaxBuses);
+       seq_printf(m, "  MaxBuses = %d\n", ioc->facts.MaxBuses);
 
        /* per-port info */
        for (p=0; p < ioc->facts.NumberOfPorts; p++) {
-               len += sprintf(buf+len, "  PortNumber = %d (of %d)\n",
+               seq_printf(m, "  PortNumber = %d (of %d)\n",
                                p+1,
                                ioc->facts.NumberOfPorts);
                if (ioc->bus_type == FC) {
                        if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
                                u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
-                               len += sprintf(buf+len, "    LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
+                               seq_printf(m, "    LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
                                                a[5], a[4], a[3], a[2], a[1], a[0]);
                        }
-                       len += sprintf(buf+len, "    WWN = %08X%08X:%08X%08X\n",
+                       seq_printf(m, "    WWN = %08X%08X:%08X%08X\n",
                                        ioc->fc_port_page0[p].WWNN.High,
                                        ioc->fc_port_page0[p].WWNN.Low,
                                        ioc->fc_port_page0[p].WWPN.High,
@@ -5961,9 +6728,21 @@ procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eo
                }
        }
 
-       MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
+       return 0;
+}
+
+static int mpt_iocinfo_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, mpt_iocinfo_proc_show, PDE(inode)->data);
 }
 
+static const struct file_operations mpt_iocinfo_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = mpt_iocinfo_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
 #endif         /* CONFIG_PROC_FS } */
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -6030,6 +6809,284 @@ mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int sh
        *size = y;
 }
 
+static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan)
+{
+       char expVer[32];
+
+       mpt_get_fw_exp_ver(expVer, ioc);
+
+       /*
+        *  Shorter summary of attached ioc's...
+        */
+       seq_printf(m, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
+                       ioc->name,
+                       ioc->prod_name,
+                       MPT_FW_REV_MAGIC_ID_STRING,     /* "FwRev=" or somesuch */
+                       ioc->facts.FWVersion.Word,
+                       expVer,
+                       ioc->facts.NumberOfPorts,
+                       ioc->req_depth);
+
+       if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
+               u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
+               seq_printf(m, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
+                       a[5], a[4], a[3], a[2], a[1], a[0]);
+       }
+
+       seq_printf(m, ", IRQ=%d", ioc->pci_irq);
+
+       if (!ioc->active)
+               seq_printf(m, " (disabled)");
+
+       seq_putc(m, '\n');
+}
+
+/**
+ *     mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
+ *     @ioc: Pointer to MPT_ADAPTER structure
+ *
+ *     Returns 0 for SUCCESS or -1 if FAILED.
+ *
+ *     If -1 is return, then it was not possible to set the flags
+ **/
+int
+mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
+{
+       unsigned long    flags;
+       int              retval;
+
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->ioc_reset_in_progress || ioc->taskmgmt_in_progress ||
+           (ioc->alt_ioc && ioc->alt_ioc->taskmgmt_in_progress)) {
+               retval = -1;
+               goto out;
+       }
+       retval = 0;
+       ioc->taskmgmt_in_progress = 1;
+       ioc->taskmgmt_quiesce_io = 1;
+       if (ioc->alt_ioc) {
+               ioc->alt_ioc->taskmgmt_in_progress = 1;
+               ioc->alt_ioc->taskmgmt_quiesce_io = 1;
+       }
+ out:
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+       return retval;
+}
+EXPORT_SYMBOL(mpt_set_taskmgmt_in_progress_flag);
+
+/**
+ *     mpt_clear_taskmgmt_in_progress_flag - clear flags associated with task management
+ *     @ioc: Pointer to MPT_ADAPTER structure
+ *
+ **/
+void
+mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
+{
+       unsigned long    flags;
+
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       ioc->taskmgmt_in_progress = 0;
+       ioc->taskmgmt_quiesce_io = 0;
+       if (ioc->alt_ioc) {
+               ioc->alt_ioc->taskmgmt_in_progress = 0;
+               ioc->alt_ioc->taskmgmt_quiesce_io = 0;
+       }
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+}
+EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag);
+
+
+/**
+ *     mpt_halt_firmware - Halts the firmware if it is operational and panic
+ *     the kernel
+ *     @ioc: Pointer to MPT_ADAPTER structure
+ *
+ **/
+void
+mpt_halt_firmware(MPT_ADAPTER *ioc)
+{
+       u32      ioc_raw_state;
+
+       ioc_raw_state = mpt_GetIocState(ioc, 0);
+
+       if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
+               printk(MYIOC_s_ERR_FMT "IOC is in FAULT state (%04xh)!!!\n",
+                       ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
+               panic("%s: IOC Fault (%04xh)!!!\n", ioc->name,
+                       ioc_raw_state & MPI_DOORBELL_DATA_MASK);
+       } else {
+               CHIPREG_WRITE32(&ioc->chip->Doorbell, 0xC0FFEE00);
+               panic("%s: Firmware is halted due to command timeout\n",
+                       ioc->name);
+       }
+}
+EXPORT_SYMBOL(mpt_halt_firmware);
+
+/**
+ *     mpt_SoftResetHandler - Issues a less expensive reset
+ *     @ioc: Pointer to MPT_ADAPTER structure
+ *     @sleepFlag: Indicates if sleep or schedule must be called.
+ *
+ *     Returns 0 for SUCCESS or -1 if FAILED.
+ *
+ *     Message Unit Reset - instructs the IOC to reset the Reply Post and
+ *     Free FIFO's. All the Message Frames on Reply Free FIFO are discarded.
+ *     All posted buffers are freed, and event notification is turned off.
+ *     IOC doesnt reply to any outstanding request. This will transfer IOC
+ *     to READY state.
+ **/
+int
+mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
+{
+       int              rc;
+       int              ii;
+       u8               cb_idx;
+       unsigned long    flags;
+       u32              ioc_state;
+       unsigned long    time_count;
+
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler Entered!\n",
+               ioc->name));
+
+       ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
+
+       if (mpt_fwfault_debug)
+               mpt_halt_firmware(ioc);
+
+       if (ioc_state == MPI_IOC_STATE_FAULT ||
+           ioc_state == MPI_IOC_STATE_RESET) {
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "skipping, either in FAULT or RESET state!\n", ioc->name));
+               return -1;
+       }
+
+       if (ioc->bus_type == FC) {
+               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                   "skipping, because the bus type is FC!\n", ioc->name));
+               return -1;
+       }
+
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->ioc_reset_in_progress) {
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+               return -1;
+       }
+       ioc->ioc_reset_in_progress = 1;
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+
+       rc = -1;
+
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptResetHandlers[cb_idx])
+                       mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
+       }
+
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->taskmgmt_in_progress) {
+               ioc->ioc_reset_in_progress = 0;
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+               return -1;
+       }
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+       /* Disable reply interrupts (also blocks FreeQ) */
+       CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
+       ioc->active = 0;
+       time_count = jiffies;
+
+       rc = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
+
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptResetHandlers[cb_idx])
+                       mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
+       }
+
+       if (rc)
+               goto out;
+
+       ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
+       if (ioc_state != MPI_IOC_STATE_READY)
+               goto out;
+
+       for (ii = 0; ii < 5; ii++) {
+               /* Get IOC facts! Allow 5 retries */
+               rc = GetIocFacts(ioc, sleepFlag,
+                       MPT_HOSTEVENT_IOC_RECOVER);
+               if (rc == 0)
+                       break;
+               if (sleepFlag == CAN_SLEEP)
+                       msleep(100);
+               else
+                       mdelay(100);
+       }
+       if (ii == 5)
+               goto out;
+
+       rc = PrimeIocFifos(ioc);
+       if (rc != 0)
+               goto out;
+
+       rc = SendIocInit(ioc, sleepFlag);
+       if (rc != 0)
+               goto out;
+
+       rc = SendEventNotification(ioc, 1, sleepFlag);
+       if (rc != 0)
+               goto out;
+
+       if (ioc->hard_resets < -1)
+               ioc->hard_resets++;
+
+       /*
+        * At this point, we know soft reset succeeded.
+        */
+
+       ioc->active = 1;
+       CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
+
+ out:
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       ioc->ioc_reset_in_progress = 0;
+       ioc->taskmgmt_quiesce_io = 0;
+       ioc->taskmgmt_in_progress = 0;
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+
+       if (ioc->active) {      /* otherwise, hard reset coming */
+               for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+                       if (MptResetHandlers[cb_idx])
+                               mpt_signal_reset(cb_idx, ioc,
+                                       MPT_IOC_POST_RESET);
+               }
+       }
+
+       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+               "SoftResetHandler: completed (%d seconds): %s\n",
+               ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
+               ((rc == 0) ? "SUCCESS" : "FAILED")));
+
+       return rc;
+}
+
+/**
+ *     mpt_Soft_Hard_ResetHandler - Try less expensive reset
+ *     @ioc: Pointer to MPT_ADAPTER structure
+ *     @sleepFlag: Indicates if sleep or schedule must be called.
+ *
+ *     Returns 0 for SUCCESS or -1 if FAILED.
+ *     Try for softreset first, only if it fails go for expensive
+ *     HardReset.
+ **/
+int
+mpt_Soft_Hard_ResetHandler(MPT_ADAPTER *ioc, int sleepFlag) {
+       int ret = -1;
+
+       ret = mpt_SoftResetHandler(ioc, sleepFlag);
+       if (ret == 0)
+               return ret;
+       ret = mpt_HardResetHandler(ioc, sleepFlag);
+       return ret;
+}
+EXPORT_SYMBOL(mpt_Soft_Hard_ResetHandler);
+
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /*
  *     Reset Handling
@@ -6054,77 +7111,99 @@ mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int sh
 int
 mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
 {
-       int              rc;
+       int      rc;
+       u8       cb_idx;
        unsigned long    flags;
+       unsigned long    time_count;
 
        dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler Entered!\n", ioc->name));
 #ifdef MFCNT
        printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
        printk("MF count 0x%x !\n", ioc->mfcnt);
 #endif
+       if (mpt_fwfault_debug)
+               mpt_halt_firmware(ioc);
 
        /* Reset the adapter. Prevent more than 1 call to
         * mpt_do_ioc_recovery at any instant in time.
         */
-       spin_lock_irqsave(&ioc->diagLock, flags);
-       if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
-               spin_unlock_irqrestore(&ioc->diagLock, flags);
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       if (ioc->ioc_reset_in_progress) {
+               spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
                return 0;
-       } else {
-               ioc->diagPending = 1;
        }
-       spin_unlock_irqrestore(&ioc->diagLock, flags);
+       ioc->ioc_reset_in_progress = 1;
+       if (ioc->alt_ioc)
+               ioc->alt_ioc->ioc_reset_in_progress = 1;
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
 
-       /* FIXME: If do_ioc_recovery fails, repeat....
-        */
 
        /* The SCSI driver needs to adjust timeouts on all current
         * commands prior to the diagnostic reset being issued.
         * Prevents timeouts occurring during a diagnostic reset...very bad.
         * For all other protocol drivers, this is a no-op.
         */
-       {
-               int      ii;
-               int      r = 0;
-
-               for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
-                       if (MptResetHandlers[ii]) {
-                               dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling IOC reset_setup handler #%d\n",
-                                               ioc->name, ii));
-                               r += mpt_signal_reset(ii, ioc, MPT_IOC_SETUP_RESET);
-                               if (ioc->alt_ioc) {
-                                       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Calling alt-%s setup reset handler #%d\n",
-                                                       ioc->name, ioc->alt_ioc->name, ii));
-                                       r += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_SETUP_RESET);
-                               }
-                       }
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptResetHandlers[cb_idx]) {
+                       mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
+                       if (ioc->alt_ioc)
+                               mpt_signal_reset(cb_idx, ioc->alt_ioc,
+                                       MPT_IOC_SETUP_RESET);
                }
        }
 
-       if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
-               printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
-                       rc, ioc->name);
+       time_count = jiffies;
+       rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag);
+       if (rc != 0) {
+               printk(KERN_WARNING MYNAM
+                      ": WARNING - (%d) Cannot recover %s, doorbell=0x%08x\n",
+                      rc, ioc->name, mpt_GetIocState(ioc, 0));
+       } else {
+               if (ioc->hard_resets < -1)
+                       ioc->hard_resets++;
        }
-       ioc->reload_fw = 0;
-       if (ioc->alt_ioc)
-               ioc->alt_ioc->reload_fw = 0;
 
-       spin_lock_irqsave(&ioc->diagLock, flags);
-       ioc->diagPending = 0;
-       if (ioc->alt_ioc)
-               ioc->alt_ioc->diagPending = 0;
-       spin_unlock_irqrestore(&ioc->diagLock, flags);
+       spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
+       ioc->ioc_reset_in_progress = 0;
+       ioc->taskmgmt_quiesce_io = 0;
+       ioc->taskmgmt_in_progress = 0;
+       if (ioc->alt_ioc) {
+               ioc->alt_ioc->ioc_reset_in_progress = 0;
+               ioc->alt_ioc->taskmgmt_quiesce_io = 0;
+               ioc->alt_ioc->taskmgmt_in_progress = 0;
+       }
+       spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
+
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptResetHandlers[cb_idx]) {
+                       mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
+                       if (ioc->alt_ioc)
+                               mpt_signal_reset(cb_idx,
+                                       ioc->alt_ioc, MPT_IOC_POST_RESET);
+               }
+       }
 
-       dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
+       dtmprintk(ioc,
+           printk(MYIOC_s_DEBUG_FMT
+               "HardResetHandler: completed (%d seconds): %s\n", ioc->name,
+               jiffies_to_msecs(jiffies - time_count)/1000, ((rc == 0) ?
+               "SUCCESS" : "FAILED")));
 
        return rc;
 }
 
-/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
+#ifdef CONFIG_FUSION_LOGGING
 static void
-EventDescriptionStr(u8 event, u32 evData0, char *evStr)
+mpt_display_event_info(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply)
 {
        char *ds = NULL;
+       u32 evData0;
+       int ii;
+       u8 event;
+       char *evStr = ioc->evStr;
+
+       event = le32_to_cpu(pEventReply->Event) & 0xFF;
+       evData0 = le32_to_cpu(pEventReply->Data[0]);
 
        switch(event) {
        case MPI_EVENT_NONE:
@@ -6158,9 +7237,9 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
                if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
                        ds = "Loop State(LIP) Change";
                else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
-                       ds = "Loop State(LPE) Change";          /* ??? */
+                       ds = "Loop State(LPE) Change";
                else
-                       ds = "Loop State(LPB) Change";          /* ??? */
+                       ds = "Loop State(LPB) Change";
                break;
        case MPI_EVENT_LOGOUT:
                ds = "Logout";
@@ -6360,28 +7439,65 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
        }
        case MPI_EVENT_IR2:
        {
+               u8 id = (u8)(evData0);
+               u8 channel = (u8)(evData0 >> 8);
+               u8 phys_num = (u8)(evData0 >> 24);
                u8 ReasonCode = (u8)(evData0 >> 16);
+
                switch (ReasonCode) {
                case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
-                       ds = "IR2: LD State Changed";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: LD State Changed: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
-                       ds = "IR2: PD State Changed";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: PD State Changed "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
-                       ds = "IR2: Bad Block Table Full";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: Bad Block Table Full: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                case MPI_EVENT_IR2_RC_PD_INSERTED:
-                       ds = "IR2: PD Inserted";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: PD Inserted: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                case MPI_EVENT_IR2_RC_PD_REMOVED:
-                       ds = "IR2: PD Removed";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: PD Removed: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
-                       ds = "IR2: Foreign CFG Detected";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: Foreign CFG Detected: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
-                       ds = "IR2: Rebuild Medium Error";
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: Rebuild Medium Error: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
+                       break;
+               case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: Dual Port Added: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
+                       break;
+               case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
+                       snprintf(evStr, EVENT_DESCR_STR_SZ,
+                           "IR2: Dual Port Removed: "
+                           "id=%d channel=%d phys_num=%d",
+                           id, channel, phys_num);
                        break;
                default:
                        ds = "IR2";
@@ -6417,13 +7533,18 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
        case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
        {
                u8 reason = (u8)(evData0);
-               u8 port_num = (u8)(evData0 >> 8);
-               u16 handle = le16_to_cpu(evData0 >> 16);
 
-               snprintf(evStr, EVENT_DESCR_STR_SZ,
-                   "SAS Initiator Device Status Change: reason=0x%02x "
-                   "port=%d handle=0x%04x",
-                   reason, port_num, handle);
+               switch (reason) {
+               case MPI_EVENT_SAS_INIT_RC_ADDED:
+                       ds = "SAS Initiator Status Change: Added";
+                       break;
+               case MPI_EVENT_SAS_INIT_RC_REMOVED:
+                       ds = "SAS Initiator Status Change: Deleted";
+                       break;
+               default:
+                       ds = "SAS Initiator Status Change";
+                       break;
+               }
                break;
        }
 
@@ -6471,6 +7592,24 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
                break;
        }
 
+       case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
+       {
+               u8 reason = (u8)(evData0);
+
+               switch (reason) {
+               case MPI_EVENT_SAS_EXP_RC_ADDED:
+                       ds = "Expander Status Change: Added";
+                       break;
+               case MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING:
+                       ds = "Expander Status Change: Deleted";
+                       break;
+               default:
+                       ds = "Expander Status Change";
+                       break;
+               }
+               break;
+       }
+
        /*
         *  MPT base "custom" events may be added here...
         */
@@ -6480,8 +7619,20 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
        }
        if (ds)
                strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
-}
 
+
+       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+           "MPT event:(%02Xh) : %s\n",
+           ioc->name, event, evStr));
+
+       devtverboseprintk(ioc, printk(KERN_DEBUG MYNAM
+           ": Event data:\n"));
+       for (ii = 0; ii < le16_to_cpu(pEventReply->EventDataLength); ii++)
+               devtverboseprintk(ioc, printk(" %08x",
+                   le32_to_cpu(pEventReply->Data[ii])));
+       devtverboseprintk(ioc, printk(KERN_DEBUG "\n"));
+}
+#endif
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
 /**
  *     ProcessEventNotification - Route EventNotificationReply to all event handlers
@@ -6498,36 +7649,24 @@ ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply
 {
        u16 evDataLen;
        u32 evData0 = 0;
-//     u32 evCtx;
        int ii;
+       u8 cb_idx;
        int r = 0;
        int handlers = 0;
-       char evStr[EVENT_DESCR_STR_SZ];
        u8 event;
 
        /*
         *  Do platform normalization of values
         */
        event = le32_to_cpu(pEventReply->Event) & 0xFF;
-//     evCtx = le32_to_cpu(pEventReply->EventContext);
        evDataLen = le16_to_cpu(pEventReply->EventDataLength);
        if (evDataLen) {
                evData0 = le32_to_cpu(pEventReply->Data[0]);
        }
 
-       EventDescriptionStr(event, evData0, evStr);
-       devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "MPT event:(%02Xh) : %s\n",
-                       ioc->name,
-                       event,
-                       evStr));
-
 #ifdef CONFIG_FUSION_LOGGING
-       devtverboseprintk(ioc, printk(KERN_DEBUG MYNAM
-           ": Event data:\n"));
-       for (ii = 0; ii < evDataLen; ii++)
-               devtverboseprintk(ioc, printk(" %08x",
-                   le32_to_cpu(pEventReply->Data[ii])));
-       devtverboseprintk(ioc, printk(KERN_DEBUG "\n"));
+       if (evDataLen)
+               mpt_display_event_info(ioc, pEventReply);
 #endif
 
        /*
@@ -6580,11 +7719,12 @@ ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply
        /*
         *  Call each currently registered protocol event handler.
         */
-       for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
-               if (MptEvHandlers[ii]) {
-                       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Routing Event to event handler #%d\n",
-                                       ioc->name, ii));
-                       r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
+       for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
+               if (MptEvHandlers[cb_idx]) {
+                       devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
+                           "Routing Event to event handler #%d\n",
+                           ioc->name, cb_idx));
+                       r += (*(MptEvHandlers[cb_idx]))(ioc, pEventReply);
                        handlers++;
                }
        }
@@ -6654,7 +7794,6 @@ mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
 /**
  *     mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
  *     @ioc: Pointer to MPT_ADAPTER structure
- *     @mr: Pointer to MPT reply frame
  *     @log_info: U32 LogInfo word from the IOC
  *
  *     Refer to lsi/sp_log.h.
@@ -6668,8 +7807,6 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
        switch (info) {
        case 0x00010000:
                desc = "bug! MID not found";
-               if (ioc->reload_fw == 0)
-                       ioc->reload_fw++;
                break;
 
        case 0x00020000:
@@ -6840,7 +7977,7 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
                NULL,                                           /* 2Eh */
                NULL,                                           /* 2Fh */
                "Compatibility Error: IR Disabled",             /* 30h */
-               "Compatibility Error: Inquiry Comand Failed",   /* 31h */
+               "Compatibility Error: Inquiry Command Failed",  /* 31h */
                "Compatibility Error: Device not Direct Access "
                    "Device ",                                  /* 32h */
                "Compatibility Error: Removable Device Found",  /* 33h */
@@ -6869,11 +8006,12 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
  *     mpt_sas_log_info - Log information returned from SAS IOC.
  *     @ioc: Pointer to MPT_ADAPTER structure
  *     @log_info: U32 LogInfo reply word from the IOC
+ *     @cb_idx: callback function's handle
  *
  *     Refer to lsi/mpi_log_sas.h.
  **/
 static void
-mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info)
+mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info, u8 cb_idx)
 {
 union loginfo_type {
        u32     loginfo;
@@ -6891,7 +8029,7 @@ union loginfo_type {
 
        sas_loginfo.loginfo = log_info;
        if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
-           (sas_loginfo.dw.originator < sizeof(originator_str)/sizeof(char*)))
+           (sas_loginfo.dw.originator < ARRAY_SIZE(originator_str)))
                return;
 
        originator_desc = originator_str[sas_loginfo.dw.originator];
@@ -6900,22 +8038,22 @@ union loginfo_type {
 
                case 0:  /* IOP */
                        if (sas_loginfo.dw.code <
-                           sizeof(iop_code_str)/sizeof(char*))
+                           ARRAY_SIZE(iop_code_str))
                                code_desc = iop_code_str[sas_loginfo.dw.code];
                        break;
                case 1:  /* PL */
                        if (sas_loginfo.dw.code <
-                           sizeof(pl_code_str)/sizeof(char*))
+                           ARRAY_SIZE(pl_code_str))
                                code_desc = pl_code_str[sas_loginfo.dw.code];
                        break;
                case 2:  /* IR */
                        if (sas_loginfo.dw.code >=
-                           sizeof(ir_code_str)/sizeof(char*))
+                           ARRAY_SIZE(ir_code_str))
                                break;
                        code_desc = ir_code_str[sas_loginfo.dw.code];
                        if (sas_loginfo.dw.subcode >=
-                           sizeof(raid_sub_code_str)/sizeof(char*))
-                       break;
+                           ARRAY_SIZE(raid_sub_code_str))
+                               break;
                        if (sas_loginfo.dw.code == 0)
                                sub_code_desc =
                                    raid_sub_code_str[sas_loginfo.dw.subcode];
@@ -6927,21 +8065,22 @@ union loginfo_type {
        if (sub_code_desc != NULL)
                printk(MYIOC_s_INFO_FMT
                        "LogInfo(0x%08x): Originator={%s}, Code={%s},"
-                       " SubCode={%s}\n",
+                       " SubCode={%s} cb_idx %s\n",
                        ioc->name, log_info, originator_desc, code_desc,
-                       sub_code_desc);
+                       sub_code_desc, MptCallbacksName[cb_idx]);
        else if (code_desc != NULL)
                printk(MYIOC_s_INFO_FMT
                        "LogInfo(0x%08x): Originator={%s}, Code={%s},"
-                       " SubCode(0x%04x)\n",
+                       " SubCode(0x%04x) cb_idx %s\n",
                        ioc->name, log_info, originator_desc, code_desc,
-                       sas_loginfo.dw.subcode);
+                       sas_loginfo.dw.subcode, MptCallbacksName[cb_idx]);
        else
                printk(MYIOC_s_INFO_FMT
                        "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
-                       " SubCode(0x%04x)\n",
+                       " SubCode(0x%04x) cb_idx %s\n",
                        ioc->name, log_info, originator_desc,
-                       sas_loginfo.dw.code, sas_loginfo.dw.subcode);
+                       sas_loginfo.dw.code, sas_loginfo.dw.subcode,
+                       MptCallbacksName[cb_idx]);
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -7019,8 +8158,8 @@ mpt_iocstatus_info_config(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
        if (!desc)
                return;
 
-       printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s: %s\n",
-           ioc->name, ioc_status, desc, extend_desc);
+       dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s: %s\n",
+           ioc->name, ioc_status, desc, extend_desc));
 }
 
 /**
@@ -7246,7 +8385,8 @@ mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
        if (!desc)
                return;
 
-       printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s\n", ioc->name, status, desc);
+       dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n",
+           ioc->name, status, desc));
 }
 
 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -7257,7 +8397,6 @@ EXPORT_SYMBOL(mpt_resume);
 EXPORT_SYMBOL(mpt_suspend);
 #endif
 EXPORT_SYMBOL(ioc_list);
-EXPORT_SYMBOL(mpt_proc_root_dir);
 EXPORT_SYMBOL(mpt_register);
 EXPORT_SYMBOL(mpt_deregister);
 EXPORT_SYMBOL(mpt_event_register);
@@ -7268,14 +8407,12 @@ EXPORT_SYMBOL(mpt_device_driver_register);
 EXPORT_SYMBOL(mpt_device_driver_deregister);
 EXPORT_SYMBOL(mpt_get_msg_frame);
 EXPORT_SYMBOL(mpt_put_msg_frame);
+EXPORT_SYMBOL(mpt_put_msg_frame_hi_pri);
 EXPORT_SYMBOL(mpt_free_msg_frame);
-EXPORT_SYMBOL(mpt_add_sge);
 EXPORT_SYMBOL(mpt_send_handshake_request);
 EXPORT_SYMBOL(mpt_verify_adapter);
 EXPORT_SYMBOL(mpt_GetIocState);
 EXPORT_SYMBOL(mpt_print_ioc_summary);
-EXPORT_SYMBOL(mpt_lan_index);
-EXPORT_SYMBOL(mpt_stm_index);
 EXPORT_SYMBOL(mpt_HardResetHandler);
 EXPORT_SYMBOL(mpt_config);
 EXPORT_SYMBOL(mpt_findImVolumes);
@@ -7293,22 +8430,23 @@ EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
 static int __init
 fusion_init(void)
 {
-       int i;
+       u8 cb_idx;
 
        show_mptmod_ver(my_NAME, my_VERSION);
        printk(KERN_INFO COPYRIGHT "\n");
 
-       for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
-               MptCallbacks[i] = NULL;
-               MptDriverClass[i] = MPTUNKNOWN_DRIVER;
-               MptEvHandlers[i] = NULL;
-               MptResetHandlers[i] = NULL;
+       for (cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
+               MptCallbacks[cb_idx] = NULL;
+               MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
+               MptEvHandlers[cb_idx] = NULL;
+               MptResetHandlers[cb_idx] = NULL;
        }
 
        /*  Register ourselves (mptbase) in order to facilitate
         *  EventNotification handling.
         */
-       mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
+       mpt_base_index = mpt_register(mptbase_reply, MPTBASE_DRIVER,
+           "mptbase_reply");
 
        /* Register for hard reset handling callbacks.
         */