--- old/./fusion.h	Tue Nov  6 14:29:38 2012
+++ new/./fusion.h	Tue Nov  6 14:29:38 2012
@@ -74,13 +74,13 @@
 #define	MPI2_WRSEQ_6TH_KEY_VALUE		(0xD)
 
 /* Invader defines */
-#define MPI2_TYPE_CUDA					0x2
-#define MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH	0x4000
-#define MR_RL_FLAGS_GRANT_DESTINATION_CPU0			0x00
-#define MR_RL_FLAGS_GRANT_DESTINATION_CPU1			0x10
-#define MR_RL_FLAGS_GRANT_DESTINATION_CUDA			0x80
-#define MR_RL_FLAGS_SEQ_NUM_ENABLE					0x8
-#define MPI2_NSEG_FLAGS_SHIFT						4
+#define	MPI2_TYPE_CUDA					0x2
+#define	MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH	0x4000
+#define	MR_RL_FLAGS_GRANT_DESTINATION_CPU0			0x00
+#define	MR_RL_FLAGS_GRANT_DESTINATION_CPU1			0x10
+#define	MR_RL_FLAGS_GRANT_DESTINATION_CUDA			0x80
+#define	MR_RL_FLAGS_SEQ_NUM_ENABLE					0x8
+#define	MPI2_NSEG_FLAGS_SHIFT						4
 
 
 #define	MR_PD_INVALID				0xFFFF
@@ -411,7 +411,7 @@
 typedef struct _MR_SPAN_INFO {
 	U32		noElements;			/* 0x00 */
 	U32		reserved1;			/* 0x04 */
-	MR_QUAD_ELEMENT	quad[MAX_RAIDMAP_SPAN_DEPTH];	/* 0x08 */
+	MR_QUAD_ELEMENT	quads[MAX_RAIDMAP_SPAN_DEPTH];	/* 0x08 */
 } MR_SPAN_INFO;						/* 0x108, Total size */
 
 typedef struct _MR_LD_SPAN_ {				/* SPAN structure */
@@ -475,7 +475,11 @@
 	U8	regTypeReqOnWrite;
 
 	U8	modFactor;		/* 0x1c, same as rowSize */
-	U8	regTypeReqOnRead;		/* 0x1d, region lock type used for read, valid only if regTypeOnReadIsValid=1 */
+	/*
+	 * 0x1d, region lock type used for read, valid only if
+	 * regTypeOnReadIsValid=1
+	 */
+	U8	regTypeReqOnRead;
 	U16	seqNum;			/* 0x1e, LD sequence number */
 
 	struct {
@@ -515,13 +519,14 @@
 	U32			ldCount;		/* count of lds */
 	U32			Reserved1;
 
-	/*   0x20 This doesn't correspond to
-	    * FW Ld Tgt Id to LD, but will purge. For example: if tgt Id is 4
-	    * and FW LD is 2, and there is only one LD, FW will populate the
-	    * array like this. [0xFF, 0xFF, 0xFF, 0xFF, 0x0.....]. This is to
-	    * help reduce the entire strcture size if there are few LDs or
-	    * driver is looking info for 1 LD only.
-	    */
+	/*
+	 * 0x20 This doesn't correspond to
+	 * FW Ld Tgt Id to LD, but will purge. For example: if tgt Id is 4
+	 * and FW LD is 2, and there is only one LD, FW will populate the
+	 * array like this. [0xFF, 0xFF, 0xFF, 0xFF, 0x0.....]. This is to
+	 * help reduce the entire structure size if there are few LDs or
+	 * driver is looking info for 1 LD only.
+	 */
 	U8			ldTgtIdToLd[MAX_RAIDMAP_LOGICAL_DRIVES+ \
 				MAX_RAIDMAP_VIEWS]; /* 0x20 */
 	/* timeout value used by driver in FP IOs */
@@ -538,7 +543,7 @@
 	U8	ldTargetId;
 	U8	reserved;
 	U16	seqNum;
-} LD_TARGET_SYNC;	
+} LD_TARGET_SYNC;
 
 #pragma pack()
 
--- old/./ld_pd_map.c	Tue Nov  6 14:29:38 2012
+++ new/./ld_pd_map.c	Tue Nov  6 14:29:38 2012
@@ -23,23 +23,19 @@
  */
 
 #include <sys/scsi/scsi.h>
-#include "ld_pd_map.h"
 #include "mr_sas.h"
+#include "ld_pd_map.h"
 
 /*
  * This function will check if FAST IO is possible on this logical drive
- * by checking the EVENT information availabe in the driver
+ * by checking the EVENT information available in the driver
  */
-#define MR_LD_STATE_OPTIMAL 3
-#define ABS_DIFF(a,b)   ( ((a) > (b)) ? ((a) - (b)) : ((b) - (a)) )
+#define	MR_LD_STATE_OPTIMAL 3
+#define	ABS_DIFF(a, b)   (((a) > (b)) ? ((a) - (b)) : ((b) - (a)))
 
-void
-mr_update_load_balance_params(MR_FW_RAID_MAP_ALL *map, PLD_LOAD_BALANCE_INFO lbInfo);
+static void mr_update_load_balance_params(MR_FW_RAID_MAP_ALL *,
+    PLD_LOAD_BALANCE_INFO);
 
-U8
-MR_BuildRaidContext(struct mrsas_instance *, struct IO_REQUEST_INFO *,
-	    MPI2_SCSI_IO_VENDOR_UNIQUE *, MR_FW_RAID_MAP_ALL *);
-
 #define	FALSE 0
 #define	TRUE 1
 
@@ -54,49 +50,55 @@
 	return (&map->raidMap.ldSpanMap[ld].ldRaid);
 }
 
-U16 MR_GetLDTgtId
-(U32 ld, MR_FW_RAID_MAP_ALL *map)
+U16
+MR_GetLDTgtId(U32 ld, MR_FW_RAID_MAP_ALL *map)
 {
 	return (map->raidMap.ldSpanMap[ld].ldRaid.targetId);
 }
 
 
-static MR_SPAN_BLOCK_INFO *MR_LdSpanInfoGet(U32 ld, MR_FW_RAID_MAP_ALL *map)
+static MR_SPAN_BLOCK_INFO *
+MR_LdSpanInfoGet(U32 ld, MR_FW_RAID_MAP_ALL *map)
 {
 	return (&map->raidMap.ldSpanMap[ld].spanBlock[0]);
 }
 
-static U8 MR_LdDataArmGet(U32 ld, U32 armIdx, MR_FW_RAID_MAP_ALL *map)
+static U8
+MR_LdDataArmGet(U32 ld, U32 armIdx, MR_FW_RAID_MAP_ALL *map)
 {
 	return (map->raidMap.ldSpanMap[ld].dataArmMap[armIdx]);
 }
 
-static U16 MR_ArPdGet(U32 ar, U32 arm, MR_FW_RAID_MAP_ALL *map)
+static U16
+MR_ArPdGet(U32 ar, U32 arm, MR_FW_RAID_MAP_ALL *map)
 {
 	return (map->raidMap.arMapInfo[ar].pd[arm]);
 }
 
-static U16 MR_LdSpanArrayGet(U32 ld, U32 span, MR_FW_RAID_MAP_ALL *map)
+static U16
+MR_LdSpanArrayGet(U32 ld, U32 span, MR_FW_RAID_MAP_ALL *map)
 {
 	return (map->raidMap.ldSpanMap[ld].spanBlock[span].span.arrayRef);
 }
 
-static U16 MR_PdDevHandleGet(U32 pd, MR_FW_RAID_MAP_ALL *map)
+static U16
+MR_PdDevHandleGet(U32 pd, MR_FW_RAID_MAP_ALL *map)
 {
 	return (map->raidMap.devHndlInfo[pd].curDevHdl);
 }
 
-U16 MR_TargetIdToLdGet(U32 ldTgtId, MR_FW_RAID_MAP_ALL *map)
+U16
+MR_TargetIdToLdGet(U32 ldTgtId, MR_FW_RAID_MAP_ALL *map)
 {
 	return (map->raidMap.ldTgtIdToLd[ldTgtId]);
 }
 
-U16 MR_CheckDIF(U32 ldTgtId, MR_FW_RAID_MAP_ALL *map)
+U16
+MR_CheckDIF(U32 ldTgtId, MR_FW_RAID_MAP_ALL *map)
 {
-	MR_FW_RAID_MAP	*pFwRaidMap = &map->raidMap;
 	MR_LD_RAID	*raid;
 	U32		ld;
-	
+
 	ld = MR_TargetIdToLdGet(ldTgtId, map);
 
 	if (ld >= MAX_LOGICAL_DRIVES) {
@@ -108,7 +110,8 @@
 	return (raid->capability.ldPiMode == 0x8);
 }
 
-static MR_LD_SPAN *MR_LdSpanPtrGet(U32 ld, U32 span, MR_FW_RAID_MAP_ALL *map)
+static MR_LD_SPAN *
+MR_LdSpanPtrGet(U32 ld, U32 span, MR_FW_RAID_MAP_ALL *map)
 {
 	return (&map->raidMap.ldSpanMap[ld].spanBlock[span].span);
 }
@@ -116,23 +119,21 @@
 /*
  * This function will validate Map info data provided by FW
  */
-U8 MR_ValidateMapInfo(MR_FW_RAID_MAP_ALL *map, PLD_LOAD_BALANCE_INFO lbInfo)
+U8
+MR_ValidateMapInfo(MR_FW_RAID_MAP_ALL *map, PLD_LOAD_BALANCE_INFO lbInfo)
 {
 	MR_FW_RAID_MAP *pFwRaidMap = &map->raidMap;
+	U32 fwsize = sizeof (MR_FW_RAID_MAP) - sizeof (MR_LD_SPAN_MAP) +
+	    (sizeof (MR_LD_SPAN_MAP) * pFwRaidMap->ldCount);
 
+	if (pFwRaidMap->totalSize != fwsize) {
 
-	if (pFwRaidMap->totalSize !=
-	    (sizeof (MR_FW_RAID_MAP) - sizeof (MR_LD_SPAN_MAP) +
-	    (sizeof (MR_LD_SPAN_MAP) * pFwRaidMap->ldCount))) {
-
-		con_log(CL_ANN1, (CE_NOTE,\
-		    "map info structure size 0x%x\
-		    is not matching with ld count\n",\
-		    ((sizeof (MR_FW_RAID_MAP) - sizeof (MR_LD_SPAN_MAP)) +\
-		    (sizeof (MR_LD_SPAN_MAP) * pFwRaidMap->ldCount))));
-
+		con_log(CL_ANN1, (CE_NOTE,
+		    "map info structure size 0x%x is "
+		    "not matching with ld count\n", fwsize));
+		/* sizeof (foo) returns size_t, which is *LONG*. */
 		con_log(CL_ANN1, (CE_NOTE, "span map 0x%x total size 0x%x\n",\
-		    sizeof (MR_LD_SPAN_MAP), pFwRaidMap->totalSize));
+		    (int)sizeof (MR_LD_SPAN_MAP), pFwRaidMap->totalSize));
 
 		return (0);
 	}
@@ -143,29 +144,30 @@
 }
 
 U32
-MR_GetSpanBlock(U32 ld, U64 row, U64 *span_blk, MR_FW_RAID_MAP_ALL *map, int *div_error)
+MR_GetSpanBlock(U32 ld, U64 row, U64 *span_blk, MR_FW_RAID_MAP_ALL *map,
+    int *div_error)
 {
 	MR_SPAN_BLOCK_INFO *pSpanBlock = MR_LdSpanInfoGet(ld, map);
-	MR_QUAD_ELEMENT	*quad;
+	MR_QUAD_ELEMENT	*qe;
 	MR_LD_RAID	*raid = MR_LdRaidGet(ld, map);
 	U32		span, j;
 
 	for (span = 0; span < raid->spanDepth; span++, pSpanBlock++) {
 		for (j = 0; j < pSpanBlock->block_span_info.noElements; j++) {
-			quad = &pSpanBlock->block_span_info.quad[j];
-			if(quad->diff == 0) {
-				*div_error=1;
+			qe = &pSpanBlock->block_span_info.quads[j];
+			if (qe->diff == 0) {
+				*div_error = 1;
 				return (span);
 			}
-			if (quad->logStart <= row &&
-			    row <= quad->logEnd &&
-			    (((row-quad->logStart) % quad->diff)) == 0) {
+			if (qe->logStart <= row && row <= qe->logEnd &&
+			    (((row - qe->logStart) % qe->diff)) == 0) {
 				if (span_blk != NULL) {
 					U64	blk;
-					blk = ((row-quad->logStart) /
-					    (quad->diff));
+					blk = ((row - qe->logStart) /
+					    (qe->diff));
 
-					blk = (blk + quad->offsetInSpan) << raid->stripeShift;	
+					blk = (blk + qe->offsetInSpan) <<
+					    raid->stripeShift;
 					*span_blk = blk;
 				}
 				return (span);
@@ -194,22 +196,24 @@
  *    block         - Absolute Block number in the physical disk
  */
 U8
-MR_GetPhyParams(struct mrsas_instance *instance, U32 ld, U64 stripRow, U16 stripRef,
-U64 *pdBlock, U16 *pDevHandle, MPI2_SCSI_IO_VENDOR_UNIQUE *pRAID_Context,
-MR_FW_RAID_MAP_ALL *map)
+MR_GetPhyParams(struct mrsas_instance *instance, U32 ld, U64 stripRow,
+    U16 stripRef, U64 *pdBlock, U16 *pDevHandle,
+    MPI2_SCSI_IO_VENDOR_UNIQUE *pRAID_Context, MR_FW_RAID_MAP_ALL *map)
 {
 	MR_LD_RAID	*raid = MR_LdRaidGet(ld, map);
 	U32		pd, arRef;
 	U8		physArm, span;
 	U64		row;
-	int		error_code=0;
+	int		error_code = 0;
 	U8		retval = TRUE;
 	U32		rowMod;
 	U32		armQ;
 	U32		arm;
 
-	row	= (stripRow / raid->rowDataSize);
+	ASSERT(raid->rowDataSize != 0);
 
+	row = (stripRow / raid->rowDataSize);
+
 	if (raid->level == 6) {
 		U32 logArm =  (stripRow % (raid->rowDataSize));
 
@@ -218,13 +222,13 @@
 		}
 		rowMod = (row % (raid->rowSize));
 		armQ = raid->rowSize-1-rowMod;
-		arm = armQ+1+logArm;
+		arm = armQ + 1 + logArm;
 		if (arm >= raid->rowSize)
 			arm -= raid->rowSize;
 		physArm = (U8)arm;
 	} else {
 		if (raid->modFactor == 0)
-			return FALSE;
+			return (FALSE);
 		physArm = MR_LdDataArmGet(ld,
 		    (stripRow % (raid->modFactor)), map);
 	}
@@ -233,37 +237,39 @@
 		*pdBlock = row << raid->stripeShift;
 	} else
 		span = (U8)MR_GetSpanBlock(ld, row, pdBlock, map, &error_code);
-	
+
 	if (error_code == 1)
-	    return FALSE;
+		return (FALSE);
 
-	// Get the array on which this span is present.
+	/* Get the array on which this span is present. */
 	arRef		= MR_LdSpanArrayGet(ld, span, map);
-	// Get the Pd.
+	/* Get the Pd. */
 	pd		= MR_ArPdGet(arRef, physArm, map);
-	// Get dev handle from Pd.
+	/* Get dev handle from Pd. */
 	if (pd != MR_PD_INVALID) {
-	    *pDevHandle	= MR_PdDevHandleGet(pd, map);
+		*pDevHandle	= MR_PdDevHandleGet(pd, map);
+	} else {
+		*pDevHandle = MR_PD_INVALID; /* set dev handle as invalid. */
+		if ((raid->level >= 5) &&
+		    ((instance->device_id != PCI_DEVICE_ID_LSI_INVADER) ||
+		    (instance->device_id == PCI_DEVICE_ID_LSI_INVADER &&
+		    raid->regTypeReqOnRead != REGION_TYPE_UNUSED))) {
+			pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
+		} else if (raid->level == 1) {
+			/* Get Alternate Pd. */
+			pd = MR_ArPdGet(arRef, physArm + 1, map);
+			/* Get dev handle from Pd. */
+			if (pd != MR_PD_INVALID)
+				*pDevHandle = MR_PdDevHandleGet(pd, map);
+		}
 	}
-    else {
-	    *pDevHandle = MR_PD_INVALID; // set dev handle as invalid.
-	    if ( (raid->level >= 5) &&
-			 ((instance->device_id != PCI_DEVICE_ID_LSI_INVADER) ||
-			  (instance->device_id == PCI_DEVICE_ID_LSI_INVADER &&
-				raid->regTypeReqOnRead != REGION_TYPE_UNUSED)) )
-		    pRAID_Context->regLockFlags = REGION_TYPE_EXCLUSIVE;
-	    else if (raid->level == 1) {
-		    pd = MR_ArPdGet(arRef, physArm + 1, map); // Get Alternate Pd.
-		    if (pd != MR_PD_INVALID)
-			    *pDevHandle = MR_PdDevHandleGet(pd, map); // Get dev handle from Pd.
-	    }
-    }
 
 	*pdBlock += stripRef + MR_LdSpanPtrGet(ld, span, map)->startBlk;
 
-	pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) | physArm;
+	pRAID_Context->spanArm = (span << RAID_CTX_SPANARM_SPAN_SHIFT) |
+	    physArm;
 
-	return retval;
+	return (retval);
 }
 
 
@@ -280,8 +286,9 @@
  */
 
 U8
-MR_BuildRaidContext(struct mrsas_instance *instance, struct IO_REQUEST_INFO *io_info,
-MPI2_SCSI_IO_VENDOR_UNIQUE *pRAID_Context, MR_FW_RAID_MAP_ALL *map)
+MR_BuildRaidContext(struct mrsas_instance *instance,
+    struct IO_REQUEST_INFO *io_info, MPI2_SCSI_IO_VENDOR_UNIQUE *pRAID_Context,
+    MR_FW_RAID_MAP_ALL *map)
 {
 	MR_LD_RAID	*raid;
 	U32		ld, stripSize, stripe_mask;
@@ -296,14 +303,14 @@
 	U64		ldStartBlock;
 	U32		numBlocks, ldTgtId;
 	U8		isRead;
-	U8	   	retval = 0;
+	U8		retval = 0;
 
 	ldStartBlock = io_info->ldStartBlock;
 	numBlocks = io_info->numBlocks;
 	ldTgtId = io_info->ldTgtId;
 	isRead = io_info->isRead;
-	
-	if ( map == NULL ) {
+
+	if (map == NULL) {
 		io_info->fpOkForIo = FALSE;
 		return (FALSE);
 	}
@@ -328,12 +335,12 @@
 	ref_in_end_stripe	= (U16)(endLba & stripe_mask);
 	endStrip		= endLba >> raid->stripeShift;
 	num_strips		= (U8)(endStrip - start_strip + 1);
-	/* Check to make sure is not deviding by zero */
-	if (raid->rowDataSize == 0)
-		return FALSE;
+	/* Check to make sure is not dividing by zero */
+	if (raid->rowDataSize == 0)
+		return (FALSE);
 	start_row		=  (start_strip / raid->rowDataSize);
 	endRow			=  (endStrip  / raid->rowDataSize);
-	// get the row count
+	/* get the row count */
 	numRows			= (U8)(endRow - start_row + 1);
 
 	/*
@@ -342,24 +349,26 @@
 	regStart	= start_row << raid->stripeShift;
 	regSize		= stripSize;
 
-	/* Check if we can send this I/O via FastPath */
-	if (raid->capability.fpCapable) {
-		if (isRead)
-			io_info->fpOkForIo = (raid->capability.fpReadCapable &&
-					      ((num_strips == 1) ||
-					       raid->capability.fpReadAcrossStripe));
-		else
-			io_info->fpOkForIo = (raid->capability.fpWriteCapable &&
-					      ((num_strips == 1) ||
-					       raid->capability.fpWriteAcrossStripe));
-	} else
-		io_info->fpOkForIo = FALSE;
+	/* Check if we can send this I/O via FastPath */
+	if (raid->capability.fpCapable) {
+		if (isRead) {
+			io_info->fpOkForIo = (raid->capability.fpReadCapable &&
+			    ((num_strips == 1) ||
+			    raid->capability.fpReadAcrossStripe));
+		} else {
+			io_info->fpOkForIo =
+			    (raid->capability.fpWriteCapable &&
+			    ((num_strips == 1) ||
+			    raid->capability.fpWriteAcrossStripe));
+		}
+	} else
+		io_info->fpOkForIo = FALSE;
 
 
 	/*
 	 * Check for DIF support
 	 */
-	if ( !raid->capability.ldPiMode ) {
+	if (!raid->capability.ldPiMode) {
 		io_info->ldPI = FALSE;
 	} else {
 		io_info->ldPI = TRUE;
@@ -377,51 +386,57 @@
 		}
 
 		if (numRows > 2) {
-			regSize += (numRows-2) << raid->stripeShift;
+			regSize += (numRows - 2) << raid->stripeShift;
 		}
 
-		if (endStrip == endRow*raid->rowDataSize) {
-			regSize += ref_in_end_stripe+1;
+		if (endStrip == endRow * raid->rowDataSize) {
+			regSize += ref_in_end_stripe + 1;
 		} else {
 			regSize += stripSize;
 		}
 	}
-	
-	pRAID_Context->timeoutValue     = map->raidMap.fpPdIoTimeoutSec;
 
-	if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) 
-		pRAID_Context->regLockFlags = 
-			(isRead)? raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
-	else
-		pRAID_Context->regLockFlags	=
-			(isRead) ? REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
+	pRAID_Context->timeoutValue = map->raidMap.fpPdIoTimeoutSec;
 
-	pRAID_Context->ldTargetId	= raid->targetId;
-	pRAID_Context->regLockRowLBA	= regStart;
-	pRAID_Context->regLockLength	= regSize;
-	pRAID_Context->configSeqNum	= raid->seqNum;
+	if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
+		pRAID_Context->regLockFlags = (isRead) ?
+		    raid->regTypeReqOnRead : raid->regTypeReqOnWrite;
+	} else {
+		pRAID_Context->regLockFlags = (isRead) ?
+		    REGION_TYPE_SHARED_READ : raid->regTypeReqOnWrite;
+	}
 
+	pRAID_Context->ldTargetId = raid->targetId;
+	pRAID_Context->regLockRowLBA = regStart;
+	pRAID_Context->regLockLength = regSize;
+	pRAID_Context->configSeqNum = raid->seqNum;
+
 	/*
 	 * Get Phy Params only if FP capable,
 	 * or else leave it to MR firmware to do the calculation.
 	 */
 	if (io_info->fpOkForIo) {
-	/* if fast path possible then get the physical parameters */
-		retval = MR_GetPhyParams(instance, ld, start_strip, ref_in_start_stripe,
-		    &io_info->pdBlock, &io_info->devHandle,
-		    pRAID_Context, map);
+		/* if fast path possible then get the physical parameters */
+		retval = MR_GetPhyParams(instance, ld, start_strip,
+		    ref_in_start_stripe, &io_info->pdBlock,
+		    &io_info->devHandle, pRAID_Context, map);
 
-		if (io_info->devHandle == MR_PD_INVALID) // If IO on an invalid Pd, then FP is not possible.
+		/* If IO on an invalid Pd, then FP is not possible. */
+		if (io_info->devHandle == MR_PD_INVALID)
 			io_info->fpOkForIo = FALSE;
 
-		return retval;
+		return (retval);
 
 	} else if (isRead) {
-		uint stripIdx;
-		for (stripIdx=0; stripIdx<num_strips; stripIdx++) {
-			if (!MR_GetPhyParams(instance, ld, start_strip + stripIdx, ref_in_start_stripe, 
-			    &io_info->pdBlock, &io_info->devHandle, pRAID_Context, map))
-			return TRUE;
+		uint_t stripIdx;
+
+		for (stripIdx = 0; stripIdx < num_strips; stripIdx++) {
+			if (!MR_GetPhyParams(instance, ld,
+			    start_strip + stripIdx, ref_in_start_stripe,
+			    &io_info->pdBlock, &io_info->devHandle,
+			    pRAID_Context, map)) {
+				return (TRUE);
+			}
 		}
 	}
 	return (TRUE);
@@ -429,41 +444,46 @@
 
 
 void
-mr_update_load_balance_params(MR_FW_RAID_MAP_ALL *map, PLD_LOAD_BALANCE_INFO lbInfo)
+mr_update_load_balance_params(MR_FW_RAID_MAP_ALL *map,
+    PLD_LOAD_BALANCE_INFO lbInfo)
 {
 	int ldCount;
 	U16 ld;
 	MR_LD_RAID *raid;
 
-	for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES; ldCount++) 
-	{
+	for (ldCount = 0; ldCount < MAX_LOGICAL_DRIVES; ldCount++) {
 		ld = MR_TargetIdToLdGet(ldCount, map);
 
-                if (ld >= MAX_LOGICAL_DRIVES) {
-                        con_log(CL_ANN1, (CE_NOTE,
-                                "mrsas: ld=%d Invalid ld \n", ld));
-                        continue;
-                }
+		if (ld >= MAX_LOGICAL_DRIVES) {
+			con_log(CL_ANN1,
+			    (CE_NOTE, "mrsas: ld=%d Invalid ld \n", ld));
+			continue;
+		}
 
 		raid = MR_LdRaidGet(ld, map);
-        
+
 		/* Two drive Optimal RAID 1 */
-		if ((raid->level == 1)  &&  (raid->rowSize == 2) && (raid->spanDepth == 1)
-		    && raid->ldState == MR_LD_STATE_OPTIMAL) {
+		if ((raid->level == 1) && (raid->rowSize == 2) &&
+		    (raid->spanDepth == 1) &&
+		    raid->ldState == MR_LD_STATE_OPTIMAL) {
 			U32 pd, arRef;
 
 			lbInfo[ldCount].loadBalanceFlag = 1;
-			//U8 physArm = 0;
-			
-			arRef = MR_LdSpanArrayGet(ld, 0, map);    // Get the array on which this span is present.
 
-			pd = MR_ArPdGet(arRef, 0, map);     // Get the Pd.
-			lbInfo[ldCount].raid1DevHandle[0] = MR_PdDevHandleGet(pd, map);          // Get dev handle from Pd.
+			/* Get the array on which this span is present. */
+			arRef = MR_LdSpanArrayGet(ld, 0, map);
 
-			pd = MR_ArPdGet(arRef, 1, map);     // Get the Pd.
-			lbInfo[ldCount].raid1DevHandle[1] = MR_PdDevHandleGet(pd, map);          // Get dev handle from Pd.
-	    		con_log(CL_ANN1, (CE_NOTE,\
-		    		"mrsas: ld=%d load balancing enabled \n", ldCount));
+			pd = MR_ArPdGet(arRef, 0, map);	    /* Get the Pd. */
+			/* Get dev handle from Pd. */
+			lbInfo[ldCount].raid1DevHandle[0] =
+			    MR_PdDevHandleGet(pd, map);
+
+			pd = MR_ArPdGet(arRef, 1, map);	    /* Get the Pd. */
+			/* Get dev handle from Pd. */
+			lbInfo[ldCount].raid1DevHandle[1] =
+			    MR_PdDevHandleGet(pd, map);
+			con_log(CL_ANN1, (CE_NOTE,
+			    "mrsas: ld=%d load balancing enabled \n", ldCount));
 		} else {
 			lbInfo[ldCount].loadBalanceFlag = 0;
 		}
@@ -471,30 +491,36 @@
 }
 
 
-U8 megasas_get_best_arm(PLD_LOAD_BALANCE_INFO lbInfo, U8 arm, U64 block, U32 count)
+U8
+megasas_get_best_arm(PLD_LOAD_BALANCE_INFO lbInfo, U8 arm, U64 block,
+    U32 count)
 {
-    U16     pend0, pend1;
-    U64     diff0, diff1;
-    U8      bestArm;
+	U16 pend0, pend1;
+	U64 diff0, diff1;
+	U8 bestArm;
 
-    /* get the pending cmds for the data and mirror arms */
-    pend0 = lbInfo->scsi_pending_cmds[0];
-    pend1 = lbInfo->scsi_pending_cmds[1];
+	/* get the pending cmds for the data and mirror arms */
+	pend0 = lbInfo->scsi_pending_cmds[0];
+	pend1 = lbInfo->scsi_pending_cmds[1];
 
-    /* Determine the disk whose head is nearer to the req. block */
-    diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[0]);
-    diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[1]);
-    bestArm = (diff0 <= diff1 ? 0 : 1);
+	/* Determine the disk whose head is nearer to the req. block */
+	diff0 = ABS_DIFF(block, lbInfo->last_accessed_block[0]);
+	diff1 = ABS_DIFF(block, lbInfo->last_accessed_block[1]);
+	bestArm = (diff0 <= diff1 ? 0 : 1);
 
-    if ((bestArm == arm && pend0 > pend1 + 16)  || (bestArm != arm && pend1 > pend0 + 16))
-        bestArm ^= 1;
+	if ((bestArm == arm && pend0 > pend1 + 16) ||
+	    (bestArm != arm && pend1 > pend0 + 16)) {
+		bestArm ^= 1;
+	}
 
-    /* Update the last accessed block on the correct pd */
-    lbInfo->last_accessed_block[bestArm] = block + count - 1;
-    return bestArm;
+	/* Update the last accessed block on the correct pd */
+	lbInfo->last_accessed_block[bestArm] = block + count - 1;
+	return (bestArm);
 }
 
-U16 get_updated_dev_handle(PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *io_info)
+U16
+get_updated_dev_handle(PLD_LOAD_BALANCE_INFO lbInfo,
+    struct IO_REQUEST_INFO *io_info)
 {
 	U8 arm, old_arm;
 	U16 devHandle;
@@ -502,11 +528,12 @@
 	old_arm = lbInfo->raid1DevHandle[0] == io_info->devHandle ? 0 : 1;
 
 	/* get best new arm */
-	arm  = megasas_get_best_arm(lbInfo, old_arm, io_info->ldStartBlock, io_info->numBlocks);
+	arm  = megasas_get_best_arm(lbInfo, old_arm, io_info->ldStartBlock,
+	    io_info->numBlocks);
 
 	devHandle = lbInfo->raid1DevHandle[arm];
 
 	lbInfo->scsi_pending_cmds[arm]++;
 
-	return devHandle;
+	return (devHandle);
 }
--- old/./ld_pd_map.h	Tue Nov  6 14:29:38 2012
+++ new/./ld_pd_map.h	Tue Nov  6 14:29:38 2012
@@ -14,11 +14,13 @@
  *		Shakeel Bukhari
  */
 
-#ifndef INCLUDE_LD_PD_MAP
-#define	INCLUDE_LD_PD_MAP
+#ifndef _LD_PD_MAP
+#define	_LD_PD_MAP
 #include <sys/scsi/scsi.h>
 #include "fusion.h"
 
+struct mrsas_instance;	/* This will be defined in mr_sas.h */
+
 /* raid->write_mode; raid->read_ahead; dcmd->state */
 /* Write through */
 #define	WRITE_THROUGH				0
@@ -26,19 +28,19 @@
 #define	WRITE_BACK				1
 
 /* SCSI CDB definitions */
-#define READ_6          0x08
-#define READ_16         0x88
-#define READ_10         0x28
-#define READ_12         0xA8
-#define WRITE_16        0x8A
-#define WRITE_10        0x2A
+#define	READ_6		0x08
+#define	READ_16		0x88
+#define	READ_10		0x28
+#define	READ_12		0xA8
+#define	WRITE_16	0x8A
+#define	WRITE_10	0x2A
 
-// maximum disks per array
+/* maximum disks per array */
 #define	MAX_ROW_SIZE				32
-// maximum spans per logical drive
+/* maximum spans per logical drive */
 #define	MAX_SPAN_DEPTH				8
-#define MEGASAS_LOAD_BALANCE_FLAG		0x1
-#define MR_DEFAULT_IO_TIMEOUT   20
+#define	MEGASAS_LOAD_BALANCE_FLAG		0x1
+#define	MR_DEFAULT_IO_TIMEOUT	20
 
 
 union desc_value {
@@ -51,11 +53,11 @@
 
 typedef struct _LD_LOAD_BALANCE_INFO
 {
-    U8      loadBalanceFlag;
-    U8      reserved1;
-    U16     raid1DevHandle[2];
-    U16     scsi_pending_cmds[2];
-    U64     last_accessed_block[2];
+    U8	    loadBalanceFlag;
+    U8	    reserved1;
+    U16	    raid1DevHandle[2];
+    U16	    scsi_pending_cmds[2];
+    U64	    last_accessed_block[2];
 } LD_LOAD_BALANCE_INFO, *PLD_LOAD_BALANCE_INFO;
 
 #pragma pack(1)
@@ -65,39 +67,40 @@
 } MR_FW_RAID_MAP_ALL;
 
 /*
- * Raid Context structure which describes MegaRAID specific IO Paramenters
+ * Raid Context structure which describes MegaRAID specific IO Parameters
  * This resides at offset 0x60 where the SGL normally starts in MPT IO Frames
  */
 typedef struct _MPI2_SCSI_IO_VENDOR_UNIQUE {
-	U8		nsegType;			// 0x00 nseg[7:4], Type[3:0] */
-	U8		resvd0;				// 0x01
-    U16     timeoutValue;       /* 0x02 -0x03  */
-    U8      regLockFlags;       /* 0x04        */
-    U8      reservedForHw1;     /* 0x05        */
-    U16     ldTargetId;         /* 0x06 - 0x07 */
-    U64     regLockRowLBA;      /* 0x08 - 0x0F */
-    U32     regLockLength;      /* 0x10 - 0x13 */
-    U16     nextLMId;           /* 0x14 - 0x15 */
-    U8      extStatus;          /* 0x16        */
-    U8      status;             /* 0x17 status */
-    U8      RAIDFlags;          /* 0x18 resvd[7:6], ioSubType[5:4], resvd[3:1], preferredCpu[0] */
-    U8      numSGE;             /* 0x19 numSge; not including chain entries*/
-    U16     configSeqNum;       /* 0x1A -0x1B */
-    U8      spanArm;            /* 0x1C span[7:5], arm[4:0] */
-    U8      resvd2[3];          /* 0x1D-0x1f */
+	U8 nsegType;		/* 0x00 nseg[7:4], Type[3:0] */
+	U8 resvd0;		/* 0x01 */
+	U16 timeoutValue;	/* 0x02 -0x03 */
+	U8 regLockFlags;	/* 0x04 */
+	U8 reservedForHw1;	/* 0x05 */
+	U16 ldTargetId;		/* 0x06 - 0x07 */
+	U64 regLockRowLBA;	/* 0x08 - 0x0F */
+	U32 regLockLength;	/* 0x10 - 0x13 */
+	U16 nextLMId;		/* 0x14 - 0x15 */
+	U8 extStatus;		/* 0x16 */
+	U8 status;		/* 0x17 status */
+	U8 RAIDFlags;		/* 0x18 resvd[7:6], ioSubType[5:4], */
+				/* resvd[3:1], preferredCpu[0] */
+	U8 numSGE;		/* 0x19 numSge; not including chain entries */
+	U16 configSeqNum;	/* 0x1A -0x1B */
+	U8 spanArm;		/* 0x1C span[7:5], arm[4:0] */
+	U8 resvd2[3];		/* 0x1D-0x1f */
 } MPI2_SCSI_IO_VENDOR_UNIQUE, MPI25_SCSI_IO_VENDOR_UNIQUE;
 
-#define RAID_CTX_SPANARM_ARM_SHIFT	(0)
-#define RAID_CTX_SPANARM_ARM_MASK	(0x1f)
+#define	RAID_CTX_SPANARM_ARM_SHIFT	(0)
+#define	RAID_CTX_SPANARM_ARM_MASK	(0x1f)
 
-#define RAID_CTX_SPANARM_SPAN_SHIFT	(5)
-#define RAID_CTX_SPANARM_SPAN_MASK	(0xE0)
+#define	RAID_CTX_SPANARM_SPAN_SHIFT	(5)
+#define	RAID_CTX_SPANARM_SPAN_MASK	(0xE0)
 
 
 /*
  * RAID SCSI IO Request Message
  * Total SGE count will be one less
- * than  _MPI2_SCSI_IO_REQUEST
+ * than	 _MPI2_SCSI_IO_REQUEST
  */
 typedef struct _MPI2_RAID_SCSI_IO_REQUEST
 {
@@ -130,7 +133,7 @@
 	uint8_t			LUN[8];				/* 0x34 */
 	uint32_t		Control;			/* 0x3C */
 	Mpi2ScsiIoCdb_t		CDB;				/* 0x40 */
-	MPI2_SCSI_IO_VENDOR_UNIQUE		RaidContext;			/* 0x60 */
+	MPI2_SCSI_IO_VENDOR_UNIQUE RaidContext;			/* 0x60 */
 	Mpi2SGEIOUnion_t	SGL; /* 0x80 */
 } MPI2_RAID_SCSI_IO_REQUEST, MPI2_POINTER PTR_MPI2_RAID_SCSI_IO_REQUEST,
 Mpi2RaidSCSIIORequest_t, MPI2_POINTER pMpi2RaidSCSIIORequest_t;
@@ -139,10 +142,10 @@
  * define region lock types
  */
 typedef enum	_REGION_TYPE {
-	REGION_TYPE_UNUSED	= 0,	// lock is currently not active
-	REGION_TYPE_SHARED_READ	= 1,	// shared lock (for reads)
+	REGION_TYPE_UNUSED	= 0,	/* lock is currently not active */
+	REGION_TYPE_SHARED_READ	= 1,	/* shared lock (for reads) */
 	REGION_TYPE_SHARED_WRITE = 2,
-	REGION_TYPE_EXCLUSIVE	= 3,	// exclusive lock (for writes)
+	REGION_TYPE_EXCLUSIVE	= 3	/* exclusive lock (for writes) */
 } REGION_TYPE;
 
 
@@ -150,10 +153,10 @@
 #define	DM_PATH_FIRSTPATH	0
 #define	DM_PATH_SECONDPATH	1
 
-// declare valid Region locking values
+/* declare valid Region locking values */
 typedef enum _REGION_LOCK {
 	REGION_LOCK_BYPASS		= 0,
-	// for RAID 6 single-drive failure
+	/* for RAID 6 single-drive failure */
 	REGION_LOCK_UNCOND_SHARED_READ	= 1,
 	REGION_LOCK_UNCOND_SHARED_WRITE	= 2,
 	REGION_LOCK_UNCOND_SHARED_OTHER	= 3,
@@ -180,7 +183,7 @@
 	uint32_t queue_info_new_phys_addr_hi;	/* 1Ch */
 	uint32_t queue_info_old_phys_addr_lo;	/* 20h */
 	uint32_t queue_info_old_phys_addr_hi;	/* 24h */
-	uint64_t 	driverversion;		/* 28h */
+	uint64_t	driverversion;		/* 28h */
 	uint32_t reserved_4[4];			/* 30h */
 };
 
@@ -189,8 +192,8 @@
  * Request descriptor types
  */
 #define	MPI2_REQ_DESCRIPT_FLAGS_LD_IO		0x7
-#define	MPI2_REQ_DESCRIPT_FLAGS_MFA			0x1
-#define MPI2_REQ_DESCRIPT_FLAGS_NO_LOCK		0x2
+#define	MPI2_REQ_DESCRIPT_FLAGS_MFA		0x1
+#define	MPI2_REQ_DESCRIPT_FLAGS_NO_LOCK		0x2
 
 #define	MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT	1
 
@@ -225,7 +228,7 @@
 	MRSAS_SCSI_SERVICE_ACTION_WRITE32	= 0xB,
 	MRSAS_SCSI_ADDL_CDB_LEN			= 0x18,
 	MRSAS_RD_WR_PROTECT			= 0x20,
-	MRSAS_EEDPBLOCKSIZE			= 512,
+	MRSAS_EEDPBLOCKSIZE			= 512
 };
 
 
@@ -238,6 +241,9 @@
 #define	IEEE_SGE_FLAGS_END_OF_LIST	(0x40)
 
 
-U8 	MR_ValidateMapInfo(MR_FW_RAID_MAP_ALL *map, PLD_LOAD_BALANCE_INFO lbInfo);
-U16	MR_CheckDIF(U32, MR_FW_RAID_MAP_ALL *);
-#endif // INCLUDE_LD_PD_MAP
+U8 MR_ValidateMapInfo(MR_FW_RAID_MAP_ALL *map, PLD_LOAD_BALANCE_INFO lbInfo);
+U16 MR_CheckDIF(U32, MR_FW_RAID_MAP_ALL *);
+U8 MR_BuildRaidContext(struct mrsas_instance *, struct IO_REQUEST_INFO *,
+    MPI2_SCSI_IO_VENDOR_UNIQUE *, MR_FW_RAID_MAP_ALL *);
+
+#endif /* _LD_PD_MAP */
--- old/./mr_sas.c	Tue Nov  6 14:29:38 2012
+++ new/./mr_sas.c	Tue Nov  6 14:29:38 2012
@@ -12,8 +12,41 @@
  *		Manju R
  *		Rasheed
  *		Shakeel Bukhari
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the author nor the names of its contributors may be
+ *    used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
  */
 
+/*
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011 Bayard G. Bell. All rights reserved.
+ * Copyright 2012 Nexenta System, Inc. All rights reserved.
+ */
+
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/file.h>
@@ -40,16 +73,24 @@
 #include "mr_sas.h"
 
 /*
+ * FMA header files
+ */
+#include <sys/ddifm.h>
+#include <sys/fm/protocol.h>
+#include <sys/fm/util.h>
+#include <sys/fm/io/ddi.h>
+
+/*
  * Local static data
  */
 static void	*mrsas_state = NULL;
-static volatile boolean_t	mrsas_relaxed_ordering = 0;
-volatile int 	debug_level_g = CL_NONE;
+static volatile boolean_t	mrsas_relaxed_ordering = B_TRUE;
+volatile int	debug_level_g = CL_NONE;
+static volatile int	msi_enable = 1;
+static volatile int 	ctio_enable = 1;
 
-static volatile int 	msi_enable = 1;
-
 /* Default Timeout value to issue online controller reset */
-volatile int  debug_timeout_g  = 0xF0;		//0xB4;
+volatile int  debug_timeout_g  = 0xF0;		/* 0xB4; */
 /* Simulate consecutive firmware fault */
 static volatile int  debug_fw_faults_after_ocr_g  = 0;
 #ifdef OCRDEBUG
@@ -57,14 +98,107 @@
 static volatile int  debug_consecutive_timeout_after_ocr_g  = 0;
 #endif
 
-/* Enable OCR on firmware fault */
-static volatile int  debug_support_ocr_isr_g  = 0;
 #pragma weak scsi_hba_open
 #pragma weak scsi_hba_close
 #pragma weak scsi_hba_ioctl
 
+/* Local static prototypes. */
+static int	mrsas_getinfo(dev_info_t *, ddi_info_cmd_t,  void *, void **);
+static int	mrsas_attach(dev_info_t *, ddi_attach_cmd_t);
+#ifdef __sparc
+static int	mrsas_reset(dev_info_t *, ddi_reset_cmd_t);
+#else
+static int	mrsas_quiesce(dev_info_t *);
+#endif
+static int	mrsas_detach(dev_info_t *, ddi_detach_cmd_t);
+static int	mrsas_open(dev_t *, int, int, cred_t *);
+static int	mrsas_close(dev_t, int, int, cred_t *);
+static int	mrsas_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
 
+static int	mrsas_tran_tgt_init(dev_info_t *, dev_info_t *,
+		    scsi_hba_tran_t *, struct scsi_device *);
+static struct scsi_pkt *mrsas_tran_init_pkt(struct scsi_address *, register
+		    struct scsi_pkt *, struct buf *, int, int, int, int,
+		    int (*)(), caddr_t);
+static int	mrsas_tran_start(struct scsi_address *,
+		    register struct scsi_pkt *);
+static int	mrsas_tran_abort(struct scsi_address *, struct scsi_pkt *);
+static int	mrsas_tran_reset(struct scsi_address *, int);
+static int	mrsas_tran_getcap(struct scsi_address *, char *, int);
+static int	mrsas_tran_setcap(struct scsi_address *, char *, int, int);
+static void	mrsas_tran_destroy_pkt(struct scsi_address *,
+		    struct scsi_pkt *);
+static void	mrsas_tran_dmafree(struct scsi_address *, struct scsi_pkt *);
+static void	mrsas_tran_sync_pkt(struct scsi_address *, struct scsi_pkt *);
+static int	mrsas_tran_quiesce(dev_info_t *dip);
+static int	mrsas_tran_unquiesce(dev_info_t *dip);
+static uint_t	mrsas_isr();
+static uint_t	mrsas_softintr();
+static void	mrsas_undo_resources(dev_info_t *, struct mrsas_instance *);
+static struct mrsas_cmd *get_mfi_pkt(struct mrsas_instance *);
+static void	return_mfi_pkt(struct mrsas_instance *,
+		    struct mrsas_cmd *);
 
+static void	free_space_for_mfi(struct mrsas_instance *);
+static uint32_t	read_fw_status_reg_ppc(struct mrsas_instance *);
+static void	issue_cmd_ppc(struct mrsas_cmd *, struct mrsas_instance *);
+static int	issue_cmd_in_poll_mode_ppc(struct mrsas_instance *,
+		    struct mrsas_cmd *);
+static int	issue_cmd_in_sync_mode_ppc(struct mrsas_instance *,
+		    struct mrsas_cmd *);
+static void	enable_intr_ppc(struct mrsas_instance *);
+static void	disable_intr_ppc(struct mrsas_instance *);
+static int	intr_ack_ppc(struct mrsas_instance *);
+static void	flush_cache(struct mrsas_instance *instance);
+void	display_scsi_inquiry(caddr_t);
+static int	start_mfi_aen(struct mrsas_instance *instance);
+static int	handle_drv_ioctl(struct mrsas_instance *instance,
+		    struct mrsas_ioctl *ioctl, int mode);
+static int	handle_mfi_ioctl(struct mrsas_instance *instance,
+		    struct mrsas_ioctl *ioctl, int mode);
+static int	handle_mfi_aen(struct mrsas_instance *instance,
+		    struct mrsas_aen *aen);
+static struct mrsas_cmd *build_cmd(struct mrsas_instance *,
+    struct scsi_address *, struct scsi_pkt *, uchar_t *);
+static int	alloc_additional_dma_buffer(struct mrsas_instance *);
+static void	complete_cmd_in_sync_mode(struct mrsas_instance *,
+		struct mrsas_cmd *);
+static int	mrsas_kill_adapter(struct mrsas_instance *);
+static int	mrsas_issue_init_mfi(struct mrsas_instance *);
+static int	mrsas_reset_ppc(struct mrsas_instance *);
+static uint32_t mrsas_initiate_ocr_if_fw_is_faulty(struct mrsas_instance *);
+static int	wait_for_outstanding(struct mrsas_instance *instance);
+static int	register_mfi_aen(struct mrsas_instance *instance,
+		    uint32_t seq_num, uint32_t class_locale_word);
+static int	issue_mfi_pthru(struct mrsas_instance *instance, struct
+		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
+static int	issue_mfi_dcmd(struct mrsas_instance *instance, struct
+		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
+static int	issue_mfi_smp(struct mrsas_instance *instance, struct
+		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
+static int	issue_mfi_stp(struct mrsas_instance *instance, struct
+		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
+static int	abort_aen_cmd(struct mrsas_instance *instance,
+		    struct mrsas_cmd *cmd_to_abort);
+
+static void	mrsas_rem_intrs(struct mrsas_instance *instance);
+static int	mrsas_add_intrs(struct mrsas_instance *instance, int intr_type);
+
+static void	mrsas_tran_tgt_free(dev_info_t *, dev_info_t *,
+		    scsi_hba_tran_t *, struct scsi_device *);
+static int	mrsas_tran_bus_config(dev_info_t *, uint_t,
+		    ddi_bus_config_op_t, void *, dev_info_t **);
+static int	mrsas_parse_devname(char *, int *, int *);
+static int	mrsas_config_all_devices(struct mrsas_instance *);
+static int	mrsas_config_ld(struct mrsas_instance *, uint16_t,
+			uint8_t, dev_info_t **);
+static int	mrsas_name_node(dev_info_t *, char *, int);
+static void	mrsas_issue_evt_taskq(struct mrsas_eventinfo *);
+static void	free_additional_dma_buffer(struct mrsas_instance *);
+static void io_timeout_checker(void *);
+static void mrsas_fm_init(struct mrsas_instance *);
+static void mrsas_fm_fini(struct mrsas_instance *);
+
 static struct mrsas_function_template mrsas_function_template_ppc = {
 	.read_fw_status_reg = read_fw_status_reg_ppc,
 	.issue_cmd = issue_cmd_ppc,
@@ -74,7 +208,6 @@
 	.disable_intr = disable_intr_ppc,
 	.intr_ack = intr_ack_ppc,
 	.init_adapter = mrsas_init_adapter_ppc
-//	.reset_adapter = mrsas_reset_adapter_ppc
 };
 
 
@@ -87,7 +220,6 @@
 	.disable_intr = tbolt_disable_intr,
 	.intr_ack = tbolt_intr_ack,
 	.init_adapter = mrsas_init_adapter_tbolt
-//	.reset_adapter = mrsas_reset_adapter_tbolt
 };
 
 
@@ -95,7 +227,7 @@
 	DMA_ATTR_V0,		/* dma_attr_version */
 	0,			/* low DMA address range */
 	0xFFFFFFFFU,		/* high DMA address range */
-	0xFFFFFFFFU,		/* DMA counter register  */
+	0xFFFFFFFFU,		/* DMA counter register	 */
 	8,			/* DMA address alignment */
 	0x07,			/* DMA burstsizes  */
 	1,			/* min DMA size */
@@ -108,7 +240,10 @@
 
 int32_t mrsas_max_cap_maxxfer = 0x1000000;
 
-//Fix for: Thunderbolt controller IO timeout when IO write size is 1MEG, Limit size to 256K
+/*
+ * Fix for: Thunderbolt controller IO timeout when IO write size is 1MEG,
+ * Limit size to 256K
+ */
 uint32_t mrsas_tbolt_max_cap_maxxfer = (512 * 512);
 
 /*
@@ -146,22 +281,21 @@
 	nulldev,		/* probe */
 	mrsas_attach,		/* attach */
 	mrsas_detach,		/* detach */
-#if defined(__SunOS_5_11)
-	nodev,
-#else
+#ifdef	__sparc
 	mrsas_reset,		/* reset */
-#endif  /* defined(__SunOS_5_11) */
+#else	/* __sparc */
+	nodev,
+#endif	/* __sparc */
 	&mrsas_cb_ops,		/* char/block ops */
 	NULL,			/* bus ops */
 	NULL,			/* power */
-#ifdef __SunOS_5_11
+#ifdef __sparc
+	ddi_quiesce_not_needed
+#else	/* __sparc */
 	mrsas_quiesce	/* quiesce */
-#endif /*__SunOS_5_11 */
-
+#endif	/* __sparc */
 };
 
-char _depends_on[] = "misc/scsi";
-
 static struct modldrv modldrv = {
 	&mod_driverops,		/* module type - driver */
 	MRSAS_VERSION,
@@ -181,15 +315,15 @@
 	DDI_DEFAULT_ACC
 };
 
-
+/* Use the LSI Fast Path for the 2208 (tbolt) commands. */
 unsigned int enable_fp = 1;
 
 
 /*
  * ************************************************************************** *
- *                                                                            *
- *         common entry points - for loadable kernel modules                  *
- *                                                                            *
+ *									      *
+ *	   common entry points - for loadable kernel modules		      *
+ *									      *
  * ************************************************************************** *
  */
 
@@ -265,9 +399,9 @@
 
 	con_log(CL_ANN1, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
 
-	if ((ret = mod_remove(&modlinkage)) != DDI_SUCCESS)
-	{
-		con_log(CL_ANN1, (CE_WARN, "_fini: mod_remove() failed, error 0x%X", ret));
+	if ((ret = mod_remove(&modlinkage)) != DDI_SUCCESS) {
+		con_log(CL_ANN1,
+		    (CE_WARN, "_fini: mod_remove() failed, error 0x%X", ret));
 		return (ret);
 	}
 
@@ -283,9 +417,9 @@
 
 /*
  * ************************************************************************** *
- *                                                                            *
- *               common entry points - for autoconfiguration                  *
- *                                                                            *
+ *									      *
+ *		 common entry points - for autoconfiguration		      *
+ *									      *
  * ************************************************************************** *
  */
 /*
@@ -311,10 +445,6 @@
  * - report that the device instance (for MegaRAID, controller instance) has
  *   attached
  */
-#if       __SunOS_5_11
-#define   DDI_PM_RESUME DDI_PM_RESUME_OBSOLETE
-#define   DDI_PM_SUSPEND DDI_PM_SUSPEND_OBSOLETE
-#endif // __SunOS_5_11
 static int
 mrsas_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
 {
@@ -321,7 +451,7 @@
 	int		instance_no;
 	int		nregs;
 	int		i = 0;
-	uint8_t 	irq;
+	uint8_t		irq;
 	uint16_t	vendor_id;
 	uint16_t	device_id;
 	uint16_t	subsysvid;
@@ -332,7 +462,7 @@
 	char		*data;
 
 	scsi_hba_tran_t		*tran;
-	ddi_dma_attr_t  tran_dma_attr;
+	ddi_dma_attr_t	tran_dma_attr;
 	struct mrsas_instance	*instance;
 
 	con_log(CL_ANN1, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
@@ -353,506 +483,496 @@
 	}
 
 	switch (cmd) {
-		case DDI_ATTACH:
+	case DDI_ATTACH:
+		/* allocate the soft state for the instance */
+		if (ddi_soft_state_zalloc(mrsas_state, instance_no)
+		    != DDI_SUCCESS) {
+			cmn_err(CE_WARN,
+			    "mr_sas%d: Failed to allocate soft state",
+			    instance_no);
+			return (DDI_FAILURE);
+		}
 
-			/* allocate the soft state for the instance */
-			if (ddi_soft_state_zalloc(mrsas_state, instance_no)
-			    != DDI_SUCCESS) {
-				cmn_err(CE_WARN,
-				    "mr_sas%d: Failed to allocate soft state",
-				    instance_no);
+		instance = (struct mrsas_instance *)ddi_get_soft_state
+		    (mrsas_state, instance_no);
 
-				return (DDI_FAILURE);
-			}
+		if (instance == NULL) {
+			cmn_err(CE_WARN,
+			    "mr_sas%d: Bad soft state", instance_no);
+			ddi_soft_state_free(mrsas_state, instance_no);
+			return (DDI_FAILURE);
+		}
 
-			instance = (struct mrsas_instance *)ddi_get_soft_state
-			    (mrsas_state, instance_no);
+		instance->unroll.softs	= 1;
 
-			if (instance == NULL) {
-				cmn_err(CE_WARN,
-				    "mr_sas%d: Bad soft state", instance_no);
+		/* Setup the PCI configuration space handles */
+		if (pci_config_setup(dip, &instance->pci_handle) !=
+		    DDI_SUCCESS) {
+			cmn_err(CE_WARN,
+			    "mr_sas%d: pci config setup failed ",
+			    instance_no);
 
-				ddi_soft_state_free(mrsas_state, instance_no);
+			ddi_soft_state_free(mrsas_state, instance_no);
+			return (DDI_FAILURE);
+		}
 
-				return (DDI_FAILURE);
-			}
+		if (ddi_dev_nregs(dip, &nregs) != DDI_SUCCESS) {
+			cmn_err(CE_WARN,
+			    "mr_sas: failed to get registers.");
 
-			bzero((caddr_t)instance,
-			    sizeof (struct mrsas_instance));
+			pci_config_teardown(&instance->pci_handle);
+			ddi_soft_state_free(mrsas_state, instance_no);
+			return (DDI_FAILURE);
+		}
 
-			instance->unroll.softs  = 1;
+		vendor_id = pci_config_get16(instance->pci_handle,
+		    PCI_CONF_VENID);
+		device_id = pci_config_get16(instance->pci_handle,
+		    PCI_CONF_DEVID);
 
-			/* Setup the PCI configuration space handles */
-			if (pci_config_setup(dip, &instance->pci_handle) !=
-			    DDI_SUCCESS) {
-				cmn_err(CE_WARN,
-				    "mr_sas%d: pci config setup failed ",
-				    instance_no);
+		subsysvid = pci_config_get16(instance->pci_handle,
+		    PCI_CONF_SUBVENID);
+		subsysid = pci_config_get16(instance->pci_handle,
+		    PCI_CONF_SUBSYSID);
 
-				ddi_soft_state_free(mrsas_state, instance_no);
-				return (DDI_FAILURE);
-			}
-			if (instance->pci_handle == NULL) {
-				cmn_err(CE_WARN,
-				    "mr_sas%d: pci config setup failed ",
-				    instance_no);
-				ddi_soft_state_free(mrsas_state, instance_no);
-				return (DDI_FAILURE);
-			}
+		pci_config_put16(instance->pci_handle, PCI_CONF_COMM,
+		    (pci_config_get16(instance->pci_handle,
+		    PCI_CONF_COMM) | PCI_COMM_ME));
+		irq = pci_config_get8(instance->pci_handle,
+		    PCI_CONF_ILINE);
 
+		con_log(CL_DLEVEL1, (CE_CONT, "mr_sas%d: "
+		    "0x%x:0x%x 0x%x:0x%x, irq:%d drv-ver:%s",
+		    instance_no, vendor_id, device_id, subsysvid,
+		    subsysid, irq, MRSAS_VERSION));
 
+		/* enable bus-mastering */
+		command = pci_config_get16(instance->pci_handle,
+		    PCI_CONF_COMM);
 
-			if (ddi_dev_nregs(dip, &nregs) != DDI_SUCCESS) {
-				cmn_err(CE_WARN,
-				    "mr_sas: failed to get registers.");
+		if (!(command & PCI_COMM_ME)) {
+			command |= PCI_COMM_ME;
 
-				pci_config_teardown(&instance->pci_handle);
-				ddi_soft_state_free(mrsas_state, instance_no);
-				return (DDI_FAILURE);
-			}
+			pci_config_put16(instance->pci_handle,
+			    PCI_CONF_COMM, command);
 
-			vendor_id = pci_config_get16(instance->pci_handle,
-			    PCI_CONF_VENID);
-			device_id = pci_config_get16(instance->pci_handle,
-			    PCI_CONF_DEVID);
+			con_log(CL_ANN, (CE_CONT, "mr_sas%d: "
+			    "enable bus-mastering", instance_no));
+		} else {
+			con_log(CL_DLEVEL1, (CE_CONT, "mr_sas%d: "
+			    "bus-mastering already set", instance_no));
+		}
 
-			subsysvid = pci_config_get16(instance->pci_handle,
-			    PCI_CONF_SUBVENID);
-			subsysid = pci_config_get16(instance->pci_handle,
-			    PCI_CONF_SUBSYSID);
+		/* initialize function pointers */
+		switch (device_id) {
+		case PCI_DEVICE_ID_LSI_TBOLT:
+		case PCI_DEVICE_ID_LSI_INVADER:
+			con_log(CL_ANN, (CE_NOTE,
+			    "mr_sas: 2208 T.B. device detected"));
 
-			pci_config_put16(instance->pci_handle, PCI_CONF_COMM,
-			    (pci_config_get16(instance->pci_handle,
-			    PCI_CONF_COMM) | PCI_COMM_ME));
-			irq = pci_config_get8(instance->pci_handle,
-			    PCI_CONF_ILINE);
+			instance->func_ptr =
+			    &mrsas_function_template_fusion;
+			instance->tbolt = 1;
+			break;
 
-			con_log(CL_DLEVEL1, (CE_CONT, "mr_sas%d: "
-			    "0x%x:0x%x 0x%x:0x%x, irq:%d drv-ver:%s",
-			    instance_no, vendor_id, device_id, subsysvid,
-			    subsysid, irq, MRSAS_VERSION));
+		case PCI_DEVICE_ID_LSI_2108VDE:
+		case PCI_DEVICE_ID_LSI_2108V:
+			con_log(CL_ANN, (CE_NOTE,
+			    "mr_sas: 2108 Liberator device detected"));
 
-			/* enable bus-mastering */
-			command = pci_config_get16(instance->pci_handle,
-			    PCI_CONF_COMM);
+			instance->func_ptr =
+			    &mrsas_function_template_ppc;
+			break;
 
-			if (!(command & PCI_COMM_ME)) {
-				command |= PCI_COMM_ME;
+		default:
+			cmn_err(CE_WARN,
+			    "mr_sas: Invalid device detected");
 
-				pci_config_put16(instance->pci_handle,
-				    PCI_CONF_COMM, command);
+			pci_config_teardown(&instance->pci_handle);
+			ddi_soft_state_free(mrsas_state, instance_no);
+			return (DDI_FAILURE);
+		}
 
-				con_log(CL_ANN, (CE_CONT, "mr_sas%d: "
-				    "enable bus-mastering", instance_no));
-			} else {
-				con_log(CL_DLEVEL1, (CE_CONT, "mr_sas%d: "
-				"bus-mastering already set", instance_no));
-			}
+		instance->baseaddress = pci_config_get32(
+		    instance->pci_handle, PCI_CONF_BASE0);
+		instance->baseaddress &= 0x0fffc;
 
-			/* initialize function pointers */
-		       switch(device_id) {
-				case PCI_DEVICE_ID_LSI_TBOLT:
-				case PCI_DEVICE_ID_LSI_INVADER:
-					con_log(CL_ANN, (CE_NOTE,
-					    "mr_sas: 2208 T.B. device detected"));
+		instance->dip		= dip;
+		instance->vendor_id	= vendor_id;
+		instance->device_id	= device_id;
+		instance->subsysvid	= subsysvid;
+		instance->subsysid	= subsysid;
+		instance->instance	= instance_no;
 
-					instance->func_ptr = &mrsas_function_template_fusion;
-					instance->tbolt = 1;
-					break;
+		/* Initialize FMA */
+		instance->fm_capabilities = ddi_prop_get_int(
+		    DDI_DEV_T_ANY, instance->dip, DDI_PROP_DONTPASS,
+		    "fm-capable", DDI_FM_EREPORT_CAPABLE |
+		    DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE
+		    | DDI_FM_ERRCB_CAPABLE);
 
-				case PCI_DEVICE_ID_LSI_2108VDE:
-				case PCI_DEVICE_ID_LSI_2108V:
-					con_log(CL_ANN, (CE_NOTE,
-					    "mr_sas: 2108 Liberator device detected"));
+		mrsas_fm_init(instance);
 
-					instance->func_ptr = &mrsas_function_template_ppc;
-					break;
+		/* Setup register map */
+		if ((ddi_dev_regsize(instance->dip,
+		    REGISTER_SET_IO_2108, &reglength) != DDI_SUCCESS) ||
+		    reglength < MINIMUM_MFI_MEM_SZ) {
+			goto fail_attach;
+		}
+		if (reglength > DEFAULT_MFI_MEM_SZ) {
+			reglength = DEFAULT_MFI_MEM_SZ;
+			con_log(CL_DLEVEL1, (CE_NOTE,
+			    "mr_sas: register length to map is 0x%lx bytes",
+			    reglength));
+		}
+		if (ddi_regs_map_setup(instance->dip,
+		    REGISTER_SET_IO_2108, &instance->regmap, 0,
+		    reglength, &endian_attr, &instance->regmap_handle)
+		    != DDI_SUCCESS) {
+			cmn_err(CE_WARN,
+			    "mr_sas: couldn't map control registers");
+			goto fail_attach;
+		}
 
-				default:
-					cmn_err(CE_WARN,
-					    "mr_sas: Invalid device detected");
+		instance->unroll.regs = 1;
 
-					pci_config_teardown(&instance->pci_handle);
-					ddi_soft_state_free(mrsas_state, instance_no);
-					return (DDI_FAILURE);
+		/*
+		 * Disable Interrupt Now.
+		 * Setup Software interrupt
+		 */
+		instance->func_ptr->disable_intr(instance);
 
-		        }
+		if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
+		    "mrsas-enable-msi", &data) == DDI_SUCCESS) {
+			if (strncmp(data, "no", 3) == 0) {
+				msi_enable = 0;
+				con_log(CL_ANN1, (CE_WARN,
+				    "msi_enable = %d disabled", msi_enable));
+			}
+			ddi_prop_free(data);
+		}
 
-			instance->baseaddress = pci_config_get32(
-			    instance->pci_handle, PCI_CONF_BASE0);
-			instance->baseaddress &= 0x0fffc;
+		con_log(CL_DLEVEL1, (CE_NOTE, "msi_enable = %d", msi_enable));
 
-			instance->dip		= dip;
-			instance->vendor_id	= vendor_id;
-			instance->device_id	= device_id;
-			instance->subsysvid	= subsysvid;
-			instance->subsysid	= subsysid;
-			instance->instance	= instance_no;
+		if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
+		    "mrsas-enable-fp", &data) == DDI_SUCCESS) {
+			if (strncmp(data, "no", 3) == 0) {
+				enable_fp = 0;
+				cmn_err(CE_NOTE,
+				    "enable_fp = %d, Fast-Path disabled.\n",
+				    enable_fp);
+			}
 
+			ddi_prop_free(data);
+		}
 
-			/* Setup register map */
-			if ((ddi_dev_regsize(instance->dip,
-			    REGISTER_SET_IO_2108, &reglength) != DDI_SUCCESS) ||
-			    reglength < MINIMUM_MFI_MEM_SZ) {
+		con_log(CL_DLEVEL1, (CE_NOTE, "enable_fp = %d\n", enable_fp));
+
+		/* Check for all supported interrupt types */
+		if (ddi_intr_get_supported_types(
+		    dip, &intr_types) != DDI_SUCCESS) {
+			cmn_err(CE_WARN,
+			    "ddi_intr_get_supported_types() failed");
+			goto fail_attach;
+		}
+
+		con_log(CL_DLEVEL1, (CE_NOTE,
+		    "ddi_intr_get_supported_types() ret: 0x%x", intr_types));
+
+		/* Initialize and Setup Interrupt handler */
+		if (msi_enable && (intr_types & DDI_INTR_TYPE_MSIX)) {
+			if (mrsas_add_intrs(instance, DDI_INTR_TYPE_MSIX) !=
+			    DDI_SUCCESS) {
+				cmn_err(CE_WARN,
+				    "MSIX interrupt query failed");
 				goto fail_attach;
 			}
-			if (reglength > DEFAULT_MFI_MEM_SZ) {
-				reglength = DEFAULT_MFI_MEM_SZ;
-				con_log(CL_DLEVEL1, (CE_NOTE,
-				    "mr_sas: register length to map is "
-				    "0x%lx bytes", reglength));
-			}
-			if (ddi_regs_map_setup(instance->dip,
-			    REGISTER_SET_IO_2108, &instance->regmap, 0,
-			    reglength, &endian_attr, &instance->regmap_handle)
-			    != DDI_SUCCESS) {
+			instance->intr_type = DDI_INTR_TYPE_MSIX;
+		} else if (msi_enable && (intr_types & DDI_INTR_TYPE_MSI)) {
+			if (mrsas_add_intrs(instance, DDI_INTR_TYPE_MSI) !=
+			    DDI_SUCCESS) {
 				cmn_err(CE_WARN,
-				    "mr_sas: couldn't map control registers");
+				    "MSI interrupt query failed");
 				goto fail_attach;
 			}
-			if (instance->regmap_handle == NULL) {
+			instance->intr_type = DDI_INTR_TYPE_MSI;
+		} else if (intr_types & DDI_INTR_TYPE_FIXED) {
+			msi_enable = 0;
+			if (mrsas_add_intrs(instance, DDI_INTR_TYPE_FIXED) !=
+			    DDI_SUCCESS) {
 				cmn_err(CE_WARN,
-				    "mr_sas: couldn't map control registers");
+				    "FIXED interrupt query failed");
 				goto fail_attach;
 			}
+			instance->intr_type = DDI_INTR_TYPE_FIXED;
+		} else {
+			cmn_err(CE_WARN, "Device cannot "
+			    "suppport either FIXED or MSI/X "
+			    "interrupts");
+			goto fail_attach;
+		}
 
-			instance->unroll.regs = 1;
+		instance->unroll.intr = 1;
 
-			/*
-			 * Disable Interrupt Now.
-			 * Setup Software interrupt
-			 */
-			instance->func_ptr->disable_intr(instance);
-
-			if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
-			    "mrsas-enable-msi", &data) == DDI_SUCCESS) {
-				if (strncmp(data, "no", 3) == 0) {
-					msi_enable = 0;
-					con_log(CL_ANN1, (CE_WARN,
-					    "msi_enable = %d disabled",
-					    msi_enable));
-				}
-				ddi_prop_free(data);
+		if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
+		    "mrsas-enable-ctio", &data) == DDI_SUCCESS) {
+			if (strncmp(data, "no", 3) == 0) {
+				ctio_enable = 0;
+				con_log(CL_ANN1, (CE_WARN,
+				    "ctio_enable = %d disabled", ctio_enable));
 			}
+			ddi_prop_free(data);
+		}
 
-			con_log(CL_DLEVEL1, (CE_NOTE, "msi_enable = %d", msi_enable));
+		con_log(CL_DLEVEL1, (CE_WARN, "ctio_enable = %d", ctio_enable));
 
-			if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
-			    "mrsas-enable-fp", &data) == DDI_SUCCESS) {
-				if (strncmp(data, "no", 3) == 0) {
-					enable_fp = 0;
-					cmn_err(CE_NOTE,
-					    "enable_fp = %d, Fast-Path disabled.\n",
-					    enable_fp);
-				}
+		/* setup the mfi based low level driver */
+		if (mrsas_init_adapter(instance) != DDI_SUCCESS) {
+			cmn_err(CE_WARN, "mr_sas: "
+			    "could not initialize the low level driver");
 
-				ddi_prop_free(data);
-			}
+			goto fail_attach;
+		}
 
-			cmn_err(CE_NOTE, "enable_fp = %d\n", enable_fp);
+		/* Initialize all Mutex */
+		INIT_LIST_HEAD(&instance->completed_pool_list);
+		mutex_init(&instance->completed_pool_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			/* Check for all supported interrupt types */
-			if (ddi_intr_get_supported_types(
-			    dip, &intr_types) != DDI_SUCCESS) {
-				cmn_err(CE_WARN,
-				    "ddi_intr_get_supported_types() failed");
-				goto fail_attach;
-			}
+		mutex_init(&instance->sync_map_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			con_log(CL_DLEVEL1, (CE_NOTE,
-			    "ddi_intr_get_supported_types() ret: 0x%x",
-			    intr_types));
+		mutex_init(&instance->app_cmd_pool_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			/* Initialize and Setup Interrupt handler */
-			if (msi_enable && (intr_types & DDI_INTR_TYPE_MSIX)) {
-				if (mrsas_add_intrs(instance,
-				    DDI_INTR_TYPE_MSIX) != DDI_SUCCESS) {
-					cmn_err(CE_WARN,
-					    "MSIX interrupt query failed");
-					goto fail_attach;
-				}
-				instance->intr_type = DDI_INTR_TYPE_MSIX;
-			} else if (msi_enable && (intr_types &
-			    DDI_INTR_TYPE_MSI)) {
-				if (mrsas_add_intrs(instance,
-				    DDI_INTR_TYPE_MSI) != DDI_SUCCESS) {
-					cmn_err(CE_WARN,
-					    "MSI interrupt query failed");
-					goto fail_attach;
-				}
-				instance->intr_type = DDI_INTR_TYPE_MSI;
-			} else if (intr_types & DDI_INTR_TYPE_FIXED) {
-				msi_enable = 0;
-				if (mrsas_add_intrs(instance,
-				    DDI_INTR_TYPE_FIXED) != DDI_SUCCESS) {
-					cmn_err(CE_WARN,
-					    "FIXED interrupt query failed");
-					goto fail_attach;
-				}
-				instance->intr_type = DDI_INTR_TYPE_FIXED;
-			} else {
-				cmn_err(CE_WARN, "Device cannot "
-				    "suppport either FIXED or MSI/X "
-				    "interrupts");
-				goto fail_attach;
-			}
+		mutex_init(&instance->config_dev_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			instance->unroll.intr = 1;
+		mutex_init(&instance->cmd_pend_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
+		mutex_init(&instance->ocr_flags_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			/* setup the mfi based low level driver */
-			if (mrsas_init_adapter(instance) != DDI_SUCCESS) {
-				cmn_err(CE_WARN, "mr_sas: "
-				"could not initialize the low level driver");
+		mutex_init(&instance->int_cmd_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
+		cv_init(&instance->int_cmd_cv, NULL, CV_DRIVER, NULL);
 
-				goto fail_attach;
-			}
+		mutex_init(&instance->cmd_pool_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			/* Initialize all Mutex */
-			INIT_LIST_HEAD(&instance->completed_pool_list);
-			mutex_init(&instance->completed_pool_mtx,
-			    "completed_pool_mtx", MUTEX_DRIVER,
-			    DDI_INTR_PRI(instance->intr_pri));
-			
-			mutex_init(&instance->sync_map_mtx,
-			    "sync_map_mtx", MUTEX_DRIVER,
-			    DDI_INTR_PRI(instance->intr_pri));
-			
-			mutex_init(&instance->app_cmd_pool_mtx,
-			    "app_cmd_pool_mtx",	MUTEX_DRIVER,
-			    DDI_INTR_PRI(instance->intr_pri));
+		mutex_init(&instance->reg_write_mtx, NULL,
+		    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			mutex_init(&instance->config_dev_mtx, "config_dev_mtx",
+		if (instance->tbolt) {
+			mutex_init(&instance->cmd_app_pool_mtx, NULL,
 			    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			mutex_init(&instance->cmd_pend_mtx, "cmd_pend_mtx",
+			mutex_init(&instance->chip_mtx, NULL,
 			    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
 
-			mutex_init(&instance->ocr_flags_mtx, "ocr_flags_mtx",
-			    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
+		}
 
-			mutex_init(&instance->int_cmd_mtx, "int_cmd_mtx",
-			    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
-			cv_init(&instance->int_cmd_cv, NULL, CV_DRIVER, NULL);
+		instance->unroll.mutexs = 1;
 
-			mutex_init(&instance->cmd_pool_mtx, "cmd_pool_mtx",
-			    MUTEX_DRIVER, DDI_INTR_PRI(instance->intr_pri));
+		instance->timeout_id = (timeout_id_t)-1;
 
-			mutex_init(&instance->reg_write_mtx,"reg_write_mtx", 
-				MUTEX_DRIVER,DDI_INTR_PRI(instance->intr_pri));
+		/* Register our soft-isr for highlevel interrupts. */
+		instance->isr_level = instance->intr_pri;
+		if (!(instance->tbolt)) {
+			if (instance->isr_level == HIGH_LEVEL_INTR) {
+				if (ddi_add_softintr(dip,
+				    DDI_SOFTINT_HIGH,
+				    &instance->soft_intr_id, NULL, NULL,
+				    mrsas_softintr, (caddr_t)instance) !=
+				    DDI_SUCCESS) {
+					cmn_err(CE_WARN,
+					    "Software ISR did not register");
 
-			if (instance->tbolt) {
-				mutex_init(&instance->cmd_app_pool_mtx,
-				    "cmd_app_pool_mtx", MUTEX_DRIVER,
-				    DDI_INTR_PRI(instance->intr_pri));
+					goto fail_attach;
+				}
 
-				mutex_init(&instance->chip_mtx,
-				    "chip_mtx", MUTEX_DRIVER,
-				    DDI_INTR_PRI(instance->intr_pri));
+				instance->unroll.soft_isr = 1;
 
 			}
+		}
 
-			instance->unroll.mutexs = 1;
+		instance->softint_running = 0;
 
-			instance->timeout_id = (timeout_id_t)-1;
+		/* Allocate a transport structure */
+		tran = scsi_hba_tran_alloc(dip, SCSI_HBA_CANSLEEP);
 
-			/* Register our soft-isr for highlevel interrupts. */
-			instance->isr_level = instance->intr_pri;
-			if (!(instance->tbolt)) {
-				if (instance->isr_level == HIGH_LEVEL_INTR) {
-					if (ddi_add_softintr(dip,
-					    DDI_SOFTINT_HIGH,
-					    &instance->soft_intr_id,
-					    NULL, NULL, mrsas_softintr,
-					    (caddr_t)instance) !=
-					    DDI_SUCCESS) {
-						cmn_err(CE_WARN,
-						    "Software ISR "
-						    "did not register");
+		if (tran == NULL) {
+			cmn_err(CE_WARN,
+			    "scsi_hba_tran_alloc failed");
+			goto fail_attach;
+		}
 
-						goto fail_attach;
-					}
+		instance->tran = tran;
+		instance->unroll.tran = 1;
 
-					instance->unroll.soft_isr = 1;
+		tran->tran_hba_private	= instance;
+		tran->tran_tgt_init	= mrsas_tran_tgt_init;
+		tran->tran_tgt_probe	= scsi_hba_probe;
+		tran->tran_tgt_free	= mrsas_tran_tgt_free;
+		if (instance->tbolt) {
+			tran->tran_init_pkt	=
+			    mrsas_tbolt_tran_init_pkt;
+			tran->tran_start	=
+			    mrsas_tbolt_tran_start;
+		} else {
+			tran->tran_init_pkt	= mrsas_tran_init_pkt;
+			tran->tran_start	= mrsas_tran_start;
+		}
+		tran->tran_abort	= mrsas_tran_abort;
+		tran->tran_reset	= mrsas_tran_reset;
+		tran->tran_getcap	= mrsas_tran_getcap;
+		tran->tran_setcap	= mrsas_tran_setcap;
+		tran->tran_destroy_pkt	= mrsas_tran_destroy_pkt;
+		tran->tran_dmafree	= mrsas_tran_dmafree;
+		tran->tran_sync_pkt	= mrsas_tran_sync_pkt;
+		tran->tran_quiesce	= mrsas_tran_quiesce;
+		tran->tran_unquiesce	= mrsas_tran_unquiesce;
+		tran->tran_bus_config	= mrsas_tran_bus_config;
 
-				}
-			}
+		if (mrsas_relaxed_ordering)
+			mrsas_generic_dma_attr.dma_attr_flags |=
+			    DDI_DMA_RELAXED_ORDERING;
 
-			instance->softint_running = 0;
 
-			/* Allocate a transport structure */
-			tran = scsi_hba_tran_alloc(dip, SCSI_HBA_CANSLEEP);
+		tran_dma_attr = mrsas_generic_dma_attr;
+		tran_dma_attr.dma_attr_sgllen = instance->max_num_sge;
 
-			if (tran == NULL) {
-				cmn_err(CE_WARN,
-				    "scsi_hba_tran_alloc failed");
-				goto fail_attach;
-			}
+		/* Attach this instance of the hba */
+		if (scsi_hba_attach_setup(dip, &tran_dma_attr, tran, 0)
+		    != DDI_SUCCESS) {
+			cmn_err(CE_WARN,
+			    "scsi_hba_attach failed");
 
-			instance->tran = tran;
-			instance->unroll.tran = 1;
+			goto fail_attach;
+		}
+		instance->unroll.tranSetup = 1;
+		con_log(CL_ANN1,
+		    (CE_CONT, "scsi_hba_attach_setup()	done."));
 
-			tran->tran_hba_private	= instance;
-			tran->tran_tgt_init	= mrsas_tran_tgt_init;
-			tran->tran_tgt_probe	= scsi_hba_probe;
-			tran->tran_tgt_free	= mrsas_tran_tgt_free;
-			if (instance->tbolt) {
-				tran->tran_init_pkt	=
-				    mrsas_tbolt_tran_init_pkt;
-				tran->tran_start	=
-				    mrsas_tbolt_tran_start;
-			} else {
-				tran->tran_init_pkt	= mrsas_tran_init_pkt;
-				tran->tran_start	= mrsas_tran_start;
-			}
-			tran->tran_abort	= mrsas_tran_abort;
-			tran->tran_reset	= mrsas_tran_reset;
-			tran->tran_getcap	= mrsas_tran_getcap;
-			tran->tran_setcap	= mrsas_tran_setcap;
-			tran->tran_destroy_pkt	= mrsas_tran_destroy_pkt;
-			tran->tran_dmafree	= mrsas_tran_dmafree;
-			tran->tran_sync_pkt	= mrsas_tran_sync_pkt;
-			tran->tran_quiesce	= mrsas_tran_quiesce;
-			tran->tran_unquiesce	= mrsas_tran_unquiesce;
-			tran->tran_bus_config	= mrsas_tran_bus_config;
+		/* create devctl node for cfgadm command */
+		if (ddi_create_minor_node(dip, "devctl",
+		    S_IFCHR, INST2DEVCTL(instance_no),
+		    DDI_NT_SCSI_NEXUS, 0) == DDI_FAILURE) {
+			cmn_err(CE_WARN,
+			    "mr_sas: failed to create devctl node.");
 
-			if (mrsas_relaxed_ordering)
-				mrsas_generic_dma_attr.dma_attr_flags |=
-				    DDI_DMA_RELAXED_ORDERING;
+			goto fail_attach;
+		}
 
+		instance->unroll.devctl = 1;
 
-			tran_dma_attr = mrsas_generic_dma_attr;
-			tran_dma_attr.dma_attr_sgllen = instance->max_num_sge;
+		/* create scsi node for cfgadm command */
+		if (ddi_create_minor_node(dip, "scsi", S_IFCHR,
+		    INST2SCSI(instance_no), DDI_NT_SCSI_ATTACHMENT_POINT, 0) ==
+		    DDI_FAILURE) {
+			cmn_err(CE_WARN,
+			    "mr_sas: failed to create scsi node.");
 
-			/* Attach this instance of the hba */
-			if (scsi_hba_attach_setup(dip, &tran_dma_attr, tran, 0)
-			    != DDI_SUCCESS) {
-				cmn_err(CE_WARN,
-				    "scsi_hba_attach failed");
+			goto fail_attach;
+		}
 
-				goto fail_attach;
-			}
-			instance->unroll.tranSetup = 1;
-			con_log(CL_ANN1, (CE_CONT,
-				"scsi_hba_attach_setup()  done."));
+		instance->unroll.scsictl = 1;
 
+		(void) sprintf(instance->iocnode, "%d:lsirdctl",
+		    instance_no);
 
-			/* create devctl node for cfgadm command */
-			if (ddi_create_minor_node(dip, "devctl",
-			    S_IFCHR, INST2DEVCTL(instance_no),
-			    DDI_NT_SCSI_NEXUS, 0) == DDI_FAILURE) {
-				cmn_err(CE_WARN,
-				    "mr_sas: failed to create devctl node.");
+		/*
+		 * Create a node for applications
+		 * for issuing ioctl to the driver.
+		 */
+		if (ddi_create_minor_node(dip, instance->iocnode,
+		    S_IFCHR, INST2LSIRDCTL(instance_no), DDI_PSEUDO, 0) ==
+		    DDI_FAILURE) {
+			cmn_err(CE_WARN,
+			    "mr_sas: failed to create ioctl node.");
 
-				goto fail_attach;
-			}
+			goto fail_attach;
+		}
 
-			instance->unroll.devctl = 1;
+		instance->unroll.ioctl = 1;
 
-			/* create scsi node for cfgadm command */
-			if (ddi_create_minor_node(dip, "scsi", S_IFCHR,
-			    INST2SCSI(instance_no),
-			    DDI_NT_SCSI_ATTACHMENT_POINT, 0) ==
-			    DDI_FAILURE) {
-				cmn_err(CE_WARN,
-				    "mr_sas: failed to create scsi node.");
+		/* Create a taskq to handle dr events */
+		if ((instance->taskq = ddi_taskq_create(dip,
+		    "mrsas_dr_taskq", 1, TASKQ_DEFAULTPRI, 0)) == NULL) {
+			cmn_err(CE_WARN,
+			    "mr_sas: failed to create taskq ");
+			instance->taskq = NULL;
+			goto fail_attach;
+		}
+		instance->unroll.taskq = 1;
+		con_log(CL_ANN1, (CE_CONT, "ddi_taskq_create()	done."));
 
-				goto fail_attach;
-			}
+		/* enable interrupt */
+		instance->func_ptr->enable_intr(instance);
 
-			instance->unroll.scsictl = 1;
+		/* initiate AEN */
+		if (start_mfi_aen(instance)) {
+			cmn_err(CE_WARN,
+			    "mr_sas: failed to initiate AEN.");
+			goto fail_attach;
+		}
+		instance->unroll.aenPend = 1;
+		con_log(CL_ANN1,
+		    (CE_CONT, "AEN started for instance %d.", instance_no));
 
-			(void) sprintf(instance->iocnode, "%d:lsirdctl",
-			    instance_no);
+		/* Finally! We are on the air.	*/
+		ddi_report_dev(dip);
 
-			/*
-			 * Create a node for applications
-			 * for issuing ioctl to the driver.
-			 */
-			if (ddi_create_minor_node(dip, instance->iocnode,
-			    S_IFCHR, INST2LSIRDCTL(instance_no),
-			    DDI_PSEUDO, 0) == DDI_FAILURE) {
-				cmn_err(CE_WARN,
-				    "mr_sas: failed to create ioctl node.");
+		/* FMA handle checking. */
+		if (mrsas_check_acc_handle(instance->regmap_handle) !=
+		    DDI_SUCCESS) {
+			goto fail_attach;
+		}
+		if (mrsas_check_acc_handle(instance->pci_handle) !=
+		    DDI_SUCCESS) {
+			goto fail_attach;
+		}
 
-				goto fail_attach;
-			}
+		instance->mr_ld_list =
+		    kmem_zalloc(MRDRV_MAX_LD * sizeof (struct mrsas_ld),
+		    KM_SLEEP);
+		instance->unroll.ldlist_buff = 1;
 
-			instance->unroll.ioctl = 1;
-
-			/* Create a taskq to handle dr events */
-			if ((instance->taskq = ddi_taskq_create(dip,
-			    "mrsas_dr_taskq", 1,
-			    TASKQ_DEFAULTPRI, 0)) == NULL) {
-				cmn_err(CE_WARN,
-				    "mr_sas: failed to create taskq ");
-				instance->taskq = NULL;
-				goto fail_attach;
+#ifdef PDSUPPORT
+		if (instance->tbolt) {
+			instance->mr_tbolt_pd_max = MRSAS_TBOLT_PD_TGT_MAX;
+			instance->mr_tbolt_pd_list =
+			    kmem_zalloc(MRSAS_TBOLT_GET_PD_MAX(instance) *
+			    sizeof (struct mrsas_tbolt_pd), KM_SLEEP);
+			ASSERT(instance->mr_tbolt_pd_list);
+			for (i = 0; i < instance->mr_tbolt_pd_max; i++) {
+				instance->mr_tbolt_pd_list[i].lun_type =
+				    MRSAS_TBOLT_PD_LUN;
+				instance->mr_tbolt_pd_list[i].dev_id =
+				    (uint8_t)i;
 			}
-			instance->unroll.taskq = 1;
-			con_log(CL_ANN1, (CE_CONT,
-				"ddi_taskq_create()  done."));
 
-			/* enable interrupt */
-			instance->func_ptr->enable_intr(instance);
-
-			/* initiate AEN */
-			if (start_mfi_aen(instance)) {
-					cmn_err(CE_WARN,
-				    "mr_sas: failed to initiate AEN.");
-				goto fail_attach;
-			}
-			instance->unroll.aenPend = 1;
-			con_log(CL_ANN1, (CE_CONT,
-			    "AEN started for instance %d.", instance_no));
-
-			/* Finally! We are on the air.  */
-			ddi_report_dev(dip);
-						
-			instance->mr_ld_list =
-			    kmem_zalloc(MRDRV_MAX_LD * sizeof (struct mrsas_ld),
-			    KM_SLEEP);
-			if (instance->mr_ld_list == NULL) {
-				cmn_err(CE_WARN,
-				    "mr_sas attach(): failed to allocate ld_list array");
-				goto fail_attach;
-			}
-			instance->unroll.ldlist_buff = 1;
-
-#ifdef PDSUPPORT
-			if(instance->tbolt) {
-				instance->mr_tbolt_pd_max = MRSAS_TBOLT_PD_TGT_MAX;
-				instance->mr_tbolt_pd_list =
-			    	    kmem_zalloc(MRSAS_TBOLT_GET_PD_MAX(instance)
-			    	    * sizeof (struct mrsas_tbolt_pd), KM_SLEEP);
-				ASSERT(instance->mr_tbolt_pd_list);
-				for (i = 0; i < instance->mr_tbolt_pd_max; i++) {
-					instance->mr_tbolt_pd_list[i].lun_type = 
-					    MRSAS_TBOLT_PD_LUN;
-					instance->mr_tbolt_pd_list[i].dev_id = 
-					    (uint8_t)i;
-				}
-
-				instance->unroll.pdlist_buff = 1;
-			}	
+			instance->unroll.pdlist_buff = 1;
+		}
 #endif
-			break;
-		case DDI_PM_RESUME:
-			con_log(CL_ANN, (CE_NOTE,
-			    "mr_sas: DDI_PM_RESUME"));
-			break;
-		case DDI_RESUME:
-			con_log(CL_ANN, (CE_NOTE,
-			    "mr_sas: DDI_RESUME"));
-			break;
-		default:
-			con_log(CL_ANN, (CE_WARN,
-			    "mr_sas: invalid attach cmd=%x", cmd));
-			return (DDI_FAILURE);
+		break;
+	case DDI_PM_RESUME:
+		con_log(CL_ANN, (CE_NOTE, "mr_sas: DDI_PM_RESUME"));
+		break;
+	case DDI_RESUME:
+		con_log(CL_ANN, (CE_NOTE, "mr_sas: DDI_RESUME"));
+		break;
+	default:
+		con_log(CL_ANN,
+		    (CE_WARN, "mr_sas: invalid attach cmd=%x", cmd));
+		return (DDI_FAILURE);
 	}
 
 
-	cmn_err(CE_NOTE, "mrsas_attach() return SUCCESS instance_num %d", instance_no);
+	con_log(CL_DLEVEL1,
+	    (CE_NOTE, "mrsas_attach() return SUCCESS instance_num %d",
+	    instance_no));
 	return (DDI_SUCCESS);
 
 fail_attach:
@@ -859,13 +979,18 @@
 
 	mrsas_undo_resources(dip, instance);
 
+	mrsas_fm_ereport(instance, DDI_FM_DEVICE_NO_RESPONSE);
+	ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+
+	mrsas_fm_fini(instance);
+
 	pci_config_teardown(&instance->pci_handle);
 	ddi_soft_state_free(mrsas_state, instance_no);
 
-	con_log(CL_ANN, (CE_WARN,
-	    "mr_sas: return failure from mrsas_attach"));
+	con_log(CL_ANN, (CE_WARN, "mr_sas: return failure from mrsas_attach"));
 
-	cmn_err(CE_WARN, "mrsas_attach() return FAILURE instance_num %d", instance_no);
+	cmn_err(CE_WARN, "mrsas_attach() return FAILURE instance_num %d",
+	    instance_no);
 
 	return (DDI_FAILURE);
 }
@@ -981,14 +1106,16 @@
 			}
 			mutex_exit(&instance->config_dev_mtx);
 
-			if(instance->unroll.tranSetup == 1) {
+			if (instance->unroll.tranSetup == 1) {
 				if (scsi_hba_detach(dip) != DDI_SUCCESS) {
 					cmn_err(CE_WARN,
-						"mr_sas2%d: failed to detach", instance_no);
+					    "mr_sas2%d: failed to detach",
+					    instance_no);
 					return (DDI_FAILURE);
 				}
 				instance->unroll.tranSetup = 0;
-			        con_log(CL_ANN1, (CE_CONT, "scsi_hba_dettach()  done."));
+				con_log(CL_ANN1,
+				    (CE_CONT, "scsi_hba_dettach()  done."));
 			}
 
 			flush_cache(instance);
@@ -995,6 +1122,8 @@
 
 			mrsas_undo_resources(dip, instance);
 
+			mrsas_fm_fini(instance);
+
 			pci_config_teardown(&instance->pci_handle);
 			ddi_soft_state_free(mrsas_state, instance_no);
 			break;
@@ -1019,8 +1148,8 @@
 }
 
 
-static int
-mrsas_undo_resources (dev_info_t *dip, struct mrsas_instance *instance)
+static void
+mrsas_undo_resources(dev_info_t *dip, struct mrsas_instance *instance)
 {
 	int	instance_no;
 
@@ -1030,42 +1159,44 @@
 	instance_no = ddi_get_instance(dip);
 
 
-	if(instance->unroll.ioctl == 1)  {
+	if (instance->unroll.ioctl == 1) {
 		ddi_remove_minor_node(dip, instance->iocnode);
 		instance->unroll.ioctl = 0;
 	}
 
-	if(instance->unroll.scsictl == 1)  {
+	if (instance->unroll.scsictl == 1) {
 		ddi_remove_minor_node(dip, "scsi");
 		instance->unroll.scsictl = 0;
 	}
 
-	if(instance->unroll.devctl == 1)  {
+	if (instance->unroll.devctl == 1) {
 		ddi_remove_minor_node(dip, "devctl");
 		instance->unroll.devctl = 0;
 	}
 
-	if(instance->unroll.tranSetup == 1)  {
+	if (instance->unroll.tranSetup == 1) {
 		if (scsi_hba_detach(dip) != DDI_SUCCESS) {
 			cmn_err(CE_WARN,
-				"mr_sas2%d: failed to detach", instance_no);
-			return (DDI_FAILURE);
+			    "mr_sas2%d: failed to detach", instance_no);
+			return;	 /* DDI_FAILURE */
 		}
 		instance->unroll.tranSetup = 0;
-		con_log(CL_ANN1, (CE_CONT, "scsi_hba_dettach()  done."));
+		con_log(CL_ANN1, (CE_CONT, "scsi_hba_dettach()	done."));
 	}
 
-	if(instance->unroll.tran == 1)  {
+	if (instance->unroll.tran == 1)	 {
 		scsi_hba_tran_free(instance->tran);
 		instance->unroll.tran = 0;
 		con_log(CL_ANN1, (CE_CONT, "scsi_hba_tran_free()  done."));
 	}
 
-	if(instance->unroll.syncCmd == 1)  {
-		if(instance->tbolt) {
-			if (abort_syncmap_cmd(instance, instance->map_update_cmd))
+	if (instance->unroll.syncCmd == 1) {
+		if (instance->tbolt) {
+			if (abort_syncmap_cmd(instance,
+			    instance->map_update_cmd)) {
 				cmn_err(CE_WARN, "mrsas_detach: "
-					"failed to abort previous syncmap command");
+				    "failed to abort previous syncmap command");
+			}
 
 			instance->unroll.syncCmd = 0;
 			con_log(CL_ANN1, (CE_CONT, "sync cmd aborted, done."));
@@ -1072,20 +1203,21 @@
 		}
 	}
 
-	if(instance->unroll.aenPend == 1)  {
-		if (abort_aen_cmd(instance, instance->aen_cmd)) 
+	if (instance->unroll.aenPend == 1) {
+		if (abort_aen_cmd(instance, instance->aen_cmd))
 			cmn_err(CE_WARN, "mrsas_detach: "
-					"failed to abort prevous AEN command");
+			    "failed to abort prevous AEN command");
 
 		instance->unroll.aenPend = 0;
 		con_log(CL_ANN1, (CE_CONT, "aen cmd aborted, done."));
-		 /*This means the controller is fully initialzed and running */
-		 // shutdown_controller();Shutdown should be a last command to controller.
+		/* This means the controller is fully initialized and running */
+		/* Shutdown should be a last command to controller. */
+		/* shutdown_controller(); */
 	}
 
 
-	if(instance->unroll.timer == 1)	 {
-		if (instance->timeout_id != (timeout_id_t)-1)  {
+	if (instance->unroll.timer == 1)	 {
+		if (instance->timeout_id != (timeout_id_t)-1) {
 			(void) untimeout(instance->timeout_id);
 			instance->timeout_id = (timeout_id_t)-1;
 
@@ -1096,7 +1228,7 @@
 	instance->func_ptr->disable_intr(instance);
 
 
-	if(instance->unroll.mutexs == 1)  {
+	if (instance->unroll.mutexs == 1) {
 		mutex_destroy(&instance->cmd_pool_mtx);
 		mutex_destroy(&instance->app_cmd_pool_mtx);
 		mutex_destroy(&instance->cmd_pend_mtx);
@@ -1114,7 +1246,7 @@
 		}
 
 		instance->unroll.mutexs = 0;
-		con_log(CL_ANN1, (CE_CONT, "Destroy mutex & cv,  done."));
+		con_log(CL_ANN1, (CE_CONT, "Destroy mutex & cv,	 done."));
 	}
 
 
@@ -1123,13 +1255,13 @@
 		instance->unroll.soft_isr = 0;
 	}
 
-	if(instance->unroll.intr == 1)	{
+	if (instance->unroll.intr == 1) {
 		mrsas_rem_intrs(instance);
 		instance->unroll.intr = 0;
 	}
-	   
 
-	if(instance->unroll.taskq == 1)	 {
+
+	if (instance->unroll.taskq == 1)	 {
 		if (instance->taskq) {
 			ddi_taskq_destroy(instance->taskq);
 			instance->unroll.taskq = 0;
@@ -1136,27 +1268,32 @@
 		}
 
 	}
-	 
-	/*free dma memory allocated for
-	  cmds/frames/queues/driver version etc */
-	if(instance->unroll.verBuff == 1) {
-		mrsas_free_dma_obj(instance, instance->drv_ver_dma_obj);
+
+	/*
+	 * free dma memory allocated for
+	 * cmds/frames/queues/driver version etc
+	 */
+	if (instance->unroll.verBuff == 1) {
+		(void) mrsas_free_dma_obj(instance, instance->drv_ver_dma_obj);
 		instance->unroll.verBuff = 0;
 	}
 
-	if(instance->unroll.pdlist_buff == 1)  {
-		if (instance->mr_tbolt_pd_list != NULL) 
+	if (instance->unroll.pdlist_buff == 1)	{
+		if (instance->mr_tbolt_pd_list != NULL) {
 			kmem_free(instance->mr_tbolt_pd_list,
-				MRSAS_TBOLT_GET_PD_MAX(instance) * sizeof (struct mrsas_tbolt_pd));
+			    MRSAS_TBOLT_GET_PD_MAX(instance) *
+			    sizeof (struct mrsas_tbolt_pd));
+		}
 
 		instance->mr_tbolt_pd_list = NULL;
 		instance->unroll.pdlist_buff = 0;
 	}
 
-	if(instance->unroll.ldlist_buff == 1)  {
-		if (instance->mr_ld_list != NULL) 
+	if (instance->unroll.ldlist_buff == 1)	{
+		if (instance->mr_ld_list != NULL) {
 			kmem_free(instance->mr_ld_list, MRDRV_MAX_LD
-				* sizeof (struct mrsas_ld));
+			    * sizeof (struct mrsas_ld));
+		}
 
 		instance->mr_ld_list = NULL;
 		instance->unroll.ldlist_buff = 0;
@@ -1163,24 +1300,22 @@
 	}
 
 	if (instance->tbolt) {
-		if(instance->unroll.alloc_space_mpi2 == 1) {		
+		if (instance->unroll.alloc_space_mpi2 == 1) {
 			free_space_for_mpi2(instance);
 			instance->unroll.alloc_space_mpi2 = 0;
 		}
 	} else {
-		if(instance->unroll.alloc_space_mfi == 1) {		
+		if (instance->unroll.alloc_space_mfi == 1) {
 			free_space_for_mfi(instance);
 			instance->unroll.alloc_space_mfi = 0;
 		}
 	}
 
-	if(instance->unroll.regs == 1)  {
+	if (instance->unroll.regs == 1)	 {
 		ddi_regs_map_free(&instance->regmap_handle);
 		instance->unroll.regs = 0;
-		con_log(CL_ANN1, (CE_CONT, "ddi_regs_map_free()  done."));
+		con_log(CL_ANN1, (CE_CONT, "ddi_regs_map_free()	 done."));
 	}
-
-	return (DDI_SUCCESS);
 }
 
 
@@ -1187,9 +1322,9 @@
 
 /*
  * ************************************************************************** *
- *                                                                            *
- *             common entry points - for character driver types               *
- *                                                                            *
+ *									      *
+ *	       common entry points - for character driver types		      *
+ *									      *
  * ************************************************************************** *
  */
 /*
@@ -1203,7 +1338,7 @@
  * through the open() and close() entry points. The primary function of
  * open() is to verify that the open request is allowed.
  */
-static  int
+static	int
 mrsas_open(dev_t *dev, int openflags, int otyp, cred_t *credp)
 {
 	int	rval = 0;
@@ -1246,7 +1381,7 @@
  * close() should perform any cleanup necessary to finish using the minor
  * device, and prepare the device (and driver) to be opened again.
  */
-static  int
+static	int
 mrsas_close(dev_t dev, int openflags, int otyp, cred_t *credp)
 {
 	int	rval = 0;
@@ -1300,11 +1435,7 @@
 
 	ioctl = (struct mrsas_ioctl *)kmem_zalloc(sizeof (struct mrsas_ioctl),
 	    KM_SLEEP);
-	if (ioctl == NULL) {
-		/* Failed to allocate memory for ioctl  */
-		con_log(CL_ANN, (CE_WARN, "mr_sas_ioctl: failed to allocate memory for ioctl"));
-		return (ENXIO);
-	}
+	ASSERT(ioctl);
 
 	switch ((uint_t)cmd) {
 		case MRSAS_IOCTL_FIRMWARE:
@@ -1331,9 +1462,6 @@
 
 			break;
 		case MRSAS_IOCTL_AEN:
-			con_log(CL_ANN, (CE_NOTE,
-				    "mrsas_ioctl: IOCTL Register AEN.\n"));
-
 			if (ddi_copyin((void *) arg, &aen,
 			    sizeof (struct mrsas_aen), mode)) {
 				con_log(CL_ANN, (CE_WARN,
@@ -1366,11 +1494,12 @@
 
 /*
  * ************************************************************************** *
- *                                                                            *
- *               common entry points - for block driver types                 *
- *                                                                            *
+ *									      *
+ *		 common entry points - for block driver types		      *
+ *									      *
  * ************************************************************************** *
  */
+#ifdef __sparc
 /*
  * reset - TBD
  * @dip:
@@ -1407,10 +1536,9 @@
 
 	return (DDI_SUCCESS);
 }
-
-
+#else /* __sparc */
 /*ARGSUSED*/
-int
+static int
 mrsas_quiesce(dev_info_t *dip)
 {
 	int	instance_no;
@@ -1457,17 +1585,19 @@
 	flush_cache(instance);
 
 	if (wait_for_outstanding(instance)) {
-		con_log(CL_ANN1, (CE_CONT, "wait_for_outstanding: return FAIL.\n"));
+		con_log(CL_ANN1,
+		    (CE_CONT, "wait_for_outstanding: return FAIL.\n"));
 		return (DDI_FAILURE);
 	}
 	return (DDI_SUCCESS);
 }
+#endif	/* __sparc */
 
 /*
  * ************************************************************************** *
- *                                                                            *
- *                          entry points (SCSI HBA)                           *
- *                                                                            *
+ *									      *
+ *			    entry points (SCSI HBA)			      *
+ *									      *
  * ************************************************************************** *
  */
 /*
@@ -1504,7 +1634,8 @@
 		 * to be created.
 		 */
 		if ((child = mrsas_find_child(instance, tgt, lun)) != NULL) {
-			con_log(CL_DLEVEL2, (CE_NOTE, "mrsas_tgt_init find child ="
+			con_log(CL_DLEVEL2,
+			    (CE_NOTE, "mrsas_tgt_init find child ="
 			    " %p t = %d l = %d", (void *)child, tgt, lun));
 			if (ndi_merge_node(tgt_dip, mrsas_name_node) !=
 			    DDI_SUCCESS)
@@ -1532,11 +1663,11 @@
 	}
 
 #ifdef PDSUPPORT
-	else if(instance->tbolt) {
+	else if (instance->tbolt) {
 		if (instance->mr_tbolt_pd_list[tgt].dip == NULL) {
 			mutex_enter(&instance->config_dev_mtx);
 			instance->mr_tbolt_pd_list[tgt].dip = tgt_dip;
-			instance->mr_tbolt_pd_list[tgt].flag = 
+			instance->mr_tbolt_pd_list[tgt].flag =
 			    MRDRV_TGT_VALID;
 			mutex_exit(&instance->config_dev_mtx);
 			con_log(CL_ANN1, (CE_NOTE, "mrsas_tran_tgt_init:"
@@ -1570,7 +1701,7 @@
 	}
 
 #ifdef PDSUPPORT
-	else if(instance->tbolt) {
+	else if (instance->tbolt) {
 		mutex_enter(&instance->config_dev_mtx);
 		instance->mr_tbolt_pd_list[tgt].dip = NULL;
 		mutex_exit(&instance->config_dev_mtx);
@@ -1578,7 +1709,7 @@
 		    "for tgt:%x", tgt));
 	}
 #endif
-		
+
 }
 
 dev_info_t *
@@ -1749,7 +1880,7 @@
 static int
 mrsas_tran_start(struct scsi_address *ap, register struct scsi_pkt *pkt)
 {
-	uchar_t 	cmd_done = 0;
+	uchar_t		cmd_done = 0;
 
 	struct mrsas_instance	*instance = ADDR2MR(ap);
 	struct mrsas_cmd	*cmd;
@@ -1803,8 +1934,10 @@
 
 	if ((pkt->pkt_flags & FLAG_NOINTR) == 0) {
 		if (instance->fw_outstanding > instance->max_fw_cmds) {
-			cmn_err(CE_WARN, "mr_sas:Firmware BUSY, fw_outstanding(0x%X) > max_fw_cmds(0x%X)",
-					instance->fw_outstanding, instance->max_fw_cmds );
+			con_log(CL_ANN, (CE_CONT, "mr_sas:Firmware busy"));
+			DTRACE_PROBE2(start_tran_err,
+			    uint16_t, instance->fw_outstanding,
+			    uint16_t, instance->max_fw_cmds);
 			return_mfi_pkt(instance, cmd);
 			return (TRAN_BUSY);
 		}
@@ -1819,9 +1952,8 @@
 	} else {
 		struct mrsas_header *hdr = &cmd->frame->hdr;
 
+		instance->func_ptr->issue_cmd_in_poll_mode(instance, cmd);
 
-		instance->func_ptr-> issue_cmd_in_poll_mode(instance, cmd);
-
 		pkt->pkt_reason		= CMD_CMPLT;
 		pkt->pkt_statistics	= 0;
 		pkt->pkt_state |= STATE_XFERRED_DATA | STATE_GOT_STATUS;
@@ -1834,7 +1966,7 @@
 
 		case MFI_STAT_SCSI_DONE_WITH_ERROR:
 			con_log(CL_ANN, (CE_CONT,
-				"mrsas_tran_start: scsi done with error"));
+			    "mrsas_tran_start: scsi done with error"));
 			pkt->pkt_reason	= CMD_CMPLT;
 			pkt->pkt_statistics = 0;
 
@@ -1843,7 +1975,7 @@
 
 		case MFI_STAT_DEVICE_NOT_FOUND:
 			con_log(CL_ANN, (CE_CONT,
-				"mrsas_tran_start: device not found error"));
+			    "mrsas_tran_start: device not found error"));
 			pkt->pkt_reason		= CMD_DEV_GONE;
 			pkt->pkt_statistics	= STAT_DISCON;
 			break;
@@ -1852,6 +1984,9 @@
 			((struct scsi_status *)pkt->pkt_scbp)->sts_busy = 1;
 		}
 
+		(void) mrsas_common_check(instance, cmd);
+		DTRACE_PROBE2(start_nointr_done, uint8_t, hdr->cmd,
+		    uint8_t, hdr->cmd_status);
 		return_mfi_pkt(instance, cmd);
 
 		if (pkt->pkt_comp) {
@@ -1907,7 +2042,8 @@
 	con_log(CL_ANN1, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
 
 	if (wait_for_outstanding(instance)) {
-		con_log(CL_ANN1, (CE_CONT, "wait_for_outstanding: return FAIL.\n"));
+		con_log(CL_ANN1,
+		    (CE_CONT, "wait_for_outstanding: return FAIL.\n"));
 		return (DDI_FAILURE);
 	} else {
 		return (DDI_SUCCESS);
@@ -1914,6 +2050,7 @@
 	}
 }
 
+#if 0
 /*
  * tran_bus_reset - reset the SCSI bus
  * @dip:
@@ -1938,12 +2075,14 @@
 	con_log(CL_ANN1, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
 
 	if (wait_for_outstanding(instance)) {
-		con_log(CL_ANN1, (CE_CONT, "wait_for_outstanding: return FAIL.\n"));
+		con_log(CL_ANN1,
+		    (CE_CONT, "wait_for_outstanding: return FAIL.\n"));
 		return (DDI_FAILURE);
 	} else {
 		return (DDI_SUCCESS);
 	}
 }
+#endif
 
 /*
  * tran_getcap - get one of a set of SCSA-defined capabilities
@@ -1978,8 +2117,8 @@
 			/* Limit to 256k max transfer */
 			rval = mrsas_tbolt_max_cap_maxxfer;
 		} else {
-		/* Limit to 16MB max transfer */
-		rval = mrsas_max_cap_maxxfer;
+			/* Limit to 16MB max transfer */
+			rval = mrsas_max_cap_maxxfer;
 		}
 		break;
 	case SCSI_CAP_MSG_OUT:
@@ -2220,7 +2359,6 @@
 	uint32_t	producer;
 	uint32_t	consumer;
 	uint32_t	context;
-	uint32_t	status, value;
 	int		retval;
 
 	struct mrsas_cmd	*cmd;
@@ -2249,10 +2387,20 @@
 	(void) ddi_dma_sync(instance->mfi_internal_dma_obj.dma_handle,
 	    0, 0, DDI_DMA_SYNC_FORCPU);
 
+	if (mrsas_check_dma_handle(instance->mfi_internal_dma_obj.dma_handle)
+	    != DDI_SUCCESS) {
+		mrsas_fm_ereport(instance, DDI_FM_DEVICE_NO_RESPONSE);
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+		con_log(CL_ANN1, (CE_WARN,
+		    "mr_sas_isr(): FMA check, returning DDI_INTR_UNCLAIMED"));
+		return (DDI_INTR_CLAIMED);
+	}
+	con_log(CL_ANN1, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
+
 #ifdef OCRDEBUG
 	if (debug_consecutive_timeout_after_ocr_g == 1) {
 		con_log(CL_ANN1, (CE_NOTE,
-		"simulating consecutive timeout after ocr"));
+		    "simulating consecutive timeout after ocr"));
 		return (DDI_INTR_CLAIMED);
 	}
 #endif
@@ -2268,7 +2416,9 @@
 	con_log(CL_ANN, (CE_CONT, " producer %x consumer %x ",
 	    producer, consumer));
 	if (producer == consumer) {
-		con_log(CL_ANN, (CE_WARN, "producer ==  consumer case"));
+		con_log(CL_ANN, (CE_WARN, "producer ==	consumer case"));
+		DTRACE_PROBE2(isr_pc_err, uint32_t, producer,
+		    uint32_t, consumer);
 		mutex_exit(&instance->cmd_pend_mtx);
 		mutex_exit(&instance->completed_pool_mtx);
 		return (DDI_INTR_CLAIMED);
@@ -2280,10 +2430,10 @@
 		cmd = instance->cmd_list[context];
 
 		if (cmd->sync_cmd == MRSAS_TRUE) {
-		hdr = (struct mrsas_header *)&cmd->frame->hdr;
-		if (hdr) {
-			mlist_del_init(&cmd->list);
-		}
+			hdr = (struct mrsas_header *)&cmd->frame->hdr;
+			if (hdr) {
+				mlist_del_init(&cmd->list);
+			}
 		} else {
 			pkt = cmd->pkt;
 			if (pkt) {
@@ -2330,9 +2480,9 @@
 
 /*
  * ************************************************************************** *
- *                                                                            *
- *                                  libraries                                 *
- *                                                                            *
+ *									      *
+ *				    libraries				      *
+ *									      *
  * ************************************************************************** *
  */
 /*
@@ -2348,11 +2498,10 @@
 static struct mrsas_cmd *
 get_mfi_pkt(struct mrsas_instance *instance)
 {
-	mlist_t 		*head = &instance->cmd_pool_list;
+	mlist_t			*head = &instance->cmd_pool_list;
 	struct mrsas_cmd	*cmd = NULL;
 
 	mutex_enter(&instance->cmd_pool_mtx);
-	ASSERT(mutex_owned(&instance->cmd_pool_mtx));
 
 	if (!mlist_empty(head)) {
 		cmd = mlist_entry(head->next, struct mrsas_cmd, list);
@@ -2376,13 +2525,12 @@
 	struct mrsas_cmd	*cmd = NULL;
 
 	mutex_enter(&instance->app_cmd_pool_mtx);
-	ASSERT(mutex_owned(&instance->app_cmd_pool_mtx));
 
 	if (!mlist_empty(head)) {
 		cmd = mlist_entry(head->next, struct mrsas_cmd, list);
 		mlist_del_init(head->next);
 	}
-	if (cmd != NULL){
+	if (cmd != NULL) {
 		cmd->pkt = NULL;
 		cmd->retry_count_for_ocr = 0;
 		cmd->drv_pkt_time = 0;
@@ -2399,8 +2547,7 @@
 return_mfi_pkt(struct mrsas_instance *instance, struct mrsas_cmd *cmd)
 {
 	mutex_enter(&instance->cmd_pool_mtx);
-	ASSERT(mutex_owned(&instance->cmd_pool_mtx));
-
+	/* use mlist_add_tail for debug assistance */
 	mlist_add_tail(&cmd->list, &instance->cmd_pool_list);
 
 	mutex_exit(&instance->cmd_pool_mtx);
@@ -2410,7 +2557,6 @@
 return_mfi_app_pkt(struct mrsas_instance *instance, struct mrsas_cmd *cmd)
 {
 	mutex_enter(&instance->app_cmd_pool_mtx);
-	ASSERT(mutex_owned(&instance->app_cmd_pool_mtx));
 
 	mlist_add(&cmd->list, &instance->app_cmd_pool_list);
 
@@ -2423,8 +2569,7 @@
 	struct mrsas_header	*hdr;
 	con_log(CL_DLEVEL2, (CE_NOTE, "push_pending_pkt(): Called\n"));
 	mutex_enter(&instance->cmd_pend_mtx);
-	ASSERT(mutex_owned(&instance->cmd_pend_mtx));
-	mlist_del_init(&cmd->list);  
+	mlist_del_init(&cmd->list);
 	mlist_add_tail(&cmd->list, &instance->cmd_pend_list);
 	if (cmd->sync_cmd == MRSAS_TRUE) {
 		hdr = (struct mrsas_header *)&cmd->frame->hdr;
@@ -2435,15 +2580,15 @@
 			    "time %llx",
 			    (void *)cmd, cmd->index,
 			    gethrtime()));
-			/* Wait for specified interval  */
+			/* Wait for specified interval	*/
 			cmd->drv_pkt_time = ddi_get16(
 			    cmd->frame_dma_obj.acc_handle, &hdr->timeout);
 			if (cmd->drv_pkt_time < debug_timeout_g)
 				cmd->drv_pkt_time = (uint16_t)debug_timeout_g;
 				con_log(CL_ANN1, (CE_CONT,
-					"push_pending_pkt(): "
-					"Called IO Timeout Value %x\n",
-					cmd->drv_pkt_time));
+				    "push_pending_pkt(): "
+				    "Called IO Timeout Value %x\n",
+				    cmd->drv_pkt_time));
 		}
 		if (hdr && instance->timeout_id == (timeout_id_t)-1) {
 			instance->timeout_id = timeout(io_timeout_checker,
@@ -2467,7 +2612,7 @@
 	}
 
 	mutex_exit(&instance->cmd_pend_mtx);
-	
+
 }
 
 int
@@ -2482,7 +2627,6 @@
 	int saved_level;
 	int cmd_count = 0;
 
-
 	saved_level = debug_level_g;
 	debug_level_g = CL_ANN1;
 
@@ -2494,7 +2638,8 @@
 		if (tmp == head) {
 			mutex_exit(&instance->cmd_pend_mtx);
 			flag = 0;
-			con_log(CL_ANN1, (CE_CONT, "mrsas_print_pending_cmds(): NO MORE CMDS PENDING....\n"));
+			con_log(CL_ANN1, (CE_CONT, "mrsas_print_pending_cmds():"
+			    " NO MORE CMDS PENDING....\n"));
 			break;
 		} else {
 			cmd = mlist_entry(tmp, struct mrsas_cmd, list);
@@ -2501,25 +2646,35 @@
 			mutex_exit(&instance->cmd_pend_mtx);
 			if (cmd) {
 				if (cmd->sync_cmd == MRSAS_TRUE) {
-				hdr = (struct mrsas_header *)&cmd->frame->hdr;
+					hdr = (struct mrsas_header *)
+					    &cmd->frame->hdr;
 					if (hdr) {
-					con_log(CL_ANN1, (CE_CONT,
-					    "print: cmd %p index 0x%x drv_pkt_time 0x%x (NO-PKT) hdr %p\n",
-					    (void *)cmd, cmd->index, cmd->drv_pkt_time, (void *)hdr));
+						con_log(CL_ANN1, (CE_CONT,
+						    "print: cmd %p index 0x%x "
+						    "drv_pkt_time 0x%x (NO-PKT)"
+						    " hdr %p\n", (void *)cmd,
+						    cmd->index,
+						    cmd->drv_pkt_time,
+						    (void *)hdr));
 					}
 				} else {
 					pkt = cmd->pkt;
 					if (pkt) {
 					con_log(CL_ANN1, (CE_CONT,
-					    "print: cmd %p index 0x%x drv_pkt_time 0x%x pkt %p \n",
-					    (void *)cmd, cmd->index,  cmd->drv_pkt_time, (void *)pkt));
+					    "print: cmd %p index 0x%x "
+					    "drv_pkt_time 0x%x pkt %p \n",
+					    (void *)cmd, cmd->index,
+					    cmd->drv_pkt_time, (void *)pkt));
 					}
 				}
 
-				if (++cmd_count == 1)
-					mrsas_print_cmd_details(instance, cmd, 0xDD);
-				else
-					mrsas_print_cmd_details(instance, cmd, 1);
+				if (++cmd_count == 1) {
+					mrsas_print_cmd_details(instance, cmd,
+					    0xDD);
+				} else {
+					mrsas_print_cmd_details(instance, cmd,
+					    1);
+				}
 
 			}
 		}
@@ -2526,7 +2681,7 @@
 	}
 	con_log(CL_ANN1, (CE_CONT, "mrsas_print_pending_cmds(): Done\n"));
 
-	
+
 	debug_level_g = saved_level;
 
 	return (DDI_SUCCESS);
@@ -2598,18 +2753,16 @@
 }
 
 void
-mrsas_print_cmd_details(struct mrsas_instance *instance, 
-					struct mrsas_cmd *cmd, int detail )
+mrsas_print_cmd_details(struct mrsas_instance *instance, struct mrsas_cmd *cmd,
+    int detail)
 {
 	struct scsi_pkt *pkt = cmd->pkt;
 	Mpi2RaidSCSIIORequest_t *scsi_io = cmd->scsi_io_request;
-	MPI2_SCSI_IO_VENDOR_UNIQUE *raidContext;
-	uint8_t *cdb_p;
-	char str[100], *strp;
-	int i, j, len;
+	int i;
 	int saved_level;
+	ddi_acc_handle_t acc_handle =
+	    instance->mpi2_frame_pool_dma_obj.acc_handle;
 
-
 	if (detail == 0xDD) {
 		saved_level = debug_level_g;
 		debug_level_g = CL_ANN1;
@@ -2617,55 +2770,56 @@
 
 
 	if (instance->tbolt) {
-		con_log(CL_ANN1, (CE_CONT, "print_cmd_details: cmd %p cmd->index 0x%x SMID 0x%x timer 0x%x sec\n",
-		         (void *)cmd, cmd->index, cmd->SMID, cmd->drv_pkt_time));
+		con_log(CL_ANN1, (CE_CONT, "print_cmd_details: cmd %p "
+		    "cmd->index 0x%x SMID 0x%x timer 0x%x sec\n",
+		    (void *)cmd, cmd->index, cmd->SMID, cmd->drv_pkt_time));
+	} else {
+		con_log(CL_ANN1, (CE_CONT, "print_cmd_details: cmd %p "
+		    "cmd->index 0x%x timer 0x%x sec\n",
+		    (void *)cmd, cmd->index, cmd->drv_pkt_time));
 	}
-	else {
-		con_log(CL_ANN1, (CE_CONT, "print_cmd_details: cmd %p cmd->index 0x%x timer 0x%x sec\n",
-		         (void *)cmd, cmd->index, cmd->drv_pkt_time));
-	}
 
-	if(pkt) {
+	if (pkt) {
 		con_log(CL_ANN1, (CE_CONT, "scsi_pkt CDB[0]=0x%x",
-	              pkt->pkt_cdbp[0]));
-	}else {
+		    pkt->pkt_cdbp[0]));
+	} else {
 		con_log(CL_ANN1, (CE_CONT, "NO-PKT"));
 	}
 
-	if((detail==0xDD) && instance->tbolt) {
+	if ((detail == 0xDD) && instance->tbolt) {
 		con_log(CL_ANN1, (CE_CONT, "RAID_SCSI_IO_REQUEST\n"));
-		con_log(CL_ANN1, (CE_CONT, "DevHandle=0x%X Function=0x%X IoFlags=0x%X SGLFlags=0x%X DataLength=0x%X\n",
-			ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->DevHandle),
-			ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->Function),
-			ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->IoFlags),
-			ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->SGLFlags),
-			ddi_get32(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->DataLength) ));
+		con_log(CL_ANN1, (CE_CONT, "DevHandle=0x%X Function=0x%X "
+		    "IoFlags=0x%X SGLFlags=0x%X DataLength=0x%X\n",
+		    ddi_get16(acc_handle, &scsi_io->DevHandle),
+		    ddi_get8(acc_handle, &scsi_io->Function),
+		    ddi_get16(acc_handle, &scsi_io->IoFlags),
+		    ddi_get16(acc_handle, &scsi_io->SGLFlags),
+		    ddi_get32(acc_handle, &scsi_io->DataLength)));
 
-		for(i=0; i < 32; i++)
-			con_log(CL_ANN1, (CE_CONT, "CDB[%d]=0x%x ",i,
-				ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->CDB.CDB32[i]) ));
+		for (i = 0; i < 32; i++) {
+			con_log(CL_ANN1, (CE_CONT, "CDB[%d]=0x%x ", i,
+			    ddi_get8(acc_handle, &scsi_io->CDB.CDB32[i])));
+		}
 
 		con_log(CL_ANN1, (CE_CONT, "RAID-CONTEXT\n"));
-		con_log(CL_ANN1, (CE_CONT, "status=0x%X extStatus=0x%X ldTargetId=0x%X timeoutValue=0x%X"
-			"regLockFlags=0x%X RAIDFlags=0x%X regLockRowLBA=0x%lX regLockLength=0x%X spanArm=0x%X\n",
-			ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.status),
-			ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.extStatus),
-			ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.ldTargetId),
-			ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.timeoutValue),
-			ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.regLockFlags),
-			ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.RAIDFlags),
-			ddi_get64(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.regLockRowLBA),
-			ddi_get32(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.regLockLength),
-			ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_io->RaidContext.spanArm) ));
-
-
+		con_log(CL_ANN1, (CE_CONT, "status=0x%X extStatus=0x%X "
+		    "ldTargetId=0x%X timeoutValue=0x%X regLockFlags=0x%X "
+		    "RAIDFlags=0x%X regLockRowLBA=0x%" PRIu64
+		    " regLockLength=0x%X spanArm=0x%X\n",
+		    ddi_get8(acc_handle, &scsi_io->RaidContext.status),
+		    ddi_get8(acc_handle, &scsi_io->RaidContext.extStatus),
+		    ddi_get16(acc_handle, &scsi_io->RaidContext.ldTargetId),
+		    ddi_get16(acc_handle, &scsi_io->RaidContext.timeoutValue),
+		    ddi_get8(acc_handle, &scsi_io->RaidContext.regLockFlags),
+		    ddi_get8(acc_handle, &scsi_io->RaidContext.RAIDFlags),
+		    ddi_get64(acc_handle, &scsi_io->RaidContext.regLockRowLBA),
+		    ddi_get32(acc_handle, &scsi_io->RaidContext.regLockLength),
+		    ddi_get8(acc_handle, &scsi_io->RaidContext.spanArm)));
 	}
 
 	if (detail == 0xDD) {
 		debug_level_g = saved_level;
 	}
-
-	return;
 }
 
 
@@ -2687,10 +2841,11 @@
 			con_log(CL_ANN1, (CE_CONT,
 			    "mrsas_issue_pending_cmds(): "
 			    "Got a cmd: cmd %p index 0x%x drv_pkt_time 0x%x ",
-					    (void *)cmd, cmd->index, cmd->drv_pkt_time));
+			    (void *)cmd, cmd->index, cmd->drv_pkt_time));
 
+			/* Reset command timeout value */
 			if (cmd->drv_pkt_time < debug_timeout_g)
-				cmd->drv_pkt_time = (uint16_t)debug_timeout_g;	/* Reset command timeout value */
+				cmd->drv_pkt_time = (uint16_t)debug_timeout_g;
 
 			cmd->retry_count_for_ocr++;
 
@@ -2698,16 +2853,16 @@
 			    cmd->retry_count_for_ocr);
 
 			if (cmd->retry_count_for_ocr > IO_RETRY_COUNT) {
-				cmn_err(CE_WARN,
-					"mrsas_issue_pending_cmds(): cmd->retry_count exceeded limit >%d\n",
+				cmn_err(CE_WARN, "mrsas_issue_pending_cmds(): "
+				    "cmd->retry_count exceeded limit >%d\n",
 				    IO_RETRY_COUNT);
 				mrsas_print_cmd_details(instance, cmd, 0xDD);
 
 				cmn_err(CE_WARN,
-					"mrsas_issue_pending_cmds():"
+				    "mrsas_issue_pending_cmds():"
 				    "Calling KILL Adapter\n");
 				if (instance->tbolt)
-					(void) mrsas_tbolt_kill_adapter(instance);
+					mrsas_tbolt_kill_adapter(instance);
 				else
 					(void) mrsas_kill_adapter(instance);
 				return (DDI_FAILURE);
@@ -2724,16 +2879,17 @@
 
 			} else {
 				cmn_err(CE_CONT,
-					"mrsas_issue_pending_cmds(): "
-					"NO-PKT, cmd %p index 0x%x drv_pkt_time 0x%x ",
-					    (void *)cmd, cmd->index, cmd->drv_pkt_time);
+				    "mrsas_issue_pending_cmds(): NO-PKT, "
+				    "cmd %p index 0x%x drv_pkt_time 0x%x ",
+				    (void *)cmd, cmd->index, cmd->drv_pkt_time);
 			}
 
 
 			if (cmd->sync_cmd == MRSAS_TRUE) {
-				cmn_err(CE_CONT, "mrsas_issue_pending_cmds(): SYNC_CMD == TRUE \n");
-
-				instance->func_ptr->issue_cmd_in_sync_mode(instance, cmd);
+				cmn_err(CE_CONT, "mrsas_issue_pending_cmds(): "
+				    "SYNC_CMD == TRUE \n");
+				instance->func_ptr->issue_cmd_in_sync_mode(
+				    instance, cmd);
 			} else {
 				instance->func_ptr->issue_cmd(cmd, instance);
 			}
@@ -2842,7 +2998,7 @@
 		}
 
 		ddi_put32(cmd->frame_dma_obj.acc_handle,
-				&cmd->frame->io.context, cmd->index);
+		    &cmd->frame->io.context, cmd->index);
 		i++;
 
 		con_log(CL_DLEVEL3, (CE_NOTE, "[%x]-%x",
@@ -2853,7 +3009,7 @@
 
 mrsas_undo_frame_pool:
 	if (i > 0)
-	  destroy_mfi_frame_pool(instance);
+		destroy_mfi_frame_pool(instance);
 
 	return (retval);
 }
@@ -2973,8 +3129,10 @@
 
 	/* First free each cmd */
 	for (i = 0; i < max_cmd; i++) {
-		if (instance->cmd_list[i] != NULL)
-			kmem_free(instance->cmd_list[i],sizeof (struct mrsas_cmd));
+		if (instance->cmd_list[i] != NULL) {
+			kmem_free(instance->cmd_list[i],
+			    sizeof (struct mrsas_cmd));
+		}
 
 		instance->cmd_list[i] = NULL;
 	}
@@ -2981,7 +3139,7 @@
 
 	/* Now, free cmd_list array */
 	if (instance->cmd_list != NULL)
-		kmem_free(instance->cmd_list,sz);
+		kmem_free(instance->cmd_list, sz);
 
 	instance->cmd_list = NULL;
 
@@ -2989,8 +3147,7 @@
 	INIT_LIST_HEAD(&instance->cmd_pend_list);
 	if (instance->tbolt) {
 		INIT_LIST_HEAD(&instance->cmd_app_pool_list);
-	}
-	else {
+	} else {
 		INIT_LIST_HEAD(&instance->app_cmd_pool_list);
 	}
 
@@ -3024,21 +3181,13 @@
 	 * commands.
 	 */
 	instance->cmd_list = kmem_zalloc(sz, KM_SLEEP);
-	if (instance->cmd_list == NULL) {
-		con_log(CL_NONE, (CE_WARN,
-		    "Failed to allocate memory for cmd_list"));
-		return (DDI_FAILURE);
-	}
+	ASSERT(instance->cmd_list);
 
 	/* create a frame pool and assign one frame to each cmd */
 	for (count = 0; count < max_cmd; count++) {
-		instance->cmd_list[count] = kmem_zalloc(sizeof (struct mrsas_cmd),
-		    KM_SLEEP);
-		if (instance->cmd_list[count] == NULL) {
-			con_log(CL_NONE, (CE_WARN,
-				"Failed to allocate memory for mrsas_cmd"));
-			goto mrsas_undo_cmds;
-		}
+		instance->cmd_list[count] =
+		    kmem_zalloc(sizeof (struct mrsas_cmd), KM_SLEEP);
+		ASSERT(instance->cmd_list[count]);
 	}
 
 	/* add all the commands to command pool */
@@ -3047,18 +3196,18 @@
 	INIT_LIST_HEAD(&instance->cmd_pend_list);
 	INIT_LIST_HEAD(&instance->app_cmd_pool_list);
 
-	reserve_cmd	= MRSAS_APP_RESERVED_CMDS;
+	reserve_cmd = MRSAS_APP_RESERVED_CMDS;
 
-	for (i = 0; i < reserve_cmd; i++) {  
-		cmd		= instance->cmd_list[i];
-		cmd->index	= i;
+	for (i = 0; i < reserve_cmd; i++) {
+		cmd = instance->cmd_list[i];
+		cmd->index = i;
 		mlist_add_tail(&cmd->list, &instance->app_cmd_pool_list);
 	}
-	
 
+
 	for (i = reserve_cmd; i < max_cmd; i++) {
-		cmd		= instance->cmd_list[i];
-		cmd->index	= i;
+		cmd = instance->cmd_list[i];
+		cmd->index = i;
 		mlist_add_tail(&cmd->list, &instance->cmd_pool_list);
 	}
 
@@ -3068,8 +3217,10 @@
 	if (count > 0) {
 		/* free each cmd */
 		for (i = 0; i < count; i++) {
-			if (instance->cmd_list[i] != NULL)
-				kmem_free(instance->cmd_list[i],sizeof (struct mrsas_cmd));
+			if (instance->cmd_list[i] != NULL) {
+				kmem_free(instance->cmd_list[i],
+				    sizeof (struct mrsas_cmd));
+			}
 			instance->cmd_list[i] = NULL;
 		}
 	}
@@ -3076,7 +3227,7 @@
 
 mrsas_undo_cmd_list:
 	if (instance->cmd_list != NULL)
-		kmem_free(instance->cmd_list,sz);
+		kmem_free(instance->cmd_list, sz);
 	instance->cmd_list = NULL;
 
 	return (DDI_FAILURE);
@@ -3112,10 +3263,10 @@
 static int
 alloc_space_for_mfi(struct mrsas_instance *instance)
 {
-	/* Allocate command pool ( memory for cmd_list & individual commands )*/
+	/* Allocate command pool (memory for cmd_list & individual commands) */
 	if (mrsas_alloc_cmd_pool(instance)) {
 		cmn_err(CE_WARN, "error creating cmd pool");
-		return (DDI_FAILURE); 
+		return (DDI_FAILURE);
 	}
 
 	/* Allocate MFI Frame pool */
@@ -3156,17 +3307,17 @@
 	struct mrsas_dcmd_frame	*dcmd;
 	struct mrsas_ctrl_info	*ci;
 
-	if(instance->tbolt) {
+	if (instance->tbolt) {
 		cmd = get_raid_msg_mfi_pkt(instance);
-	}
-	else {
+	} else {
 		cmd = get_mfi_pkt(instance);
 	}
 
 	if (!cmd) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in get_ctrl_info(). fw_outstanding=0x%X max_fw_cmds=0x%X",
-				instance->fw_outstanding, instance->max_fw_cmds);
+		con_log(CL_ANN, (CE_WARN,
+		    "Failed to get a cmd for ctrl info"));
+		DTRACE_PROBE2(info_mfi_err, uint16_t, instance->fw_outstanding,
+		    uint16_t, instance->max_fw_cmds);
 		return (DDI_FAILURE);
 	}
 
@@ -3210,38 +3361,40 @@
 	cmd->frame_count = 1;
 
 	if (instance->tbolt) {
-    	mr_sas_tbolt_build_mfi_cmd(instance, cmd);
-    }
-	
+		mr_sas_tbolt_build_mfi_cmd(instance, cmd);
+	}
+
 	if (!instance->func_ptr->issue_cmd_in_poll_mode(instance, cmd)) {
-	ret = 0;
+		ret = 0;
 
-	ctrl_info->max_request_size = ddi_get32(
-	    cmd->frame_dma_obj.acc_handle, &ci->max_request_size);
+		ctrl_info->max_request_size = ddi_get32(
+		    cmd->frame_dma_obj.acc_handle, &ci->max_request_size);
 
-	ctrl_info->ld_present_count = ddi_get16(
-	    cmd->frame_dma_obj.acc_handle, &ci->ld_present_count);
+		ctrl_info->ld_present_count = ddi_get16(
+		    cmd->frame_dma_obj.acc_handle, &ci->ld_present_count);
 
-	ctrl_info->properties.on_off_properties =
-	    ddi_get32(cmd->frame_dma_obj.acc_handle,
-	    &ci->properties.on_off_properties);
-	ddi_rep_get8(cmd->frame_dma_obj.acc_handle,
-	    (uint8_t *)(ctrl_info->product_name),
-	    (uint8_t *)(ci->product_name), 80 * sizeof (char),
-	    DDI_DEV_AUTOINCR);
-	/* should get more members of ci with ddi_get when needed */
+		ctrl_info->properties.on_off_properties = ddi_get32(
+		    cmd->frame_dma_obj.acc_handle,
+		    &ci->properties.on_off_properties);
+		ddi_rep_get8(cmd->frame_dma_obj.acc_handle,
+		    (uint8_t *)(ctrl_info->product_name),
+		    (uint8_t *)(ci->product_name), 80 * sizeof (char),
+		    DDI_DEV_AUTOINCR);
+		/* should get more members of ci with ddi_get when needed */
 	} else {
 		cmn_err(CE_WARN, "get_ctrl_info: Ctrl info failed");
 		ret = -1;
 	}
 
-	if(instance->tbolt) {
-		return_raid_msg_mfi_pkt(instance, cmd);
+	if (mrsas_common_check(instance, cmd) != DDI_SUCCESS) {
+		ret = -1;
 	}
-	else {
+	if (instance->tbolt) {
+		return_raid_msg_mfi_pkt(instance, cmd);
+	} else {
 		return_mfi_pkt(instance, cmd);
 	}
-	
+
 	return (ret);
 }
 
@@ -3266,11 +3419,13 @@
 	}
 
 	if (!cmd) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in abort_aen_cmd(). fw_outstanding=0x%X max_fw_cmds=0x%X",
-				instance->fw_outstanding, instance->max_fw_cmds);
+		con_log(CL_ANN1, (CE_WARN,
+		    "abort_aen_cmd():Failed to get a cmd for abort_aen_cmd"));
+		DTRACE_PROBE2(abort_mfi_err, uint16_t, instance->fw_outstanding,
+		    uint16_t, instance->max_fw_cmds);
 		return (DDI_FAILURE);
 	}
+
 	/* Clear the frame buffer and assign back the context id */
 	(void) memset((char *)&cmd->frame[0], 0, sizeof (union mrsas_frame));
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &cmd->frame->hdr.context,
@@ -3323,12 +3478,13 @@
 
 
 static int
-mrsas_build_init_cmd(struct mrsas_instance *instance, struct mrsas_cmd **cmd_ptr)
+mrsas_build_init_cmd(struct mrsas_instance *instance,
+    struct mrsas_cmd **cmd_ptr)
 {
 	struct mrsas_cmd		*cmd;
 	struct mrsas_init_frame		*init_frame;
 	struct mrsas_init_queue_info	*initq_info;
-	struct mrsas_drv_ver		drv_ver_info;	
+	struct mrsas_drv_ver		drv_ver_info;
 
 
 	/*
@@ -3387,11 +3543,11 @@
 	    &init_frame->queue_info_new_phys_addr_hi, 0);
 
 
-	/* fill driver version information*/
+	/* fill driver version information */
 	fill_up_drv_ver(&drv_ver_info);
 
 	/* allocate the driver version data transfer buffer */
-	instance->drv_ver_dma_obj.size = sizeof(drv_ver_info.drv_ver);
+	instance->drv_ver_dma_obj.size = sizeof (drv_ver_info.drv_ver);
 	instance->drv_ver_dma_obj.dma_attr = mrsas_generic_dma_attr;
 	instance->drv_ver_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
 	instance->drv_ver_dma_obj.dma_attr.dma_attr_count_max = 0xFFFFFFFFU;
@@ -3404,17 +3560,18 @@
 		    "init_mfi : Could not allocate driver version buffer."));
 		return (DDI_FAILURE);
 	}
-	/* copy driver version to dma  buffer*/
-	(void) memset(instance->drv_ver_dma_obj.buffer, 0,sizeof(drv_ver_info.drv_ver));
+	/* copy driver version to dma buffer */
+	(void) memset(instance->drv_ver_dma_obj.buffer, 0,
+	    sizeof (drv_ver_info.drv_ver));
 	ddi_rep_put8(cmd->frame_dma_obj.acc_handle,
-		(uint8_t *)drv_ver_info.drv_ver,
-                (uint8_t *)instance->drv_ver_dma_obj.buffer, 
-		sizeof(drv_ver_info.drv_ver), DDI_DEV_AUTOINCR);	
+	    (uint8_t *)drv_ver_info.drv_ver,
+	    (uint8_t *)instance->drv_ver_dma_obj.buffer,
+	    sizeof (drv_ver_info.drv_ver), DDI_DEV_AUTOINCR);
 
 
-	/*copy driver version physical address to init frame*/
-	ddi_put64(cmd->frame_dma_obj.acc_handle,
-	    &init_frame->driverversion, instance->drv_ver_dma_obj.dma_cookie[0].dmac_address);
+	/* copy driver version physical address to init frame */
+	ddi_put64(cmd->frame_dma_obj.acc_handle, &init_frame->driverversion,
+	    instance->drv_ver_dma_obj.dma_cookie[0].dmac_address);
 
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &init_frame->data_xfer_len,
 	    sizeof (struct mrsas_init_queue_info));
@@ -3431,37 +3588,49 @@
  * mrsas_init_adapter_ppc - Initialize MFI interface adapter.
  */
 int
-mrsas_init_adapter_ppc (struct mrsas_instance *instance)
+mrsas_init_adapter_ppc(struct mrsas_instance *instance)
 {
 	struct mrsas_cmd		*cmd;
 
-	/* allocate memory for mfi adapter(cmd pool, individual commands, mfi frames etc */
-	if (alloc_space_for_mfi(instance) != DDI_SUCCESS){
+	/*
+	 * allocate memory for mfi adapter(cmd pool, individual commands, mfi
+	 * frames etc
+	 */
+	if (alloc_space_for_mfi(instance) != DDI_SUCCESS) {
 		con_log(CL_ANN, (CE_NOTE,
-			"Error, failed to allocate memory for MFI adapter"));
-		return (DDI_FAILURE); 
+		    "Error, failed to allocate memory for MFI adapter"));
+		return (DDI_FAILURE);
 	}
 
 	/* Build INIT command */
 	cmd = get_mfi_pkt(instance);
 
-	if (mrsas_build_init_cmd(instance, &cmd) != DDI_SUCCESS){
-		con_log(CL_ANN, (CE_NOTE,
-			"Error, failed to build INIT command"));
+	if (mrsas_build_init_cmd(instance, &cmd) != DDI_SUCCESS) {
+		con_log(CL_ANN,
+		    (CE_NOTE, "Error, failed to build INIT command"));
 
 		goto fail_undo_alloc_mfi_space;
 	}
 
-	//Disalbe interrupt before sending init frame ( see linux driver code)
-	/* send INIT MFI frame in polled mode */
+	/*
+	 * Disable interrupt before sending init frame ( see linux driver code)
+	 * send INIT MFI frame in polled mode
+	 */
 	if (instance->func_ptr->issue_cmd_in_poll_mode(instance, cmd)) {
 		con_log(CL_ANN, (CE_WARN, "failed to init firmware"));
 		goto fail_fw_init;
 	}
 
-	if (instance->func_ptr->read_fw_status_reg(instance) & 0x04000000) {
+	if (mrsas_common_check(instance, cmd) != DDI_SUCCESS)
+		goto fail_fw_init;
+	return_mfi_pkt(instance, cmd);
+
+	if (ctio_enable &&
+	    (instance->func_ptr->read_fw_status_reg(instance) & 0x04000000)) {
 		con_log(CL_ANN, (CE_NOTE, "mr_sas: IEEE SGL's supported"));
 		instance->flag_ieee = 1;
+	} else {
+		instance->flag_ieee = 0;
 	}
 
 	instance->unroll.alloc_space_mfi = 1;
@@ -3471,7 +3640,7 @@
 
 
 fail_fw_init:
-	mrsas_free_dma_obj(instance, instance->drv_ver_dma_obj);
+	(void) mrsas_free_dma_obj(instance, instance->drv_ver_dma_obj);
 
 fail_undo_alloc_mfi_space:
 	return_mfi_pkt(instance, cmd);
@@ -3485,7 +3654,7 @@
  * mrsas_init_adapter - Initialize adapter.
  */
 int
-mrsas_init_adapter (struct mrsas_instance *instance)
+mrsas_init_adapter(struct mrsas_instance *instance)
 {
 	struct mrsas_ctrl_info		ctrl_info;
 
@@ -3517,11 +3686,11 @@
 
 	/* Initialize adapter */
 	if (instance->func_ptr->init_adapter(instance) != DDI_SUCCESS) {
-		con_log(CL_ANN, (CE_WARN, "mr_sas: "
-			"could not initialize adapter"));
+		con_log(CL_ANN,
+		    (CE_WARN, "mr_sas: could not initialize adapter"));
 		return (DDI_FAILURE);
 	}
-	
+
 	/* gather misc FW related information */
 	instance->disable_online_ctrl_reset = 0;
 
@@ -3535,15 +3704,8 @@
 		    PAGESIZE / 512;
 	}
 
-	if (ctrl_info.properties.on_off_properties & DISABLE_OCR_PROP_FLAG) {
+	if (ctrl_info.properties.on_off_properties & DISABLE_OCR_PROP_FLAG)
 		instance->disable_online_ctrl_reset = 1;
-		con_log(CL_ANN1, (CE_NOTE,
-              		"Disable online control Flag is set\n"));
-	}
-	else {
-		con_log(CL_ANN1, (CE_NOTE,
-			"Disable online control Flag is not set\n"));	
-	}
 
 	return (DDI_SUCCESS);
 
@@ -3632,6 +3794,11 @@
 		return (DDI_FAILURE);
 	}
 
+	if (mrsas_common_check(instance, cmd) != DDI_SUCCESS) {
+		return_mfi_pkt(instance, cmd);
+		return (DDI_FAILURE);
+	}
+
 	return_mfi_app_pkt(instance, cmd);
 	con_log(CL_ANN1, (CE_CONT, "mrsas_issue_init_mfi: Done"));
 
@@ -3688,7 +3855,7 @@
 				WR_RESERVED0_REGISTER(MFI_INIT_CLEAR_HANDSHAKE |
 				    MFI_INIT_HOTPLUG, instance);
 			}
-			max_wait 	= (instance->tbolt == 1) ? 180 : 2;
+			max_wait	= (instance->tbolt == 1) ? 180 : 2;
 			cur_state	= MFI_STATE_WAIT_HANDSHAKE;
 			break;
 		case MFI_STATE_BOOT_MESSAGE_PENDING:
@@ -3706,7 +3873,7 @@
 				WR_RESERVED0_REGISTER(MFI_INIT_HOTPLUG,
 				    instance);
 			}
-			max_wait 	= (instance->tbolt == 1) ? 180 : 10;
+			max_wait	= (instance->tbolt == 1) ? 180 : 10;
 			cur_state	= MFI_STATE_BOOT_MESSAGE_PENDING;
 			break;
 		case MFI_STATE_OPERATIONAL:
@@ -3729,15 +3896,16 @@
 				for (i = 0; i < (10 * 1000); i++) {
 					status =
 					    RD_RESERVED0_REGISTER(instance);
-					if (status & 1)
+					if (status & 1) {
 						delay(1 *
 						    drv_usectohz(MILLISEC));
-					else
+					} else {
 						break;
+					}
 				}
 
 			}
-			max_wait 	= (instance->tbolt == 1) ? 180 : 10;
+			max_wait	= (instance->tbolt == 1) ? 180 : 10;
 			cur_state	= MFI_STATE_OPERATIONAL;
 			break;
 		case MFI_STATE_UNDEFINED:
@@ -3744,19 +3912,19 @@
 			/* this state should not last for more than 2 seconds */
 			con_log(CL_ANN1, (CE_NOTE, "FW state undefined"));
 
-			max_wait 	= (instance->tbolt == 1) ? 180 : 2;
+			max_wait	= (instance->tbolt == 1) ? 180 : 2;
 			cur_state	= MFI_STATE_UNDEFINED;
 			break;
 		case MFI_STATE_BB_INIT:
-			max_wait 	= (instance->tbolt == 1) ? 180 : 2;
+			max_wait	= (instance->tbolt == 1) ? 180 : 2;
 			cur_state	= MFI_STATE_BB_INIT;
 			break;
 		case MFI_STATE_FW_INIT:
-			max_wait 	= (instance->tbolt == 1) ? 180 : 2;
+			max_wait	= (instance->tbolt == 1) ? 180 : 2;
 			cur_state	= MFI_STATE_FW_INIT;
 			break;
 		case MFI_STATE_FW_INIT_2:
-			max_wait 	= 180;
+			max_wait	= 180;
 			cur_state	= MFI_STATE_FW_INIT_2;
 			break;
 		case MFI_STATE_DEVICE_SCAN:
@@ -3767,7 +3935,7 @@
 			    "Device scan in progress ...\n"));
 			break;
 		case MFI_STATE_FLUSH_CACHE:
-			max_wait 	= 180;
+			max_wait	= 180;
 			cur_state	= MFI_STATE_FLUSH_CACHE;
 			break;
 		default:
@@ -3807,22 +3975,22 @@
 		fw_ctrl = RD_IB_DOORBELL(instance);
 		con_log(CL_ANN1, (CE_CONT,
 		    "mfi_state_transition_to_ready:FW ctrl = 0x%x", fw_ctrl));
-	}
 
-#if 0
-	/*
-	 * Write 0xF to the doorbell register to do the following.
-	 * - Abort all outstanding commands (bit 0).
-	 * - Transition from OPERATIONAL to READY state (bit 1).
-	 * - Discard (possible) low MFA posted in 64-bit mode (bit-2).
-	 * - Set to release FW to continue running (i.e. BIOS handshake
-	 *   (bit 3).
-	 */
-	if (!instance->tbolt) {
+		/*
+		 * Write 0xF to the doorbell register to do the following.
+		 * - Abort all outstanding commands (bit 0).
+		 * - Transition from OPERATIONAL to READY state (bit 1).
+		 * - Discard (possible) low MFA posted in 64-bit mode (bit-2).
+		 * - Set to release FW to continue running (i.e. BIOS handshake
+		 *   (bit 3).
+		 */
 		WR_IB_DOORBELL(0xF, instance);
 	}
-#endif
 
+	if (mrsas_check_acc_handle(instance->regmap_handle) != DDI_SUCCESS) {
+		return (EIO);
+	}
+
 	return (DDI_SUCCESS);
 }
 
@@ -3846,9 +4014,9 @@
 	}
 
 	if (!cmd) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in get_seq_num(). fw_outstanding=0x%X max_fw_cmds=0x%X",
-			instance->fw_outstanding, instance->max_fw_cmds);
+		cmn_err(CE_WARN, "mr_sas: failed to get a cmd");
+		DTRACE_PROBE2(seq_num_mfi_err, uint16_t,
+		    instance->fw_outstanding, uint16_t, instance->max_fw_cmds);
 		return (ENOMEM);
 	}
 
@@ -3857,7 +4025,7 @@
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &cmd->frame->hdr.context,
 	    cmd->index);
 
-	dcmd	= &cmd->frame->dcmd;
+	dcmd = &cmd->frame->dcmd;
 
 	/* allocate the data transfer buffer */
 	dcmd_dma_obj.size = sizeof (struct mrsas_evt_log_info);
@@ -3968,7 +4136,6 @@
 {
 	struct mrsas_cmd		*cmd = NULL;
 	struct mrsas_dcmd_frame		*dcmd;
-	uint32_t	max_cmd = instance->max_fw_cmds;
 	if (instance->tbolt) {
 		cmd = get_raid_msg_mfi_pkt(instance);
 	} else {
@@ -3976,9 +4143,10 @@
 	}
 
 	if (!cmd) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in flush_cache(). fw_outstanding=0x%X max_fw_cmds=0x%X",
-				instance->fw_outstanding, instance->max_fw_cmds);
+		con_log(CL_ANN1, (CE_WARN,
+		    "flush_cache():Failed to get a cmd for flush_cache"));
+		DTRACE_PROBE2(flush_cache_err, uint16_t,
+		    instance->fw_outstanding, uint16_t, instance->max_fw_cmds);
 		return;
 	}
 
@@ -4032,7 +4200,6 @@
 service_mfi_aen(struct mrsas_instance *instance, struct mrsas_cmd *cmd)
 {
 	uint32_t	seq_num;
-	uint32_t	i;
 	struct mrsas_evt_detail *evt_detail =
 	    (struct mrsas_evt_detail *)instance->mfi_evt_detail_obj.buffer;
 	int		rval = 0;
@@ -4078,7 +4245,7 @@
 			if (instance->mr_ld_list[tgt].dip != NULL) {
 				mutex_enter(&instance->config_dev_mtx);
 				instance->mr_ld_list[tgt].flag =
-				    ~MRDRV_TGT_VALID;
+				    (uint8_t)~MRDRV_TGT_VALID;
 				mutex_exit(&instance->config_dev_mtx);
 				rval = mrsas_service_evt(instance, tgt, 0,
 				    MRSAS_EVT_UNCONFIG_TGT, NULL);
@@ -4093,7 +4260,7 @@
 	case MR_EVT_LD_DELETED: {
 		tgt = ddi_get16(acc_handle, &evt_detail->args.ld.target_id);
 		mutex_enter(&instance->config_dev_mtx);
-		instance->mr_ld_list[tgt].flag = ~MRDRV_TGT_VALID;
+		instance->mr_ld_list[tgt].flag = (uint8_t)~MRDRV_TGT_VALID;
 		mutex_exit(&instance->config_dev_mtx);
 		rval = mrsas_service_evt(instance,
 		    ddi_get16(acc_handle, &evt_detail->args.ld.target_id), 0,
@@ -4117,73 +4284,81 @@
 	} /* End of MR_EVT_LD_CREATED */
 
 #ifdef PDSUPPORT
-	case MR_EVT_PD_REMOVED_EXT: { 
+	case MR_EVT_PD_REMOVED_EXT: {
 		if (instance->tbolt) {
 			pd_addr = &evt_detail->args.pd_addr;
 			dtype = pd_addr->scsi_dev_type;
 			con_log(CL_DLEVEL1, (CE_NOTE,
-		    	   " MR_EVT_PD_REMOVED_EXT: dtype = %x," 
+			    " MR_EVT_PD_REMOVED_EXT: dtype = %x,"
 			    " arg_type = %d ", dtype, evt_detail->arg_type));
-			    tgt = ddi_get16(acc_handle, &evt_detail->args.pd.device_id);
+			tgt = ddi_get16(acc_handle,
+			    &evt_detail->args.pd.device_id);
 			mutex_enter(&instance->config_dev_mtx);
-			instance->mr_tbolt_pd_list[tgt].flag = (uint8_t)~MRDRV_TGT_VALID;
+			instance->mr_tbolt_pd_list[tgt].flag =
+			    (uint8_t)~MRDRV_TGT_VALID;
 			mutex_exit(&instance->config_dev_mtx);
-			rval = mrsas_service_evt(instance,
-		    	ddi_get16(acc_handle, &evt_detail->args.pd.device_id),
-		    	    1, MRSAS_EVT_UNCONFIG_TGT, NULL);
+			rval = mrsas_service_evt(instance, ddi_get16(
+			    acc_handle, &evt_detail->args.pd.device_id),
+			    1, MRSAS_EVT_UNCONFIG_TGT, NULL);
 			con_log(CL_ANN1, (CE_WARN, "mr_sas: PD_REMOVED:"
 			    "rval = %d tgt id = %d ", rval,
-			ddi_get16(acc_handle, &evt_detail->args.pd.device_id)));
-			break;
+			    ddi_get16(acc_handle,
+			    &evt_detail->args.pd.device_id)));
 		}
-	}/* End of MR_EVT_PD_REMOVED_EXT */
+		break;
+	} /* End of MR_EVT_PD_REMOVED_EXT */
 
 	case MR_EVT_PD_INSERTED_EXT: {
 		if (instance->tbolt) {
 			rval = mrsas_service_evt(instance,
-		    	ddi_get16(acc_handle, &evt_detail->args.pd.device_id),
-		    	    1, MRSAS_EVT_CONFIG_TGT, NULL);
+			    ddi_get16(acc_handle,
+			    &evt_detail->args.pd.device_id),
+			    1, MRSAS_EVT_CONFIG_TGT, NULL);
 			con_log(CL_ANN1, (CE_WARN, "mr_sas: PD_INSERTEDi_EXT:"
-		    	    "rval = %d tgt id = %d ", rval,
-		    	    ddi_get16(acc_handle, &evt_detail->args.pd.device_id)));
-			break;
+			    "rval = %d tgt id = %d ", rval,
+			    ddi_get16(acc_handle,
+			    &evt_detail->args.pd.device_id)));
 		}
-	}/* End of MR_EVT_PD_INSERTED_EXT */
+		break;
+	} /* End of MR_EVT_PD_INSERTED_EXT */
 
 	case MR_EVT_PD_STATE_CHANGE: {
 		if (instance->tbolt) {
-			tgt = ddi_get16(acc_handle, &evt_detail->args.pd.device_id);
-			if ((evt_detail->args.pd_state.prevState == PD_SYSTEM) &&
-		    	    (evt_detail->args.pd_state.newState != PD_SYSTEM)) {
+			tgt = ddi_get16(acc_handle,
+			    &evt_detail->args.pd.device_id);
+			if ((evt_detail->args.pd_state.prevState ==
+			    PD_SYSTEM) &&
+			    (evt_detail->args.pd_state.newState != PD_SYSTEM)) {
 				mutex_enter(&instance->config_dev_mtx);
 				instance->mr_tbolt_pd_list[tgt].flag =
-			    	    (uint8_t)~MRDRV_TGT_VALID;
+				    (uint8_t)~MRDRV_TGT_VALID;
 				mutex_exit(&instance->config_dev_mtx);
 				rval = mrsas_service_evt(instance,
-			   	    ddi_get16(acc_handle,
-			       	    &evt_detail->args.pd.device_id),
+				    ddi_get16(acc_handle,
+				    &evt_detail->args.pd.device_id),
 				    1, MRSAS_EVT_UNCONFIG_TGT, NULL);
 				con_log(CL_ANN1, (CE_WARN, "mr_sas: PD_REMOVED:"
-			    	    "rval = %d tgt id = %d ", rval,
-			    	    ddi_get16(acc_handle,
-			    	    &evt_detail->args.pd.device_id)));	
+				    "rval = %d tgt id = %d ", rval,
+				    ddi_get16(acc_handle,
+				    &evt_detail->args.pd.device_id)));
 				break;
-			}					
+			}
 			if ((evt_detail->args.pd_state.prevState
-		    	    == UNCONFIGURED_GOOD) &&
-		    	    (evt_detail->args.pd_state.newState == PD_SYSTEM)) {
+			    == UNCONFIGURED_GOOD) &&
+			    (evt_detail->args.pd_state.newState == PD_SYSTEM)) {
 				rval = mrsas_service_evt(instance,
-		    	    	ddi_get16(acc_handle,
-			    	    &evt_detail->args.pd.device_id),
-		    	    	    1, MRSAS_EVT_CONFIG_TGT, NULL);
+				    ddi_get16(acc_handle,
+				    &evt_detail->args.pd.device_id),
+				    1, MRSAS_EVT_CONFIG_TGT, NULL);
 				con_log(CL_ANN1, (CE_WARN,
-			    	    "mr_sas: PD_INSERTED: rval = %d "
-		    	    	    " tgt id = %d ", rval,
-			    	    ddi_get16(acc_handle,
-			    	    &evt_detail->args.pd.device_id)));
+				    "mr_sas: PD_INSERTED: rval = %d "
+				    " tgt id = %d ", rval,
+				    ddi_get16(acc_handle,
+				    &evt_detail->args.pd.device_id)));
 				break;
-			}	
+			}
 		}
+		break;
 	}
 #endif
 
@@ -4256,15 +4431,15 @@
 	if (fw_state == MFI_STATE_FAULT) {
 		if (instance->disable_online_ctrl_reset == 1) {
 			cmn_err(CE_WARN,
-				"mrsas_initiate_ocr_if_fw_is_faulty: "
-				"FW in Fault state, detected in ISR: "
-				"FW doesn't support ocr ");
+			    "mrsas_initiate_ocr_if_fw_is_faulty: "
+			    "FW in Fault state, detected in ISR: "
+			    "FW doesn't support ocr ");
 
 			return (ADAPTER_RESET_NOT_REQUIRED);
 		} else {
 			con_log(CL_ANN, (CE_NOTE,
-				"mrsas_initiate_ocr_if_fw_is_faulty: "
-				"FW in Fault state, detected in ISR: FW supports ocr "));
+			    "mrsas_initiate_ocr_if_fw_is_faulty: FW in Fault "
+			    "state, detected in ISR: FW supports ocr "));
 
 			return (ADAPTER_RESET_REQUIRED);
 		}
@@ -4318,6 +4493,16 @@
 		(void) ddi_dma_sync(cmd->frame_dma_obj.dma_handle,
 		    0, 0, DDI_DMA_SYNC_FORCPU);
 
+		if (mrsas_check_dma_handle(cmd->frame_dma_obj.dma_handle) !=
+		    DDI_SUCCESS) {
+			mrsas_fm_ereport(instance, DDI_FM_DEVICE_NO_RESPONSE);
+			ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+			con_log(CL_ANN1, (CE_WARN,
+			    "mrsas_softintr: "
+			    "FMA check reports DMA handle failure"));
+			return (DDI_INTR_CLAIMED);
+		}
+
 		hdr = &cmd->frame->hdr;
 
 		/* remove the internal command from the process list */
@@ -4362,6 +4547,9 @@
 			    "CDB[0] = %x completed for %s: size %lx context %x",
 			    pkt->pkt_cdbp[0], ((acmd->islogical) ? "LD" : "PD"),
 			    acmd->cmd_dmacount, hdr->context));
+			DTRACE_PROBE3(softintr_cdb, uint8_t, pkt->pkt_cdbp[0],
+			    uint_t, acmd->cmd_cdblen, ulong_t,
+			    acmd->cmd_dmacount);
 
 			if (pkt->pkt_cdbp[0] == SCMD_INQUIRY) {
 				struct scsi_inquiry	*inq;
@@ -4390,6 +4578,9 @@
 				}
 			}
 
+			DTRACE_PROBE2(softintr_done, uint8_t, hdr->cmd,
+			    uint8_t, hdr->cmd_status);
+
 			switch (hdr->cmd_status) {
 			case MFI_STAT_OK:
 				pkt->pkt_scbp[0] = STATUS_GOOD;
@@ -4399,7 +4590,8 @@
 				pkt->pkt_scbp[0] = STATUS_GOOD;
 				break;
 			case MFI_STAT_LD_INIT_IN_PROGRESS:
-				con_log(CL_ANN, (CE_WARN, "Initialization in Progress"));
+				con_log(CL_ANN,
+				    (CE_WARN, "Initialization in Progress"));
 				pkt->pkt_reason	= CMD_TRAN_ERR;
 
 				break;
@@ -4411,9 +4603,8 @@
 				    pkt->pkt_scbp)->sts_chk = 1;
 
 				if (pkt->pkt_cdbp[0] == SCMD_TEST_UNIT_READY) {
-
-					con_log(CL_ANN, (CE_WARN, "TEST_UNIT_READY fail"));
-
+					con_log(CL_ANN,
+					    (CE_WARN, "TEST_UNIT_READY fail"));
 				} else {
 					pkt->pkt_state |= STATE_ARQ_DONE;
 					arqstat = (void *)(pkt->pkt_scbp);
@@ -4480,6 +4671,18 @@
 
 			atomic_add_16(&instance->fw_outstanding, (-1));
 
+			(void) mrsas_common_check(instance, cmd);
+
+			if (acmd->cmd_dmahandle) {
+				if (mrsas_check_dma_handle(
+				    acmd->cmd_dmahandle) != DDI_SUCCESS) {
+					ddi_fm_service_impact(instance->dip,
+					    DDI_SERVICE_UNAFFECTED);
+					pkt->pkt_reason = CMD_TRAN_ERR;
+					pkt->pkt_statistics = 0;
+				}
+			}
+
 			/* Call the callback routine */
 			if (((pkt->pkt_flags & FLAG_NOINTR) == 0) &&
 			    pkt->pkt_comp) {
@@ -4531,6 +4734,9 @@
 			break;
 
 		default:
+			mrsas_fm_ereport(instance, DDI_FM_DEVICE_NO_RESPONSE);
+			ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+
 			if (cmd->pkt != NULL) {
 				pkt = cmd->pkt;
 				if (((pkt->pkt_flags & FLAG_NOINTR) == 0) &&
@@ -4608,10 +4814,6 @@
 
 		return (-1);
 	}
-	if (obj->dma_handle == NULL) {
-		con_log(CL_ANN, (CE_WARN, "Failed : ddi_dma_mem_alloc"));
-		return (-1);
-	}
 
 	if (ddi_dma_addr_bind_handle(obj->dma_handle, NULL, obj->buffer,
 	    obj->size, DDI_DMA_RDWR | DDI_DMA_STREAMING, DDI_DMA_SLEEP,
@@ -4624,14 +4826,16 @@
 
 		return (-1);
 	}
-	if (obj->acc_handle == NULL) {
-		ddi_dma_mem_free(&obj->acc_handle);
-		ddi_dma_free_handle(&obj->dma_handle);
 
-		con_log(CL_ANN, (CE_WARN, "Failed : ddi_dma_addr_bind_handle"));
+	if (mrsas_check_dma_handle(obj->dma_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
 		return (-1);
 	}
 
+	if (mrsas_check_acc_handle(obj->acc_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+		return (-1);
+	}
 
 	return (cookie_cnt);
 }
@@ -4646,10 +4850,24 @@
 mrsas_free_dma_obj(struct mrsas_instance *instance, dma_obj_t obj)
 {
 
-	if ( (obj.dma_handle == NULL) || (obj.acc_handle == NULL) ) {
+	if ((obj.dma_handle == NULL) || (obj.acc_handle == NULL)) {
 		return (DDI_SUCCESS);
 	}
 
+	/*
+	 * NOTE: These check-handle functions fail if *_handle == NULL, but
+	 * this function succeeds because of the previous check.
+	 */
+	if (mrsas_check_dma_handle(obj.dma_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_UNAFFECTED);
+		return (DDI_FAILURE);
+	}
+
+	if (mrsas_check_acc_handle(obj.acc_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_UNAFFECTED);
+		return (DDI_FAILURE);
+	}
+
 	(void) ddi_dma_unbind_handle(obj.dma_handle);
 	ddi_dma_mem_free(&obj.acc_handle);
 	ddi_dma_free_handle(&obj.dma_handle);
@@ -4700,12 +4918,13 @@
 	tmp_dma_attr.dma_attr_sgllen = instance->max_num_sge;
 	tmp_dma_attr.dma_attr_addr_hi = 0xffffffffffffffffull;
 	if (instance->tbolt) {
-		//OCR-RESET FIX
-		tmp_dma_attr.dma_attr_count_max = (U64)mrsas_tbolt_max_cap_maxxfer;  //limit to 256K
-		tmp_dma_attr.dma_attr_maxxfer = (U64)mrsas_tbolt_max_cap_maxxfer;  //limit to 256K
+		/* OCR-RESET FIX */
+		tmp_dma_attr.dma_attr_count_max =
+		    (U64)mrsas_tbolt_max_cap_maxxfer;  /* limit to 256K */
+		tmp_dma_attr.dma_attr_maxxfer =
+		    (U64)mrsas_tbolt_max_cap_maxxfer;  /* limit to 256K */
 	}
 
-
 	if ((i = ddi_dma_alloc_handle(instance->dip, &tmp_dma_attr,
 	    cb, 0, &acmd->cmd_dmahandle)) != DDI_SUCCESS) {
 		switch (i) {
@@ -4886,7 +5105,7 @@
 {
 	uint16_t	flags = 0;
 	uint32_t	i;
-	uint32_t 	context;
+	uint32_t	context;
 	uint32_t	sge_bytes;
 	uint32_t	tmp_data_xfer_len;
 	ddi_acc_handle_t acc_handle;
@@ -4894,7 +5113,7 @@
 	struct mrsas_sge64		*mfi_sgl;
 	struct mrsas_sge_ieee		*mfi_sgl_ieee;
 	struct scsa_cmd			*acmd = PKT2CMD(pkt);
-	struct mrsas_pthru_frame 	*pthru;
+	struct mrsas_pthru_frame	*pthru;
 	struct mrsas_io_frame		*ldio;
 
 	/* find out if this is logical or physical drive command.  */
@@ -4904,9 +5123,8 @@
 
 	/* get the command packet */
 	if (!(cmd = get_mfi_pkt(instance))) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in build_cmd(). fw_outstanding=0x%X max_fw_cmds=0x%X",
-				instance->fw_outstanding, instance->max_fw_cmds);
+		DTRACE_PROBE2(build_cmd_mfi_err, uint16_t,
+		    instance->fw_outstanding, uint16_t, instance->max_fw_cmds);
 		return (NULL);
 	}
 
@@ -4918,6 +5136,8 @@
 
 	cmd->pkt = pkt;
 	cmd->cmd = acmd;
+	DTRACE_PROBE3(build_cmds, uint8_t, pkt->pkt_cdbp[0],
+	    ulong_t, acmd->cmd_dmacount, ulong_t, acmd->cmd_dma_len);
 
 	/* lets get the command directions */
 	if (acmd->cmd_flags & CFLAG_DMASEND) {
@@ -4949,7 +5169,7 @@
 
 	/*
 	 * case SCMD_SYNCHRONIZE_CACHE:
-	 * 	flush_cache(instance);
+	 *	flush_cache(instance);
 	 *	return_mfi_pkt(instance, cmd);
 	 *	*cmd_done = 1;
 	 *
@@ -5002,7 +5222,8 @@
 
 			context = ddi_get32(acc_handle, &ldio->context);
 
-			if (acmd->cmd_cdblen == CDB_GROUP0) {			/* 6-byte cdb */
+			if (acmd->cmd_cdblen == CDB_GROUP0) {
+				/* 6-byte cdb */
 				ddi_put32(acc_handle, &ldio->lba_count, (
 				    (uint16_t)(pkt->pkt_cdbp[4])));
 
@@ -5011,7 +5232,8 @@
 				    ((uint32_t)(pkt->pkt_cdbp[2]) << 8) |
 				    ((uint32_t)((pkt->pkt_cdbp[1]) & 0x1F)
 				    << 16)));
-			} else if (acmd->cmd_cdblen == CDB_GROUP1) {		/* 10-byte cdb */
+			} else if (acmd->cmd_cdblen == CDB_GROUP1) {
+				/* 10-byte cdb */
 				ddi_put32(acc_handle, &ldio->lba_count, (
 				    ((uint16_t)(pkt->pkt_cdbp[8])) |
 				    ((uint16_t)(pkt->pkt_cdbp[7]) << 8)));
@@ -5021,7 +5243,8 @@
 				    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
 				    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
 				    ((uint32_t)(pkt->pkt_cdbp[2]) << 24)));
-			} else if (acmd->cmd_cdblen == CDB_GROUP5) {		/* 12-byte cdb */
+			} else if (acmd->cmd_cdblen == CDB_GROUP5) {
+				/* 12-byte cdb */
 				ddi_put32(acc_handle, &ldio->lba_count, (
 				    ((uint32_t)(pkt->pkt_cdbp[9])) |
 				    ((uint32_t)(pkt->pkt_cdbp[8]) << 8) |
@@ -5033,7 +5256,8 @@
 				    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
 				    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
 				    ((uint32_t)(pkt->pkt_cdbp[2]) << 24)));
-			} else if (acmd->cmd_cdblen == CDB_GROUP4) {		/* 16-byte cdb */
+			} else if (acmd->cmd_cdblen == CDB_GROUP4) {
+				/* 16-byte cdb */
 				ddi_put32(acc_handle, &ldio->lba_count, (
 				    ((uint32_t)(pkt->pkt_cdbp[13])) |
 				    ((uint32_t)(pkt->pkt_cdbp[12]) << 8) |
@@ -5149,6 +5373,7 @@
 	return (cmd);
 }
 
+#ifndef __sparc
 /*
  * wait_for_outstanding -	Wait for all outstanding cmds
  * @instance:				Adapter soft state
@@ -5177,8 +5402,8 @@
 
 	return (0);
 }
+#endif	/* __sparc */
 
-
 /*
  * issue_mfi_pthru
  */
@@ -5189,7 +5414,7 @@
 	void		*ubuf;
 	uint32_t	kphys_addr = 0;
 	uint32_t	xferlen = 0;
-	uint32_t new_xfer_length =0;
+	uint32_t	new_xfer_length = 0;
 	uint_t		model;
 	ddi_acc_handle_t	acc_handle = cmd->frame_dma_obj.acc_handle;
 	dma_obj_t			pthru_dma_obj;
@@ -5226,8 +5451,9 @@
 	if (xferlen) {
 		/* means IOCTL requires DMA */
 		/* allocate the data transfer buffer */
-		//pthru_dma_obj.size = xferlen;
-		MRSAS_GET_BOUNDARY_ALIGNED_LEN(xferlen,new_xfer_length,PAGESIZE);	
+		/* pthru_dma_obj.size = xferlen; */
+		MRSAS_GET_BOUNDARY_ALIGNED_LEN(xferlen, new_xfer_length,
+		    PAGESIZE);
 		pthru_dma_obj.size = new_xfer_length;
 		pthru_dma_obj.dma_attr = mrsas_generic_dma_attr;
 		pthru_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
@@ -5274,7 +5500,7 @@
 
 	ddi_put32(acc_handle, &pthru->sense_buf_phys_addr_hi, 0);
 	pthru->sense_buf_phys_addr_lo = cmd->sense_phys_addr;
-	/*ddi_put32(acc_handle, &pthru->sense_buf_phys_addr_lo, 0); */
+	/* ddi_put32(acc_handle, &pthru->sense_buf_phys_addr_lo, 0); */
 
 	ddi_rep_put8(acc_handle, (uint8_t *)kpthru->cdb, (uint8_t *)pthru->cdb,
 	    pthru->cdb_len, DDI_DEV_AUTOINCR);
@@ -5313,14 +5539,17 @@
 
 	con_log(CL_ANN, (CE_CONT, "issue_mfi_pthru: cmd_status %x, "
 	    "scsi_status %x", kpthru->cmd_status, kpthru->scsi_status));
-	
+	DTRACE_PROBE3(issue_pthru, uint8_t, kpthru->cmd, uint8_t,
+	    kpthru->cmd_status, uint8_t, kpthru->scsi_status);
+
 	if (kpthru->sense_len) {
-		uint sense_len = SENSE_LENGTH;
-		void *sense_ubuf = (void *)(ulong_t)kpthru->sense_buf_phys_addr_lo;
+		uint_t sense_len = SENSE_LENGTH;
+		void *sense_ubuf =
+		    (void *)(ulong_t)kpthru->sense_buf_phys_addr_lo;
 		if (kpthru->sense_len <= SENSE_LENGTH) {
 			sense_len = kpthru->sense_len;
 		}
-		
+
 		for (i = 0; i < sense_len; i++) {
 			if (ddi_copyout(
 			    (uint8_t *)cmd->sense+i,
@@ -5330,11 +5559,12 @@
 				    "copy to user space failed"));
 			}
 			con_log(CL_DLEVEL1, (CE_WARN,
-			    "Copying Sense info sense_buff[%d] = 0x%X\n",i,*((uint8_t *)cmd->sense+i)));
+			    "Copying Sense info sense_buff[%d] = 0x%X",
+			    i, *((uint8_t *)cmd->sense + i)));
 		}
 	}
 	(void) ddi_dma_sync(cmd->frame_dma_obj.dma_handle, 0, 0,
-		    DDI_DMA_SYNC_FORDEV);
+	    DDI_DMA_SYNC_FORDEV);
 
 	if (xferlen) {
 		/* free kernel buffer */
@@ -5355,7 +5585,7 @@
 	void		*ubuf;
 	uint32_t	kphys_addr = 0;
 	uint32_t	xferlen = 0;
-	uint32_t        new_xfer_length = 0; 
+	uint32_t	new_xfer_length = 0;
 	uint32_t	model;
 	dma_obj_t	dcmd_dma_obj;
 	struct mrsas_dcmd_frame	*kdcmd;
@@ -5366,8 +5596,8 @@
 	kdcmd = (struct mrsas_dcmd_frame *)&ioctl->frame[0];
 
 	if (instance->adapterresetinprogress) {
-		con_log(CL_ANN1, (CE_WARN, "Reset flag set, "
-		"returning mfi_pkt and setting TRAN_BUSY\n"));
+		con_log(CL_ANN1, (CE_NOTE, "Reset flag set, "
+		"returning mfi_pkt and setting TRAN_BUSY"));
 		return (DDI_FAILURE);
 	}
 	model = ddi_model_convert_from(mode & FMODELS);
@@ -5391,8 +5621,9 @@
 	if (xferlen) {
 		/* means IOCTL requires DMA */
 		/* allocate the data transfer buffer */
-		//dcmd_dma_obj.size = xferlen;
-		 MRSAS_GET_BOUNDARY_ALIGNED_LEN(xferlen,new_xfer_length,PAGESIZE);
+		/* dcmd_dma_obj.size = xferlen; */
+		MRSAS_GET_BOUNDARY_ALIGNED_LEN(xferlen, new_xfer_length,
+		    PAGESIZE);
 		dcmd_dma_obj.size = new_xfer_length;
 		dcmd_dma_obj.dma_attr = mrsas_generic_dma_attr;
 		dcmd_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
@@ -5403,8 +5634,9 @@
 		/* allocate kernel buffer for DMA */
 			if (mrsas_alloc_dma_obj(instance, &dcmd_dma_obj,
 			    (uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
-				con_log(CL_ANN, (CE_WARN, "issue_mfi_dcmd: "
-				    "could not allocate data transfer buffer."));
+				con_log(CL_ANN,
+				    (CE_WARN, "issue_mfi_dcmd: could not "
+				    "allocate data transfer buffer."));
 				return (DDI_FAILURE);
 			}
 		(void) memset(dcmd_dma_obj.buffer, 0, xferlen);
@@ -5466,12 +5698,15 @@
 	}
 
 	kdcmd->cmd_status = ddi_get8(acc_handle, &dcmd->cmd_status);
-	con_log(CL_ANN, (CE_CONT, "issue_mfi_dcmd: cmd_status %x", kdcmd->cmd_status));
+	con_log(CL_ANN,
+	    (CE_CONT, "issue_mfi_dcmd: cmd_status %x", kdcmd->cmd_status));
+	DTRACE_PROBE3(issue_dcmd, uint32_t, kdcmd->opcode, uint8_t,
+	    kdcmd->cmd, uint8_t, kdcmd->cmd_status);
 
 	if (xferlen) {
 		/* free kernel buffer */
-			if (mrsas_free_dma_obj(instance, dcmd_dma_obj) != DDI_SUCCESS)
-				return (DDI_FAILURE);
+		if (mrsas_free_dma_obj(instance, dcmd_dma_obj) != DDI_SUCCESS)
+			return (DDI_FAILURE);
 	}
 
 	return (DDI_SUCCESS);
@@ -5557,8 +5792,9 @@
 	if (request_xferlen) {
 		/* means IOCTL requires DMA */
 		/* allocate the data transfer buffer */
-		//request_dma_obj.size = request_xferlen;
-		MRSAS_GET_BOUNDARY_ALIGNED_LEN(request_xferlen,new_xfer_length1,PAGESIZE);
+		/* request_dma_obj.size = request_xferlen; */
+		MRSAS_GET_BOUNDARY_ALIGNED_LEN(request_xferlen,
+		    new_xfer_length1, PAGESIZE);
 		request_dma_obj.size = new_xfer_length1;
 		request_dma_obj.dma_attr = mrsas_generic_dma_attr;
 		request_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
@@ -5590,8 +5826,9 @@
 	if (response_xferlen) {
 		/* means IOCTL requires DMA */
 		/* allocate the data transfer buffer */
-		//response_dma_obj.size = response_xferlen;
-		MRSAS_GET_BOUNDARY_ALIGNED_LEN(response_xferlen,new_xfer_length2,PAGESIZE);
+		/* response_dma_obj.size = response_xferlen; */
+		MRSAS_GET_BOUNDARY_ALIGNED_LEN(response_xferlen,
+		    new_xfer_length2, PAGESIZE);
 		response_dma_obj.size = new_xfer_length2;
 		response_dma_obj.dma_attr = mrsas_generic_dma_attr;
 		response_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
@@ -5721,6 +5958,7 @@
 	ksmp->cmd_status = ddi_get8(acc_handle, &smp->cmd_status);
 	con_log(CL_ANN1, (CE_NOTE, "issue_mfi_smp: smp->cmd_status = %d",
 	    ksmp->cmd_status));
+	DTRACE_PROBE2(issue_smp, uint8_t, ksmp->cmd, uint8_t, ksmp->cmd_status);
 
 	if (request_xferlen) {
 		/* free kernel buffer */
@@ -5777,9 +6015,7 @@
 
 		fis_ubuf	= (void *)(ulong_t)kstp->sgl.sge32[0].phys_addr;
 		data_ubuf	= (void *)(ulong_t)kstp->sgl.sge32[1].phys_addr;
-	}
-	else
-	{
+	} else {
 #ifdef _ILP32
 		con_log(CL_ANN1, (CE_CONT, "issue_mfi_stp: DDI_MODEL_ILP32"));
 
@@ -5806,8 +6042,9 @@
 
 		/* means IOCTL requires DMA */
 		/* allocate the data transfer buffer */
-		//fis_dma_obj.size = fis_xferlen;
-		MRSAS_GET_BOUNDARY_ALIGNED_LEN(fis_xferlen,new_xfer_length1,PAGESIZE);	
+		/* fis_dma_obj.size = fis_xferlen; */
+		MRSAS_GET_BOUNDARY_ALIGNED_LEN(fis_xferlen,
+		    new_xfer_length1, PAGESIZE);
 		fis_dma_obj.size = new_xfer_length1;
 		fis_dma_obj.dma_attr = mrsas_generic_dma_attr;
 		fis_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
@@ -5841,8 +6078,9 @@
 
 		/* means IOCTL requires DMA */
 		/* allocate the data transfer buffer */
-		//data_dma_obj.size = data_xferlen;
-		MRSAS_GET_BOUNDARY_ALIGNED_LEN(data_xferlen,new_xfer_length2,PAGESIZE);	
+		/* data_dma_obj.size = data_xferlen; */
+		MRSAS_GET_BOUNDARY_ALIGNED_LEN(data_xferlen, new_xfer_length2,
+		    PAGESIZE);
 		data_dma_obj.size = new_xfer_length2;
 		data_dma_obj.dma_attr = mrsas_generic_dma_attr;
 		data_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
@@ -5850,7 +6088,7 @@
 		data_dma_obj.dma_attr.dma_attr_sgllen = 1;
 		data_dma_obj.dma_attr.dma_attr_align = 1;
 
-/* allocate kernel buffer for DMA */
+		/* allocate kernel buffer for DMA */
 		if (mrsas_alloc_dma_obj(instance, &data_dma_obj,
 		    (uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
 			con_log(CL_ANN, (CE_WARN, "issue_mfi_stp: "
@@ -5931,6 +6169,7 @@
 	kstp->cmd_status = ddi_get8(acc_handle, &stp->cmd_status);
 	con_log(CL_ANN1, (CE_NOTE, "issue_mfi_stp: stp->cmd_status = %d",
 	    kstp->cmd_status));
+	DTRACE_PROBE2(issue_stp, uint8_t, kstp->cmd, uint8_t, kstp->cmd_status);
 
 	if (fis_xferlen) {
 		/* free kernel buffer */
@@ -6094,10 +6333,10 @@
 		cmd = get_mfi_pkt(instance);
 	}
 	if (!cmd) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in handle_mfi_ioctl(). "
-			"fw_outstanding=0x%X max_fw_cmds=0x%X",
-			instance->fw_outstanding, instance->max_fw_cmds);
+		con_log(CL_ANN, (CE_WARN, "mr_sas: "
+		    "failed to get a cmd packet"));
+		DTRACE_PROBE2(mfi_ioctl_err, uint16_t,
+		    instance->fw_outstanding, uint16_t, instance->max_fw_cmds);
 		return (DDI_FAILURE);
 	}
 
@@ -6129,6 +6368,9 @@
 		break;
 	}
 
+	if (mrsas_common_check(instance, cmd) != DDI_SUCCESS)
+		rval = DDI_FAILURE;
+
 	if (instance->tbolt) {
 		return_raid_msg_mfi_pkt(instance, cmd);
 	} else {
@@ -6233,14 +6475,11 @@
 	}
 
 	if (!cmd) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in register_mfi_aen(). "
-			"fw_outstanding=0x%X max_fw_cmds=0x%X",
-			instance->fw_outstanding, instance->max_fw_cmds);
+		DTRACE_PROBE2(mfi_aen_err, uint16_t, instance->fw_outstanding,
+		    uint16_t, instance->max_fw_cmds);
 		return (ENOMEM);
 	}
 
-
 	/* Clear the frame buffer and assign back the context id */
 	(void) memset((char *)&cmd->frame[0], 0, sizeof (union mrsas_frame));
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &cmd->frame->hdr.context,
@@ -6305,31 +6544,31 @@
 	char		inquiry_buf[256] = {0};
 	int		len;
 	const char	*const scsi_device_types[] = {
-		"Direct-Access    ",
+		"Direct-Access	  ",
 		"Sequential-Access",
-		"Printer          ",
-		"Processor        ",
-		"WORM             ",
-		"CD-ROM           ",
-		"Scanner          ",
-		"Optical Device   ",
-		"Medium Changer   ",
-		"Communications   ",
-		"Unknown          ",
-		"Unknown          ",
-		"Unknown          ",
-		"Enclosure        ",
+		"Printer	  ",
+		"Processor	  ",
+		"WORM		  ",
+		"CD-ROM		  ",
+		"Scanner	  ",
+		"Optical Device	  ",
+		"Medium Changer	  ",
+		"Communications	  ",
+		"Unknown	  ",
+		"Unknown	  ",
+		"Unknown	  ",
+		"Enclosure	  ",
 	};
 
 	len = 0;
 
-	len += snprintf(inquiry_buf + len, 265 - len, "  Vendor: ");
+	len += snprintf(inquiry_buf + len, 265 - len, "	 Vendor: ");
 	for (i = 8; i < 16; i++) {
 		len += snprintf(inquiry_buf + len, 265 - len, "%c",
 		    scsi_inq[i]);
 	}
 
-	len += snprintf(inquiry_buf + len, 265 - len, "  Model: ");
+	len += snprintf(inquiry_buf + len, 265 - len, "	 Model: ");
 
 	for (i = 16; i < 32; i++) {
 		len += snprintf(inquiry_buf + len, 265 - len, "%c",
@@ -6336,7 +6575,7 @@
 		    scsi_inq[i]);
 	}
 
-	len += snprintf(inquiry_buf + len, 265 - len, "  Rev: ");
+	len += snprintf(inquiry_buf + len, 265 - len, "	 Rev: ");
 
 	for (i = 32; i < 36; i++) {
 		len += snprintf(inquiry_buf + len, 265 - len, "%c",
@@ -6349,13 +6588,13 @@
 	i = scsi_inq[0] & 0x1f;
 
 
-	len += snprintf(inquiry_buf + len, 265 - len, "  Type:   %s ",
+	len += snprintf(inquiry_buf + len, 265 - len, "	 Type:	 %s ",
 	    i < MAX_SCSI_DEVICE_CODE ? scsi_device_types[i] :
-	    "Unknown          ");
+	    "Unknown	      ");
 
 
 	len += snprintf(inquiry_buf + len, 265 - len,
-	    "                 ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);
+	    "		      ANSI SCSI revision: %02x", scsi_inq[2] & 0x07);
 
 	if ((scsi_inq[2] & 0x07) == 1 && (scsi_inq[3] & 0x0f) == 1) {
 		len += snprintf(inquiry_buf + len, 265 - len, " CCS\n");
@@ -6366,7 +6605,7 @@
 	con_log(CL_DLEVEL2, (CE_CONT, inquiry_buf));
 }
 
-void
+static void
 io_timeout_checker(void *arg)
 {
 	struct scsi_pkt *pkt;
@@ -6389,17 +6628,18 @@
 
 	/* See if this check needs to be in the beginning or last in ISR */
 	if (mrsas_initiate_ocr_if_fw_is_faulty(instance) ==  1) {
-		cmn_err(CE_WARN, "io_timeout_checker:"
+		cmn_err(CE_WARN, "io_timeout_checker: "
 		    "FW Fault, calling reset adapter");
-		cmn_err(CE_CONT, "io_timeout_checker: fw_outstanding 0x%X max_fw_cmds 0x%X",
-			instance->fw_outstanding, instance->max_fw_cmds );
+		cmn_err(CE_CONT, "io_timeout_checker: "
+		    "fw_outstanding 0x%X max_fw_cmds 0x%X",
+		    instance->fw_outstanding, instance->max_fw_cmds);
 		if (instance->adapterresetinprogress == 0) {
-			instance->adapterresetinprogress = 1;  
+			instance->adapterresetinprogress = 1;
 			if (instance->tbolt)
-				mrsas_tbolt_reset_ppc(instance);
+				(void) mrsas_tbolt_reset_ppc(instance);
 			else
-				mrsas_reset_ppc(instance);
-			instance->adapterresetinprogress = 0;	
+				(void) mrsas_reset_ppc(instance);
+			instance->adapterresetinprogress = 0;
 		}
 		instance->timeout_id = timeout(io_timeout_checker,
 		    (void *) instance, drv_usectohz(MRSAS_1_SECOND));
@@ -6422,7 +6662,7 @@
 				continue;
 			}
 			time = --cmd->drv_pkt_time;
-		} else {     
+		} else {
 			pkt = cmd->pkt;
 			if (pkt == NULL) {
 				continue;
@@ -6431,9 +6671,10 @@
 		}
 		if (time <= 0) {
 			cmn_err(CE_WARN, "%llx: "
-			    "io_timeout_checker: TIMING OUT: pkt "
-			    ": %p, cmd %p fw_outstanding 0x%X max_fw_cmds 0x%X\n",
-				gethrtime(), (void *)pkt, (void *)cmd, instance->fw_outstanding, instance->max_fw_cmds);
+			    "io_timeout_checker: TIMING OUT: pkt: %p, "
+			    "cmd %p fw_outstanding 0x%X max_fw_cmds 0x%X\n",
+			    gethrtime(), (void *)pkt, (void *)cmd,
+			    instance->fw_outstanding, instance->max_fw_cmds);
 
 			counter++;
 			break;
@@ -6443,27 +6684,31 @@
 
 	if (counter) {
 		if (instance->disable_online_ctrl_reset == 1) {
-			cmn_err(CE_WARN, "mr_sas %d: %s(): OCR is NOT supported by Firmware, KILL adapter!!!",
-		            instance->instance, __func__);
+			cmn_err(CE_WARN, "mr_sas %d: %s(): OCR is NOT "
+			    "supported by Firmware, KILL adapter!!!",
+			    instance->instance, __func__);
 
 			if (instance->tbolt)
-				(void) mrsas_tbolt_kill_adapter(instance);
+				mrsas_tbolt_kill_adapter(instance);
 			else
 				(void) mrsas_kill_adapter(instance);
 
 			return;
 		} else {
-			if (cmd->retry_count_for_ocr <=  IO_RETRY_COUNT) {
+			if (cmd->retry_count_for_ocr <=	 IO_RETRY_COUNT) {
 				if (instance->adapterresetinprogress == 0) {
-					if (instance->tbolt)
-						mrsas_tbolt_reset_ppc(instance);
-					else
-						mrsas_reset_ppc(instance);
+					if (instance->tbolt) {
+						(void) mrsas_tbolt_reset_ppc(
+						    instance);
+					} else {
+						(void) mrsas_reset_ppc(
+						    instance);
+					}
 				}
 			} else {
 				cmn_err(CE_WARN,
 				    "io_timeout_checker: "
-					"cmd %p cmd->index %d "
+				    "cmd %p cmd->index %d "
 				    "timed out even after 3 resets: "
 				    "so KILL adapter", (void *)cmd, cmd->index);
 
@@ -6470,7 +6715,7 @@
 				mrsas_print_cmd_details(instance, cmd, 0xDD);
 
 				if (instance->tbolt)
-					(void) mrsas_tbolt_kill_adapter(instance);
+					mrsas_tbolt_kill_adapter(instance);
 				else
 					(void) mrsas_kill_adapter(instance);
 				return;
@@ -6518,7 +6763,6 @@
 	}
 
 	mutex_enter(&instance->reg_write_mtx);
-	ASSERT(mutex_owned(&instance->reg_write_mtx));
 	/* Issue the command to the FW */
 	WR_IB_QPORT((cmd->frame_phys_addr) |
 	    (((cmd->frame_count - 1) << 1) | 1), instance);
@@ -6559,7 +6803,6 @@
 	cmd->cmd_status	= ENODATA;
 
 	mutex_enter(&instance->reg_write_mtx);
-	ASSERT(mutex_owned(&instance->reg_write_mtx));
 	/* Issue the command to the FW */
 	WR_IB_QPORT((cmd->frame_phys_addr) |
 	    (((cmd->frame_count - 1) << 1) | 1), instance);
@@ -6598,7 +6841,7 @@
 	ddi_put8(cmd->frame_dma_obj.acc_handle, &frame_hdr->cmd_status,
 	    MFI_CMD_STATUS_POLL_MODE);
 	flags = ddi_get16(cmd->frame_dma_obj.acc_handle, &frame_hdr->flags);
-	flags 	|= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
+	flags	|= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
 
 	ddi_put16(cmd->frame_dma_obj.acc_handle, &frame_hdr->flags, flags);
 
@@ -6683,6 +6926,11 @@
 		ret = DDI_INTR_UNCLAIMED;
 	}
 
+	if (mrsas_check_acc_handle(instance->regmap_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+		ret = DDI_INTR_UNCLAIMED;
+	}
+
 	if (ret == DDI_INTR_UNCLAIMED) {
 		return (ret);
 	}
@@ -6710,7 +6958,7 @@
 		return (DDI_FAILURE);
 
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_kill_adapter: "
-		"Writing to doorbell with MFI_STOP_ADP "));
+	    "Writing to doorbell with MFI_STOP_ADP "));
 	mutex_enter(&instance->ocr_flags_mtx);
 	instance->deadadapter = 1;
 	mutex_exit(&instance->ocr_flags_mtx);
@@ -6760,7 +7008,7 @@
 		status = RD_OB_DRWE(instance);
 		if (retry++ == 100) {
 			cmn_err(CE_WARN, "mrsas_reset_ppc: DRWE bit "
-			    "check retry count %d\n", retry);
+			    "check retry count %d", retry);
 			return (DDI_FAILURE);
 		}
 	}
@@ -6771,8 +7019,8 @@
 		delay(100 * drv_usectohz(MILLISEC));
 		status = RD_OB_DRWE(instance);
 		if (retry++ == 100) {
-			cmn_err(CE_WARN,
-				"mrsas_reset_ppc: RESET FAILED. KILL adapter called\n.");
+			cmn_err(CE_WARN, "mrsas_reset_ppc: "
+			    "RESET FAILED. KILL adapter called.");
 
 			(void) mrsas_kill_adapter(instance);
 			return (DDI_FAILURE);
@@ -6807,14 +7055,15 @@
 			    < MAX_FW_RESET_COUNT) {
 				cmn_err(CE_WARN, "mrsas_reset_ppc: "
 				    "FW is in fault after OCR count %d "
-					"Retry Reset",
+				    "Retry Reset",
 				    instance->fw_fault_count_after_ocr);
 				goto retry_reset;
 
 			} else {
 				cmn_err(CE_WARN, "mrsas_reset_ppc: "
-					"Max Reset Count exceeded >%d"
-				    "Mark HBA as bad, KILL adapter", MAX_FW_RESET_COUNT);
+				    "Max Reset Count exceeded >%d"
+				    "Mark HBA as bad, KILL adapter",
+				    MAX_FW_RESET_COUNT);
 
 				(void) mrsas_kill_adapter(instance);
 				return (DDI_FAILURE);
@@ -6855,7 +7104,7 @@
 	    "Calling mrsas_issue_pending_cmds"));
 	(void) mrsas_issue_pending_cmds(instance);
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_reset_ppc: "
-	"issue_pending_cmds done.\n"));
+	    "issue_pending_cmds done.\n"));
 
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_reset_ppc: "
 	    "Calling aen registration"));
@@ -6877,8 +7126,184 @@
 	return (DDI_SUCCESS);
 }
 
+/*
+ * FMA functions.
+ */
+int
+mrsas_common_check(struct mrsas_instance *instance, struct  mrsas_cmd *cmd)
+{
+	int ret = DDI_SUCCESS;
 
+	if (cmd != NULL &&
+	    mrsas_check_dma_handle(cmd->frame_dma_obj.dma_handle) !=
+	    DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_UNAFFECTED);
+		if (cmd->pkt != NULL) {
+			cmd->pkt->pkt_reason = CMD_TRAN_ERR;
+			cmd->pkt->pkt_statistics = 0;
+		}
+		ret = DDI_FAILURE;
+	}
+	if (mrsas_check_dma_handle(instance->mfi_internal_dma_obj.dma_handle)
+	    != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_UNAFFECTED);
+		if (cmd != NULL && cmd->pkt != NULL) {
+			cmd->pkt->pkt_reason = CMD_TRAN_ERR;
+			cmd->pkt->pkt_statistics = 0;
+		}
+		ret = DDI_FAILURE;
+	}
+	if (mrsas_check_dma_handle(instance->mfi_evt_detail_obj.dma_handle) !=
+	    DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_UNAFFECTED);
+		if (cmd != NULL && cmd->pkt != NULL) {
+			cmd->pkt->pkt_reason = CMD_TRAN_ERR;
+			cmd->pkt->pkt_statistics = 0;
+		}
+		ret = DDI_FAILURE;
+	}
+	if (mrsas_check_acc_handle(instance->regmap_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_UNAFFECTED);
+
+		ddi_fm_acc_err_clear(instance->regmap_handle, DDI_FME_VER0);
+
+		if (cmd != NULL && cmd->pkt != NULL) {
+			cmd->pkt->pkt_reason = CMD_TRAN_ERR;
+			cmd->pkt->pkt_statistics = 0;
+		}
+		ret = DDI_FAILURE;
+	}
+
+	return (ret);
+}
+
+/*ARGSUSED*/
 static int
+mrsas_fm_error_cb(dev_info_t *dip, ddi_fm_error_t *err, const void *impl_data)
+{
+	/*
+	 * as the driver can always deal with an error in any dma or
+	 * access handle, we can just return the fme_status value.
+	 */
+	pci_ereport_post(dip, err, NULL);
+	return (err->fme_status);
+}
+
+static void
+mrsas_fm_init(struct mrsas_instance *instance)
+{
+	/* Need to change iblock to priority for new MSI intr */
+	ddi_iblock_cookie_t fm_ibc;
+
+	/* Only register with IO Fault Services if we have some capability */
+	if (instance->fm_capabilities) {
+		/* Adjust access and dma attributes for FMA */
+		endian_attr.devacc_attr_access = DDI_FLAGERR_ACC;
+		mrsas_generic_dma_attr.dma_attr_flags = DDI_DMA_FLAGERR;
+
+		/*
+		 * Register capabilities with IO Fault Services.
+		 * fm_capabilities will be updated to indicate
+		 * capabilities actually supported (not requested.)
+		 */
+
+		ddi_fm_init(instance->dip, &instance->fm_capabilities, &fm_ibc);
+
+		/*
+		 * Initialize pci ereport capabilities if ereport
+		 * capable (should always be.)
+		 */
+
+		if (DDI_FM_EREPORT_CAP(instance->fm_capabilities) ||
+		    DDI_FM_ERRCB_CAP(instance->fm_capabilities)) {
+			pci_ereport_setup(instance->dip);
+		}
+
+		/*
+		 * Register error callback if error callback capable.
+		 */
+		if (DDI_FM_ERRCB_CAP(instance->fm_capabilities)) {
+			ddi_fm_handler_register(instance->dip,
+			    mrsas_fm_error_cb, (void*) instance);
+		}
+	} else {
+		endian_attr.devacc_attr_access = DDI_DEFAULT_ACC;
+		mrsas_generic_dma_attr.dma_attr_flags = 0;
+	}
+}
+
+static void
+mrsas_fm_fini(struct mrsas_instance *instance)
+{
+	/* Only unregister FMA capabilities if registered */
+	if (instance->fm_capabilities) {
+		/*
+		 * Un-register error callback if error callback capable.
+		 */
+		if (DDI_FM_ERRCB_CAP(instance->fm_capabilities)) {
+			ddi_fm_handler_unregister(instance->dip);
+		}
+
+		/*
+		 * Release any resources allocated by pci_ereport_setup()
+		 */
+		if (DDI_FM_EREPORT_CAP(instance->fm_capabilities) ||
+		    DDI_FM_ERRCB_CAP(instance->fm_capabilities)) {
+			pci_ereport_teardown(instance->dip);
+		}
+
+		/* Unregister from IO Fault Services */
+		ddi_fm_fini(instance->dip);
+
+		/* Adjust access and dma attributes for FMA */
+		endian_attr.devacc_attr_access = DDI_DEFAULT_ACC;
+		mrsas_generic_dma_attr.dma_attr_flags = 0;
+	}
+}
+
+int
+mrsas_check_acc_handle(ddi_acc_handle_t handle)
+{
+	ddi_fm_error_t de;
+
+	if (handle == NULL) {
+		return (DDI_FAILURE);
+	}
+
+	ddi_fm_acc_err_get(handle, &de, DDI_FME_VERSION);
+
+	return (de.fme_status);
+}
+
+int
+mrsas_check_dma_handle(ddi_dma_handle_t handle)
+{
+	ddi_fm_error_t de;
+
+	if (handle == NULL) {
+		return (DDI_FAILURE);
+	}
+
+	ddi_fm_dma_err_get(handle, &de, DDI_FME_VERSION);
+
+	return (de.fme_status);
+}
+
+void
+mrsas_fm_ereport(struct mrsas_instance *instance, char *detail)
+{
+	uint64_t ena;
+	char buf[FM_MAX_CLASS];
+
+	(void) snprintf(buf, FM_MAX_CLASS, "%s.%s", DDI_FM_DEVICE, detail);
+	ena = fm_ena_generate(0, FM_ENA_FMT1);
+	if (DDI_FM_EREPORT_CAP(instance->fm_capabilities)) {
+		ddi_fm_ereport_post(instance->dip, buf, ena, DDI_NOSLEEP,
+		    FM_VERSION, DATA_TYPE_UINT8, FM_EREPORT_VERSION, NULL);
+	}
+}
+
+static int
 mrsas_add_intrs(struct mrsas_instance *instance, int intr_type)
 {
 
@@ -6920,20 +7345,17 @@
 	 * only one interrupt. The framework can be extended later.
 	 */
 	instance->intr_htable_size = count * sizeof (ddi_intr_handle_t);
-	instance->intr_htable = kmem_zalloc(instance->intr_htable_size, KM_SLEEP);
-	if (instance->intr_htable == NULL) {
-		con_log(CL_ANN, (CE_WARN, "mrsas_add_intrs: "
-			"failed to allocate memory for intr-handle table"));
-		instance->intr_htable_size = 0;
-		return (DDI_FAILURE);
-	}
+	instance->intr_htable = kmem_zalloc(instance->intr_htable_size,
+	    KM_SLEEP);
+	ASSERT(instance->intr_htable);
 
-	flag = ((intr_type == DDI_INTR_TYPE_MSI) || (intr_type ==
-		DDI_INTR_TYPE_MSIX)) ? DDI_INTR_ALLOC_STRICT:DDI_INTR_ALLOC_NORMAL;
+	flag = ((intr_type == DDI_INTR_TYPE_MSI) ||
+	    (intr_type == DDI_INTR_TYPE_MSIX)) ?
+	    DDI_INTR_ALLOC_STRICT : DDI_INTR_ALLOC_NORMAL;
 
 	/* Allocate interrupt */
 	ret = ddi_intr_alloc(dip, instance->intr_htable, intr_type, 0,
-			count, &actual, flag);
+	    count, &actual, flag);
 
 	if ((ret != DDI_SUCCESS) || (actual == 0)) {
 		con_log(CL_ANN, (CE_WARN, "mrsas_add_intrs: "
@@ -7011,21 +7433,17 @@
 
 mrsas_free_handlers:
 	for (i = 0; i < actual; i++)
-	{
 		(void) ddi_intr_remove_handler(instance->intr_htable[i]);
-	}
 
 mrsas_free_handles:
 	for (i = 0; i < actual; i++)
-	{
 		(void) ddi_intr_free(instance->intr_htable[i]);
-	}
 
 mrsas_free_htable:
 	if (instance->intr_htable != NULL)
 		kmem_free(instance->intr_htable, instance->intr_htable_size);
 
-	instance->intr_htable =NULL;
+	instance->intr_htable = NULL;
 	instance->intr_htable_size = 0;
 
 	return (DDI_FAILURE);
@@ -7043,7 +7461,7 @@
 	/* Disable all interrupts first */
 	if (instance->intr_cap & DDI_INTR_FLAG_BLOCK) {
 		(void) ddi_intr_block_disable(instance->intr_htable,
-				instance->intr_cnt);
+		    instance->intr_cnt);
 	} else {
 		for (i = 0; i < instance->intr_cnt; i++) {
 			(void) ddi_intr_disable(instance->intr_htable[i]);
@@ -7060,7 +7478,7 @@
 	if (instance->intr_htable != NULL)
 		kmem_free(instance->intr_htable, instance->intr_htable_size);
 
-	instance->intr_htable =NULL;
+	instance->intr_htable = NULL;
 	instance->intr_htable_size = 0;
 
 }
@@ -7102,14 +7520,12 @@
 
 		if (lun == 0) {
 			rval = mrsas_config_ld(instance, tgt, lun, childp);
-		}
 #ifdef PDSUPPORT
-		else if ( instance->tbolt == 1 && lun != 0) {
-			rval = mrsas_tbolt_config_pd(instance, 
+		} else if (instance->tbolt == 1 && lun != 0) {
+			rval = mrsas_tbolt_config_pd(instance,
 			    tgt, lun, childp);
-		}
 #endif
-		else {
+		} else {
 			rval = NDI_FAILURE;
 		}
 
@@ -7148,7 +7564,7 @@
 
 #ifdef PDSUPPORT
 	/* Config PD devices connected to the card */
-	if(instance->tbolt) {
+	if (instance->tbolt) {
 		for (tgt = 0; tgt < instance->mr_tbolt_pd_max; tgt++) {
 			(void) mrsas_tbolt_config_pd(instance, tgt, 1, NULL);
 		}
@@ -7230,11 +7646,6 @@
 	}
 
 	sd = kmem_zalloc(sizeof (struct scsi_device), KM_SLEEP);
-	if (sd == NULL) {
-		con_log(CL_ANN1, (CE_WARN,
-			    "mrsas_config_ld: failed to allocate mem for scsi_device"));
-		return (NDI_FAILURE);
-	}
 	sd->sd_address.a_hba_tran = instance->tran;
 	sd->sd_address.a_target = (uint16_t)tgt;
 	sd->sd_address.a_lun = (uint8_t)lun;
@@ -7369,7 +7780,7 @@
 		kmem_free(mrevt, sizeof (struct mrsas_eventinfo));
 		return (DDI_FAILURE);
 	}
-
+	DTRACE_PROBE3(service_evt, int, tgt, int, lun, int, event);
 	return (DDI_SUCCESS);
 }
 
@@ -7389,16 +7800,15 @@
 		mutex_enter(&instance->config_dev_mtx);
 		dip = instance->mr_ld_list[mrevt->tgt].dip;
 		mutex_exit(&instance->config_dev_mtx);
-	}
-
 #ifdef PDSUPPORT
-	else {
+	} else {
 		mutex_enter(&instance->config_dev_mtx);
 		dip = instance->mr_tbolt_pd_list[mrevt->tgt].dip;
 		mutex_exit(&instance->config_dev_mtx);
-	}
 #endif
+	}
 
+
 	ndi_devi_enter(instance->dip, &circ1);
 	switch (mrevt->event) {
 	case MRSAS_EVT_CONFIG_TGT:
@@ -7407,14 +7817,13 @@
 			if (mrevt->lun == 0) {
 				(void) mrsas_config_ld(instance, mrevt->tgt,
 				    0, NULL);
-			}
 #ifdef PDSUPPORT
-			else if (instance->tbolt) {
+			} else if (instance->tbolt) {
 				(void) mrsas_tbolt_config_pd(instance,
 				    mrevt->tgt,
 				    1, NULL);
-			}
 #endif
+			}
 			con_log(CL_ANN1, (CE_NOTE,
 			    "mr_sas: EVT_CONFIG_TGT called:"
 			    " for tgt %d lun %d event %d",
@@ -7462,7 +7871,7 @@
 mrsas_mode_sense_build(struct scsi_pkt *pkt)
 {
 	union scsi_cdb		*cdbp;
-	uint16_t 		page_code;
+	uint16_t		page_code;
 	struct scsa_cmd		*acmd;
 	struct buf		*bp;
 	struct mode_header	*modehdrp;
@@ -7514,4 +7923,3 @@
 	}
 	return (NULL);
 }
-
--- old/./mr_sas.h	Tue Nov  6 14:29:40 2012
+++ new/./mr_sas.h	Tue Nov  6 14:29:40 2012
@@ -12,8 +12,39 @@
  *		Manju R
  *		Rasheed
  *		Shakeel Bukhari
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the author nor the names of its contributors may be
+ *    used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
  */
 
+/*
+ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+ */
+
 #ifndef	_MR_SAS_H_
 #define	_MR_SAS_H_
 
@@ -28,7 +59,7 @@
 /*
  * MegaRAID SAS2.0 Driver meta data
  */
-#define	MRSAS_VERSION				"6.503.00.00JOYENT"
+#define	MRSAS_VERSION				"6.503.00.00ILLUMOS"
 #define	MRSAS_RELDATE				"July 30, 2012"
 
 #define	MRSAS_TRUE				1
@@ -37,23 +68,21 @@
 #define	ADAPTER_RESET_NOT_REQUIRED		0
 #define	ADAPTER_RESET_REQUIRED			1
 
-#define PDSUPPORT	1
+#define	PDSUPPORT	1
 
-#define	SWAP_BYTES(w)	((((w)>>8)&0xFF) | (((w)&0xFF)<<8))
-#define	BIG_ENDIAN(d)	(SWAP_BYTES((d) >> 16) | (SWAP_BYTES(d) << 16))
 /*
  * MegaRAID SAS2.0 device id conversion definitions.
  */
 #define	INST2LSIRDCTL(x)		((x) << INST_MINOR_SHIFT)
-#define MRSAS_GET_BOUNDARY_ALIGNED_LEN(len, new_len, boundary_len)  { \
-        int rem; \
-        rem = (len / boundary_len); \
-        if ((rem * boundary_len) != len) { \
-                new_len = len + ((rem + 1) * boundary_len - len); \
-         } else { \
-                new_len = len; \
-        } \
-} \
+#define	MRSAS_GET_BOUNDARY_ALIGNED_LEN(len, new_len, boundary_len)  { \
+	int rem; \
+	rem = (len / boundary_len); \
+	if ((rem * boundary_len) != len) { \
+		new_len = len + ((rem + 1) * boundary_len - len); \
+	} else { \
+		new_len = len; \
+	} \
+}
 
 
 /*
@@ -83,7 +112,7 @@
 #define	UNCONFIGURED_GOOD			0x0
 #define	PD_SYSTEM				0x40
 #define	MR_EVT_PD_STATE_CHANGE			0x0072
-#define MR_EVT_PD_REMOVED_EXT		0x00f8
+#define	MR_EVT_PD_REMOVED_EXT		0x00f8
 #define	MR_EVT_PD_INSERTED_EXT		0x00f7
 #define	MR_DCMD_PD_GET_INFO			0x02020000
 #define	MRSAS_TBOLT_PD_LUN		1
@@ -93,11 +122,11 @@
 #endif
 
 /* Raid Context Flags */
-#define MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT        0x4
-#define MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_MASK 0x30
-typedef enum    MR_RAID_FLAGS_IO_SUB_TYPE {
-        MR_RAID_FLAGS_IO_SUB_TYPE_NONE = 0,
-        MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD = 1
+#define	MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT 0x4
+#define	MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_MASK 0x30
+typedef enum MR_RAID_FLAGS_IO_SUB_TYPE {
+	MR_RAID_FLAGS_IO_SUB_TYPE_NONE = 0,
+	MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD = 1
 } MR_RAID_FLAGS_IO_SUB_TYPE;
 
 /* Dynamic Enumeration Flags */
@@ -510,31 +539,33 @@
 	int		baseaddress;
 	char		iocnode[16];
 
-	/*Driver resources unroll flags.
-	  The flag is set for resources that are needed to be free'd at detach() time */
-
-	struct _unroll {                             
-		uint8_t softs;     	// The software state was allocated.
-		uint8_t regs;           // Controller registers mapped.
-		uint8_t intr;           // Interrupt handler added.
-		uint8_t reqs;           // Request structs allocated.
-		uint8_t mutexs;         // Mutex's allocated.
-		uint8_t taskq;          // Task q's created.
-		uint8_t tran;           // Tran struct allocated
-		uint8_t tranSetup;      // Tran attached to the ddi.
-		uint8_t devctl;         // Device nodes for cfgadm created.
-		uint8_t scsictl;        // Device nodes for cfgadm created.
-		uint8_t ioctl;          // Device nodes for ioctl's created.
-		uint8_t timer;          // Timer started.
-		uint8_t aenPend;        // AEN cmd pending f/w.
-		uint8_t mapUpdate_pend; // LD MAP update cmd pending f/w.
-		uint8_t soft_isr;
-		uint8_t ldlist_buff;
-		uint8_t pdlist_buff;
-		uint8_t syncCmd;
-		uint8_t verBuff;
-		uint8_t alloc_space_mfi;
-		uint8_t alloc_space_mpi2;
+	int		fm_capabilities;
+	/*
+	 * Driver resources unroll flags.  The flag is set for resources that
+	 * are needed to be free'd at detach() time.
+	 */
+	struct _unroll {
+		uint8_t softs;		/* The software state was allocated. */
+		uint8_t regs;		/* Controller registers mapped. */
+		uint8_t intr;		/* Interrupt handler added. */
+		uint8_t reqs;		/* Request structs allocated. */
+		uint8_t mutexs;		/* Mutex's allocated. */
+		uint8_t taskq;		/* Task q's created. */
+		uint8_t tran;		/* Tran struct allocated */
+		uint8_t tranSetup;	/* Tran attached to the ddi. */
+		uint8_t devctl;		/* Device nodes for cfgadm created. */
+		uint8_t scsictl;	/* Device nodes for cfgadm created. */
+		uint8_t ioctl;		/* Device nodes for ioctl's created. */
+		uint8_t timer;		/* Timer started. */
+		uint8_t aenPend;	/* AEN cmd pending f/w. */
+		uint8_t mapUpdate_pend; /* LD MAP update cmd pending f/w. */
+		uint8_t soft_isr;	/* Soft interrupt handler allocated. */
+		uint8_t ldlist_buff;	/* Logical disk list allocated. */
+		uint8_t pdlist_buff;	/* Physical disk list allocated. */
+		uint8_t syncCmd;	/* Sync map command allocated. */
+		uint8_t verBuff;	/* 2108 MFI buffer allocated. */
+		uint8_t alloc_space_mfi;  /* Allocated space for 2108 MFI. */
+		uint8_t alloc_space_mpi2; /* Allocated space for 2208 MPI2. */
 	} unroll;
 
 
@@ -543,8 +574,8 @@
 
 
 	/* MSI interrupts specific */
-	ddi_intr_handle_t *intr_htable;       //Interrupt handle array
-	size_t		intr_htable_size;     //Interrupt handle array size
+	ddi_intr_handle_t *intr_htable;		/* Interrupt handle array */
+	size_t		intr_htable_size;	/* Int. handle array size */
 	int		intr_type;
 	int		intr_cnt;
 	uint_t		intr_pri;
@@ -565,17 +596,22 @@
 
 	uint16_t	tbolt;
 	uint16_t	reply_read_index;
-	uint16_t	reply_size; 		// Single Reply structure size
-	uint16_t	raid_io_msg_size; 	// Single message size
+	uint16_t	reply_size; 		/* Single Reply struct size */
+	uint16_t	raid_io_msg_size; 	/* Single message size */
 	uint32_t	io_request_frames_phy;
 	uint8_t 	*io_request_frames;
-	MRSAS_REQUEST_DESCRIPTOR_UNION	*request_message_pool;   // Virtual address of request desc frame pool
-	uint32_t	request_message_pool_phy;		 // Physical address of request desc frame pool
-	MPI2_REPLY_DESCRIPTORS_UNION	*reply_frame_pool;	 // Virtual address of reply Frame
-	uint32_t	reply_frame_pool_phy;			 // Physical address of reply Frame
-	uint8_t		*reply_pool_limit;			 // Last reply frame address
-	uint32_t	reply_pool_limit_phy;			 // Physical address of Last reply frame
-	uint32_t	reply_q_depth;				 // Reply Queue Depth
+	/* Virtual address of request desc frame pool */
+	MRSAS_REQUEST_DESCRIPTOR_UNION	*request_message_pool;
+	/* Physical address of request desc frame pool */
+	uint32_t	request_message_pool_phy;
+	/* Virtual address of reply Frame */
+	MPI2_REPLY_DESCRIPTORS_UNION	*reply_frame_pool;
+	/* Physical address of reply Frame */
+	uint32_t	reply_frame_pool_phy;
+	uint8_t		*reply_pool_limit;	/* Last reply frame address */
+	/* Physical address of Last reply frame */
+	uint32_t	reply_pool_limit_phy;
+	uint32_t	reply_q_depth;		/* Reply Queue Depth */
 	uint8_t		max_sge_in_main_msg;
 	uint8_t		max_sge_in_chain;
 	uint8_t    	chain_offset_io_req;
@@ -588,7 +624,7 @@
 	struct mrsas_cmd *map_update_cmd;
 	uint32_t	SyncRequired;
 	kmutex_t	ocr_flags_mtx;
-	dma_obj_t        drv_ver_dma_obj;
+	dma_obj_t	drv_ver_dma_obj;
 } mrsas_t;
 
 
@@ -606,7 +642,7 @@
 	void (*disable_intr)(struct mrsas_instance *);
 	int (*intr_ack)(struct mrsas_instance *);
 	int (*init_adapter)(struct mrsas_instance *);
-//	int (*reset_adapter)(struct mrsas_instance *);
+/*	int (*reset_adapter)(struct mrsas_instance *); */
 };
 
 /*
@@ -627,13 +663,13 @@
  */
 #define	CL_NONE		0	/* No debug information */
 #define	CL_ANN		1	/* print unconditionally, announcements */
-#define	CL_ANN1		2	/* No o/p  */
+#define	CL_ANN1		2	/* No-op  */
 #define	CL_DLEVEL1	3	/* debug level 1, informative */
 #define	CL_DLEVEL2	4	/* debug level 2, verbose */
 #define	CL_DLEVEL3	5	/* debug level 3, very verbose */
 
 #ifdef __SUNPRO_C
-#define	__func__	__FUNCTION__	//""
+#define	__func__ ""
 #endif
 
 #define	con_log(level, fmt) { if (debug_level_g >= level) cmn_err fmt; }
@@ -1917,122 +1953,22 @@
 #define	DDI_VENDOR_LSI		"LSI"
 #endif /* DDI_VENDOR_LSI */
 
-static int	mrsas_getinfo(dev_info_t *, ddi_info_cmd_t,  void *, void **);
-static int	mrsas_attach(dev_info_t *, ddi_attach_cmd_t);
-static int	mrsas_reset(dev_info_t *, ddi_reset_cmd_t);
-int	mrsas_quiesce(dev_info_t *);
-static int	mrsas_detach(dev_info_t *, ddi_detach_cmd_t);
-static int	mrsas_open(dev_t *, int, int, cred_t *);
-static int	mrsas_close(dev_t, int, int, cred_t *);
-static int	mrsas_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
+int mrsas_config_scsi_device(struct mrsas_instance *,
+    struct scsi_device *, dev_info_t **);
 
-static int	mrsas_tran_tgt_init(dev_info_t *, dev_info_t *,
-		    scsi_hba_tran_t *, struct scsi_device *);
-static struct scsi_pkt *mrsas_tran_init_pkt(struct scsi_address *, register
-		    struct scsi_pkt *, struct buf *, int, int, int, int,
-		    int (*)(), caddr_t);
-static int	mrsas_tran_start(struct scsi_address *,
-		    register struct scsi_pkt *);
-static int	mrsas_tran_abort(struct scsi_address *, struct scsi_pkt *);
-static int	mrsas_tran_reset(struct scsi_address *, int);
-static int	mrsas_tran_bus_reset(dev_info_t *, int);
-static int	mrsas_tran_getcap(struct scsi_address *, char *, int);
-static int	mrsas_tran_setcap(struct scsi_address *, char *, int, int);
-static void	mrsas_tran_destroy_pkt(struct scsi_address *,
-		    struct scsi_pkt *);
-static void	mrsas_tran_dmafree(struct scsi_address *, struct scsi_pkt *);
-static void	mrsas_tran_sync_pkt(struct scsi_address *, struct scsi_pkt *);
-static int	mrsas_tran_quiesce(dev_info_t *dip);
-static int	mrsas_tran_unquiesce(dev_info_t *dip);
-static uint_t	mrsas_isr();
-static uint_t	mrsas_softintr();
-
-static struct mrsas_cmd *get_mfi_pkt(struct mrsas_instance *);
-static void	return_mfi_pkt(struct mrsas_instance *,
-		    struct mrsas_cmd *);
-
-static void	free_space_for_mfi(struct mrsas_instance *);
-static int	mrsas_tbolt_alloc_additional_dma_buffer
-(struct mrsas_instance *);
-int 		mrsas_tbolt_sync_map_info(struct mrsas_instance *instance);
-static int	alloc_additional_dma_buffer(struct mrsas_instance *);
-static uint32_t	read_fw_status_reg_ppc(struct mrsas_instance *);
-static void	issue_cmd_ppc(struct mrsas_cmd *, struct mrsas_instance *);
-static int	issue_cmd_in_poll_mode_ppc(struct mrsas_instance *,
-		    struct mrsas_cmd *);
-static int	issue_cmd_in_sync_mode_ppc(struct mrsas_instance *,
-		    struct mrsas_cmd *);
-static void	enable_intr_ppc(struct mrsas_instance *);
-static void	disable_intr_ppc(struct mrsas_instance *);
-static int	intr_ack_ppc(struct mrsas_instance *);
-int	mfi_state_transition_to_ready(struct mrsas_instance *);
-static void	flush_cache(struct mrsas_instance *instance);
-void	display_scsi_inquiry(caddr_t);
-static int	start_mfi_aen(struct mrsas_instance *instance);
-static int	handle_drv_ioctl(struct mrsas_instance *instance,
-		    struct mrsas_ioctl *ioctl, int mode);
-static int	handle_mfi_ioctl(struct mrsas_instance *instance,
-		    struct mrsas_ioctl *ioctl, int mode);
-static int	handle_mfi_aen(struct mrsas_instance *instance,
-		    struct mrsas_aen *aen);
-void	fill_up_drv_ver(struct mrsas_drv_ver *dv);
-static struct mrsas_cmd *build_cmd(struct mrsas_instance *instance,
-		    struct scsi_address *ap, struct scsi_pkt *pkt,
-		    uchar_t *cmd_done);
-static struct mrsas_cmd *mrsas_tbolt_build_cmd(struct mrsas_instance *instance,
-		    struct scsi_address *ap, struct scsi_pkt *pkt,
-		    uchar_t *cmd_done);
-static int	wait_for_outstanding(struct mrsas_instance *instance);
-static int	register_mfi_aen(struct mrsas_instance *instance,
-		    uint32_t seq_num, uint32_t class_locale_word);
-static int	issue_mfi_pthru(struct mrsas_instance *instance, struct
-		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
-static int	issue_mfi_dcmd(struct mrsas_instance *instance, struct
-		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
-static int	issue_mfi_smp(struct mrsas_instance *instance, struct
-		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
-static int	issue_mfi_stp(struct mrsas_instance *instance, struct
-		    mrsas_ioctl *ioctl, struct mrsas_cmd *cmd, int mode);
-static int	abort_aen_cmd(struct mrsas_instance *instance,
-		    struct mrsas_cmd *cmd_to_abort);
-
-
-static void	mrsas_rem_intrs(struct mrsas_instance *instance);
-static int	mrsas_add_intrs(struct mrsas_instance *instance, int intr_type);
-
-static void	mrsas_tran_tgt_free(dev_info_t *, dev_info_t *,
-		    scsi_hba_tran_t *, struct scsi_device *);
-static int	mrsas_tran_bus_config(dev_info_t *, uint_t,
-		    ddi_bus_config_op_t, void *, dev_info_t **);
-static int	mrsas_parse_devname(char *, int *, int *);
-static int	mrsas_config_all_devices(struct mrsas_instance *);
-int 	mrsas_config_scsi_device(struct mrsas_instance *,
-		    struct scsi_device *, dev_info_t **);
-static int 	mrsas_config_ld(struct mrsas_instance *, uint16_t,
-			uint8_t, dev_info_t **);
-
 #ifdef PDSUPPORT
-int 	mrsas_tbolt_config_pd(struct mrsas_instance *, uint16_t,
-			uint8_t, dev_info_t **);
-static void	mrsas_tbolt_get_pd_info(struct mrsas_instance *,
-			struct mrsas_tbolt_pd_info *, int);
+int mrsas_tbolt_config_pd(struct mrsas_instance *, uint16_t,
+    uint8_t, dev_info_t **);
 #endif
 
-dev_info_t *mrsas_find_child(struct mrsas_instance *, uint16_t,
-			uint8_t);
-static int	mrsas_name_node(dev_info_t *, char *, int);
-static void	mrsas_issue_evt_taskq(struct mrsas_eventinfo *);
-int	mrsas_service_evt(struct mrsas_instance *, int, int, int,
-			uint64_t);
-static void 	free_additional_dma_buffer(struct mrsas_instance *);
-
-struct mrsas_cmd *get_raid_msg_pkt(struct mrsas_instance *);
+dev_info_t *mrsas_find_child(struct mrsas_instance *, uint16_t, uint8_t);
+int mrsas_service_evt(struct mrsas_instance *, int, int, int, uint64_t);
 void return_raid_msg_pkt(struct mrsas_instance *, struct mrsas_cmd *);
 struct mrsas_cmd *get_raid_msg_mfi_pkt(struct mrsas_instance *);
 void return_raid_msg_mfi_pkt(struct mrsas_instance *, struct mrsas_cmd *);
 
 int	alloc_space_for_mpi2(struct mrsas_instance *);
-int	alloc_additional_dma_buffer(struct mrsas_instance *);
+void	fill_up_drv_ver(struct mrsas_drv_ver *dv);
 
 int	mrsas_issue_init_mpi2(struct mrsas_instance *);
 struct scsi_pkt *mrsas_tbolt_tran_init_pkt(struct scsi_address *, register
@@ -2060,37 +1996,18 @@
 			struct scsi_pkt *, struct buf *);
 int	mrsas_alloc_dma_obj(struct mrsas_instance *, dma_obj_t *,
 		    uchar_t);
-int 	mrsas_tbolt_ioc_init(struct mrsas_instance *, dma_obj_t *,
-	ddi_acc_handle_t);
-int	mrsas_tbolt_prepare_pkt(struct scsa_cmd *);
 void 	mr_sas_tbolt_build_mfi_cmd(struct mrsas_instance *, struct mrsas_cmd *);
 int 	mrsas_dma_alloc_dmd(struct mrsas_instance *, dma_obj_t *);
-int	mr_sas_tbolt_build_sgl(struct mrsas_instance *,
-	struct scsa_cmd *,
-	struct mrsas_cmd *,
-	Mpi2RaidSCSIIORequest_t *,
-	uint32_t *);
 void 	tbolt_complete_cmd_in_sync_mode(struct mrsas_instance *,
 	struct mrsas_cmd *);
 int 	alloc_req_rep_desc(struct mrsas_instance *);
-static void 	complete_cmd_in_sync_mode(struct mrsas_instance *,
-		struct mrsas_cmd *);
-static void 	io_timeout_checker(void *instance);
-static int	mrsas_kill_adapter(struct mrsas_instance *);
 int		mrsas_mode_sense_build(struct scsi_pkt *);
 void		push_pending_mfi_pkt(struct mrsas_instance *,
 			struct mrsas_cmd *);
-static int 	mrsas_issue_init_mfi(struct mrsas_instance *);
-int		mrsas_issue_pending_cmds(struct mrsas_instance *);
+int	mrsas_issue_pending_cmds(struct mrsas_instance *);
 int 	mrsas_print_pending_cmds(struct mrsas_instance *);
 int  	mrsas_complete_pending_cmds(struct mrsas_instance *);
-static int	mrsas_reset_ppc(struct mrsas_instance *);
-static uint32_t mrsas_initiate_ocr_if_fw_is_faulty(struct mrsas_instance *);
 
-MRSAS_REQUEST_DESCRIPTOR_UNION *\
-	mr_sas_get_request_descriptor(struct mrsas_instance *,
-	uint16_t, struct mrsas_cmd *);
-
 int	create_mfi_frame_pool(struct mrsas_instance *);
 void	destroy_mfi_frame_pool(struct mrsas_instance *);
 int 	create_mfi_mpi_frame_pool(struct mrsas_instance *);
@@ -2103,34 +2020,37 @@
 void 	free_space_for_mpi2(struct mrsas_instance *);
 void 	mrsas_dump_reply_desc(struct mrsas_instance *);
 void 	tbolt_complete_cmd(struct mrsas_instance *, struct mrsas_cmd *);
-void 	io_timeout_checker(void *);
 void	display_scsi_inquiry(caddr_t);
 void	service_mfi_aen(struct mrsas_instance *, struct mrsas_cmd *);
 int	mrsas_mode_sense_build(struct scsi_pkt *);
 int 	mrsas_tbolt_get_ld_map_info(struct mrsas_instance *);
-void 	mrsas_tbolt_set_pd_lba(U8 cdb[], uint8_t *cdb_len, U64 start_blk, U32 num_blocks, U8 DifCapable);
-U8 	mrsas_tbolt_check_map_info(struct mrsas_instance *);
 struct mrsas_cmd *mrsas_tbolt_build_poll_cmd(struct mrsas_instance *,
 	struct scsi_address *, struct scsi_pkt *, uchar_t *);
 int	mrsas_tbolt_reset_ppc(struct mrsas_instance *instance);
-int	mrsas_tbolt_kill_adapter(struct mrsas_instance *instance);
+void	mrsas_tbolt_kill_adapter(struct mrsas_instance *instance);
 int 	abort_syncmap_cmd(struct mrsas_instance *, struct mrsas_cmd *);
-void 	mrsas_tbolt_prepare_cdb(struct mrsas_instance *instance, U8 cdb[],struct IO_REQUEST_INFO *,
-	Mpi2RaidSCSIIORequest_t *, U32);
+void	mrsas_tbolt_prepare_cdb(struct mrsas_instance *instance, U8 cdb[],
+    struct IO_REQUEST_INFO *, Mpi2RaidSCSIIORequest_t *, U32);
 
 
-static int
-mrsas_undo_resources (dev_info_t *dip, struct mrsas_instance *instance);
+int mrsas_init_adapter_ppc(struct mrsas_instance *instance);
+int mrsas_init_adapter_tbolt(struct mrsas_instance *instance);
+int mrsas_init_adapter(struct mrsas_instance *instance);
 
-int mrsas_init_adapter_ppc (struct mrsas_instance *instance);
-int mrsas_init_adapter_tbolt (struct mrsas_instance *instance);
-int mrsas_init_adapter (struct mrsas_instance *instance);
-
 int mrsas_alloc_cmd_pool(struct mrsas_instance *instance);
 void mrsas_free_cmd_pool(struct mrsas_instance *instance);
 
-void mrsas_print_cmd_details(struct mrsas_instance *, struct mrsas_cmd *, int );
+void mrsas_print_cmd_details(struct mrsas_instance *, struct mrsas_cmd *, int);
+struct mrsas_cmd *get_raid_msg_pkt(struct mrsas_instance *);
 
+int mfi_state_transition_to_ready(struct mrsas_instance *);
+
+
+/* FMA functions. */
+int mrsas_common_check(struct mrsas_instance *, struct  mrsas_cmd *);
+void mrsas_fm_ereport(struct mrsas_instance *, char *);
+
+
 #ifdef	__cplusplus
 }
 #endif
--- old/./mr_sas_list.h	Tue Nov  6 14:29:40 2012
+++ new/./mr_sas_list.h	Tue Nov  6 14:29:40 2012
@@ -2,8 +2,35 @@
  * mr_sas_list.h: header for mr_sas
  *
  * Solaris MegaRAID driver for SAS2.0 controllers
- * Copyright (c) 2008-20012, LSI Logic Corporation.
+ * Copyright (c) 2008-2012, LSI Logic Corporation.
  * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the author nor the names of its contributors may be
+ *    used to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
  */
 
 #ifndef	_MR_SAS_LIST_H_
@@ -39,126 +66,15 @@
 }
 
 
-/*
- * Insert a new entry between two known consecutive entries.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static void __list_add(struct mlist_head *new,
-	struct mlist_head *prev,
-	struct mlist_head *next)
-{
-	next->prev = new;
-	new->next = next;
-	new->prev = prev;
-	prev->next = new;
-}
-
-
-/*
- * mlist_add - add a new entry
- * @new: new entry to be added
- * @head: list head to add it after
- *
- * Insert a new entry after the specified head.
- * This is good for implementing stacks.
- */
-static void mlist_add(struct mlist_head *new, struct mlist_head *head)
-{
-	__list_add(new, head, head->next);
-}
-
-
-/*
- * mlist_add_tail - add a new entry
- * @new: new entry to be added
- * @head: list head to add it before
- *
- * Insert a new entry before the specified head.
- * This is useful for implementing queues.
- */
-static void mlist_add_tail(struct mlist_head *new, struct mlist_head *head)
-{
-	__list_add(new, head->prev, head);
-}
-
-
-
-/*
- * Delete a list entry by making the prev/next entries
- * point to each other.
- *
- * This is only for internal list manipulation where we know
- * the prev/next entries already!
- */
-static void __list_del(struct mlist_head *prev,
-			struct mlist_head *next)
-{
-	next->prev = prev;
-	prev->next = next;
-}
-
-
+void mlist_add(struct mlist_head *, struct mlist_head *);
+void mlist_add_tail(struct mlist_head *, struct mlist_head *);
 #if 0
-/*
- * mlist_del - deletes entry from list.
- * @entry:	the element to delete from the list.
- * Note:	list_empty on entry does not return true after this, the entry
- * is in an undefined state.
- */
-
-static void mlist_del(struct mlist_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-	entry->next = entry->prev = 0;
-}
+void mlist_del(struct mlist_head *);
 #endif
+void mlist_del_init(struct mlist_head *);
+int mlist_empty(struct mlist_head *);
+void mlist_splice(struct mlist_head *, struct mlist_head *);
 
-/*
- * mlist_del_init - deletes entry from list and reinitialize it.
- * @entry: the element to delete from the list.
- */
-static void mlist_del_init(struct mlist_head *entry)
-{
-	__list_del(entry->prev, entry->next);
-	INIT_LIST_HEAD(entry);
-}
-
-
-/*
- * mlist_empty - tests whether a list is empty
- * @head: the list to test.
- */
-static int mlist_empty(struct mlist_head *head)
-{
-	return (head->next == head);
-}
-
-
-/*
- * mlist_splice - join two lists
- * @list: the new list to add.
- * @head: the place to add it in the first list.
- */
-static void mlist_splice(struct mlist_head *list, struct mlist_head *head)
-{
-	struct mlist_head *first = list->next;
-
-	if (first != list) {
-		struct mlist_head *last = list->prev;
-		struct mlist_head *at = head->next;
-
-		first->prev = head;
-		head->next = first;
-
-		last->next = at;
-		at->prev = last;
-	}
-}
-
-
-
 /* TODO: set this */
 #if 0
 #pragma	inline(list_add, list_add_tail, __list_del, list_del,
--- /dev/null	Tue Nov  6 14:28:58 2012
+++ new/./mr_sas_list.c	Tue Nov  6 14:29:40 2012
@@ -0,0 +1,134 @@
+/*
+ * mr_sas_list.h: header for mr_sas
+ *
+ * Solaris MegaRAID driver for SAS2.0 controllers
+ * Copyright (c) 2008-2012, LSI Logic Corporation.
+ * All rights reserved.
+ */
+
+/* Copyright 2012 Nexenta Systems, Inc. All rights reserved. */
+
+/*
+ * Extract C functions from LSI-provided mr_sas_list.h such that we can both
+ * be lint-clean and provide a slightly better source organizational model
+ * beyond preprocessor abuse.
+ */
+
+#include "mr_sas_list.h"
+
+/*
+ * Insert a new entry between two known consecutive entries.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void
+__list_add(struct mlist_head *new, struct mlist_head *prev,
+    struct mlist_head *next)
+{
+	next->prev = new;
+	new->next = next;
+	new->prev = prev;
+	prev->next = new;
+}
+
+/*
+ * mlist_add - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it after
+ *
+ * Insert a new entry after the specified head.
+ * This is good for implementing stacks.
+ */
+void
+mlist_add(struct mlist_head *new, struct mlist_head *head)
+{
+	__list_add(new, head, head->next);
+}
+
+/*
+ * mlist_add_tail - add a new entry
+ * @new: new entry to be added
+ * @head: list head to add it before
+ *
+ * Insert a new entry before the specified head.
+ * This is useful for implementing queues.
+ */
+void
+mlist_add_tail(struct mlist_head *new, struct mlist_head *head)
+{
+	__list_add(new, head->prev, head);
+}
+
+/*
+ * Delete a list entry by making the prev/next entries
+ * point to each other.
+ *
+ * This is only for internal list manipulation where we know
+ * the prev/next entries already!
+ */
+static inline void
+__list_del(struct mlist_head *prev, struct mlist_head *next)
+{
+	next->prev = prev;
+	prev->next = next;
+}
+
+#if 0
+/*
+ * mlist_del - deletes entry from list.
+ * @entry:	the element to delete from the list.
+ * Note:	list_empty on entry does not return true after this, the entry
+ * is in an undefined state.
+ */
+
+void
+mlist_del(struct mlist_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+	entry->next = entry->prev = 0;
+}
+#endif
+
+/*
+ * mlist_del_init - deletes entry from list and reinitialize it.
+ * @entry: the element to delete from the list.
+ */
+void
+mlist_del_init(struct mlist_head *entry)
+{
+	__list_del(entry->prev, entry->next);
+	INIT_LIST_HEAD(entry);
+}
+
+/*
+ * mlist_empty - tests whether a list is empty
+ * @head: the list to test.
+ */
+int
+mlist_empty(struct mlist_head *head)
+{
+	return (head->next == head);
+}
+
+/*
+ * mlist_splice - join two lists
+ * @list: the new list to add.
+ * @head: the place to add it in the first list.
+ */
+void
+mlist_splice(struct mlist_head *list, struct mlist_head *head)
+{
+	struct mlist_head *first = list->next;
+
+	if (first != list) {
+		struct mlist_head *last = list->prev;
+		struct mlist_head *at = head->next;
+
+		first->prev = head;
+		head->next = first;
+
+		last->next = at;
+		at->prev = last;
+	}
+}
--- old/./mr_sas_tbolt.c	Tue Nov  6 14:29:40 2012
+++ new/./mr_sas_tbolt.c	Tue Nov  6 14:29:40 2012
@@ -16,7 +16,6 @@
  */
 
 
-#include <stddef.h>
 #include <sys/types.h>
 #include <sys/file.h>
 #include <sys/atomic.h>
@@ -26,25 +25,31 @@
 #include "mr_sas.h"
 #include "fusion.h"
 
+/*
+ * FMA header files
+ */
+#include <sys/ddifm.h>
+#include <sys/fm/protocol.h>
+#include <sys/fm/util.h>
+#include <sys/fm/io/ddi.h>
 
-// Pre-TB command size and TB command size.
-#define	MR_COMMAND_SIZE (64*20)	// 1280 bytes
+
+/* Pre-TB command size and TB command size. */
+#define	MR_COMMAND_SIZE (64*20)	/* 1280 bytes */
 MR_LD_RAID *MR_LdRaidGet(U32 ld, MR_FW_RAID_MAP_ALL *map);
 U16 MR_TargetIdToLdGet(U32 ldTgtId, MR_FW_RAID_MAP_ALL *map);
 U16 MR_GetLDTgtId(U32 ld, MR_FW_RAID_MAP_ALL *map);
-U16 get_updated_dev_handle(PLD_LOAD_BALANCE_INFO lbInfo, struct IO_REQUEST_INFO *in_info);
+U16 get_updated_dev_handle(PLD_LOAD_BALANCE_INFO, struct IO_REQUEST_INFO *);
 extern ddi_dma_attr_t mrsas_generic_dma_attr;
 extern uint32_t mrsas_tbolt_max_cap_maxxfer;
 extern struct ddi_device_acc_attr endian_attr;
-extern int 	debug_level_g;
+extern int	debug_level_g;
 extern unsigned int	enable_fp;
 volatile int dump_io_wait_time = 90;
 extern void
 io_timeout_checker(void *arg);
-extern int
-mfi_state_transition_to_ready(struct mrsas_instance *instance);
 extern volatile int  debug_timeout_g;
-extern int 	mrsas_issue_pending_cmds(struct mrsas_instance *);
+extern int	mrsas_issue_pending_cmds(struct mrsas_instance *);
 extern int mrsas_complete_pending_cmds(struct mrsas_instance *instance);
 extern void	push_pending_mfi_pkt(struct mrsas_instance *,
 			struct mrsas_cmd *);
@@ -51,8 +56,22 @@
 extern U8 MR_BuildRaidContext(struct mrsas_instance *, struct IO_REQUEST_INFO *,
 	    MPI2_SCSI_IO_VENDOR_UNIQUE *, MR_FW_RAID_MAP_ALL *);
 
-static volatile int  debug_tbolt_fw_faults_after_ocr_g  = 0;
+/* Local static prototypes. */
+static struct mrsas_cmd *mrsas_tbolt_build_cmd(struct mrsas_instance *,
+    struct scsi_address *, struct scsi_pkt *, uchar_t *);
+static void mrsas_tbolt_set_pd_lba(U8 cdb[], uint8_t *cdb_len_ptr,
+    U64 start_blk, U32 num_blocks);
+static int mrsas_tbolt_check_map_info(struct mrsas_instance *);
+static int mrsas_tbolt_sync_map_info(struct mrsas_instance *);
+static int mrsas_tbolt_prepare_pkt(struct scsa_cmd *);
+static int mrsas_tbolt_ioc_init(struct mrsas_instance *, dma_obj_t *);
+#ifdef PDSUPPORT
+static void mrsas_tbolt_get_pd_info(struct mrsas_instance *,
+    struct mrsas_tbolt_pd_info *, int);
+#endif /* PDSUPPORT */
 
+static int debug_tbolt_fw_faults_after_ocr_g = 0;
+
 /*
  * destroy_mfi_mpi_frame_pool
  */
@@ -66,10 +85,11 @@
 	/* return all mfi frames to pool */
 	for (i = 0; i < MRSAS_APP_RESERVED_CMDS; i++) {
 		cmd = instance->cmd_list[i];
-		if (cmd->frame_dma_obj_status == DMA_OBJ_ALLOCATED)
+		if (cmd->frame_dma_obj_status == DMA_OBJ_ALLOCATED) {
 			(void) mrsas_free_dma_obj(instance,
 			    cmd->frame_dma_obj);
-		cmd->frame_dma_obj_status  = DMA_OBJ_FREED;
+		}
+		cmd->frame_dma_obj_status = DMA_OBJ_FREED;
 	}
 }
 
@@ -95,11 +115,12 @@
 mrsas_tbolt_free_additional_dma_buffer(struct mrsas_instance *instance)
 {
 	int i;
-	 if (instance->mfi_internal_dma_obj.status == DMA_OBJ_ALLOCATED) {
-                (void) mrsas_free_dma_obj(instance,
-                    instance->mfi_internal_dma_obj);
-                instance->mfi_internal_dma_obj.status = DMA_OBJ_FREED;
-        }
+
+	if (instance->mfi_internal_dma_obj.status == DMA_OBJ_ALLOCATED) {
+		(void) mrsas_free_dma_obj(instance,
+		    instance->mfi_internal_dma_obj);
+		instance->mfi_internal_dma_obj.status = DMA_OBJ_FREED;
+	}
 	if (instance->mfi_evt_detail_obj.status == DMA_OBJ_ALLOCATED) {
 		(void) mrsas_free_dma_obj(instance,
 		    instance->mfi_evt_detail_obj);
@@ -109,7 +130,7 @@
 	for (i = 0; i < 2; i++) {
 		if (instance->ld_map_obj[i].status == DMA_OBJ_ALLOCATED) {
 			(void) mrsas_free_dma_obj(instance,
-		    	instance->ld_map_obj[i]);
+			    instance->ld_map_obj[i]);
 			instance->ld_map_obj[i].status = DMA_OBJ_FREED;
 		}
 	}
@@ -145,14 +166,13 @@
 create_mpi2_frame_pool(struct mrsas_instance *instance)
 {
 	int		i = 0;
-	int		cookie_cnt;
 	uint16_t	max_cmd;
 	uint32_t	sgl_sz;
 	uint32_t	raid_msg_size;
 	uint32_t	total_size;
-	uint32_t  	offset;
-	uint32_t 	io_req_base_phys;
-	uint8_t 	*io_req_base;
+	uint32_t	offset;
+	uint32_t	io_req_base_phys;
+	uint8_t		*io_req_base;
 	struct mrsas_cmd	*cmd;
 
 	max_cmd = instance->max_fw_cmds;
@@ -160,12 +180,12 @@
 	sgl_sz		= 1024;
 	raid_msg_size	= MRSAS_THUNDERBOLT_MSG_SIZE;
 
-	// Allocating additional 256 bytes to accomodate SMID 0.
+	/* Allocating additional 256 bytes to accomodate SMID 0. */
 	total_size = MRSAS_THUNDERBOLT_MSG_SIZE + (max_cmd * raid_msg_size) +
 	    (max_cmd * sgl_sz) + (max_cmd * SENSE_LENGTH);
 
 	con_log(CL_ANN1, (CE_NOTE, "create_mpi2_frame_pool: "
-	    "max_cmd %x ", max_cmd));
+	    "max_cmd %x", max_cmd));
 
 	con_log(CL_DLEVEL3, (CE_NOTE, "create_mpi2_frame_pool: "
 	    "request message frame pool size %x", total_size));
@@ -203,12 +223,10 @@
 	    (uint32_t)
 	    instance->mpi2_frame_pool_dma_obj.dma_cookie[0].dmac_address;
 
-	con_log(CL_DLEVEL3, (CE_NOTE,
-	    "io_request_frames 0x%x",
-	    instance->io_request_frames));
+	con_log(CL_DLEVEL3, (CE_NOTE, "io_request_frames 0x%p",
+	    (void *)instance->io_request_frames));
 
-	con_log(CL_DLEVEL3, (CE_NOTE,
-	    "io_request_frames_phy 0x%x",
+	con_log(CL_DLEVEL3, (CE_NOTE, "io_request_frames_phy 0x%x",
 	    instance->io_request_frames_phy));
 
 	io_req_base = (uint8_t *)instance->io_request_frames +
@@ -228,50 +246,39 @@
 		    ((uint8_t *)io_req_base + offset);
 		cmd->scsi_io_request_phys_addr = io_req_base_phys + offset;
 
-		cmd->sgl = (Mpi2SGEIOUnion_t *)
-		    ((uint8_t *)io_req_base +
-		    (max_cmd * raid_msg_size) +  i * sgl_sz);
+		cmd->sgl = (Mpi2SGEIOUnion_t *)((uint8_t *)io_req_base +
+		    (max_cmd * raid_msg_size) + i * sgl_sz);
 
-		cmd->sgl_phys_addr =
-		    (io_req_base_phys +
+		cmd->sgl_phys_addr = (io_req_base_phys +
 		    (max_cmd * raid_msg_size) + i * sgl_sz);
 
-		cmd->sense1 = (uint8_t *)
-		    ((uint8_t *)io_req_base +
+		cmd->sense1 = (uint8_t *)((uint8_t *)io_req_base +
 		    (max_cmd * raid_msg_size) + (max_cmd * sgl_sz) +
 		    (i * SENSE_LENGTH));
 
-		cmd->sense_phys_addr1 =
-		    (io_req_base_phys +
+		cmd->sense_phys_addr1 = (io_req_base_phys +
 		    (max_cmd * raid_msg_size) + (max_cmd * sgl_sz) +
 		    (i * SENSE_LENGTH));
 
 
-		cmd->SMID = i+1;
+		cmd->SMID = i + 1;
 
-		con_log(CL_DLEVEL3, (CE_NOTE,
-		    "Frame Pool Addr [%x]0x%x",
-		    cmd->index, cmd->scsi_io_request));
+		con_log(CL_DLEVEL3, (CE_NOTE, "Frame Pool Addr [%x]0x%p",
+		    cmd->index, (void *)cmd->scsi_io_request));
 
-		con_log(CL_DLEVEL3, (CE_NOTE,
-		    "Frame Pool Phys Addr [%x]0x%x",
+		con_log(CL_DLEVEL3, (CE_NOTE, "Frame Pool Phys Addr [%x]0x%x",
 		    cmd->index, cmd->scsi_io_request_phys_addr));
 
-		con_log(CL_DLEVEL3, (CE_NOTE,
-		    "Sense Addr [%x]0x%x",
-		    cmd->index, cmd->sense1));
+		con_log(CL_DLEVEL3, (CE_NOTE, "Sense Addr [%x]0x%p",
+		    cmd->index, (void *)cmd->sense1));
 
-		con_log(CL_DLEVEL3, (CE_NOTE,
-		    "Sense Addr Phys [%x]0x%x",
+		con_log(CL_DLEVEL3, (CE_NOTE, "Sense Addr Phys [%x]0x%x",
 		    cmd->index, cmd->sense_phys_addr1));
 
+		con_log(CL_DLEVEL3, (CE_NOTE, "Sgl bufffers [%x]0x%p",
+		    cmd->index, (void *)cmd->sgl));
 
-		con_log(CL_DLEVEL3, (CE_NOTE,
-		    "Sgl bufffers [%x]0x%x",
-		    cmd->index, cmd->sgl));
-
-		con_log(CL_DLEVEL3, (CE_NOTE,
-		    "Sgl bufffers phys  [%x]0x%x",
+		con_log(CL_DLEVEL3, (CE_NOTE, "Sgl bufffers phys [%x]0x%x",
 		    cmd->index, cmd->sgl_phys_addr));
 	}
 
@@ -286,7 +293,7 @@
 int
 mrsas_tbolt_alloc_additional_dma_buffer(struct mrsas_instance *instance)
 {
-	uint32_t        internal_buf_size = PAGESIZE*2;	
+	uint32_t	internal_buf_size = PAGESIZE*2;
 	int i;
 
 	/* Initialize buffer status as free */
@@ -299,25 +306,26 @@
 	instance->mfi_internal_dma_obj.size = internal_buf_size;
 	instance->mfi_internal_dma_obj.dma_attr = mrsas_generic_dma_attr;
 	instance->mfi_internal_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
-	instance->mfi_internal_dma_obj.dma_attr.dma_attr_count_max = 0xFFFFFFFFU;
+	instance->mfi_internal_dma_obj.dma_attr.dma_attr_count_max =
+	    0xFFFFFFFFU;
 	instance->mfi_internal_dma_obj.dma_attr.dma_attr_sgllen = 1;
 
 	if (mrsas_alloc_dma_obj(instance, &instance->mfi_internal_dma_obj,
-			(uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
+	    (uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
 		cmn_err(CE_WARN,
-			"mr_sas: could not alloc reply queue");
+		    "mr_sas: could not alloc reply queue");
 		return (DDI_FAILURE);
 	}
 
 	bzero(instance->mfi_internal_dma_obj.buffer, internal_buf_size);
 
-	instance->mfi_internal_dma_obj.status |= DMA_OBJ_ALLOCATED;	
-	instance->internal_buf = (caddr_t)(((unsigned long)
-	instance->mfi_internal_dma_obj.buffer));
+	instance->mfi_internal_dma_obj.status |= DMA_OBJ_ALLOCATED;
+	instance->internal_buf =
+	    (caddr_t)(((unsigned long)instance->mfi_internal_dma_obj.buffer));
 	instance->internal_buf_dmac_add =
-	instance->mfi_internal_dma_obj.dma_cookie[0].dmac_address; 
+	    instance->mfi_internal_dma_obj.dma_cookie[0].dmac_address;
 	instance->internal_buf_size = internal_buf_size;
-         
+
 	/* allocate evt_detail */
 	instance->mfi_evt_detail_obj.size = sizeof (struct mrsas_evt_detail);
 	instance->mfi_evt_detail_obj.dma_attr = mrsas_generic_dma_attr;
@@ -328,8 +336,7 @@
 
 	if (mrsas_alloc_dma_obj(instance, &instance->mfi_evt_detail_obj,
 	    (uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
-		cmn_err(CE_WARN,
-		    "mrsas_tbolt_alloc_additional_dma_buffer: "
+		cmn_err(CE_WARN, "mrsas_tbolt_alloc_additional_dma_buffer: "
 		    "could not allocate data transfer buffer.");
 		goto fail_tbolt_additional_buff;
 	}
@@ -347,32 +354,32 @@
 		instance->ld_map_obj[i].size = instance->size_map_info;
 		instance->ld_map_obj[i].dma_attr = mrsas_generic_dma_attr;
 		instance->ld_map_obj[i].dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
-		instance->ld_map_obj[i].dma_attr.dma_attr_count_max = 0xFFFFFFFFU;
+		instance->ld_map_obj[i].dma_attr.dma_attr_count_max =
+		    0xFFFFFFFFU;
 		instance->ld_map_obj[i].dma_attr.dma_attr_sgllen = 1;
 		instance->ld_map_obj[i].dma_attr.dma_attr_align = 1;
 
 		if (mrsas_alloc_dma_obj(instance, &instance->ld_map_obj[i],
-	    		(uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
+		    (uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
 			cmn_err(CE_WARN,
-		    	"could not allocate data transfer buffer.");
+			    "could not allocate data transfer buffer.");
 			goto fail_tbolt_additional_buff;
 		}
 
 		instance->ld_map_obj[i].status |= DMA_OBJ_ALLOCATED;
 
-		(void) memset(instance->ld_map_obj[i].buffer, 0,
-	    	instance->size_map_info);
+		bzero(instance->ld_map_obj[i].buffer, instance->size_map_info);
 
-		instance->ld_map[i] = (MR_FW_RAID_MAP_ALL *)instance->ld_map_obj[i].buffer;
-		instance->ld_map_phy[i] =
-	    		(uint32_t)instance->ld_map_obj[i].dma_cookie[0].dmac_address;
+		instance->ld_map[i] =
+		    (MR_FW_RAID_MAP_ALL *)instance->ld_map_obj[i].buffer;
+		instance->ld_map_phy[i] = (uint32_t)instance->
+		    ld_map_obj[i].dma_cookie[0].dmac_address;
 
 		con_log(CL_DLEVEL3, (CE_NOTE,
-			"ld_map Addr Phys 0x%x", instance->ld_map_phy[i]));
+		    "ld_map Addr Phys 0x%x", instance->ld_map_phy[i]));
 
 		con_log(CL_DLEVEL3, (CE_NOTE,
-			"size_map_info 0x%x", instance->size_map_info));
-
+		    "size_map_info 0x%x", instance->size_map_info));
 	}
 
 	return (DDI_SUCCESS);
@@ -384,8 +391,7 @@
 }
 
 MRSAS_REQUEST_DESCRIPTOR_UNION *
-mr_sas_get_request_descriptor(struct mrsas_instance *instance,
-    uint16_t index, struct mrsas_cmd *cmd)
+mr_sas_get_request_descriptor(struct mrsas_instance *instance, uint16_t index)
 {
 	MRSAS_REQUEST_DESCRIPTOR_UNION *req_desc;
 
@@ -393,7 +399,7 @@
 		con_log(CL_ANN1, (CE_NOTE,
 		    "Invalid SMID 0x%x request for descriptor", index));
 		con_log(CL_ANN1, (CE_NOTE,
-		    "max_fw_cmds : 0x%x\n", instance->max_fw_cmds));
+		    "max_fw_cmds : 0x%x", instance->max_fw_cmds));
 		return (NULL);
 	}
 
@@ -402,10 +408,10 @@
 	    (sizeof (MRSAS_REQUEST_DESCRIPTOR_UNION) * index));
 
 	con_log(CL_ANN1, (CE_NOTE,
-	    "request descriptor : 0x%08lx\n", (unsigned long)req_desc));
+	    "request descriptor : 0x%08lx", (unsigned long)req_desc));
 
 	con_log(CL_ANN1, (CE_NOTE,
-	    "request descriptor base phy : 0x%08lx\n",
+	    "request descriptor base phy : 0x%08lx",
 	    (unsigned long)instance->request_message_pool_phy));
 
 	return ((MRSAS_REQUEST_DESCRIPTOR_UNION *)req_desc);
@@ -419,10 +425,8 @@
 alloc_req_rep_desc(struct mrsas_instance *instance)
 {
 	uint32_t	request_q_sz, reply_q_sz;
-	int 		i, max_request_q_sz, max_reply_q_sz;
-	uint64_t	request_desc;
+	int		i, max_reply_q_sz;
 	MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
-	uint64_t	*reply_ptr;
 
 	/*
 	 * ThunderBolt(TB) There's no longer producer consumer mechanism.
@@ -432,17 +436,17 @@
 	 */
 
 	/* Allocate Reply Descriptors */
-	con_log(CL_ANN1, (CE_NOTE, " reply q desc len = %x\n",
-	    sizeof (MPI2_REPLY_DESCRIPTORS_UNION)));
+	con_log(CL_ANN1, (CE_NOTE, " reply q desc len = %x",
+	    (uint_t)sizeof (MPI2_REPLY_DESCRIPTORS_UNION)));
 
-	// reply queue size should be multiple of 16
+	/* reply queue size should be multiple of 16 */
 	max_reply_q_sz = ((instance->max_fw_cmds + 1 + 15)/16)*16;
 
 	reply_q_sz = 8 * max_reply_q_sz;
 
 
-	con_log(CL_ANN1, (CE_NOTE, " reply q desc len = %x\n",
-	    sizeof (MPI2_REPLY_DESCRIPTORS_UNION)));
+	con_log(CL_ANN1, (CE_NOTE, " reply q desc len = %x",
+	    (uint_t)sizeof (MPI2_REPLY_DESCRIPTORS_UNION)));
 
 	instance->reply_desc_dma_obj.size = reply_q_sz;
 	instance->reply_desc_dma_obj.dma_attr = mrsas_generic_dma_attr;
@@ -452,7 +456,7 @@
 	instance->reply_desc_dma_obj.dma_attr.dma_attr_align = 16;
 
 	if (mrsas_alloc_dma_obj(instance, &instance->reply_desc_dma_obj,
-			(uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
+	    (uchar_t)DDI_STRUCTURE_LE_ACC) != 1) {
 		cmn_err(CE_WARN,
 		    "mr_sas: could not alloc reply queue");
 		return (DDI_FAILURE);
@@ -461,7 +465,7 @@
 	bzero(instance->reply_desc_dma_obj.buffer, reply_q_sz);
 	instance->reply_desc_dma_obj.status |= DMA_OBJ_ALLOCATED;
 
-	// virtual address of  reply queue
+	/* virtual address of  reply queue */
 	instance->reply_frame_pool = (MPI2_REPLY_DESCRIPTORS_UNION *)(
 	    instance->reply_desc_dma_obj.buffer);
 
@@ -470,8 +474,8 @@
 	con_log(CL_ANN1, (CE_NOTE, "[reply queue depth]0x%x",
 	    instance->reply_q_depth));
 
-	con_log(CL_ANN1, (CE_NOTE, "[reply queue virt addr]0x%x",
-	    instance->reply_frame_pool));
+	con_log(CL_ANN1, (CE_NOTE, "[reply queue virt addr]0x%p",
+	    (void *)instance->reply_frame_pool));
 
 	/* initializing reply address to 0xFFFFFFFF */
 	reply_desc = instance->reply_frame_pool;
@@ -496,12 +500,12 @@
 	    instance->reply_pool_limit_phy));
 
 
-	con_log(CL_ANN1, (CE_NOTE, " request q desc len = %x\n",
-	    sizeof (MRSAS_REQUEST_DESCRIPTOR_UNION)));
+	con_log(CL_ANN1, (CE_NOTE, " request q desc len = %x",
+	    (int)sizeof (MRSAS_REQUEST_DESCRIPTOR_UNION)));
 
 	/* Allocate Request Descriptors */
-	con_log(CL_ANN1, (CE_NOTE, " request q desc len = %x\n",
-	    sizeof (MRSAS_REQUEST_DESCRIPTOR_UNION)));
+	con_log(CL_ANN1, (CE_NOTE, " request q desc len = %x",
+	    (int)sizeof (MRSAS_REQUEST_DESCRIPTOR_UNION)));
 
 	request_q_sz = 8 *
 	    (instance->max_fw_cmds);
@@ -509,7 +513,8 @@
 	instance->request_desc_dma_obj.size = request_q_sz;
 	instance->request_desc_dma_obj.dma_attr	= mrsas_generic_dma_attr;
 	instance->request_desc_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
-	instance->request_desc_dma_obj.dma_attr.dma_attr_count_max = 0xFFFFFFFFU;
+	instance->request_desc_dma_obj.dma_attr.dma_attr_count_max =
+	    0xFFFFFFFFU;
 	instance->request_desc_dma_obj.dma_attr.dma_attr_sgllen	= 1;
 	instance->request_desc_dma_obj.dma_attr.dma_attr_align = 16;
 
@@ -530,8 +535,6 @@
 	instance->request_message_pool_phy =
 	    (uint32_t)instance->request_desc_dma_obj.dma_cookie[0].dmac_address;
 
-	max_request_q_sz = instance->max_fw_cmds;
-
 	return (DDI_SUCCESS);
 
 fail_undo_reply_queue:
@@ -546,7 +549,9 @@
 
 /*
  * mrsas_alloc_cmd_pool_tbolt
- * TODO: merge tbolt-specific codee into mrsas_alloc_cmd_pool() to have single routine
+ *
+ * TODO: merge tbolt-specific code into mrsas_alloc_cmd_pool() to have single
+ * routine
  */
 int
 mrsas_alloc_cmd_pool_tbolt(struct mrsas_instance *instance)
@@ -572,21 +577,11 @@
 	 * commands.
 	 */
 	instance->cmd_list = kmem_zalloc(sz, KM_SLEEP);
-	if (instance->cmd_list == NULL) {
-		con_log(CL_NONE, (CE_WARN,
-		    "Failed to allocate memory for cmd_list"));
-		return (DDI_FAILURE);
-	}
 
 	/* create a frame pool and assign one frame to each cmd */
 	for (count = 0; count < max_cmd; count++) {
-		instance->cmd_list[count] = kmem_zalloc(sizeof (struct mrsas_cmd),
-		    KM_SLEEP);
-		if (instance->cmd_list[count] == NULL) {
-			con_log(CL_NONE, (CE_WARN,
-				"Failed to allocate memory for mrsas_cmd"));
-			goto mrsas_undo_cmds;
-		}
+		instance->cmd_list[count] =
+		    kmem_zalloc(sizeof (struct mrsas_cmd), KM_SLEEP);
 	}
 
 	/* add all the commands to command pool */
@@ -595,15 +590,16 @@
 	INIT_LIST_HEAD(&instance->cmd_pend_list);
 	INIT_LIST_HEAD(&instance->cmd_app_pool_list);
 
-	reserve_cmd	= MRSAS_APP_RESERVED_CMDS;
+	reserve_cmd = MRSAS_APP_RESERVED_CMDS;
 
-	for (i = 1; i < reserve_cmd; i++) {    //cmd index 0 reservered for IOC INIT
+	/* cmd index 0 reservered for IOC INIT */
+	for (i = 1; i < reserve_cmd; i++) {
 		cmd		= instance->cmd_list[i];
 		cmd->index	= i;
 		mlist_add_tail(&cmd->list, &instance->cmd_app_pool_list);
 	}
-	
 
+
 	for (i = reserve_cmd; i < max_cmd; i++) {
 		cmd		= instance->cmd_list[i];
 		cmd->index	= i;
@@ -616,8 +612,10 @@
 	if (count > 0) {
 		/* free each cmd */
 		for (i = 0; i < count; i++) {
-			if (instance->cmd_list[i] != NULL)
-				kmem_free(instance->cmd_list[i],sizeof (struct mrsas_cmd));
+			if (instance->cmd_list[i] != NULL) {
+				kmem_free(instance->cmd_list[i],
+				    sizeof (struct mrsas_cmd));
+			}
 			instance->cmd_list[i] = NULL;
 		}
 	}
@@ -624,7 +622,7 @@
 
 mrsas_undo_cmd_list:
 	if (instance->cmd_list != NULL)
-		kmem_free(instance->cmd_list,sz);
+		kmem_free(instance->cmd_list, sz);
 	instance->cmd_list = NULL;
 
 	return (DDI_FAILURE);
@@ -666,10 +664,10 @@
 int
 alloc_space_for_mpi2(struct mrsas_instance *instance)
 {
-	/* Allocate command pool ( memory for cmd_list & individual commands )*/
+	/* Allocate command pool (memory for cmd_list & individual commands) */
 	if (mrsas_alloc_cmd_pool_tbolt(instance)) {
 		cmn_err(CE_WARN, "Error creating cmd pool");
-		return (DDI_FAILURE); 
+		return (DDI_FAILURE);
 	}
 
 	/* Initialize single reply size and Message size */
@@ -696,7 +694,7 @@
 	/* Make sure the buffer is aligned to 8 for req/rep  descriptor Pool */
 	if (alloc_req_rep_desc(instance)) {
 		cmn_err(CE_WARN,
-			"Error, allocating memory for descripter-pool");
+		    "Error, allocating memory for descripter-pool");
 		goto mpi2_undo_cmd_pool;
 	}
 	con_log(CL_ANN1, (CE_NOTE, "[request message pool phys addr]0x%x",
@@ -706,7 +704,7 @@
 	/* Allocate MFI Frame pool - for MPI-MFI passthru commands */
 	if (create_mfi_frame_pool(instance)) {
 		cmn_err(CE_WARN,
-			"Error, allocating memory for MFI frame-pool");
+		    "Error, allocating memory for MFI frame-pool");
 		goto mpi2_undo_descripter_pool;
 	}
 
@@ -719,7 +717,7 @@
 
 	if (create_mpi2_frame_pool(instance)) {
 		cmn_err(CE_WARN,
-			"Error, allocating memory for MPI2 Message-pool");
+		    "Error, allocating memory for MPI2 Message-pool");
 		goto mpi2_undo_mfi_frame_pool;
 	}
 
@@ -740,7 +738,7 @@
 	/* Allocate additional dma buffer */
 	if (mrsas_tbolt_alloc_additional_dma_buffer(instance)) {
 		cmn_err(CE_WARN,
-			"Error, allocating tbolt additional DMA buffer");
+		    "Error, allocating tbolt additional DMA buffer");
 		goto mpi2_undo_message_pool;
 	}
 
@@ -766,7 +764,7 @@
  * mrsas_init_adapter_tbolt - Initialize fusion interface adapter.
  */
 int
-mrsas_init_adapter_tbolt (struct mrsas_instance *instance)
+mrsas_init_adapter_tbolt(struct mrsas_instance *instance)
 {
 
 	/*
@@ -781,11 +779,11 @@
 	}
 
 	con_log(CL_ANN, (CE_NOTE, "mrsas_init_adapter_tbolt: "
-		    " instance->max_fw_cmds 0x%X.", instance->max_fw_cmds));
+	    " instance->max_fw_cmds 0x%X.", instance->max_fw_cmds));
 
 
 	/* create a pool of commands */
-	if ( alloc_space_for_mpi2(instance) != DDI_SUCCESS) {
+	if (alloc_space_for_mpi2(instance) != DDI_SUCCESS) {
 		cmn_err(CE_WARN,
 		    " alloc_space_for_mpi2() failed.");
 
@@ -793,7 +791,8 @@
 	}
 
 	/* Send ioc init message */
-	if ( mrsas_issue_init_mpi2(instance) != DDI_SUCCESS) {
+	/* NOTE: the issue_init call does FMA checking already. */
+	if (mrsas_issue_init_mpi2(instance) != DDI_SUCCESS) {
 		cmn_err(CE_WARN,
 		    " mrsas_issue_init_mpi2() failed.");
 
@@ -803,13 +802,11 @@
 	instance->unroll.alloc_space_mpi2 = 1;
 
 	con_log(CL_ANN, (CE_NOTE,
-		    "mrsas_init_adapter_tbolt: SUCCESSFULL\n"));
+	    "mrsas_init_adapter_tbolt: SUCCESSFUL"));
 
 	return (DDI_SUCCESS);
 
 fail_init_fusion:
-
-fail_undo_alloc_mpi2:
 	free_space_for_mpi2(instance);
 
 	return (DDI_FAILURE);
@@ -840,20 +837,18 @@
 		    "could not allocate data transfer buffer.");
 		return (DDI_FAILURE);
 	}
-	(void) memset(init2_dma_obj.buffer, 2,
-	    sizeof (Mpi2IOCInitRequest_t));
+	(void) memset(init2_dma_obj.buffer, 2, sizeof (Mpi2IOCInitRequest_t));
 
 	con_log(CL_ANN1, (CE_NOTE,
-	    "mrsas_issue_init_mpi2 _phys adr: %x \n",
+	    "mrsas_issue_init_mpi2 _phys adr: %x",
 	    init2_dma_obj.dma_cookie[0].dmac_address));
 
 
 	/* Initialize and send ioc init message */
-	ret_val = mrsas_tbolt_ioc_init(instance, &init2_dma_obj,
-	    init2_dma_obj.acc_handle);
+	ret_val = mrsas_tbolt_ioc_init(instance, &init2_dma_obj);
 	if (ret_val == DDI_FAILURE) {
 		con_log(CL_ANN1, (CE_WARN,
-		    "mrsas_issue_init_mpi2: Failed\n"));
+		    "mrsas_issue_init_mpi2: Failed"));
 		goto fail_init_mpi2;
 	}
 
@@ -861,38 +856,36 @@
 	if (mrsas_free_dma_obj(instance, init2_dma_obj)
 	    != DDI_SUCCESS) {
 		con_log(CL_ANN1, (CE_WARN,
-		    "mrsas_issue_init_mpi2: Free Failed\n"));
+		    "mrsas_issue_init_mpi2: Free Failed"));
 		return (DDI_FAILURE);
 	}
 
-
 	/* Get/Check and sync ld_map info */
 	instance->map_id = 0;
-	if( mrsas_tbolt_check_map_info(instance) == DDI_SUCCESS ) 
-	   	mrsas_tbolt_sync_map_info(instance);
-	
+	if (mrsas_tbolt_check_map_info(instance) == DDI_SUCCESS)
+		(void) mrsas_tbolt_sync_map_info(instance);
+
+
+	/* No mrsas_cmd to send, so send NULL. */
+	if (mrsas_common_check(instance, NULL) != DDI_SUCCESS)
+		goto fail_init_mpi2;
+
 	con_log(CL_ANN, (CE_NOTE,
-		    "mrsas_issue_init_mpi2: SUCCESSFULL\n"));
+	    "mrsas_issue_init_mpi2: SUCCESSFUL"));
 
 	return (DDI_SUCCESS);
 
 fail_init_mpi2:
-	mrsas_free_dma_obj(instance, init2_dma_obj);
+	(void) mrsas_free_dma_obj(instance, init2_dma_obj);
 
 	return (DDI_FAILURE);
 }
 
-int
-mrsas_tbolt_ioc_init(struct mrsas_instance *instance, dma_obj_t *mpi2_dma_obj,
-    ddi_acc_handle_t accessp)
+static int
+mrsas_tbolt_ioc_init(struct mrsas_instance *instance, dma_obj_t *mpi2_dma_obj)
 {
-	int				numbytes, i;
-	int ret				= DDI_SUCCESS;
+	int				numbytes;
 	uint16_t			flags;
-	int				status;
-	timespec_t			time;
-	uint64_t			mSec;
-	uint32_t msecs			= MFI_POLL_TIMEOUT_SECS * MILLISEC;
 	struct mrsas_init_frame2	*mfiFrameInit2;
 	struct mrsas_header		*frame_hdr;
 	Mpi2IOCInitRequest_t		*init;
@@ -900,18 +893,17 @@
 	struct mrsas_drv_ver		drv_ver_info;
 	MRSAS_REQUEST_DESCRIPTOR_UNION	*req_desc;
 
-
 	con_log(CL_ANN, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
 
 
 #ifdef DEBUG
 	con_log(CL_ANN1, (CE_CONT, " mfiFrameInit2 len = %x\n",
-	    sizeof (*mfiFrameInit2)));
-	con_log(CL_ANN1, (CE_CONT, " MPI len = %x\n", sizeof (*init)));
+	    (int)sizeof (*mfiFrameInit2)));
+	con_log(CL_ANN1, (CE_CONT, " MPI len = %x\n", (int)sizeof (*init)));
 	con_log(CL_ANN1, (CE_CONT, " mfiFrameInit2 len = %x\n",
-	    sizeof (struct mrsas_init_frame2)));
+	    (int)sizeof (struct mrsas_init_frame2)));
 	con_log(CL_ANN1, (CE_CONT, " MPI len = %x\n",
-	    sizeof (Mpi2IOCInitRequest_t)));
+	    (int)sizeof (Mpi2IOCInitRequest_t)));
 #endif
 
 	init = (Mpi2IOCInitRequest_t *)mpi2_dma_obj->buffer;
@@ -969,7 +961,7 @@
 	cmd->drv_pkt_time = 0;
 
 	mfiFrameInit2 = (struct mrsas_init_frame2 *)cmd->scsi_io_request;
-	con_log(CL_ANN1, (CE_CONT, "[mfi vaddr]%x", mfiFrameInit2));
+	con_log(CL_ANN1, (CE_CONT, "[mfi vaddr]%p", (void *)mfiFrameInit2));
 
 	frame_hdr = &cmd->frame->hdr;
 
@@ -978,7 +970,7 @@
 
 	flags = ddi_get16(cmd->frame_dma_obj.acc_handle, &frame_hdr->flags);
 
-	flags 	|= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
+	flags	|= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
 
 	ddi_put16(cmd->frame_dma_obj.acc_handle, &frame_hdr->flags, flags);
 
@@ -985,7 +977,7 @@
 	con_log(CL_ANN, (CE_CONT,
 	    "mrsas_tbolt_ioc_init: SMID:%x\n", cmd->SMID));
 
-	// Init the MFI Header
+	/* Init the MFI Header */
 	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
 	    &mfiFrameInit2->cmd, MFI_CMD_OP_INIT);
 
@@ -1006,13 +998,13 @@
 	    sizeof (Mpi2IOCInitRequest_t));
 
 	con_log(CL_ANN1, (CE_CONT, "[reply q desc addr]%x",
-	    init->ReplyDescriptorPostQueueAddress));
+	    (int)init->ReplyDescriptorPostQueueAddress));
 
-	/* fill driver version information*/	
+	/* fill driver version information */
 	fill_up_drv_ver(&drv_ver_info);
-	
+
 	/* allocate the driver version data transfer buffer */
-	instance->drv_ver_dma_obj.size = sizeof(drv_ver_info.drv_ver);
+	instance->drv_ver_dma_obj.size = sizeof (drv_ver_info.drv_ver);
 	instance->drv_ver_dma_obj.dma_attr = mrsas_generic_dma_attr;
 	instance->drv_ver_dma_obj.dma_attr.dma_attr_addr_hi = 0xFFFFFFFFU;
 	instance->drv_ver_dma_obj.dma_attr.dma_attr_count_max = 0xFFFFFFFFU;
@@ -1025,25 +1017,26 @@
 		    "fusion init: Could not allocate driver version buffer.");
 		return (DDI_FAILURE);
 	}
-	/* copy driver version to dma  buffer*/
-	(void) memset(instance->drv_ver_dma_obj.buffer, 0,sizeof(drv_ver_info.drv_ver));
+	/* copy driver version to dma buffer */
+	bzero(instance->drv_ver_dma_obj.buffer, sizeof (drv_ver_info.drv_ver));
 	ddi_rep_put8(cmd->frame_dma_obj.acc_handle,
-		(uint8_t *)drv_ver_info.drv_ver,
-                (uint8_t *)instance->drv_ver_dma_obj.buffer, 
-		sizeof(drv_ver_info.drv_ver), DDI_DEV_AUTOINCR);	
+	    (uint8_t *)drv_ver_info.drv_ver,
+	    (uint8_t *)instance->drv_ver_dma_obj.buffer,
+	    sizeof (drv_ver_info.drv_ver), DDI_DEV_AUTOINCR);
 
-	/*send driver version physical address to firmware*/
-	ddi_put64(cmd->frame_dma_obj.acc_handle,
-	    &mfiFrameInit2->driverversion, instance->drv_ver_dma_obj.dma_cookie[0].dmac_address);
+	/* send driver version physical address to firmware */
+	ddi_put64(cmd->frame_dma_obj.acc_handle, &mfiFrameInit2->driverversion,
+	    instance->drv_ver_dma_obj.dma_cookie[0].dmac_address);
 
 	con_log(CL_ANN1, (CE_CONT, "[MPIINIT2 frame Phys addr ]0x%x len = %x",
 	    mfiFrameInit2->queue_info_new_phys_addr_lo,
-	    sizeof (Mpi2IOCInitRequest_t)));
+	    (int)sizeof (Mpi2IOCInitRequest_t)));
 
 	con_log(CL_ANN1, (CE_CONT, "[Length]%x", mfiFrameInit2->data_xfer_len));
 
 	con_log(CL_ANN1, (CE_CONT, "[MFI frame Phys Address]%x len = %x",
-	    cmd->scsi_io_request_phys_addr, sizeof (struct mrsas_init_frame2)));
+	    cmd->scsi_io_request_phys_addr,
+	    (int)sizeof (struct mrsas_init_frame2)));
 
 	/* disable interrupts before sending INIT2 frame */
 	instance->func_ptr->disable_intr(instance);
@@ -1066,7 +1059,6 @@
 	if (ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle,
 	    &mfiFrameInit2->cmd_status) == 0) {
 		con_log(CL_ANN, (CE_NOTE, "INIT2 Success"));
-		ret = DDI_SUCCESS;
 	} else {
 		con_log(CL_ANN, (CE_WARN, "INIT2 Fail"));
 		mrsas_dump_reply_desc(instance);
@@ -1077,21 +1069,20 @@
 
 	instance->unroll.verBuff = 1;
 
-	con_log(CL_ANN, (CE_NOTE,
-		    "mrsas_tbolt_ioc_init: SUCCESSFULL\n"));
+	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_ioc_init: SUCCESSFUL"));
 
-
 	return (DDI_SUCCESS);
 
 
 fail_ioc_init:
 
-	mrsas_free_dma_obj(instance, instance->drv_ver_dma_obj);
+	(void) mrsas_free_dma_obj(instance, instance->drv_ver_dma_obj);
 
 	return (DDI_FAILURE);
 }
 
-int wait_for_outstanding_poll_io(struct mrsas_instance *instance)
+int
+wait_for_outstanding_poll_io(struct mrsas_instance *instance)
 {
 	int i;
 	uint32_t wait_time = dump_io_wait_time;
@@ -1124,10 +1115,7 @@
 	struct mrsas_instance	*instance = ADDR2MR(ap);
 	struct scsa_cmd		*acmd = PKT2CMD(pkt);
 	struct mrsas_cmd	*cmd = NULL;
-	int			rval, i;
-	uchar_t 		cmd_done = 0;
-	Mpi2RaidSCSIIORequest_t *scsi_raid_io;
-	uint32_t		msecs = 120 * MILLISEC;
+	uchar_t			cmd_done = 0;
 
 	con_log(CL_DLEVEL1, (CE_NOTE, "chkpnt:%s:%d", __func__, __LINE__));
 	if (instance->deadadapter == 1) {
@@ -1145,7 +1133,7 @@
 		    "returning mfi_pkt and setting TRAN_BUSY\n"));
 		return (TRAN_BUSY);
 	}
-	rval = mrsas_tbolt_prepare_pkt(acmd);
+	(void) mrsas_tbolt_prepare_pkt(acmd);
 
 	cmd = mrsas_tbolt_build_cmd(instance, ap, pkt, &cmd_done);
 
@@ -1174,7 +1162,7 @@
 	if ((pkt->pkt_flags & FLAG_NOINTR) == 0) {
 		if (instance->fw_outstanding > instance->max_fw_cmds) {
 			cmn_err(CE_WARN,
-			    "Command Queue Full... Returning BUSY \n");
+			    "Command Queue Full... Returning BUSY");
 			return_raid_msg_pkt(instance, cmd);
 			return (TRAN_BUSY);
 		}
@@ -1184,17 +1172,17 @@
 		    DDI_DMA_SYNC_FORDEV);
 
 		con_log(CL_ANN, (CE_CONT, "tbolt_issue_cmd: SCSI CDB[0]=0x%x "
-		    "cmd->index:0x%x SMID %0x%x\n", pkt->pkt_cdbp[0], cmd->index, cmd->SMID));
+		    "cmd->index:0x%x SMID 0x%x\n", pkt->pkt_cdbp[0],
+		    cmd->index, cmd->SMID));
 
 		instance->func_ptr->issue_cmd(cmd, instance);
-
-		return (TRAN_ACCEPT);
-
 	} else {
-		instance->func_ptr->issue_cmd(cmd, instance);	
+		instance->func_ptr->issue_cmd(cmd, instance);
 		(void) wait_for_outstanding_poll_io(instance);
-		return (TRAN_ACCEPT);
+		(void) mrsas_common_check(instance, cmd);
 	}
+
+	return (TRAN_ACCEPT);
 }
 
 /*
@@ -1202,7 +1190,7 @@
  * the pkt may have been resubmitted or just reused so
  * initialize some fields and do some checks.
  */
-int
+static int
 mrsas_tbolt_prepare_pkt(struct scsa_cmd *acmd)
 {
 	struct scsi_pkt	*pkt = CMD2PKT(acmd);
@@ -1235,11 +1223,12 @@
 {
 	uint32_t		MaxSGEs;
 	int			sg_to_process;
-	uint32_t		i, j, SGEdwords = 0;
+	uint32_t		i, j;
 	uint32_t		numElements, endElement;
 	Mpi25IeeeSgeChain64_t	*ieeeChainElement = NULL;
 	Mpi25IeeeSgeChain64_t	*scsi_raid_io_sgl_ieee = NULL;
-	uint32_t		SGLFlags = 0;
+	ddi_acc_handle_t acc_handle =
+	    instance->mpi2_frame_pool_dma_obj.acc_handle;
 
 	con_log(CL_ANN1, (CE_NOTE,
 	    "chkpnt: Building Chained SGL :%d", __LINE__));
@@ -1248,25 +1237,21 @@
 	/* Clear the datalen before updating it. */
 	*datalen = 0;
 
-	SGEdwords = sizeof (Mpi25IeeeSgeChain64_t) / 4;
-
 	MaxSGEs = instance->max_sge_in_main_msg;
 
-	ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->SGLFlags,
+	ddi_put16(acc_handle, &scsi_raid_io->SGLFlags,
 	    MPI2_SGE_FLAGS_64_BIT_ADDRESSING);
 
-	// set data transfer flag.
+	/* set data transfer flag. */
 	if (acmd->cmd_flags & CFLAG_DMASEND) {
-		ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->Control,
+		ddi_put32(acc_handle, &scsi_raid_io->Control,
 		    MPI2_SCSIIO_CONTROL_WRITE);
 	} else {
-		ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->Control, MPI2_SCSIIO_CONTROL_READ);
+		ddi_put32(acc_handle, &scsi_raid_io->Control,
+		    MPI2_SCSIIO_CONTROL_READ);
 	}
 
-	
+
 	numElements = acmd->cmd_cookiecnt;
 
 	con_log(CL_DLEVEL1, (CE_NOTE, "[SGE Count]:%x", numElements));
@@ -1274,11 +1259,11 @@
 	if (numElements > instance->max_num_sge) {
 		con_log(CL_ANN, (CE_NOTE,
 		    "[Max SGE Count Exceeded]:%x", numElements));
-		return (numElements);	
+		return (numElements);
 	}
 
-	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->RaidContext.numSGE, (uint8_t)numElements);
+	ddi_put8(acc_handle, &scsi_raid_io->RaidContext.numSGE,
+	    (uint8_t)numElements);
 
 	/* set end element in main message frame */
 	endElement = (numElements <= MaxSGEs) ? numElements : (MaxSGEs - 1);
@@ -1290,33 +1275,31 @@
 	if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
 		Mpi25IeeeSgeChain64_t *sgl_ptr_end = scsi_raid_io_sgl_ieee;
 		sgl_ptr_end += instance->max_sge_in_main_msg - 1;
-		
-		ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &sgl_ptr_end->Flags, 0);
+
+		ddi_put8(acc_handle, &sgl_ptr_end->Flags, 0);
 	}
 
 	for (i = 0; i < endElement; i++, scsi_raid_io_sgl_ieee++) {
-		ddi_put64(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io_sgl_ieee->Address,
+		ddi_put64(acc_handle, &scsi_raid_io_sgl_ieee->Address,
 		    acmd->cmd_dmacookies[i].dmac_laddress);
 
-		ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io_sgl_ieee->Length,
+		ddi_put32(acc_handle, &scsi_raid_io_sgl_ieee->Length,
 		    acmd->cmd_dmacookies[i].dmac_size);
 
-		ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io_sgl_ieee->Flags, 0);
-        
+		ddi_put8(acc_handle, &scsi_raid_io_sgl_ieee->Flags, 0);
+
 		if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
-			if (i == (numElements - 1))
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io_sgl_ieee->Flags, IEEE_SGE_FLAGS_END_OF_LIST);
+			if (i == (numElements - 1)) {
+				ddi_put8(acc_handle,
+				    &scsi_raid_io_sgl_ieee->Flags,
+				    IEEE_SGE_FLAGS_END_OF_LIST);
+			}
 		}
 
 		*datalen += acmd->cmd_dmacookies[i].dmac_size;
 
 #ifdef DEBUG
-		con_log(CL_DLEVEL1, (CE_NOTE, "[SGL Address]:%llx",
+		con_log(CL_DLEVEL1, (CE_NOTE, "[SGL Address]: %" PRIx64,
 		    scsi_raid_io_sgl_ieee->Address));
 		con_log(CL_DLEVEL1, (CE_NOTE, "[SGL Length]:%x",
 		    scsi_raid_io_sgl_ieee->Length));
@@ -1326,51 +1309,49 @@
 
 	}
 
-	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->ChainOffset, 0);
+	ddi_put8(acc_handle, &scsi_raid_io->ChainOffset, 0);
 
 	/* check if chained SGL required */
 	if (i < numElements) {
 
 		con_log(CL_ANN1, (CE_NOTE, "[Chain Element index]:%x", i));
-        
+
 		if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
-			uint16_t	ioFlags = ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-				                      &scsi_raid_io->IoFlags);
+			uint16_t ioFlags =
+			    ddi_get16(acc_handle, &scsi_raid_io->IoFlags);
 
-			if ((ioFlags & MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) != MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH)
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->ChainOffset, (U8)instance->chain_offset_io_req);
-			else
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->ChainOffset, 0);
+			if ((ioFlags &
+			    MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) !=
+			    MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH) {
+				ddi_put8(acc_handle, &scsi_raid_io->ChainOffset,
+				    (U8)instance->chain_offset_io_req);
+			} else {
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->ChainOffset, 0);
+			}
+		} else {
+			ddi_put8(acc_handle, &scsi_raid_io->ChainOffset,
+			    (U8)instance->chain_offset_io_req);
 		}
-		else {
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-				&scsi_raid_io->ChainOffset, (U8)instance->chain_offset_io_req);
-		}
 
 		/* prepare physical chain element */
-		ieeeChainElement  = scsi_raid_io_sgl_ieee;
+		ieeeChainElement = scsi_raid_io_sgl_ieee;
 
-		ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &ieeeChainElement->NextChainOffset, 0);
+		ddi_put8(acc_handle, &ieeeChainElement->NextChainOffset, 0);
 
- 		if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) 
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-				&ieeeChainElement->Flags, IEEE_SGE_FLAGS_CHAIN_ELEMENT );
-		else
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-				&ieeeChainElement->Flags,
-				(IEEE_SGE_FLAGS_CHAIN_ELEMENT |
-                   MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR));
+		if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
+			ddi_put8(acc_handle, &ieeeChainElement->Flags,
+			    IEEE_SGE_FLAGS_CHAIN_ELEMENT);
+		} else {
+			ddi_put8(acc_handle, &ieeeChainElement->Flags,
+			    (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
+			    MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR));
+		}
 
-		ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &ieeeChainElement->Length,
+		ddi_put32(acc_handle, &ieeeChainElement->Length,
 		    (sizeof (MPI2_SGE_IO_UNION) * (numElements - i)));
 
-		ddi_put64(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &ieeeChainElement->Address,
+		ddi_put64(acc_handle, &ieeeChainElement->Address,
 		    (U64)cmd->sgl_phys_addr);
 
 		sg_to_process = numElements - i;
@@ -1385,21 +1366,20 @@
 		for (j = 0; j < sg_to_process; j++, scsi_raid_io_sgl_ieee++) {
 			con_log(CL_DLEVEL3, (CE_NOTE, "[remaining SGL]:%x", i));
 
-			ddi_put64(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io_sgl_ieee->Address,
+			ddi_put64(acc_handle, &scsi_raid_io_sgl_ieee->Address,
 			    acmd->cmd_dmacookies[i].dmac_laddress);
 
-			ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io_sgl_ieee->Length,
+			ddi_put32(acc_handle, &scsi_raid_io_sgl_ieee->Length,
 			    acmd->cmd_dmacookies[i].dmac_size);
 
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io_sgl_ieee->Flags, 0);
+			ddi_put8(acc_handle, &scsi_raid_io_sgl_ieee->Flags, 0);
 
 			if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
-				if (i == (numElements - 1))
-					ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						&scsi_raid_io_sgl_ieee->Flags, IEEE_SGE_FLAGS_END_OF_LIST);
+				if (i == (numElements - 1)) {
+					ddi_put8(acc_handle,
+					    &scsi_raid_io_sgl_ieee->Flags,
+					    IEEE_SGE_FLAGS_END_OF_LIST);
+				}
 			}
 
 			*datalen += acmd->cmd_dmacookies[i].dmac_size;
@@ -1406,7 +1386,7 @@
 
 #if DEBUG
 			con_log(CL_DLEVEL1, (CE_NOTE,
-			    "[SGL Address]:%llx",
+			    "[SGL Address]: %" PRIx64,
 			    scsi_raid_io_sgl_ieee->Address));
 			con_log(CL_DLEVEL1, (CE_NOTE,
 			    "[SGL Length]:%x", scsi_raid_io_sgl_ieee->Length));
@@ -1425,31 +1405,24 @@
 /*
  * build_cmd
  */
-struct mrsas_cmd *
+static struct mrsas_cmd *
 mrsas_tbolt_build_cmd(struct mrsas_instance *instance, struct scsi_address *ap,
     struct scsi_pkt *pkt, uchar_t *cmd_done)
 {
 	uint8_t		fp_possible = 0;
-	uint16_t	flags = 0;
-	uint32_t	i, index;
-	uint32_t 	context;
-	uint32_t	sge_bytes;
-	uint8_t		ChainOffsetValue;
-	uint32_t	SGLFlags;
-	uint32_t	lba_count=0;
-	uint32_t	start_lba_hi=0; 
-	uint32_t	start_lba_lo=0;
-	ddi_acc_handle_t acc_handle;
+	uint32_t	index;
+	uint32_t	lba_count = 0;
+	uint32_t	start_lba_hi = 0;
+	uint32_t	start_lba_lo = 0;
+	ddi_acc_handle_t acc_handle =
+	    instance->mpi2_frame_pool_dma_obj.acc_handle;
 	struct mrsas_cmd		*cmd = NULL;
 	struct scsa_cmd			*acmd = PKT2CMD(pkt);
-	MRSAS_REQUEST_DESCRIPTOR_UNION 	*ReqDescUnion;
-	Mpi2RaidSCSIIORequest_t 	*scsi_raid_io;
-	Mpi25IeeeSgeChain64_t		*scsi_raid_io_sgl_ieee;
+	MRSAS_REQUEST_DESCRIPTOR_UNION	*ReqDescUnion;
+	Mpi2RaidSCSIIORequest_t		*scsi_raid_io;
 	uint32_t			datalen;
 	struct IO_REQUEST_INFO io_info;
 	MR_FW_RAID_MAP_ALL *local_map_ptr;
-	MR_LD_RAID *raid;
-	U32	ld;
 	uint16_t pd_cmd_cdblen;
 
 	con_log(CL_DLEVEL1, (CE_NOTE,
@@ -1467,7 +1440,7 @@
 	}
 
 	index = cmd->index;
-	ReqDescUnion =  mr_sas_get_request_descriptor(instance, index, cmd);
+	ReqDescUnion =	mr_sas_get_request_descriptor(instance, index);
 	ReqDescUnion->Words = 0;
 	ReqDescUnion->SCSIIO.SMID = cmd->SMID;
 	ReqDescUnion->SCSIIO.RequestFlags =
@@ -1493,34 +1466,30 @@
 			    DDI_DMA_SYNC_FORCPU);
 		}
 	} else {
-		con_log(CL_ANN, (CE_NOTE, "NO DMA\n"));
+		con_log(CL_ANN, (CE_NOTE, "NO DMA"));
 	}
 
 
-	// get SCSI_IO raid message frame pointer
+	/* get SCSI_IO raid message frame pointer */
 	scsi_raid_io = (Mpi2RaidSCSIIORequest_t *)cmd->scsi_io_request;
 
 	/* zero out SCSI_IO raid message frame */
-	memset(scsi_raid_io, 0, sizeof(Mpi2RaidSCSIIORequest_t));
+	bzero(scsi_raid_io, sizeof (Mpi2RaidSCSIIORequest_t));
 
-	/*Set the ldTargetId set by BuildRaidContext() */
-	ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->RaidContext.ldTargetId,
-		    acmd->device_id);
+	/* Set the ldTargetId set by BuildRaidContext() */
+	ddi_put16(acc_handle, &scsi_raid_io->RaidContext.ldTargetId,
+	    acmd->device_id);
 
 	/*  Copy CDB to scsi_io_request message frame */
-	ddi_rep_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    (uint8_t *)pkt->pkt_cdbp,
-		    (uint8_t *)scsi_raid_io->CDB.CDB32,
-		    acmd->cmd_cdblen, DDI_DEV_AUTOINCR);
+	ddi_rep_put8(acc_handle,
+	    (uint8_t *)pkt->pkt_cdbp, (uint8_t *)scsi_raid_io->CDB.CDB32,
+	    acmd->cmd_cdblen, DDI_DEV_AUTOINCR);
 
-	/* 
-	* Just the CDB length,rest of the Flags are zero
-	* This will be modified later.
-	*/
-	ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	   	    &scsi_raid_io->IoFlags,
-	   	    acmd->cmd_cdblen);     
+	/*
+	 * Just the CDB length, rest of the Flags are zero
+	 * This will be modified later.
+	 */
+	ddi_put16(acc_handle, &scsi_raid_io->IoFlags, acmd->cmd_cdblen);
 
 	pd_cmd_cdblen = acmd->cmd_cdblen;
 
@@ -1534,127 +1503,136 @@
 	case SCMD_READ_G5:
 	case SCMD_WRITE_G5:
 
-	if (acmd->islogical) {
-		/* Initialize sense Information */
-		if (cmd->sense1 == NULL) {
-			con_log(CL_ANN, (CE_NOTE,
-				"tbolt_build_cmd: Sense buffer ptr NULL \n"));
-		}
-		bzero(cmd->sense1, SENSE_LENGTH);
-		con_log(CL_DLEVEL2, (CE_NOTE,
-		    "tbolt_build_cmd CDB[0] = %x\n", pkt->pkt_cdbp[0]));
+		if (acmd->islogical) {
+			/* Initialize sense Information */
+			if (cmd->sense1 == NULL) {
+				con_log(CL_ANN, (CE_NOTE, "tbolt_build_cmd: "
+				    "Sense buffer ptr NULL "));
+			}
+			bzero(cmd->sense1, SENSE_LENGTH);
+			con_log(CL_DLEVEL2, (CE_NOTE, "tbolt_build_cmd "
+			    "CDB[0] = %x\n", pkt->pkt_cdbp[0]));
 
-		if (acmd->cmd_cdblen == CDB_GROUP0) {			/* 6-byte cdb */
-			lba_count = (uint16_t)(pkt->pkt_cdbp[4]);
-			start_lba_lo =
-			    ((uint32_t)(pkt->pkt_cdbp[3]) |
-			    ((uint32_t)(pkt->pkt_cdbp[2]) << 8) |
-			    ((uint32_t)((pkt->pkt_cdbp[1]) & 0x1F) << 16));
-		} else if (acmd->cmd_cdblen == CDB_GROUP1) {		/* 10-byte cdb */
-			lba_count =
-			    (((uint16_t)(pkt->pkt_cdbp[8])) |
-			    ((uint16_t)(pkt->pkt_cdbp[7]) << 8));
+			if (acmd->cmd_cdblen == CDB_GROUP0) {
+				/* 6-byte cdb */
+				lba_count = (uint16_t)(pkt->pkt_cdbp[4]);
+				start_lba_lo = ((uint32_t)(pkt->pkt_cdbp[3]) |
+				    ((uint32_t)(pkt->pkt_cdbp[2]) << 8) |
+				    ((uint32_t)((pkt->pkt_cdbp[1]) & 0x1F)
+				    << 16));
+			} else if (acmd->cmd_cdblen == CDB_GROUP1) {
+				/* 10-byte cdb */
+				lba_count =
+				    (((uint16_t)(pkt->pkt_cdbp[8])) |
+				    ((uint16_t)(pkt->pkt_cdbp[7]) << 8));
 
-			start_lba_lo =
-			    (((uint32_t)(pkt->pkt_cdbp[5])) |
-			    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
-			    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
-			    ((uint32_t)(pkt->pkt_cdbp[2]) << 24));
+				start_lba_lo =
+				    (((uint32_t)(pkt->pkt_cdbp[5])) |
+				    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
+				    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
+				    ((uint32_t)(pkt->pkt_cdbp[2]) << 24));
 
-		} else if (acmd->cmd_cdblen == CDB_GROUP5) {		/* 12-byte cdb */
-			lba_count = (
-			    ((uint32_t)(pkt->pkt_cdbp[9])) |
-			    ((uint32_t)(pkt->pkt_cdbp[8]) << 8) |
-			    ((uint32_t)(pkt->pkt_cdbp[7]) << 16) |
-			    ((uint32_t)(pkt->pkt_cdbp[6]) << 24));
+			} else if (acmd->cmd_cdblen == CDB_GROUP5) {
+				/* 12-byte cdb */
+				lba_count = (
+				    ((uint32_t)(pkt->pkt_cdbp[9])) |
+				    ((uint32_t)(pkt->pkt_cdbp[8]) << 8) |
+				    ((uint32_t)(pkt->pkt_cdbp[7]) << 16) |
+				    ((uint32_t)(pkt->pkt_cdbp[6]) << 24));
 
-			start_lba_lo =
-			    (((uint32_t)(pkt->pkt_cdbp[5])) |
-			    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
-			    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
-			    ((uint32_t)(pkt->pkt_cdbp[2]) << 24));
+				start_lba_lo =
+				    (((uint32_t)(pkt->pkt_cdbp[5])) |
+				    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
+				    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
+				    ((uint32_t)(pkt->pkt_cdbp[2]) << 24));
 
-		} else if (acmd->cmd_cdblen == CDB_GROUP4) {		/* 16-byte cdb */
-			lba_count = (
-			    ((uint32_t)(pkt->pkt_cdbp[13])) |
-			    ((uint32_t)(pkt->pkt_cdbp[12]) << 8) |
-			    ((uint32_t)(pkt->pkt_cdbp[11]) << 16) |
-			    ((uint32_t)(pkt->pkt_cdbp[10]) << 24));
+			} else if (acmd->cmd_cdblen == CDB_GROUP4) {
+				/* 16-byte cdb */
+				lba_count = (
+				    ((uint32_t)(pkt->pkt_cdbp[13])) |
+				    ((uint32_t)(pkt->pkt_cdbp[12]) << 8) |
+				    ((uint32_t)(pkt->pkt_cdbp[11]) << 16) |
+				    ((uint32_t)(pkt->pkt_cdbp[10]) << 24));
 
-			start_lba_lo = (
-			    ((uint32_t)(pkt->pkt_cdbp[9])) |
-			    ((uint32_t)(pkt->pkt_cdbp[8]) << 8) |
-			    ((uint32_t)(pkt->pkt_cdbp[7]) << 16) |
-			    ((uint32_t)(pkt->pkt_cdbp[6]) << 24));
+				start_lba_lo = (
+				    ((uint32_t)(pkt->pkt_cdbp[9])) |
+				    ((uint32_t)(pkt->pkt_cdbp[8]) << 8) |
+				    ((uint32_t)(pkt->pkt_cdbp[7]) << 16) |
+				    ((uint32_t)(pkt->pkt_cdbp[6]) << 24));
 
-			start_lba_hi = (
-			    ((uint32_t)(pkt->pkt_cdbp[5])) |
-			    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
-			    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
-			    ((uint32_t)(pkt->pkt_cdbp[2]) << 24));
-		}
+				start_lba_hi = (
+				    ((uint32_t)(pkt->pkt_cdbp[5])) |
+				    ((uint32_t)(pkt->pkt_cdbp[4]) << 8) |
+				    ((uint32_t)(pkt->pkt_cdbp[3]) << 16) |
+				    ((uint32_t)(pkt->pkt_cdbp[2]) << 24));
+			}
 
-		if (instance->tbolt && 
-				((lba_count * 512) > mrsas_tbolt_max_cap_maxxfer) )
-			cmn_err(CE_WARN," IO SECTOR COUNT exceeds controller limit 0x%x sectors\n", lba_count);
+			if (instance->tbolt &&
+			    ((lba_count * 512) > mrsas_tbolt_max_cap_maxxfer)) {
+				cmn_err(CE_WARN, " IO SECTOR COUNT exceeds "
+				    "controller limit 0x%x sectors",
+				    lba_count);
+			}
 
-		memset(&io_info, 0, sizeof (struct IO_REQUEST_INFO));
-		io_info.ldStartBlock = ((uint64_t)start_lba_hi << 32) | start_lba_lo;
-		io_info.numBlocks = lba_count;
-		io_info.ldTgtId = acmd->device_id;
+			bzero(&io_info, sizeof (struct IO_REQUEST_INFO));
+			io_info.ldStartBlock = ((uint64_t)start_lba_hi << 32) |
+			    start_lba_lo;
+			io_info.numBlocks = lba_count;
+			io_info.ldTgtId = acmd->device_id;
 
-		if (acmd->cmd_flags & CFLAG_DMASEND)
-			io_info.isRead = 0;
-		else
-			io_info.isRead = 1;
+			if (acmd->cmd_flags & CFLAG_DMASEND)
+				io_info.isRead = 0;
+			else
+				io_info.isRead = 1;
 
-		
-		/*Aquire SYNC MAP UPDATE lock */
-		mutex_enter(&instance->sync_map_mtx);
 
-		local_map_ptr = instance->ld_map[(instance->map_id & 1)];
+			/* Acquire SYNC MAP UPDATE lock */
+			mutex_enter(&instance->sync_map_mtx);
 
-		if  ( (MR_TargetIdToLdGet(acmd->device_id, local_map_ptr) >= MAX_LOGICAL_DRIVES) || !instance->fast_path_io ){
-			cmn_err(CE_NOTE,
-			    	"Fast Path NOT Possible, targetId >= MAX_LOGICAL_DRIVES || !instance->fast_path_io\n");
-			fp_possible = 0;
-			/* Set Regionlock flags to BYPASS
-			io_request->RaidContext.regLockFlags  = 0; */
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
+			local_map_ptr =
+			    instance->ld_map[(instance->map_id & 1)];
+
+			if ((MR_TargetIdToLdGet(
+			    acmd->device_id, local_map_ptr) >=
+			    MAX_LOGICAL_DRIVES) || !instance->fast_path_io) {
+				cmn_err(CE_NOTE, "Fast Path NOT Possible, "
+				    "targetId >= MAX_LOGICAL_DRIVES || "
+				    "!instance->fast_path_io");
+				fp_possible = 0;
+				/* Set Regionlock flags to BYPASS */
+				/* io_request->RaidContext.regLockFlags  = 0; */
+				ddi_put8(acc_handle,
 				    &scsi_raid_io->RaidContext.regLockFlags, 0);
-		} else {
-			if (MR_BuildRaidContext(instance, &io_info,
-			    		&scsi_raid_io->RaidContext, local_map_ptr))
-				fp_possible = io_info.fpOkForIo;
-		}
+			} else {
+				if (MR_BuildRaidContext(instance, &io_info,
+				    &scsi_raid_io->RaidContext, local_map_ptr))
+					fp_possible = io_info.fpOkForIo;
+			}
 
-		if (!enable_fp) {
-			fp_possible = 0;  
-		}
-		con_log(CL_ANN1, (CE_NOTE,
-			    	"enable_fp %d  instance->fast_path_io %d fp_possible %d \n",
-				enable_fp, instance->fast_path_io, fp_possible));
+			if (!enable_fp)
+				fp_possible = 0;
 
+			con_log(CL_ANN1, (CE_NOTE, "enable_fp %d  "
+			    "instance->fast_path_io %d fp_possible %d",
+			    enable_fp, instance->fast_path_io, fp_possible));
+
 		if (fp_possible) {
 
-			/* Check for DIF enabled LD */	
+			/* Check for DIF enabled LD */
 			if (MR_CheckDIF(acmd->device_id, local_map_ptr)) {
 				/* Prepare 32 Byte CDB for DIF capable Disk */
 				mrsas_tbolt_prepare_cdb(instance,
-			    	    scsi_raid_io->CDB.CDB32,
-			    	    &io_info,
-			    	    scsi_raid_io,
-			    	    start_lba_lo);
+				    scsi_raid_io->CDB.CDB32,
+				    &io_info, scsi_raid_io, start_lba_lo);
 			} else {
 				mrsas_tbolt_set_pd_lba(scsi_raid_io->CDB.CDB32,
-				   (uint8_t *)&pd_cmd_cdblen, io_info.pdBlock, io_info.numBlocks, 0);
-				ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    					&scsi_raid_io->IoFlags,
-	    					pd_cmd_cdblen); 
+				    (uint8_t *)&pd_cmd_cdblen,
+				    io_info.pdBlock, io_info.numBlocks);
+				ddi_put16(acc_handle,
+				    &scsi_raid_io->IoFlags, pd_cmd_cdblen);
 			}
 
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io->Function,
+			ddi_put8(acc_handle, &scsi_raid_io->Function,
 			    MPI2_FUNCTION_SCSI_IO_REQUEST);
 
 			ReqDescUnion->SCSIIO.RequestFlags =
@@ -1662,45 +1640,58 @@
 			    MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
 
 			if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
-				uint8_t regLockFlags = ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-								&scsi_raid_io->RaidContext.regLockFlags);
-				uint16_t IoFlags = ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-								&scsi_raid_io->IoFlags);
+				uint8_t regLockFlags = ddi_get8(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockFlags);
+				uint16_t IoFlags = ddi_get16(acc_handle,
+				    &scsi_raid_io->IoFlags);
 
 				if (regLockFlags == REGION_TYPE_UNUSED)
-					ReqDescUnion->SCSIIO.RequestFlags = 
-						(MPI2_REQ_DESCRIPT_FLAGS_NO_LOCK << MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+					ReqDescUnion->SCSIIO.RequestFlags =
+					    (MPI2_REQ_DESCRIPT_FLAGS_NO_LOCK <<
+					    MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
 
-				IoFlags |= MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH;
-				regLockFlags |= (MR_RL_FLAGS_GRANT_DESTINATION_CUDA | MR_RL_FLAGS_SEQ_NUM_ENABLE);
+				IoFlags |=
+				    MPI25_SAS_DEVICE0_FLAGS_ENABLED_FAST_PATH;
+				regLockFlags |=
+				    (MR_RL_FLAGS_GRANT_DESTINATION_CUDA |
+				    MR_RL_FLAGS_SEQ_NUM_ENABLE);
 
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-							&scsi_raid_io->ChainOffset, 0);
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						    &scsi_raid_io->RaidContext.nsegType, ((0x01 << MPI2_NSEG_FLAGS_SHIFT) | MPI2_TYPE_CUDA));
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						    &scsi_raid_io->RaidContext.regLockFlags, regLockFlags);
-				ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						    &scsi_raid_io->IoFlags, IoFlags);
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->ChainOffset, 0);
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->RaidContext.nsegType,
+				    ((0x01 << MPI2_NSEG_FLAGS_SHIFT) |
+				    MPI2_TYPE_CUDA));
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockFlags,
+				    regLockFlags);
+				ddi_put16(acc_handle,
+				    &scsi_raid_io->IoFlags, IoFlags);
 			}
 
-			if ((instance->load_balance_info[acmd->device_id].loadBalanceFlag) && (io_info.isRead)) {
-				io_info.devHandle = get_updated_dev_handle(&instance->load_balance_info[acmd->device_id], &io_info);
-				cmd->load_balance_flag |= MEGASAS_LOAD_BALANCE_FLAG;
-			} else
-				cmd->load_balance_flag &= ~MEGASAS_LOAD_BALANCE_FLAG;
+			if ((instance->load_balance_info[
+			    acmd->device_id].loadBalanceFlag) &&
+			    (io_info.isRead)) {
+				io_info.devHandle =
+				    get_updated_dev_handle(&instance->
+				    load_balance_info[acmd->device_id],
+				    &io_info);
+				cmd->load_balance_flag |=
+				    MEGASAS_LOAD_BALANCE_FLAG;
+			} else {
+				cmd->load_balance_flag &=
+				    ~MEGASAS_LOAD_BALANCE_FLAG;
+			}
 
-			ReqDescUnion->SCSIIO.DevHandle = io_info.devHandle; 
-			ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io->DevHandle,
+			ReqDescUnion->SCSIIO.DevHandle = io_info.devHandle;
+			ddi_put16(acc_handle, &scsi_raid_io->DevHandle,
 			    io_info.devHandle);
 
 		} else {
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io->Function,
+			ddi_put8(acc_handle, &scsi_raid_io->Function,
 			    MPI2_FUNCTION_LD_IO_REQUEST);
 
-			ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
+			ddi_put16(acc_handle,
 			    &scsi_raid_io->DevHandle, acmd->device_id);
 
 			ReqDescUnion->SCSIIO.RequestFlags =
@@ -1707,55 +1698,58 @@
 			    (MPI2_REQ_DESCRIPT_FLAGS_LD_IO <<
 			    MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
 
-			ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					    &scsi_raid_io->RaidContext.timeoutValue, local_map_ptr->raidMap.fpPdIoTimeoutSec);
+			ddi_put16(acc_handle,
+			    &scsi_raid_io->RaidContext.timeoutValue,
+			    local_map_ptr->raidMap.fpPdIoTimeoutSec);
 
 			if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
-				uint8_t regLockFlags = ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-									&scsi_raid_io->RaidContext.regLockFlags);
+				uint8_t regLockFlags = ddi_get8(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockFlags);
 
-				if (regLockFlags == REGION_TYPE_UNUSED)
-					ReqDescUnion->SCSIIO.RequestFlags = 
-						(MPI2_REQ_DESCRIPT_FLAGS_NO_LOCK << MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+				if (regLockFlags == REGION_TYPE_UNUSED) {
+					ReqDescUnion->SCSIIO.RequestFlags =
+					    (MPI2_REQ_DESCRIPT_FLAGS_NO_LOCK <<
+					    MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+				}
 
-				regLockFlags |= (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 | MR_RL_FLAGS_SEQ_NUM_ENABLE);
+				regLockFlags |=
+				    (MR_RL_FLAGS_GRANT_DESTINATION_CPU0 |
+				    MR_RL_FLAGS_SEQ_NUM_ENABLE);
 
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						    &scsi_raid_io->RaidContext.nsegType, ((0x01 << MPI2_NSEG_FLAGS_SHIFT) | MPI2_TYPE_CUDA));
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						    &scsi_raid_io->RaidContext.regLockFlags, regLockFlags);
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->RaidContext.nsegType,
+				    ((0x01 << MPI2_NSEG_FLAGS_SHIFT) |
+				    MPI2_TYPE_CUDA));
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockFlags,
+				    regLockFlags);
 			}
-	
 		} /* Not FP */
 
-		/*Release SYNC MAP UPDATE lock */
+		/* Release SYNC MAP UPDATE lock */
 		mutex_exit(&instance->sync_map_mtx);
 
-		
-		/* Set sense buffer physical address/length in scsi_io_request.*/
-		ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->SenseBufferLowAddress,
+
+		/*
+		 * Set sense buffer physical address/length in scsi_io_request.
+		 */
+		ddi_put32(acc_handle, &scsi_raid_io->SenseBufferLowAddress,
 		    cmd->sense_phys_addr1);
-		ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->SenseBufferLength,
-		    SENSE_LENGTH); 
-			
-		/* Construct SGL*/			
-		ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->SGLOffset0,
+		ddi_put8(acc_handle, &scsi_raid_io->SenseBufferLength,
+		    SENSE_LENGTH);
+
+		/* Construct SGL */
+		ddi_put8(acc_handle, &scsi_raid_io->SGLOffset0,
 		    offsetof(MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4);
 
-		mr_sas_tbolt_build_sgl(instance, acmd, cmd,
+		(void) mr_sas_tbolt_build_sgl(instance, acmd, cmd,
 		    scsi_raid_io, &datalen);
 
-		ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &scsi_raid_io->DataLength, datalen);
+		ddi_put32(acc_handle, &scsi_raid_io->DataLength, datalen);
 
 		break;
-
-	}
-	else {
 #ifndef PDSUPPORT	/* if PDSUPPORT, skip break and fall through */
+	} else {
 		break;
 #endif
 	}
@@ -1762,7 +1756,7 @@
 	/* fall through For all non-rd/wr cmds */
 	default:
 		switch (pkt->pkt_cdbp[0]) {
-		case 0x35: { // SCMD_SYNCHRONIZE_CACHE
+		case 0x35: { /* SCMD_SYNCHRONIZE_CACHE */
 			return_raid_msg_pkt(instance, cmd);
 			*cmd_done = 1;
 			return (NULL);
@@ -1787,74 +1781,86 @@
 		}
 
 		default: {
-			/* Here we need to handle PASSTHRU for
-			   Logical Devices. Like Inquiry etc.*/
+			/*
+			 * Here we need to handle PASSTHRU for
+			 * Logical Devices. Like Inquiry etc.
+			 */
 
-			if(!(acmd->islogical)) {
+			if (!(acmd->islogical)) {
 
-				/* Aquire SYNC MAP UPDATE lock */
+				/* Acquire SYNC MAP UPDATE lock */
 				mutex_enter(&instance->sync_map_mtx);
 
-				local_map_ptr = instance->ld_map[(instance->map_id & 1)];	
-			
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-				    &scsi_raid_io->Function, MPI2_FUNCTION_SCSI_IO_REQUEST);
-			
+				local_map_ptr =
+				    instance->ld_map[(instance->map_id & 1)];
+
+				ddi_put8(acc_handle, &scsi_raid_io->Function,
+				    MPI2_FUNCTION_SCSI_IO_REQUEST);
+
 				ReqDescUnion->SCSIIO.RequestFlags =
-					(MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
-						MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+				    (MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY <<
+				    MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
 
-				ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->DevHandle,
-						local_map_ptr->raidMap.devHndlInfo[acmd->device_id].curDevHdl);
-		
+				ddi_put16(acc_handle, &scsi_raid_io->DevHandle,
+				    local_map_ptr->raidMap.
+				    devHndlInfo[acmd->device_id].curDevHdl);
 
-				/*Set regLockFlasgs to REGION_TYPE_BYPASS */
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->RaidContext.regLockFlags, 0);
-				ddi_put64(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->RaidContext.regLockRowLBA, 0);
-				ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->RaidContext.regLockLength, 0);
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_raid_io->RaidContext.RAIDFlags,
-					MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD << MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
-				ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-				    &scsi_raid_io->RaidContext.timeoutValue, local_map_ptr->raidMap.fpPdIoTimeoutSec);
-				ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->RaidContext.ldTargetId, acmd->device_id);
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-					&scsi_raid_io->LUN[1], acmd->lun); 
 
+				/* Set regLockFlasgs to REGION_TYPE_BYPASS */
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockFlags, 0);
+				ddi_put64(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockRowLBA,
+				    0);
+				ddi_put32(acc_handle,
+				    &scsi_raid_io->RaidContext.regLockLength,
+				    0);
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->RaidContext.RAIDFlags,
+				    MR_RAID_FLAGS_IO_SUB_TYPE_SYSTEM_PD <<
+				    MR_RAID_CTX_RAID_FLAGS_IO_SUB_TYPE_SHIFT);
+				ddi_put16(acc_handle,
+				    &scsi_raid_io->RaidContext.timeoutValue,
+				    local_map_ptr->raidMap.fpPdIoTimeoutSec);
+				ddi_put16(acc_handle,
+				    &scsi_raid_io->RaidContext.ldTargetId,
+				    acmd->device_id);
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->LUN[1], acmd->lun);
+
 				/* Release SYNC MAP UPDATE lock */
 				mutex_exit(&instance->sync_map_mtx);
-			
+
 			} else {
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						&scsi_raid_io->Function, MPI2_FUNCTION_LD_IO_REQUEST);
-				ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						&scsi_raid_io->LUN[1], acmd->lun);
-				ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-						&scsi_raid_io->DevHandle, acmd->device_id);
-				ReqDescUnion->SCSIIO.RequestFlags = 
-					(MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO << MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
+				ddi_put8(acc_handle, &scsi_raid_io->Function,
+				    MPI2_FUNCTION_LD_IO_REQUEST);
+				ddi_put8(acc_handle,
+				    &scsi_raid_io->LUN[1], acmd->lun);
+				ddi_put16(acc_handle,
+				    &scsi_raid_io->DevHandle, acmd->device_id);
+				ReqDescUnion->SCSIIO.RequestFlags =
+				    (MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO <<
+				    MPI2_REQ_DESCRIPT_FLAGS_TYPE_SHIFT);
 			}
 
-			/* Set sense buffer physical address/length in scsi_io_request.*/
-			ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
+			/*
+			 * Set sense buffer physical address/length in
+			 * scsi_io_request.
+			 */
+			ddi_put32(acc_handle,
 			    &scsi_raid_io->SenseBufferLowAddress,
 			    cmd->sense_phys_addr1);
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
+			ddi_put8(acc_handle,
 			    &scsi_raid_io->SenseBufferLength, SENSE_LENGTH);
 
-			/* Construct SGL*/			
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io->SGLOffset0,
+			/* Construct SGL */
+			ddi_put8(acc_handle, &scsi_raid_io->SGLOffset0,
 			    offsetof(MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4);
 
-			mr_sas_tbolt_build_sgl(instance, acmd, cmd,
+			(void) mr_sas_tbolt_build_sgl(instance, acmd, cmd,
 			    scsi_raid_io, &datalen);
 
-			ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
+			ddi_put32(acc_handle,
 			    &scsi_raid_io->DataLength, datalen);
 
 
@@ -1867,14 +1873,11 @@
 			con_log(CL_DLEVEL1, (CE_CONT,
 			    "cdb length = %x\n",
 			    acmd->cmd_cdblen));
-			}
+		}
 			break;
 		}
 
 	}
-#ifdef lint
-	context = context;
-#endif
 
 	return (cmd);
 }
@@ -1983,16 +1986,18 @@
 
 	struct scsi_pkt *pkt;
 
-	con_log(CL_ANN1, (CE_NOTE, "tbolt_issue_cmd: cmd->[SMID]=0x%X", cmd->SMID));
+	con_log(CL_ANN1,
+	    (CE_NOTE, "tbolt_issue_cmd: cmd->[SMID]=0x%X", cmd->SMID));
 
 	con_log(CL_DLEVEL1, (CE_CONT,
-	    " [req desc Words] %llx \n", req_desc->Words));
+	    " [req desc Words] %" PRIx64 " \n", req_desc->Words));
 	con_log(CL_DLEVEL1, (CE_CONT,
-	    " [req desc low part] %x \n", req_desc->Words));
+	    " [req desc low part] %x \n",
+	    (uint_t)(req_desc->Words & 0xffffffffff)));
 	con_log(CL_DLEVEL1, (CE_CONT,
-	    " [req desc high part] %x \n", (req_desc->Words >> 32)));
+	    " [req desc high part] %x \n", (uint_t)(req_desc->Words >> 32)));
 	pkt = cmd->pkt;
-	
+
 	if (pkt) {
 		con_log(CL_ANN1, (CE_CONT, "%llx :TBOLT issue_cmd_ppc:"
 		    "ISSUED CMD TO FW : called : cmd:"
@@ -2034,7 +2039,9 @@
 	struct mrsas_header	*hdr;
 	hdr = (struct mrsas_header *)&cmd->frame->hdr;
 
-	con_log(CL_ANN, (CE_NOTE, "tbolt_issue_cmd_in_sync_mode: cmd->[SMID]=0x%X", cmd->SMID));
+	con_log(CL_ANN,
+	    (CE_NOTE, "tbolt_issue_cmd_in_sync_mode: cmd->[SMID]=0x%X",
+	    cmd->SMID));
 
 
 	if (instance->adapterresetinprogress) {
@@ -2043,7 +2050,7 @@
 		if (cmd->drv_pkt_time < debug_timeout_g)
 			cmd->drv_pkt_time = (uint16_t)debug_timeout_g;
 		con_log(CL_ANN, (CE_NOTE, "tbolt_issue_cmd_in_sync_mode:"
-		    "RESET-IN-PROGRESS, issue cmd & return.\n"));
+		    "RESET-IN-PROGRESS, issue cmd & return."));
 
 		mutex_enter(&instance->reg_write_mtx);
 		WR_IB_LOW_QPORT((uint32_t)(req_desc->Words), instance);
@@ -2052,16 +2059,17 @@
 
 		return (DDI_SUCCESS);
 	} else {
-		con_log(CL_ANN1, (CE_NOTE, "tbolt_issue_cmd_in_sync_mode: pushing the pkt\n"));
+		con_log(CL_ANN1, (CE_NOTE,
+		    "tbolt_issue_cmd_in_sync_mode: pushing the pkt"));
 		push_pending_mfi_pkt(instance, cmd);
 	}
 
 	con_log(CL_DLEVEL2, (CE_NOTE,
-	    "HighQport offset :%lx",
-	    (uint32_t *)((uintptr_t)(instance)->regmap + IB_HIGH_QPORT)));
+	    "HighQport offset :%p",
+	    (void *)((uintptr_t)(instance)->regmap + IB_HIGH_QPORT)));
 	con_log(CL_DLEVEL2, (CE_NOTE,
-	    "LowQport offset :%lx",
-	    (uint32_t *)((uintptr_t)(instance)->regmap + IB_LOW_QPORT)));
+	    "LowQport offset :%p",
+	    (void *)((uintptr_t)(instance)->regmap + IB_LOW_QPORT)));
 
 	cmd->sync_cmd = MRSAS_TRUE;
 	cmd->cmd_status =  ENODATA;
@@ -2073,9 +2081,9 @@
 	mutex_exit(&instance->reg_write_mtx);
 
 	con_log(CL_ANN1, (CE_NOTE,
-	    " req desc high part %x \n", (req_desc->Words >> 32)));
-	con_log(CL_ANN1, (CE_NOTE,
-	    " req desc low part %x \n", req_desc->Words));
+	    " req desc high part %x", (uint_t)(req_desc->Words >> 32)));
+	con_log(CL_ANN1, (CE_NOTE, " req desc low part %x",
+	    (uint_t)(req_desc->Words & 0xffffffff)));
 
 	mutex_enter(&instance->int_cmd_mtx);
 	for (i = 0; i < msecs && (cmd->cmd_status == ENODATA); i++) {
@@ -2103,8 +2111,10 @@
 	uint32_t	msecs = MFI_POLL_TIMEOUT_SECS * MILLISEC;
 	struct mrsas_header *frame_hdr;
 
-	con_log(CL_ANN, (CE_NOTE, "tbolt_issue_cmd_in_poll_mode: cmd->[SMID]=0x%X", cmd->SMID));
-	
+	con_log(CL_ANN,
+	    (CE_NOTE, "tbolt_issue_cmd_in_poll_mode: cmd->[SMID]=0x%X",
+	    cmd->SMID));
+
 	MRSAS_REQUEST_DESCRIPTOR_UNION *req_desc = cmd->request_desc;
 
 	frame_hdr = (struct mrsas_header *)&cmd->frame->hdr;
@@ -2111,13 +2121,13 @@
 	ddi_put8(cmd->frame_dma_obj.acc_handle, &frame_hdr->cmd_status,
 	    MFI_CMD_STATUS_POLL_MODE);
 	flags = ddi_get16(cmd->frame_dma_obj.acc_handle, &frame_hdr->flags);
-	flags 	|= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
+	flags	|= MFI_FRAME_DONT_POST_IN_REPLY_QUEUE;
 	ddi_put16(cmd->frame_dma_obj.acc_handle, &frame_hdr->flags, flags);
 
+	con_log(CL_ANN1, (CE_NOTE, " req desc low part %x",
+	    (uint_t)(req_desc->Words & 0xffffffff)));
 	con_log(CL_ANN1, (CE_NOTE,
-	    " req desc low part %x \n", req_desc->Words));
-	con_log(CL_ANN1, (CE_NOTE,
-	    " req desc high part %x \n", (req_desc->Words >> 32)));
+	    " req desc high part %x", (uint_t)(req_desc->Words >> 32)));
 
 	/* issue the frame using inbound queue port */
 	mutex_enter(&instance->reg_write_mtx);
@@ -2135,7 +2145,7 @@
 	if (ddi_get8(cmd->frame_dma_obj.acc_handle,
 	    &frame_hdr->cmd_status) == MFI_CMD_STATUS_POLL_MODE) {
 		con_log(CL_ANN1, (CE_NOTE,
-		    " cmd failed %x \n", (req_desc->Words)));
+		    " cmd failed %" PRIx64, (req_desc->Words)));
 		return (DDI_FAILURE);
 	}
 
@@ -2145,16 +2155,14 @@
 void
 tbolt_enable_intr(struct mrsas_instance *instance)
 {
-	uint32_t	mask;
-
 	/* TODO: For Thunderbolt/Invader also clear intr on enable */
-	//writel(~0, &regs->outbound_intr_status);
-	//readl(&regs->outbound_intr_status);	
+	/* writel(~0, &regs->outbound_intr_status); */
+	/* readl(&regs->outbound_intr_status); */
 
 	WR_OB_INTR_MASK(~(MFI_FUSION_ENABLE_INTERRUPT_MASK), instance);
 
 	/* dummy read to force PCI flush */
-	mask = RD_OB_INTR_MASK(instance);
+	(void) RD_OB_INTR_MASK(instance);
 
 }
 
@@ -2162,14 +2170,12 @@
 tbolt_disable_intr(struct mrsas_instance *instance)
 {
 	uint32_t mask = 0xFFFFFFFF;
-	uint32_t status;
 
-
 	WR_OB_INTR_MASK(mask, instance);
 
 	/* Dummy readl to force pci flush */
 
-	status = RD_OB_INTR_MASK(instance);
+	(void) RD_OB_INTR_MASK(instance);
 }
 
 
@@ -2181,18 +2187,23 @@
 	/* check if it is our interrupt */
 	status = RD_OB_INTR_STATUS(instance);
 	con_log(CL_ANN1, (CE_NOTE,
-	    "chkpnt: Entered tbolt_intr_ack status = %d \n", status));
+	    "chkpnt: Entered tbolt_intr_ack status = %d", status));
 
 	if (!(status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) {
 		return (DDI_INTR_UNCLAIMED);
 	}
 
+	if (mrsas_check_acc_handle(instance->regmap_handle) != DDI_SUCCESS) {
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+		return (DDI_INTR_UNCLAIMED);
+	}
+
 	if ((status & 1) || (status & MFI_FUSION_ENABLE_INTERRUPT_MASK)) {
 		/* clear the interrupt by writing back the same value */
 		WR_OB_INTR_STATUS(status, instance);
 		/* dummy READ */
-		RD_OB_INTR_STATUS(instance);
-		}
+		(void) RD_OB_INTR_STATUS(instance);
+	}
 	return (DDI_INTR_CLAIMED);
 }
 
@@ -2296,23 +2307,24 @@
 mr_sas_tbolt_build_mfi_cmd(struct mrsas_instance *instance,
     struct mrsas_cmd *cmd)
 {
-	Mpi2RaidSCSIIORequest_t 	*scsi_raid_io;
+	Mpi2RaidSCSIIORequest_t		*scsi_raid_io;
 	Mpi25IeeeSgeChain64_t		*scsi_raid_io_sgl_ieee;
-	MRSAS_REQUEST_DESCRIPTOR_UNION 	*ReqDescUnion;
+	MRSAS_REQUEST_DESCRIPTOR_UNION	*ReqDescUnion;
 	uint32_t			index;
+	ddi_acc_handle_t acc_handle =
+	    instance->mpi2_frame_pool_dma_obj.acc_handle;
 
 	if (!instance->tbolt) {
-		con_log(CL_ANN, (CE_NOTE, "Not MFA enabled.\n"));
+		con_log(CL_ANN, (CE_NOTE, "Not MFA enabled."));
 		return;
 	}
 
 	index = cmd->index;
 
-	ReqDescUnion =
-	    mr_sas_get_request_descriptor(instance, index, cmd);
+	ReqDescUnion = mr_sas_get_request_descriptor(instance, index);
 
 	if (!ReqDescUnion) {
-		con_log(CL_ANN1, (CE_NOTE, "[NULL REQDESC]%x"));
+		con_log(CL_ANN1, (CE_NOTE, "[NULL REQDESC]"));
 		return;
 	}
 
@@ -2328,30 +2340,26 @@
 
 	cmd->request_desc = ReqDescUnion;
 
-	// get raid message frame pointer
+	/* get raid message frame pointer */
 	scsi_raid_io = (Mpi2RaidSCSIIORequest_t *)cmd->scsi_io_request;
 
 	if (instance->device_id == PCI_DEVICE_ID_LSI_INVADER) {
-		Mpi25IeeeSgeChain64_t *sgl_ptr_end = (Mpi25IeeeSgeChain64_t *)&scsi_raid_io->SGL.IeeeChain;
+		Mpi25IeeeSgeChain64_t *sgl_ptr_end = (Mpi25IeeeSgeChain64_t *)
+		    &scsi_raid_io->SGL.IeeeChain;
 		sgl_ptr_end += instance->max_sge_in_main_msg - 1;
-		ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		    &sgl_ptr_end->Flags, 0);
+		ddi_put8(acc_handle, &sgl_ptr_end->Flags, 0);
 	}
 
-	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->Function,
+	ddi_put8(acc_handle, &scsi_raid_io->Function,
 	    MPI2_FUNCTION_PASSTHRU_IO_REQUEST);
 
-	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->SGLOffset0,
+	ddi_put8(acc_handle, &scsi_raid_io->SGLOffset0,
 	    offsetof(MPI2_RAID_SCSI_IO_REQUEST, SGL) / 4);
 
-	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->ChainOffset,
+	ddi_put8(acc_handle, &scsi_raid_io->ChainOffset,
 	    (U8)offsetof(MPI2_RAID_SCSI_IO_REQUEST, SGL) / 16);
 
-	ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->SenseBufferLowAddress,
+	ddi_put32(acc_handle, &scsi_raid_io->SenseBufferLowAddress,
 	    cmd->sense_phys_addr1);
 
 
@@ -2358,19 +2366,17 @@
 	scsi_raid_io_sgl_ieee =
 	    (Mpi25IeeeSgeChain64_t *)&scsi_raid_io->SGL.IeeeChain;
 
-	ddi_put64(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io_sgl_ieee->Address,
+	ddi_put64(acc_handle, &scsi_raid_io_sgl_ieee->Address,
 	    (U64)cmd->frame_phys_addr);
 
-	ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io_sgl_ieee->Flags,
-	    (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
-                   MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR));
-	ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io_sgl_ieee->Length, 1024); //MEGASAS_MAX_SZ_CHAIN_FRAME
+	ddi_put8(acc_handle,
+	    &scsi_raid_io_sgl_ieee->Flags, (IEEE_SGE_FLAGS_CHAIN_ELEMENT |
+	    MPI2_IEEE_SGE_FLAGS_IOCPLBNTA_ADDR));
+	/* LSI put hardcoded 1024 instead of MEGASAS_MAX_SZ_CHAIN_FRAME. */
+	ddi_put32(acc_handle, &scsi_raid_io_sgl_ieee->Length, 1024);
 
 	con_log(CL_ANN1, (CE_NOTE,
-	    "[MFI CMD PHY ADDRESS]:%x",
+	    "[MFI CMD PHY ADDRESS]:%" PRIx64,
 	    scsi_raid_io_sgl_ieee->Address));
 	con_log(CL_ANN1, (CE_NOTE,
 	    "[SGL Length]:%x", scsi_raid_io_sgl_ieee->Length));
@@ -2390,15 +2396,14 @@
 	struct scsi_pkt			*pkt;
 	struct scsi_arq_status		*arqstat;
 	Mpi2RaidSCSIIORequest_t		*scsi_raid_io;
-	LD_LOAD_BALANCE_INFO 		*lbinfo;
-	int i;
+	LD_LOAD_BALANCE_INFO		*lbinfo;
+	ddi_acc_handle_t acc_handle =
+	    instance->mpi2_frame_pool_dma_obj.acc_handle;
 
 	scsi_raid_io = (Mpi2RaidSCSIIORequest_t *)cmd->scsi_io_request;
 
-	status = ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->RaidContext.status);
-	extStatus = ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->RaidContext.extStatus);
+	status = ddi_get8(acc_handle, &scsi_raid_io->RaidContext.status);
+	extStatus = ddi_get8(acc_handle, &scsi_raid_io->RaidContext.extStatus);
 
 	con_log(CL_DLEVEL3, (CE_NOTE, "status %x", status));
 	con_log(CL_DLEVEL3, (CE_NOTE, "extStatus %x", extStatus));
@@ -2413,243 +2418,242 @@
 
 	/* regular commands */
 
-	switch (ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_raid_io->Function)) {
+	switch (ddi_get8(acc_handle, &scsi_raid_io->Function)) {
 
-		case MPI2_FUNCTION_SCSI_IO_REQUEST :  /* Fast Path IO. */
-			acmd =	(struct scsa_cmd *)cmd->cmd;
-			lbinfo = &instance->load_balance_info[acmd->device_id];
+	case MPI2_FUNCTION_SCSI_IO_REQUEST :  /* Fast Path IO. */
+		acmd =	(struct scsa_cmd *)cmd->cmd;
+		lbinfo = &instance->load_balance_info[acmd->device_id];
 
-			if (cmd->load_balance_flag & MEGASAS_LOAD_BALANCE_FLAG) {
-				arm = lbinfo->raid1DevHandle[0] == scsi_raid_io->DevHandle ? 0 : 1;
+		if (cmd->load_balance_flag & MEGASAS_LOAD_BALANCE_FLAG) {
+			arm = lbinfo->raid1DevHandle[0] ==
+			    scsi_raid_io->DevHandle ? 0 : 1;
 
-				lbinfo->scsi_pending_cmds[arm]--;
-				cmd->load_balance_flag &= ~MEGASAS_LOAD_BALANCE_FLAG;
-			}
-			con_log(CL_DLEVEL3, (CE_NOTE,
-			    "FastPath IO Completion Success "));
+			lbinfo->scsi_pending_cmds[arm]--;
+			cmd->load_balance_flag &= ~MEGASAS_LOAD_BALANCE_FLAG;
+		}
+		con_log(CL_DLEVEL3, (CE_NOTE,
+		    "FastPath IO Completion Success "));
+		/* FALLTHRU */
 
-		case MPI2_FUNCTION_LD_IO_REQUEST :   {// Regular Path IO.
-			acmd =	(struct scsa_cmd *)cmd->cmd;
-			pkt =	(struct scsi_pkt *)CMD2PKT(acmd);
+	case MPI2_FUNCTION_LD_IO_REQUEST :   { /* Regular Path IO. */
+		acmd =	(struct scsa_cmd *)cmd->cmd;
+		pkt =	(struct scsi_pkt *)CMD2PKT(acmd);
 
-			if (acmd->cmd_flags & CFLAG_DMAVALID) {
-				if (acmd->cmd_flags & CFLAG_CONSISTENT) {
-					(void) ddi_dma_sync(acmd->cmd_dmahandle,
-					    acmd->cmd_dma_offset,
-					    acmd->cmd_dma_len,
-					    DDI_DMA_SYNC_FORCPU);
-				}
+		if (acmd->cmd_flags & CFLAG_DMAVALID) {
+			if (acmd->cmd_flags & CFLAG_CONSISTENT) {
+				(void) ddi_dma_sync(acmd->cmd_dmahandle,
+				    acmd->cmd_dma_offset, acmd->cmd_dma_len,
+				    DDI_DMA_SYNC_FORCPU);
 			}
+		}
 
-			pkt->pkt_reason		= CMD_CMPLT;
-			pkt->pkt_statistics	= 0;
-			pkt->pkt_state = STATE_GOT_BUS
-			    | STATE_GOT_TARGET | STATE_SENT_CMD
-			    | STATE_XFERRED_DATA | STATE_GOT_STATUS;
+		pkt->pkt_reason		= CMD_CMPLT;
+		pkt->pkt_statistics	= 0;
+		pkt->pkt_state = STATE_GOT_BUS | STATE_GOT_TARGET |
+		    STATE_SENT_CMD | STATE_XFERRED_DATA | STATE_GOT_STATUS;
 
-			con_log(CL_ANN, (CE_CONT,
-			    " CDB[0] = %x completed for %s: size %lx SMID %x cmd_status %x",
-			    pkt->pkt_cdbp[0],
-			    ((acmd->islogical) ? "LD" : "PD"),
-			    acmd->cmd_dmacount, cmd->SMID, status));
+		con_log(CL_ANN, (CE_CONT, " CDB[0] = %x completed for %s: "
+		    "size %lx SMID %x cmd_status %x", pkt->pkt_cdbp[0],
+		    ((acmd->islogical) ? "LD" : "PD"),
+		    acmd->cmd_dmacount, cmd->SMID, status));
 
-			if (pkt->pkt_cdbp[0] == SCMD_INQUIRY) {
-				struct scsi_inquiry	*inq;
+		if (pkt->pkt_cdbp[0] == SCMD_INQUIRY) {
+			struct scsi_inquiry	*inq;
 
-				if (acmd->cmd_dmacount != 0) {
-					bp_mapin(acmd->cmd_buf);
-					inq = (struct scsi_inquiry *)
-					    acmd->cmd_buf->b_un.b_addr;
+			if (acmd->cmd_dmacount != 0) {
+				bp_mapin(acmd->cmd_buf);
+				inq = (struct scsi_inquiry *)
+				    acmd->cmd_buf->b_un.b_addr;
 
-					/* don't expose physical drives to OS */
-					if (acmd->islogical &&
-					    (status == MFI_STAT_OK)) {
-						display_scsi_inquiry(
-						    (caddr_t)inq);
-					} 
+				/* don't expose physical drives to OS */
+				if (acmd->islogical &&
+				    (status == MFI_STAT_OK)) {
+					display_scsi_inquiry((caddr_t)inq);
 #ifdef PDSUPPORT
-					else if ((status ==
-					    MFI_STAT_OK) && inq->inq_dtype ==
-					    DTYPE_DIRECT) {
-
-						display_scsi_inquiry(
-						    (caddr_t)inq);
-					}
+				} else if ((status == MFI_STAT_OK) &&
+				    inq->inq_dtype == DTYPE_DIRECT) {
+					display_scsi_inquiry((caddr_t)inq);
 #endif
-					else {
-						/* for physical disk */
-						status =
-						    MFI_STAT_DEVICE_NOT_FOUND;
-					}
+				} else {
+					/* for physical disk */
+					status = MFI_STAT_DEVICE_NOT_FOUND;
 				}
 			}
+		}
 
-			switch (status) {
-			case MFI_STAT_OK:
-				pkt->pkt_scbp[0] = STATUS_GOOD;
-				break;
-			case MFI_STAT_LD_CC_IN_PROGRESS:
-			case MFI_STAT_LD_RECON_IN_PROGRESS:
-				pkt->pkt_scbp[0] = STATUS_GOOD;
-				break;
-			case MFI_STAT_LD_INIT_IN_PROGRESS:
-				pkt->pkt_reason	= CMD_TRAN_ERR;
-				break;
-			case MFI_STAT_SCSI_IO_FAILED:
-				cmn_err(CE_WARN, "tbolt_complete_cmd: scsi_io failed");
-				pkt->pkt_reason	= CMD_TRAN_ERR;
-				break;
-			case MFI_STAT_SCSI_DONE_WITH_ERROR:
-				con_log(CL_ANN, (CE_WARN,
-					"tbolt_complete_cmd: scsi_done with error"));
+		switch (status) {
+		case MFI_STAT_OK:
+			pkt->pkt_scbp[0] = STATUS_GOOD;
+			break;
+		case MFI_STAT_LD_CC_IN_PROGRESS:
+		case MFI_STAT_LD_RECON_IN_PROGRESS:
+			pkt->pkt_scbp[0] = STATUS_GOOD;
+			break;
+		case MFI_STAT_LD_INIT_IN_PROGRESS:
+			pkt->pkt_reason	= CMD_TRAN_ERR;
+			break;
+		case MFI_STAT_SCSI_IO_FAILED:
+			cmn_err(CE_WARN, "tbolt_complete_cmd: scsi_io failed");
+			pkt->pkt_reason	= CMD_TRAN_ERR;
+			break;
+		case MFI_STAT_SCSI_DONE_WITH_ERROR:
+			con_log(CL_ANN, (CE_WARN,
+			    "tbolt_complete_cmd: scsi_done with error"));
 
-				pkt->pkt_reason	= CMD_CMPLT;
-				((struct scsi_status *)
-				    pkt->pkt_scbp)->sts_chk = 1;
+			pkt->pkt_reason	= CMD_CMPLT;
+			((struct scsi_status *)pkt->pkt_scbp)->sts_chk = 1;
 
-				if (pkt->pkt_cdbp[0] == SCMD_TEST_UNIT_READY) {
-					con_log(CL_ANN, (CE_WARN, "TEST_UNIT_READY fail"));
-				} else {
-					pkt->pkt_state |= STATE_ARQ_DONE;
-					arqstat = (void *)(pkt->pkt_scbp);
-					arqstat->sts_rqpkt_reason = CMD_CMPLT;
-					arqstat->sts_rqpkt_resid = 0;
-					arqstat->sts_rqpkt_state |=
-					    STATE_GOT_BUS | STATE_GOT_TARGET
-					    | STATE_SENT_CMD
-					    | STATE_XFERRED_DATA;
-					*(uint8_t *)&arqstat->sts_rqpkt_status =
-					    STATUS_GOOD;
-					con_log(CL_ANN1, (CE_NOTE,
-					    "Copying Sense data %x",
-					    cmd->SMID));
-
-					ddi_rep_get8(
-					    instance->
-					    mpi2_frame_pool_dma_obj.acc_handle,
-					    (uint8_t *)
-					    &(arqstat->sts_sensedata),
-					    cmd->sense1,
-					    sizeof (struct scsi_extended_sense),
-					    DDI_DEV_AUTOINCR);
-			
-				}
-				break;
-			case MFI_STAT_LD_OFFLINE:
-				cmn_err(CE_WARN,
-					"tbolt_complete_cmd: ld offline "
-					"CDB[0]=0x%x targetId=0x%x devhandle=0x%x\n",	//UNDO:
-					ddi_get8(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_raid_io->CDB.CDB32[0]),
-					ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_raid_io->RaidContext.ldTargetId),
-					ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle, &scsi_raid_io->DevHandle) );
-				pkt->pkt_reason	= CMD_DEV_GONE;
-				pkt->pkt_statistics  = STAT_DISCON;
-				break;
-			case MFI_STAT_DEVICE_NOT_FOUND:
-			con_log(CL_ANN, (CE_CONT,
-				"tbolt_complete_cmd: device not found error"));
-				pkt->pkt_reason	= CMD_DEV_GONE;
-				pkt->pkt_statistics  = STAT_DISCON;
-				break;
-
-			case MFI_STAT_LD_LBA_OUT_OF_RANGE:
+			if (pkt->pkt_cdbp[0] == SCMD_TEST_UNIT_READY) {
+				con_log(CL_ANN,
+				    (CE_WARN, "TEST_UNIT_READY fail"));
+			} else {
 				pkt->pkt_state |= STATE_ARQ_DONE;
-				pkt->pkt_reason	= CMD_CMPLT;
-				((struct scsi_status *)
-				    pkt->pkt_scbp)->sts_chk = 1;
-
 				arqstat = (void *)(pkt->pkt_scbp);
 				arqstat->sts_rqpkt_reason = CMD_CMPLT;
 				arqstat->sts_rqpkt_resid = 0;
-				arqstat->sts_rqpkt_state |= STATE_GOT_BUS
-				    | STATE_GOT_TARGET | STATE_SENT_CMD
+				arqstat->sts_rqpkt_state |=
+				    STATE_GOT_BUS | STATE_GOT_TARGET
+				    | STATE_SENT_CMD
 				    | STATE_XFERRED_DATA;
 				*(uint8_t *)&arqstat->sts_rqpkt_status =
 				    STATUS_GOOD;
+				con_log(CL_ANN1,
+				    (CE_NOTE, "Copying Sense data %x",
+				    cmd->SMID));
 
-				arqstat->sts_sensedata.es_valid = 1;
-				arqstat->sts_sensedata.es_key =
-				    KEY_ILLEGAL_REQUEST;
-				arqstat->sts_sensedata.es_class =
-				    CLASS_EXTENDED_SENSE;
+				ddi_rep_get8(acc_handle,
+				    (uint8_t *)&(arqstat->sts_sensedata),
+				    cmd->sense1,
+				    sizeof (struct scsi_extended_sense),
+				    DDI_DEV_AUTOINCR);
 
-				/*
-				 * LOGICAL BLOCK ADDRESS OUT OF RANGE:
-				 * ASC: 0x21h; ASCQ: 0x00h;
-				 */
-				arqstat->sts_sensedata.es_add_code = 0x21;
-				arqstat->sts_sensedata.es_qual_code = 0x00;
-				break;
-			case MFI_STAT_INVALID_CMD:
-			case MFI_STAT_INVALID_DCMD:
-			case MFI_STAT_INVALID_PARAMETER:
-			case MFI_STAT_INVALID_SEQUENCE_NUMBER:
-			default:
-				cmn_err(CE_WARN, "tbolt_complete_cmd: Unknown status!");
-				pkt->pkt_reason	= CMD_TRAN_ERR;
-
-				break;
 			}
+			break;
+		case MFI_STAT_LD_OFFLINE:
+			cmn_err(CE_WARN,
+			    "tbolt_complete_cmd: ld offline "
+			    "CDB[0]=0x%x targetId=0x%x devhandle=0x%x",
+			    /* UNDO: */
+			    ddi_get8(acc_handle, &scsi_raid_io->CDB.CDB32[0]),
 
-			atomic_add_16(&instance->fw_outstanding, (-1));
+			    ddi_get16(acc_handle,
+			    &scsi_raid_io->RaidContext.ldTargetId),
 
-			/* Call the callback routine */
-			if (((pkt->pkt_flags & FLAG_NOINTR) == 0) &&
-			    pkt->pkt_comp) {
-				(*pkt->pkt_comp)(pkt);
-			}
+			    ddi_get16(acc_handle, &scsi_raid_io->DevHandle));
 
-			con_log(CL_ANN1, (CE_NOTE, "Free smid %x", cmd->SMID));
+			pkt->pkt_reason	= CMD_DEV_GONE;
+			pkt->pkt_statistics  = STAT_DISCON;
+			break;
+		case MFI_STAT_DEVICE_NOT_FOUND:
+			con_log(CL_ANN, (CE_CONT,
+			    "tbolt_complete_cmd: device not found error"));
+			pkt->pkt_reason	= CMD_DEV_GONE;
+			pkt->pkt_statistics  = STAT_DISCON;
+			break;
 
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io->RaidContext.status, 0);
+		case MFI_STAT_LD_LBA_OUT_OF_RANGE:
+			pkt->pkt_state |= STATE_ARQ_DONE;
+			pkt->pkt_reason	= CMD_CMPLT;
+			((struct scsi_status *)pkt->pkt_scbp)->sts_chk = 1;
 
-			ddi_put8(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			    &scsi_raid_io->RaidContext.extStatus, 0);
+			arqstat = (void *)(pkt->pkt_scbp);
+			arqstat->sts_rqpkt_reason = CMD_CMPLT;
+			arqstat->sts_rqpkt_resid = 0;
+			arqstat->sts_rqpkt_state |= STATE_GOT_BUS
+			    | STATE_GOT_TARGET | STATE_SENT_CMD
+			    | STATE_XFERRED_DATA;
+			*(uint8_t *)&arqstat->sts_rqpkt_status = STATUS_GOOD;
 
-			return_raid_msg_pkt(instance, cmd);
+			arqstat->sts_sensedata.es_valid = 1;
+			arqstat->sts_sensedata.es_key = KEY_ILLEGAL_REQUEST;
+			arqstat->sts_sensedata.es_class = CLASS_EXTENDED_SENSE;
+
+			/*
+			 * LOGICAL BLOCK ADDRESS OUT OF RANGE:
+			 * ASC: 0x21h; ASCQ: 0x00h;
+			 */
+			arqstat->sts_sensedata.es_add_code = 0x21;
+			arqstat->sts_sensedata.es_qual_code = 0x00;
 			break;
+		case MFI_STAT_INVALID_CMD:
+		case MFI_STAT_INVALID_DCMD:
+		case MFI_STAT_INVALID_PARAMETER:
+		case MFI_STAT_INVALID_SEQUENCE_NUMBER:
+		default:
+			cmn_err(CE_WARN, "tbolt_complete_cmd: Unknown status!");
+			pkt->pkt_reason	= CMD_TRAN_ERR;
+
+			break;
 		}
-	case MPI2_FUNCTION_PASSTHRU_IO_REQUEST:  // MFA command.
 
-		if (cmd->frame->dcmd.opcode
-			 == MR_DCMD_LD_MAP_GET_INFO && 
-			 cmd->frame->dcmd.mbox.b[1] 
-			 == 1) {
-			
+		atomic_add_16(&instance->fw_outstanding, (-1));
+
+		(void) mrsas_common_check(instance, cmd);
+		if (acmd->cmd_dmahandle) {
+			if (mrsas_check_dma_handle(acmd->cmd_dmahandle) !=
+			    DDI_SUCCESS) {
+				ddi_fm_service_impact(instance->dip,
+				    DDI_SERVICE_UNAFFECTED);
+				pkt->pkt_reason = CMD_TRAN_ERR;
+				pkt->pkt_statistics = 0;
+			}
+		}
+
+		/* Call the callback routine */
+		if (((pkt->pkt_flags & FLAG_NOINTR) == 0) && pkt->pkt_comp)
+			(*pkt->pkt_comp)(pkt);
+
+		con_log(CL_ANN1, (CE_NOTE, "Free smid %x", cmd->SMID));
+
+		ddi_put8(acc_handle, &scsi_raid_io->RaidContext.status, 0);
+
+		ddi_put8(acc_handle, &scsi_raid_io->RaidContext.extStatus, 0);
+
+		return_raid_msg_pkt(instance, cmd);
+		break;
+	}
+	case MPI2_FUNCTION_PASSTHRU_IO_REQUEST:	 /* MFA command. */
+
+		if (cmd->frame->dcmd.opcode == MR_DCMD_LD_MAP_GET_INFO &&
+		    cmd->frame->dcmd.mbox.b[1] == 1) {
+
 			mutex_enter(&instance->sync_map_mtx);
 
 			con_log(CL_ANN, (CE_NOTE,
-                           "LDMAP sync command  SMID RECEIVED 0x%X",
-                           cmd->SMID));
+			    "LDMAP sync command	SMID RECEIVED 0x%X",
+			    cmd->SMID));
 			if (cmd->frame->hdr.cmd_status != 0) {
 				cmn_err(CE_WARN,
-			    		"map sync failed, status = 0x%x.\n",cmd->frame->hdr.cmd_status);
-			}
-			else {
+				    "map sync failed, status = 0x%x.",
+				    cmd->frame->hdr.cmd_status);
+			} else {
 				instance->map_id++;
 				cmn_err(CE_NOTE,
-			    		"map sync received, switched map_id to %ld \n",instance->map_id);
+				    "map sync received, switched map_id to %"
+				    PRIu64 " \n", instance->map_id);
 			}
 
-			if (MR_ValidateMapInfo(instance->ld_map[(instance->map_id & 1)], instance->load_balance_info))
-				instance->fast_path_io = 1; 
-			else 
-				instance->fast_path_io = 0;     
-			
+			if (MR_ValidateMapInfo(instance->ld_map[
+			    (instance->map_id & 1)],
+			    instance->load_balance_info)) {
+				instance->fast_path_io = 1;
+			} else {
+				instance->fast_path_io = 0;
+			}
+
 			con_log(CL_ANN, (CE_NOTE,
-		    		"instance->fast_path_io %d \n",instance->fast_path_io));
+			    "instance->fast_path_io %d",
+			    instance->fast_path_io));
 
 			instance->unroll.syncCmd = 0;
 
-			if(instance->map_update_cmd == cmd) {
+			if (instance->map_update_cmd == cmd) {
 				return_raid_msg_pkt(instance, cmd);
 				atomic_add_16(&instance->fw_outstanding, (-1));
-				mrsas_tbolt_sync_map_info(instance);
+				(void) mrsas_tbolt_sync_map_info(instance);
 			}
-	
-			cmn_err(CE_NOTE, "LDMAP sync completed.\n");
+
+			cmn_err(CE_NOTE, "LDMAP sync completed.");
 			mutex_exit(&instance->sync_map_mtx);
 			break;
 		}
@@ -2656,38 +2660,37 @@
 
 		if (cmd->frame->dcmd.opcode == MR_DCMD_CTRL_EVENT_WAIT) {
 			con_log(CL_ANN1, (CE_CONT,
-                           "AEN command SMID RECEIVED 0x%X",
-                           cmd->SMID));
-			 if ((instance->aen_cmd == cmd) &&
-                                    (instance->aen_cmd->abort_aen)) {
-                                        con_log(CL_ANN, (CE_WARN,
-                                            "mrsas_softintr: "
-                                            "aborted_aen returned"));
-			}
-			else
-			{
+			    "AEN command SMID RECEIVED 0x%X",
+			    cmd->SMID));
+			if ((instance->aen_cmd == cmd) &&
+			    (instance->aen_cmd->abort_aen)) {
+				con_log(CL_ANN, (CE_WARN, "mrsas_softintr: "
+				    "aborted_aen returned"));
+			} else {
 				atomic_add_16(&instance->fw_outstanding, (-1));
-                   service_mfi_aen(instance, cmd);
+				service_mfi_aen(instance, cmd);
 			}
 		}
 
-		if (cmd->sync_cmd == MRSAS_TRUE ) {
+		if (cmd->sync_cmd == MRSAS_TRUE) {
 			con_log(CL_ANN1, (CE_CONT,
-                           "Sync-mode Command Response SMID RECEIVED 0x%X",
-                           cmd->SMID));
+			    "Sync-mode Command Response SMID RECEIVED 0x%X",
+			    cmd->SMID));
 
 			tbolt_complete_cmd_in_sync_mode(instance, cmd);
-		}
-		else
-		{
+		} else {
 			con_log(CL_ANN, (CE_CONT,
-				"tbolt_complete_cmd: Wrong SMID RECEIVED 0x%X",
-                           	cmd->SMID));
+			    "tbolt_complete_cmd: Wrong SMID RECEIVED 0x%X",
+			    cmd->SMID));
 		}
 		break;
 	default:
+		mrsas_fm_ereport(instance, DDI_FM_DEVICE_NO_RESPONSE);
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+
 		/* free message */
-		con_log(CL_ANN, (CE_NOTE, "tbolt_complete_cmd: Unknown Type!!!!!!!!"));
+		con_log(CL_ANN,
+		    (CE_NOTE, "tbolt_complete_cmd: Unknown Type!!!!!!!!"));
 		break;
 	}
 }
@@ -2697,13 +2700,10 @@
 {
 	uint8_t				replyType;
 	Mpi2SCSIIOSuccessReplyDescriptor_t *replyDesc;
-	Mpi2ReplyDescriptorsUnion_t 	*desc;
+	Mpi2ReplyDescriptorsUnion_t	*desc;
 	uint16_t			smid;
-	union desc_value 		d_val;
+	union desc_value		d_val;
 	struct mrsas_cmd		*cmd;
-	uint32_t 			i;
-	Mpi2RaidSCSIIORequest_t		*scsi_raid_io;
-	uint8_t				status;
 
 	struct mrsas_header	*hdr;
 	struct scsi_pkt		*pkt;
@@ -2724,60 +2724,69 @@
 	if (replyType == MPI2_RPY_DESCRIPT_FLAGS_UNUSED)
 		return (DDI_INTR_UNCLAIMED);
 
-	con_log(CL_ANN1, (CE_NOTE, "Reply Desc  = %llx  Words = %llx \n",
-				desc, desc->Words));
+	if (mrsas_check_dma_handle(instance->mfi_internal_dma_obj.dma_handle)
+	    != DDI_SUCCESS) {
+		mrsas_fm_ereport(instance, DDI_FM_DEVICE_NO_RESPONSE);
+		ddi_fm_service_impact(instance->dip, DDI_SERVICE_LOST);
+		con_log(CL_ANN1,
+		    (CE_WARN, "mr_sas_tbolt_process_outstanding_cmd(): "
+		    "FMA check, returning DDI_INTR_UNCLAIMED"));
+		return (DDI_INTR_CLAIMED);
+	}
 
+	con_log(CL_ANN1, (CE_NOTE, "Reply Desc	= %p  Words = %" PRIx64,
+	    (void *)desc, desc->Words));
+
 	d_val.word = desc->Words;
-	
 
+
 	/* Read Reply descriptor */
 	while ((d_val.u1.low != 0xffffffff) &&
 	    (d_val.u1.high != 0xffffffff)) {
 
 		(void) ddi_dma_sync(instance->reply_desc_dma_obj.dma_handle,
-	    	0, 0, DDI_DMA_SYNC_FORCPU);
+		    0, 0, DDI_DMA_SYNC_FORCPU);
 
 		smid = replyDesc->SMID;
 
 		if (!smid || smid > instance->max_fw_cmds + 1) {
 			con_log(CL_ANN1, (CE_NOTE,
-			    "Reply Desc at Break  = %llx  Words = %llx \n",
-			    desc, desc->Words));
+			    "Reply Desc at Break  = %p	Words = %" PRIx64,
+			    (void *)desc, desc->Words));
 			break;
 		}
 
 		cmd	= instance->cmd_list[smid - 1];
-		if(!cmd ) {
-	  		con_log(CL_ANN1, (CE_NOTE,
-				"mr_sas_tbolt_process_outstanding_cmd: Invalid command "
-				" or Poll commad Received in completion path\n"));
-		}
-		else {
+		if (!cmd) {
+			con_log(CL_ANN1, (CE_NOTE, "mr_sas_tbolt_process_"
+			    "outstanding_cmd: Invalid command "
+			    " or Poll commad Received in completion path"));
+		} else {
 			mutex_enter(&instance->cmd_pend_mtx);
 			if (cmd->sync_cmd == MRSAS_TRUE) {
 				hdr = (struct mrsas_header *)&cmd->frame->hdr;
 				if (hdr) {
-	  				con_log(CL_ANN1, (CE_NOTE,
-						"mr_sas_tbolt_process_outstanding_cmd:"
-						" mlist_del_init(&cmd->list).\n"));
+					con_log(CL_ANN1, (CE_NOTE, "mr_sas_"
+					    "tbolt_process_outstanding_cmd:"
+					    " mlist_del_init(&cmd->list)."));
 					mlist_del_init(&cmd->list);
 				}
-				} else {
-					pkt = cmd->pkt;
-					if (pkt) {
-	  					con_log(CL_ANN1, (CE_NOTE,
-							"mr_sas_tbolt_process_outstanding_cmd:"
-							"mlist_del_init(&cmd->list).\n"));
+			} else {
+				pkt = cmd->pkt;
+				if (pkt) {
+					con_log(CL_ANN1, (CE_NOTE, "mr_sas_"
+					    "tbolt_process_outstanding_cmd:"
+					    "mlist_del_init(&cmd->list)."));
 					mlist_del_init(&cmd->list);
 				}
 			}
 
 			mutex_exit(&instance->cmd_pend_mtx);
-			
+
 			tbolt_complete_cmd(instance, cmd);
-		}	
-		// set it back to all 0xfffffffff.
-		desc->Words = (uint64_t)~0;
+		}
+		/* set it back to all 1s. */
+		desc->Words = -1LL;
 
 		instance->reply_read_index++;
 
@@ -2797,8 +2806,8 @@
 		d_val.word = desc->Words;
 
 		con_log(CL_ANN1, (CE_NOTE,
-		    "Next Reply Desc  = %llx Words = %llx\n",
-		    desc, desc->Words));
+		    "Next Reply Desc  = %p Words = %" PRIx64,
+		    (void *)desc, desc->Words));
 
 		replyType = replyDesc->ReplyFlags &
 		    MPI2_RPY_DESCRIPT_FLAGS_TYPE_MASK;
@@ -2852,7 +2861,7 @@
 }
 
 /*
- * mrsas_tbolt_get_ld_map_info -	Returns  ld_map structure
+ * mrsas_tbolt_get_ld_map_info -	Returns	 ld_map structure
  * instance:				Adapter soft state
  *
  * Issues an internal command (DCMD) to get the FW's controller PD
@@ -2890,14 +2899,13 @@
 	ci_h = instance->ld_map_phy[(instance->map_id & 1)];
 
 	if (!ci) {
-		cmn_err(CE_WARN,
-			"Failed to alloc mem for ld_map_info");
+		cmn_err(CE_WARN, "Failed to alloc mem for ld_map_info");
 		return_raid_msg_pkt(instance, cmd);
 		return (-1);
 	}
 
-	memset(ci, 0, sizeof (*ci));
-	memset(dcmd->mbox.b, 0, DCMD_MBOX_SZ);
+	bzero(ci, sizeof (*ci));
+	bzero(dcmd->mbox.b, DCMD_MBOX_SZ);
 
 	dcmd->cmd = MFI_CMD_OP_DCMD;
 	dcmd->cmd_status = 0xFF;
@@ -2915,11 +2923,9 @@
 
 	if (!instance->func_ptr->issue_cmd_in_poll_mode(instance, cmd)) {
 		ret = 0;
-		con_log(CL_ANN1, (CE_NOTE,
-		    "Get LD Map Info success\n"));
+		con_log(CL_ANN1, (CE_NOTE, "Get LD Map Info success"));
 	} else {
-		cmn_err(CE_WARN,
-		    "Get LD Map Info failed\n");
+		cmn_err(CE_WARN, "Get LD Map Info failed");
 		ret = -1;
 	}
 
@@ -2945,7 +2951,7 @@
 	}
 }
 
-/**
+/*
  * mrsas_tbolt_command_create -	Create command for fast path.
  * @io_info:	MegaRAID IO request packet pointer.
  * @ref_tag:	Reference tag for RD/WRPROTECT
@@ -2953,94 +2959,93 @@
  * Create the command for fast path.
  */
 void
-mrsas_tbolt_prepare_cdb(struct mrsas_instance *instance, U8 cdb[],struct IO_REQUEST_INFO *io_info,Mpi2RaidSCSIIORequest_t *scsi_io_request, U32 ref_tag)
+mrsas_tbolt_prepare_cdb(struct mrsas_instance *instance, U8 cdb[],
+    struct IO_REQUEST_INFO *io_info, Mpi2RaidSCSIIORequest_t *scsi_io_request,
+    U32 ref_tag)
 {
 	uint16_t		EEDPFlags;
 	uint32_t		Control;
-	// Prepare 32-byte CDB if DIF is supported on this device
-	con_log(CL_ANN, (CE_NOTE, "Prepare DIF CDB\n"));
+	ddi_acc_handle_t acc_handle =
+	    instance->mpi2_frame_pool_dma_obj.acc_handle;
 
-	memset(cdb, 0, 32);	
-	
+	/* Prepare 32-byte CDB if DIF is supported on this device */
+	con_log(CL_ANN, (CE_NOTE, "Prepare DIF CDB"));
+
+	bzero(cdb, 32);
+
 	cdb[0] =  MRSAS_SCSI_VARIABLE_LENGTH_CMD;
 
-		
+
 	cdb[7] =  MRSAS_SCSI_ADDL_CDB_LEN;
 
-	if (io_info->isRead) {
+	if (io_info->isRead)
 		cdb[9] = MRSAS_SCSI_SERVICE_ACTION_READ32;
-	}
-	else {
+	else
 		cdb[9] = MRSAS_SCSI_SERVICE_ACTION_WRITE32;
-	}
 
-	cdb[10] = MRSAS_RD_WR_PROTECT;	// Verify with in linux driver, set to MEGASAS_RD_WR_PROTECT_CHECK_ALL
+	/* Verify within linux driver, set to MEGASAS_RD_WR_PROTECT_CHECK_ALL */
+	cdb[10] = MRSAS_RD_WR_PROTECT;
 
 	/* LOGICAL BLOCK ADDRESS */
-	cdb[12] = (U8)(((io_info->pdBlock) >> 56) & 0xff);	
+	cdb[12] = (U8)(((io_info->pdBlock) >> 56) & 0xff);
 	cdb[13] = (U8)(((io_info->pdBlock) >> 48) & 0xff);
-	cdb[14] = (U8)(((io_info->pdBlock) >> 40) & 0xff); 
-	cdb[15] = (U8)(((io_info->pdBlock) >> 32) & 0xff); 
-	cdb[16] = (U8)(((io_info->pdBlock) >> 24) & 0xff); 
-	cdb[17] = (U8)(((io_info->pdBlock) >> 16) & 0xff); 
-	cdb[18] = (U8)(((io_info->pdBlock) >> 8) & 0xff);  
-	cdb[19] = (U8)((io_info->pdBlock) & 0xff);         
+	cdb[14] = (U8)(((io_info->pdBlock) >> 40) & 0xff);
+	cdb[15] = (U8)(((io_info->pdBlock) >> 32) & 0xff);
+	cdb[16] = (U8)(((io_info->pdBlock) >> 24) & 0xff);
+	cdb[17] = (U8)(((io_info->pdBlock) >> 16) & 0xff);
+	cdb[18] = (U8)(((io_info->pdBlock) >> 8) & 0xff);
+	cdb[19] = (U8)((io_info->pdBlock) & 0xff);
 
 	/* Logical block reference tag */
-	ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-                            &scsi_io_request->CDB.EEDP32.PrimaryReferenceTag,
-							BIG_ENDIAN(ref_tag));	
-	
-	ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_io_request->CDB.EEDP32.PrimaryApplicationTagMask,
-	    0xffff);
+	ddi_put32(acc_handle, &scsi_io_request->CDB.EEDP32.PrimaryReferenceTag,
+	    BE_32(ref_tag));
 
-	ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-	    &scsi_io_request->DataLength,
+	ddi_put16(acc_handle,
+	    &scsi_io_request->CDB.EEDP32.PrimaryApplicationTagMask, 0xffff);
+
+	ddi_put32(acc_handle, &scsi_io_request->DataLength,
 	    ((io_info->numBlocks)*512));
-	ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-		&scsi_io_request->IoFlags,32);  /* Specify 32-byte cdb */
+	/* Specify 32-byte cdb */
+	ddi_put16(acc_handle, &scsi_io_request->IoFlags, 32);
 
 	/* Transfer length */
-	cdb[28] = (U8)(((io_info->numBlocks) >> 24) & 0xff);	
+	cdb[28] = (U8)(((io_info->numBlocks) >> 24) & 0xff);
 	cdb[29] = (U8)(((io_info->numBlocks) >> 16) & 0xff);
 	cdb[30] = (U8)(((io_info->numBlocks) >> 8) & 0xff);
 	cdb[31] = (U8)((io_info->numBlocks) & 0xff);
 
 	/* set SCSI IO EEDPFlags */
-	EEDPFlags = ddi_get16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-							&scsi_io_request->EEDPFlags);
-	Control = ddi_get32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-							&scsi_io_request->Control);
+	EEDPFlags = ddi_get16(acc_handle, &scsi_io_request->EEDPFlags);
+	Control = ddi_get32(acc_handle, &scsi_io_request->Control);
 
-	// set SCSI IO EEDPFlags bits
+	/* set SCSI IO EEDPFlags bits */
 	if (io_info->isRead) {
-		// For READ commands, the EEDPFlags shall be set to specify to
-		// Increment the Primary Reference Tag, to Check the Reference
-		// Tag, and to Check and Remove the Protection Information
-		// fields.
-		EEDPFlags	= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG	|
-			MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG	|
-			MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP	|
-			MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG	|
-			MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
+		/*
+		 * For READ commands, the EEDPFlags shall be set to specify to
+		 * Increment the Primary Reference Tag, to Check the Reference
+		 * Tag, and to Check and Remove the Protection Information
+		 * fields.
+		 */
+		EEDPFlags = MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG	|
+		    MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG	|
+		    MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP	|
+		    MPI2_SCSIIO_EEDPFLAGS_CHECK_APPTAG	|
+		    MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
+	} else {
+		/*
+		 * For WRITE commands, the EEDPFlags shall be set to specify to
+		 * Increment the Primary Reference Tag, and to Insert
+		 * Protection Information fields.
+		 */
+		EEDPFlags = MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG	|
+		    MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
 	}
-	else {
-		// For WRITE commands, the EEDPFlags shall be set to specify to
-		// Increment the Primary Reference Tag, and to Insert
-		// Protection Information fields.
-		EEDPFlags	= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG	|
-			MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
-	}
 	Control |= (0x4 << 26);
 
-	ddi_put16(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			&scsi_io_request->EEDPFlags, EEDPFlags);
-	ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,
-			&scsi_io_request->Control, Control);
-	ddi_put32(instance->mpi2_frame_pool_dma_obj.acc_handle,	
-	    &scsi_io_request->EEDPBlockSize,
-	    MRSAS_EEDPBLOCKSIZE);
+	ddi_put16(acc_handle, &scsi_io_request->EEDPFlags, EEDPFlags);
+	ddi_put32(acc_handle, &scsi_io_request->Control, Control);
+	ddi_put32(acc_handle,
+	    &scsi_io_request->EEDPBlockSize, MRSAS_EEDPBLOCKSIZE);
 }
 
 
@@ -3052,23 +3057,26 @@
  *
  * Used to set the PD LBA in CDB for FP IOs
  */
-void
-mrsas_tbolt_set_pd_lba(U8 cdb[], uint8_t *cdb_len_ptr, U64 start_blk, U32 num_blocks, U8 DifCapable)
+static void
+mrsas_tbolt_set_pd_lba(U8 cdb[], uint8_t *cdb_len_ptr, U64 start_blk,
+    U32 num_blocks)
 {
 	U8 cdb_len = *cdb_len_ptr;
 	U8 flagvals = 0, opcode = 0, groupnum = 0, control = 0;
 
 	/* Some drives don't support 16/12 byte CDB's, convert to 10 */
-	if (((cdb_len == 12) || (cdb_len == 16)) && 
-		 (start_blk <= 0xffffffff)) {
+	if (((cdb_len == 12) || (cdb_len == 16)) &&
+	    (start_blk <= 0xffffffff)) {
 		if (cdb_len == 16) {
-			con_log(CL_ANN, (CE_NOTE, "Converting READ/WRITE(16) to READ10\n"));
+			con_log(CL_ANN,
+			    (CE_NOTE, "Converting READ/WRITE(16) to READ10"));
 			opcode = cdb[0] == READ_16 ? READ_10 : WRITE_10;
 			flagvals = cdb[1];
 			groupnum = cdb[14];
 			control = cdb[15];
 		} else {
-			con_log(CL_ANN, (CE_NOTE, "Converting READ/WRITE(12) to READ10\n"));
+			con_log(CL_ANN,
+			    (CE_NOTE, "Converting READ/WRITE(12) to READ10"));
 			opcode = cdb[0] == READ_12 ? READ_10 : WRITE_10;
 			flagvals = cdb[1];
 			groupnum = cdb[10];
@@ -3075,7 +3083,7 @@
 			control = cdb[11];
 		}
 
-		memset(cdb, 0, sizeof(cdb));
+		bzero(cdb, sizeof (cdb));
 
 		cdb[0] = opcode;
 		cdb[1] = flagvals;
@@ -3086,93 +3094,94 @@
 		cdb[7] = (U8)((num_blocks >> 8) & 0xff);
 		cdb_len = 10;
 	} else if ((cdb_len < 16) && (start_blk > 0xffffffff)) {
-			/* Convert to 16 byte CDB for large LBA's */
-			con_log(CL_ANN, (CE_NOTE, "Converting 6/10/12 CDB to 16 byte CDB\n"));
-			switch (cdb_len) {
-			case 6:
-				opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
-				control = cdb[5];
-				break;
-			case 10:
-				opcode = cdb[0] == READ_10 ? READ_16 : WRITE_16;
-				flagvals = cdb[1];
-				groupnum = cdb[6];
-				control = cdb[9];
-				break;
-			case 12:
-				opcode = cdb[0] == READ_12 ? READ_16 : WRITE_16;
-				flagvals = cdb[1];
-				groupnum = cdb[10];
-				control = cdb[11];
-				break;
-			}
+		/* Convert to 16 byte CDB for large LBA's */
+		con_log(CL_ANN,
+		    (CE_NOTE, "Converting 6/10/12 CDB to 16 byte CDB"));
+		switch (cdb_len) {
+		case 6:
+			opcode = cdb[0] == READ_6 ? READ_16 : WRITE_16;
+			control = cdb[5];
+			break;
+		case 10:
+			opcode = cdb[0] == READ_10 ? READ_16 : WRITE_16;
+			flagvals = cdb[1];
+			groupnum = cdb[6];
+			control = cdb[9];
+			break;
+		case 12:
+			opcode = cdb[0] == READ_12 ? READ_16 : WRITE_16;
+			flagvals = cdb[1];
+			groupnum = cdb[10];
+			control = cdb[11];
+			break;
+		}
 
-			memset(cdb, 0, sizeof(cdb));
+		bzero(cdb, sizeof (cdb));
 
-			cdb[0] = opcode;
-			cdb[1] = flagvals;
-			cdb[14] = groupnum;
-			cdb[15] = control;
+		cdb[0] = opcode;
+		cdb[1] = flagvals;
+		cdb[14] = groupnum;
+		cdb[15] = control;
 
-			/* Transfer length */
-			cdb[13] = (U8)(num_blocks & 0xff);
-			cdb[12] = (U8)((num_blocks >> 8) & 0xff);
-			cdb[11] = (U8)((num_blocks >> 16) & 0xff);
-			cdb[10] = (U8)((num_blocks >> 24) & 0xff);
+		/* Transfer length */
+		cdb[13] = (U8)(num_blocks & 0xff);
+		cdb[12] = (U8)((num_blocks >> 8) & 0xff);
+		cdb[11] = (U8)((num_blocks >> 16) & 0xff);
+		cdb[10] = (U8)((num_blocks >> 24) & 0xff);
 
-			/* Specify 16-byte cdb */
-			cdb_len = 16;
-	} else 	if ((cdb_len == 6) && (start_blk > 0x1fffff)) {
-				/* convert to 10 byte CDB */
-				opcode = cdb[0] == READ_6 ? READ_10 : WRITE_10;
-				control = cdb[5];
-		
-				memset(cdb, 0, sizeof(cdb));
-				cdb[0] = opcode;
-				cdb[9] = control;
+		/* Specify 16-byte cdb */
+		cdb_len = 16;
+	} else if ((cdb_len == 6) && (start_blk > 0x1fffff)) {
+		/* convert to 10 byte CDB */
+		opcode = cdb[0] == READ_6 ? READ_10 : WRITE_10;
+		control = cdb[5];
 
-				/* Set transfer length */
-				cdb[8] = (U8)(num_blocks & 0xff);
-				cdb[7] = (U8)((num_blocks >> 8) & 0xff);
+		bzero(cdb, sizeof (cdb));
+		cdb[0] = opcode;
+		cdb[9] = control;
 
-				/* Specify 10-byte cdb */
-				cdb_len = 10;
+		/* Set transfer length */
+		cdb[8] = (U8)(num_blocks & 0xff);
+		cdb[7] = (U8)((num_blocks >> 8) & 0xff);
+
+		/* Specify 10-byte cdb */
+		cdb_len = 10;
 	}
 
 
 	/* Fall through Normal case, just load LBA here */
 	switch (cdb_len) {
-		case 6:
-		{
-			U8 val = cdb[1] & 0xE0;
-			cdb[3] = (U8)(start_blk & 0xff);
-			cdb[2] = (U8)((start_blk >> 8) & 0xff);
-			cdb[1] = val | ((U8)(start_blk >> 16) & 0x1f);
-			break;
-		}
-		case 10:
-			cdb[5] = (U8)(start_blk & 0xff);
-			cdb[4] = (U8)((start_blk >> 8) & 0xff);
-			cdb[3] = (U8)((start_blk >> 16) & 0xff);
-			cdb[2] = (U8)((start_blk >> 24) & 0xff);
-			break;
-		case 12:
-			cdb[5]    = (U8)(start_blk & 0xff);
-			cdb[4]    = (U8)((start_blk >> 8) & 0xff);
-			cdb[3]    = (U8)((start_blk >> 16) & 0xff);
-			cdb[2]    = (U8)((start_blk >> 24) & 0xff);
-			break;
+	case 6:
+	{
+		U8 val = cdb[1] & 0xE0;
+		cdb[3] = (U8)(start_blk & 0xff);
+		cdb[2] = (U8)((start_blk >> 8) & 0xff);
+		cdb[1] = val | ((U8)(start_blk >> 16) & 0x1f);
+		break;
+	}
+	case 10:
+		cdb[5] = (U8)(start_blk & 0xff);
+		cdb[4] = (U8)((start_blk >> 8) & 0xff);
+		cdb[3] = (U8)((start_blk >> 16) & 0xff);
+		cdb[2] = (U8)((start_blk >> 24) & 0xff);
+		break;
+	case 12:
+		cdb[5]	  = (U8)(start_blk & 0xff);
+		cdb[4]	  = (U8)((start_blk >> 8) & 0xff);
+		cdb[3]	  = (U8)((start_blk >> 16) & 0xff);
+		cdb[2]	  = (U8)((start_blk >> 24) & 0xff);
+		break;
 
-		case 16:
-			cdb[9]	= (U8)(start_blk & 0xff);
-			cdb[8]	= (U8)((start_blk >> 8) & 0xff);
-			cdb[7]	= (U8)((start_blk >> 16) & 0xff);
-			cdb[6]	= (U8)((start_blk >> 24) & 0xff);
-			cdb[5]	= (U8)((start_blk >> 32) & 0xff);
-			cdb[4]	= (U8)((start_blk >> 40) & 0xff);
-			cdb[3]	= (U8)((start_blk >> 48) & 0xff);
-			cdb[2]	= (U8)((start_blk >> 56) & 0xff);
-			break;
+	case 16:
+		cdb[9]	= (U8)(start_blk & 0xff);
+		cdb[8]	= (U8)((start_blk >> 8) & 0xff);
+		cdb[7]	= (U8)((start_blk >> 16) & 0xff);
+		cdb[6]	= (U8)((start_blk >> 24) & 0xff);
+		cdb[5]	= (U8)((start_blk >> 32) & 0xff);
+		cdb[4]	= (U8)((start_blk >> 40) & 0xff);
+		cdb[3]	= (U8)((start_blk >> 48) & 0xff);
+		cdb[2]	= (U8)((start_blk >> 56) & 0xff);
+		break;
 	}
 
 	*cdb_len_ptr = cdb_len;
@@ -3179,7 +3188,7 @@
 }
 
 
-U8
+static int
 mrsas_tbolt_check_map_info(struct mrsas_instance *instance)
 {
 	MR_FW_RAID_MAP_ALL *ld_map;
@@ -3188,16 +3197,18 @@
 
 		ld_map = instance->ld_map[(instance->map_id & 1)];
 
-		con_log(CL_ANN1, (CE_NOTE, "ldCount=%d, map size=%d\n",
+		con_log(CL_ANN1, (CE_NOTE, "ldCount=%d, map size=%d",
 		    ld_map->raidMap.ldCount, ld_map->raidMap.totalSize));
 
-		if (MR_ValidateMapInfo(instance->ld_map[(instance->map_id & 1)], instance->load_balance_info)) {
-			con_log(CL_ANN, (CE_CONT,
-				"MR_ValidateMapInfo success"));
+		if (MR_ValidateMapInfo(instance->ld_map[
+		    (instance->map_id & 1)], instance->load_balance_info)) {
+			con_log(CL_ANN,
+			    (CE_CONT, "MR_ValidateMapInfo success"));
 
-			instance->fast_path_io = 1;  
-			con_log(CL_ANN, (CE_NOTE,
-		    		"instance->fast_path_io %d \n",instance->fast_path_io));
+			instance->fast_path_io = 1;
+			con_log(CL_ANN,
+			    (CE_NOTE, "instance->fast_path_io %d",
+			    instance->fast_path_io));
 
 			return (DDI_SUCCESS);
 		}
@@ -3204,14 +3215,14 @@
 
 	}
 
-	instance->fast_path_io = 0;	
+	instance->fast_path_io = 0;
 	cmn_err(CE_WARN, "MR_ValidateMapInfo failed");
 	con_log(CL_ANN, (CE_NOTE,
-    		"instance->fast_path_io %d \n",instance->fast_path_io));
+	    "instance->fast_path_io %d", instance->fast_path_io));
 
-	
 	return (DDI_FAILURE);
 }
+
 /*
  * Marks HBA as bad. This will be called either when an
  * IO packet times out even after 3 FW resets
@@ -3218,16 +3229,16 @@
  * or FW is found to be fault even after 3 continuous resets.
  */
 
-int
+void
 mrsas_tbolt_kill_adapter(struct mrsas_instance *instance)
 {
-	cmn_err(CE_WARN, "TBOLT Kill adapter called\n");
+	cmn_err(CE_NOTE, "TBOLT Kill adapter called");
 
 	if (instance->deadadapter == 1)
-		return (DDI_FAILURE);
+		return;
 
 	con_log(CL_ANN1, (CE_NOTE, "tbolt_kill_adapter: "
-		    "Writing to doorbell with MFI_STOP_ADP "));
+	    "Writing to doorbell with MFI_STOP_ADP "));
 	mutex_enter(&instance->ocr_flags_mtx);
 	instance->deadadapter = 1;
 	mutex_exit(&instance->ocr_flags_mtx);
@@ -3234,18 +3245,19 @@
 	instance->func_ptr->disable_intr(instance);
 	WR_RESERVED0_REGISTER(MFI_STOP_ADP, instance);
 	/* Flush */
-	RD_RESERVED0_REGISTER(instance);	
+	(void) RD_RESERVED0_REGISTER(instance);
 
 	(void) mrsas_print_pending_cmds(instance);
-	mrsas_complete_pending_cmds(instance);
-	return (DDI_SUCCESS);
+	(void) mrsas_complete_pending_cmds(instance);
 }
-void  mrsas_reset_reply_desc(struct mrsas_instance *instance)
+
+void
+mrsas_reset_reply_desc(struct mrsas_instance *instance)
 {
 	int i;
-	MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;	
-	instance->reply_read_index= 0;
-	
+	MPI2_REPLY_DESCRIPTORS_UNION *reply_desc;
+	instance->reply_read_index = 0;
+
 	/* initializing reply address to 0xFFFFFFFF */
 	reply_desc = instance->reply_frame_pool;
 
@@ -3258,17 +3270,15 @@
 int
 mrsas_tbolt_reset_ppc(struct mrsas_instance *instance)
 {
-	uint32_t status=0x00;
+	uint32_t status = 0x00;
 	uint32_t retry = 0;
-	uint32_t seq_num;
 	uint32_t cur_abs_reg_val;
 	uint32_t fw_state;
-	union mrsas_evt_class_locale	class_locale;
 	uint32_t abs_state;
 	uint32_t i;
 
 	con_log(CL_ANN, (CE_NOTE,
-	    "mrsas_tbolt_reset_ppc entered\n "));
+	    "mrsas_tbolt_reset_ppc entered"));
 
 	if (instance->deadadapter == 1) {
 		cmn_err(CE_WARN, "mrsas_tbolt_reset_ppc: "
@@ -3284,12 +3294,12 @@
 
 	instance->func_ptr->disable_intr(instance);
 
-	/*Add delay inorder to complete the ioctl & io cmds in-flight */
-	for (i = 0; i<3000; i++) {
+	/* Add delay inorder to complete the ioctl & io cmds in-flight */
+	for (i = 0; i < 3000; i++) {
 		drv_usecwait(MILLISEC); /* wait for 1000 usecs */
 	}
 
-	instance->reply_read_index= 0;
+	instance->reply_read_index = 0;
 
 retry_reset:
 	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
@@ -3303,13 +3313,13 @@
 	WR_TBOLT_IB_WRITE_SEQ(0xd, instance);
 	con_log(CL_ANN1, (CE_NOTE,
 	    "mrsas_tbolt_reset_ppc: magic number written "
-	    "to write sequence register\n"));
+	    "to write sequence register"));
 	delay(100 * drv_usectohz(MILLISEC));
 	status = RD_TBOLT_HOST_DIAG(instance);
 	con_log(CL_ANN1, (CE_NOTE,
 	    "mrsas_tbolt_reset_ppc: READ HOSTDIAG SUCCESS "
-	    "to write sequence register\n"));
-        
+	    "to write sequence register"));
+
 	while (status & DIAG_TBOLT_RESET_ADAPTER) {
 		delay(100 * drv_usectohz(MILLISEC));
 		status = RD_TBOLT_HOST_DIAG(instance);
@@ -3317,7 +3327,7 @@
 			cmn_err(CE_WARN,
 			    "mrsas_tbolt_reset_ppc:"
 			    "resetadapter bit is set already "
-			    "check retry count %d\n", retry);
+			    "check retry count %d", retry);
 			return (DDI_FAILURE);
 		}
 	}
@@ -3325,28 +3335,31 @@
 	WR_TBOLT_HOST_DIAG(status | DIAG_TBOLT_RESET_ADAPTER, instance);
 	delay(100 * drv_usectohz(MILLISEC));
 
-	ddi_rep_get8((instance)->regmap_handle, (uint8_t *)&status, 
-		(uint8_t *)((uintptr_t)(instance)->regmap + 
-		RESET_TBOLT_STATUS_OFF),4,DDI_DEV_AUTOINCR); 
-	
+	ddi_rep_get8((instance)->regmap_handle, (uint8_t *)&status,
+	    (uint8_t *)((uintptr_t)(instance)->regmap +
+	    RESET_TBOLT_STATUS_OFF), 4, DDI_DEV_AUTOINCR);
+
 	while ((status & DIAG_TBOLT_RESET_ADAPTER)) {
 		delay(100 * drv_usectohz(MILLISEC));
-		ddi_rep_get8((instance)->regmap_handle, (uint8_t *)&status, 
-			(uint8_t *)((uintptr_t)(instance)->regmap + 
-			RESET_TBOLT_STATUS_OFF),4,DDI_DEV_AUTOINCR); 
+		ddi_rep_get8((instance)->regmap_handle, (uint8_t *)&status,
+		    (uint8_t *)((uintptr_t)(instance)->regmap +
+		    RESET_TBOLT_STATUS_OFF), 4, DDI_DEV_AUTOINCR);
 		if (retry++ == 100) {
 			/* Dont call kill adapter here */
-			/* RESET BIT ADAPTER is cleared by firmare */	
-			//mrsas_tbolt_kill_adapter(instance);
-			cmn_err(CE_WARN, "mr_sas %d: %s(): RESET FAILED; return failure!!!", instance->instance, __func__);
+			/* RESET BIT ADAPTER is cleared by firmare */
+			/* mrsas_tbolt_kill_adapter(instance); */
+			cmn_err(CE_WARN,
+			    "mr_sas %d: %s(): RESET FAILED; return failure!!!",
+			    instance->instance, __func__);
 			return (DDI_FAILURE);
 		}
 	}
-	
-	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc: Adapter reset complete"));
+
+	con_log(CL_ANN,
+	    (CE_NOTE, "mrsas_tbolt_reset_ppc: Adapter reset complete"));
 	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
 	    "Calling mfi_state_transition_to_ready"));
-	
+
 	abs_state = instance->func_ptr->read_fw_status_reg(instance);
 	retry = 0;
 	while ((abs_state <= MFI_STATE_FW_INIT) && (retry++ < 1000)) {
@@ -3354,8 +3367,9 @@
 		abs_state = instance->func_ptr->read_fw_status_reg(instance);
 	}
 	if (abs_state <= MFI_STATE_FW_INIT) {
-		cmn_err(CE_WARN, "mrsas_tbolt_reset_ppc: firmware state < MFI_STATE_FW_INIT" 
-		    "state = 0x%x, RETRY RESET.\n", abs_state);
+		cmn_err(CE_WARN,
+		    "mrsas_tbolt_reset_ppc: firmware state < MFI_STATE_FW_INIT"
+		    "state = 0x%x, RETRY RESET.", abs_state);
 		goto retry_reset;
 	}
 
@@ -3372,25 +3386,27 @@
 		if (debug_tbolt_fw_faults_after_ocr_g == 1)
 			fw_state = MFI_STATE_FAULT;
 
-		con_log(CL_ANN, (CE_NOTE,  "mrsas_tbolt_reset_ppc : FW is not ready "
+		con_log(CL_ANN,
+		    (CE_NOTE,  "mrsas_tbolt_reset_ppc : FW is not ready "
 		    "FW state = 0x%x", fw_state));
 
 		if (fw_state == MFI_STATE_FAULT) {
-			// increment the count
+			/* increment the count */
 			instance->fw_fault_count_after_ocr++;
 			if (instance->fw_fault_count_after_ocr
 			    < MAX_FW_RESET_COUNT) {
 				cmn_err(CE_WARN, "mrsas_tbolt_reset_ppc: "
 				    "FW is in fault after OCR count %d "
-					"Retry Reset",
+				    "Retry Reset",
 				    instance->fw_fault_count_after_ocr);
 				goto retry_reset;
 
 			} else {
 				cmn_err(CE_WARN, "mrsas %d: %s:"
-					"Max Reset Count exceeded >%d"
+				    "Max Reset Count exceeded >%d"
 				    "Mark HBA as bad, KILL adapter",
-					instance->instance, __func__, MAX_FW_RESET_COUNT);
+				    instance->instance, __func__,
+				    MAX_FW_RESET_COUNT);
 
 				mrsas_tbolt_kill_adapter(instance);
 				return (DDI_FAILURE);
@@ -3397,29 +3413,29 @@
 			}
 		}
 	}
-	
-	// reset the counter as FW is up after OCR
+
+	/* reset the counter as FW is up after OCR */
 	instance->fw_fault_count_after_ocr = 0;
-	
+
 	mrsas_reset_reply_desc(instance);
 
-	
+
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
 	    "Calling mrsas_issue_init_mpi2"));
 	abs_state = mrsas_issue_init_mpi2(instance);
-	if(abs_state == DDI_FAILURE) {
-	cmn_err(CE_WARN, "mrsas_tbolt_reset_ppc: "
-	    "INIT failed Retrying Reset");
-		goto retry_reset;	
+	if (abs_state == (uint32_t)DDI_FAILURE) {
+		cmn_err(CE_WARN, "mrsas_tbolt_reset_ppc: "
+		    "INIT failed Retrying Reset");
+		goto retry_reset;
 	}
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
 	    "mrsas_issue_init_mpi2 Done"));
 
 	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
-	    "Calling mrsas_print_pending_cmd\n"));
-	mrsas_print_pending_cmds(instance);
+	    "Calling mrsas_print_pending_cmd"));
+	(void) mrsas_print_pending_cmds(instance);
 	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
-	    "mrsas_print_pending_cmd done\n"));
+	    "mrsas_print_pending_cmd done"));
 
 	instance->func_ptr->enable_intr(instance);
 	instance->fw_outstanding = 0;
@@ -3426,9 +3442,9 @@
 
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
 	    "Calling mrsas_issue_pending_cmds"));
-	mrsas_issue_pending_cmds(instance);
+	(void) mrsas_issue_pending_cmds(instance);
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
-	"issue_pending_cmds done.\n"));
+	"issue_pending_cmds done."));
 
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
 	    "Calling aen registration"));
@@ -3438,7 +3454,7 @@
 
 	instance->func_ptr->issue_cmd(instance->aen_cmd, instance);
 
-	con_log(CL_ANN1, (CE_NOTE, "Unsetting adpresetinprogress flag.\n"));
+	con_log(CL_ANN1, (CE_NOTE, "Unsetting adpresetinprogress flag."));
 	mutex_enter(&instance->ocr_flags_mtx);
 	instance->adapterresetinprogress = 0;
 	mutex_exit(&instance->ocr_flags_mtx);
@@ -3445,7 +3461,7 @@
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_reset_ppc: "
 	    "adpterresetinprogress flag unset"));
 
-	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc done\n"));
+	con_log(CL_ANN, (CE_NOTE, "mrsas_tbolt_reset_ppc done"));
 	return (DDI_SUCCESS);
 
 }
@@ -3460,10 +3476,10 @@
  * supported by the FW.
  */
 
-int
+static int
 mrsas_tbolt_sync_map_info(struct mrsas_instance *instance)
 {
-	int 			ret = 0, i;
+	int			ret = 0, i;
 	struct mrsas_cmd	*cmd = NULL;
 	struct mrsas_dcmd_frame	*dcmd;
 	uint32_t size_sync_info, num_lds;
@@ -3475,20 +3491,20 @@
 	uint32_t size_map_info;
 
 	cmd = get_raid_msg_pkt(instance);
-	
+
 	if (cmd == NULL) {
-		cmn_err(CE_WARN,
-		    "Failed to get a cmd from free-pool in mrsas_tbolt_sync_map_info(). ");
+		cmn_err(CE_WARN, "Failed to get a cmd from free-pool in "
+		    "mrsas_tbolt_sync_map_info(). ");
 		return (DDI_FAILURE);
 	}
-		
+
 	/* Clear the frame buffer and assign back the context id */
-	(void) memset((char *)&cmd->frame[0], 0, sizeof (union mrsas_frame));
+	bzero((char *)&cmd->frame[0], sizeof (union mrsas_frame));
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &cmd->frame->hdr.context,
-			cmd->index);
+	    cmd->index);
 	bzero(cmd->scsi_io_request, sizeof (Mpi2RaidSCSIIORequest_t));
 
-	
+
 	map = instance->ld_map[instance->map_id & 1];
 
 	num_lds = map->raidMap.ldCount;
@@ -3497,16 +3513,15 @@
 
 	size_sync_info = sizeof (LD_TARGET_SYNC) * num_lds;
 
-	con_log(CL_ANN, (CE_NOTE,
-		    "size_sync_info =0x%x ; ld count = 0x%x \n ",
-		    size_sync_info, num_lds));
+	con_log(CL_ANN, (CE_NOTE, "size_sync_info =0x%x ; ld count = 0x%x",
+	    size_sync_info, num_lds));
 
- 	ci = (LD_TARGET_SYNC *)instance->ld_map[(instance->map_id - 1) & 1];
+	ci = (LD_TARGET_SYNC *)instance->ld_map[(instance->map_id - 1) & 1];
 
-	memset(ci, 0, sizeof(MR_FW_RAID_MAP_ALL));
+	bzero(ci, sizeof (MR_FW_RAID_MAP_ALL));
 	ci_h = instance->ld_map_phy[(instance->map_id - 1) & 1];
 
-	(void) memset(dcmd->mbox.b, 0, DCMD_MBOX_SZ);
+	bzero(dcmd->mbox.b, DCMD_MBOX_SZ);
 
 	ld_sync = (LD_TARGET_SYNC *)ci;
 
@@ -3513,12 +3528,13 @@
 	for (i = 0; i < num_lds; i++, ld_sync++) {
 		raid = MR_LdRaidGet(i, map);
 
-		con_log(CL_ANN1, (CE_NOTE, "i : 0x%x, Seq Num : 0x%x, Sync Reqd : 0x%x\n",
+		con_log(CL_ANN1,
+		    (CE_NOTE, "i : 0x%x, Seq Num : 0x%x, Sync Reqd : 0x%x",
 		    i, raid->seqNum, raid->flags.ldSyncRequired));
 
 		ld_sync->ldTargetId = MR_GetLDTgtId(i, map);
 
-		con_log(CL_ANN1, (CE_NOTE, "i : 0x%x, tgt : 0x%x \n",
+		con_log(CL_ANN1, (CE_NOTE, "i : 0x%x, tgt : 0x%x",
 		    i, ld_sync->ldTargetId));
 
 		ld_sync->seqNum = raid->seqNum;
@@ -3525,8 +3541,8 @@
 	}
 
 
-	size_map_info = sizeof(MR_FW_RAID_MAP) +
-		(sizeof(MR_LD_SPAN_MAP) * (MAX_LOGICAL_DRIVES - 1));
+	size_map_info = sizeof (MR_FW_RAID_MAP) +
+	    (sizeof (MR_LD_SPAN_MAP) * (MAX_LOGICAL_DRIVES - 1));
 
 	dcmd->cmd = MFI_CMD_OP_DCMD;
 	dcmd->cmd_status = 0xFF;
@@ -3535,7 +3551,8 @@
 	dcmd->timeout = 0;
 	dcmd->pad_0 = 0;
 	dcmd->data_xfer_len = size_map_info;
-	dcmd->mbox.b[0] = num_lds;
+	ASSERT(num_lds <= 255);
+	dcmd->mbox.b[0] = (U8)num_lds;
 	dcmd->mbox.b[1] = 1; /* Pend */
 	dcmd->opcode = MR_DCMD_LD_MAP_GET_INFO;
 	dcmd->sgl.sge32[0].phys_addr = ci_h;
@@ -3546,9 +3563,9 @@
 	mr_sas_tbolt_build_mfi_cmd(instance, cmd);
 
 	instance->func_ptr->issue_cmd(cmd, instance);
-	
+
 	instance->unroll.syncCmd = 1;
-	con_log(CL_ANN1, (CE_NOTE, "sync cmd issued. [SMID]:%x",cmd->SMID));
+	con_log(CL_ANN1, (CE_NOTE, "sync cmd issued. [SMID]:%x", cmd->SMID));
 
 	return (ret);
 }
@@ -3575,7 +3592,7 @@
 		return (DDI_FAILURE);
 	}
 	/* Clear the frame buffer and assign back the context id */
-	(void) memset((char *)&cmd->frame[0], 0, sizeof (union mrsas_frame));
+	bzero((char *)&cmd->frame[0], sizeof (union mrsas_frame));
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &cmd->frame->hdr.context,
 	    cmd->index);
 
@@ -3623,9 +3640,7 @@
 	dev_info_t *child;
 	int rval, dtype;
 	struct mrsas_tbolt_pd_info *pds = NULL;
-	uint64_t *wwn;
 
-
 	con_log(CL_ANN1, (CE_NOTE, "mrsas_tbolt_config_pd: t = %d l = %d",
 	    tgt, lun));
 
@@ -3635,10 +3650,10 @@
 		}
 		if (instance->mr_tbolt_pd_list[tgt].flag != MRDRV_TGT_VALID) {
 			rval = mrsas_service_evt(instance, tgt, 1,
-				MRSAS_EVT_UNCONFIG_TGT, NULL);
+			    MRSAS_EVT_UNCONFIG_TGT, NULL);
 			con_log(CL_ANN1, (CE_WARN,
-				"mr_sas:DELETING STALE ENTRY  rval = %d "
-				"tgt id = %d ", rval, tgt));
+			    "mr_sas:DELETING STALE ENTRY  rval = %d "
+			    "tgt id = %d", rval, tgt));
 			return (NDI_FAILURE);
 		}
 		return (NDI_SUCCESS);
@@ -3649,10 +3664,11 @@
 	mrsas_tbolt_get_pd_info(instance, pds, tgt);
 	dtype = pds->scsiDevType;
 
-	/* Check for Disk*/
+	/* Check for Disk */
 	if ((dtype == DTYPE_DIRECT)) {
 		if ((dtype == DTYPE_DIRECT) &&
 		    (LE_16(pds->fwState) != PD_SYSTEM)) {
+			kmem_free(pds, sizeof (struct mrsas_tbolt_pd_info));
 			return (NDI_FAILURE);
 		}
 		sd = kmem_zalloc(sizeof (struct scsi_device), KM_SLEEP);
@@ -3667,8 +3683,8 @@
 			    tgt, dtype, sd->sd_inq->inq_vid));
 		} else {
 			rval = NDI_FAILURE;
-			con_log(CL_DLEVEL1, (CE_NOTE,
-			    "Phys. device Not found scsi_hba_probe Failed: tgt %d dtype %d: %s",
+			con_log(CL_DLEVEL1, (CE_NOTE, "Phys. device Not found "
+			    "scsi_hba_probe Failed: tgt %d dtype %d: %s",
 			    tgt, dtype, sd->sd_inq->inq_vid));
 		}
 
@@ -3691,9 +3707,10 @@
 	    rval));
 	return (rval);
 }
+
 static void
-mrsas_tbolt_get_pd_info(struct mrsas_instance *instance, struct mrsas_tbolt_pd_info *pds,
-    int tgt)
+mrsas_tbolt_get_pd_info(struct mrsas_instance *instance,
+    struct mrsas_tbolt_pd_info *pds, int tgt)
 {
 	struct mrsas_cmd	*cmd;
 	struct mrsas_dcmd_frame	*dcmd;
@@ -3702,12 +3719,13 @@
 	cmd = get_raid_msg_pkt(instance);
 
 	if (!cmd) {
-            con_log(CL_ANN1, (CE_WARN, "Failed to get a cmd for get pd info"));
-            return;
-        }
+		con_log(CL_ANN1,
+		    (CE_WARN, "Failed to get a cmd for get pd info"));
+		return;
+	}
 
-        /* Clear the frame buffer and assign back the context id */
-        memset((char *)&cmd->frame[0], 0, sizeof (union mrsas_frame));
+	/* Clear the frame buffer and assign back the context id */
+	bzero((char *)&cmd->frame[0], sizeof (union mrsas_frame));
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &cmd->frame->hdr.context,
 	    cmd->index);
 
@@ -3722,12 +3740,13 @@
 
 	(void) mrsas_alloc_dma_obj(instance, &dcmd_dma_obj,
 	    DDI_STRUCTURE_LE_ACC);
-	(void) memset(dcmd_dma_obj.buffer, 0, sizeof (struct mrsas_tbolt_pd_info));
-	(void) memset(dcmd->mbox.b, 0, 12);
+	bzero(dcmd_dma_obj.buffer, sizeof (struct mrsas_tbolt_pd_info));
+	bzero(dcmd->mbox.b, 12);
 	ddi_put8(cmd->frame_dma_obj.acc_handle, &dcmd->cmd, MFI_CMD_OP_DCMD);
 	ddi_put8(cmd->frame_dma_obj.acc_handle, &dcmd->cmd_status, 0);
 	ddi_put8(cmd->frame_dma_obj.acc_handle, &dcmd->sge_count, 1);
-	ddi_put16(cmd->frame_dma_obj.acc_handle, &dcmd->flags, MFI_FRAME_DIR_READ);
+	ddi_put16(cmd->frame_dma_obj.acc_handle, &dcmd->flags,
+	    MFI_FRAME_DIR_READ);
 	ddi_put16(cmd->frame_dma_obj.acc_handle, &dcmd->timeout, 0);
 	ddi_put32(cmd->frame_dma_obj.acc_handle, &dcmd->data_xfer_len,
 	    sizeof (struct mrsas_tbolt_pd_info));
@@ -3743,11 +3762,11 @@
 	cmd->frame_count = 1;
 
 	if (instance->tbolt) {
-                mr_sas_tbolt_build_mfi_cmd(instance, cmd);
-        }
+		mr_sas_tbolt_build_mfi_cmd(instance, cmd);
+	}
 
 	instance->func_ptr->issue_cmd_in_sync_mode(instance, cmd);
-	
+
 	ddi_rep_get8(cmd->frame_dma_obj.acc_handle, (uint8_t *)pds,
 	    (uint8_t *)dcmd_dma_obj.buffer, sizeof (struct mrsas_tbolt_pd_info),
 	    DDI_DEV_AUTOINCR);
