--- old/usr/src/uts/common/io/1394/targets/scsa1394/hba.c	2013-12-01 10:18:18.180739071 -0500
+++ new/usr/src/uts/common/io/1394/targets/scsa1394/hba.c	2013-12-01 10:18:18.206190718 -0500
@@ -56,8 +56,6 @@
 static void	scsa1394_detach_threads(scsa1394_state_t *);
 static int	scsa1394_attach_scsa(scsa1394_state_t *);
 static void	scsa1394_detach_scsa(scsa1394_state_t *);
-static int	scsa1394_create_cmd_cache(scsa1394_state_t *);
-static void	scsa1394_destroy_cmd_cache(scsa1394_state_t *);
 static int	scsa1394_add_events(scsa1394_state_t *);
 static void	scsa1394_remove_events(scsa1394_state_t *);
 
@@ -98,11 +96,6 @@
 		struct scsi_pkt *);
 
 /* pkt resource allocation routines */
-static int	scsa1394_cmd_cache_constructor(void *, void *, int);
-static void	scsa1394_cmd_cache_destructor(void *, void *);
-static int	scsa1394_cmd_ext_alloc(scsa1394_state_t *, scsa1394_cmd_t *,
-		int);
-static void	scsa1394_cmd_ext_free(scsa1394_state_t *, scsa1394_cmd_t *);
 static int	scsa1394_cmd_cdb_dma_alloc(scsa1394_state_t *, scsa1394_cmd_t *,
 		int, int (*)(), caddr_t);
 static void	scsa1394_cmd_cdb_dma_free(scsa1394_state_t *, scsa1394_cmd_t *);
@@ -306,13 +299,8 @@
 		return (DDI_FAILURE);
 	}
 
-	if (scsa1394_create_cmd_cache(sp) != DDI_SUCCESS) {
-		scsa1394_cleanup(sp, 5);
-		return (DDI_FAILURE);
-	}
-
 	if (scsa1394_add_events(sp) != DDI_SUCCESS) {
-		scsa1394_cleanup(sp, 6);
+		scsa1394_cleanup(sp, 5);
 		return (DDI_FAILURE);
 	}
 
@@ -459,11 +447,8 @@
 	default:
 		scsa1394_remove_events(sp);
 		/* FALLTHRU */
-	case 6:
-		scsa1394_detach_scsa(sp);
-		/* FALLTHRU */
 	case 5:
-		scsa1394_destroy_cmd_cache(sp);
+		scsa1394_detach_scsa(sp);
 		/* FALLTHRU */
 	case 4:
 		scsa1394_detach_threads(sp);
@@ -597,26 +582,6 @@
 }
 
 static int
-scsa1394_create_cmd_cache(scsa1394_state_t *sp)
-{
-	char	name[64];
-
-	(void) sprintf(name, "scsa1394%d_cache", sp->s_instance);
-	sp->s_cmd_cache = kmem_cache_create(name,
-	    SCSA1394_CMD_SIZE, sizeof (void *),
-	    scsa1394_cmd_cache_constructor, scsa1394_cmd_cache_destructor,
-	    NULL, (void *)sp, NULL, 0);
-
-	return ((sp->s_cmd_cache == NULL) ? DDI_FAILURE : DDI_SUCCESS);
-}
-
-static void
-scsa1394_destroy_cmd_cache(scsa1394_state_t *sp)
-{
-	kmem_cache_destroy(sp->s_cmd_cache);
-}
-
-static int
 scsa1394_add_events(scsa1394_state_t *sp)
 {
 	ddi_eventcookie_t	br_evc, rem_evc, ins_evc;
@@ -1295,36 +1260,17 @@
 	 */
 	if (pkt == NULL) {
 		is_new = B_TRUE;
-		if ((cmd = kmem_cache_alloc(sp->s_cmd_cache, kf)) == NULL) {
+		pkt = scsi_hba_pkt_alloc(NULL, ap, max(SCSI_CDB_SIZE, cmdlen),
+		    statuslen, tgtlen, sizeof (scsa1394_cmd_t), callback, arg);
+		if (!pkt)
 			return (NULL);
-		}
 
 		/* initialize cmd */
-		pkt = &cmd->sc_scsi_pkt;
-		pkt->pkt_ha_private	= cmd;
-		pkt->pkt_address	= *ap;
-		pkt->pkt_private	= cmd->sc_priv;
-		pkt->pkt_scbp		= (uchar_t *)&cmd->sc_scb;
-		pkt->pkt_cdbp		= (uchar_t *)&cmd->sc_pkt_cdb;
-		pkt->pkt_resid		= 0;
-
-		cmd->sc_lun		= lp;
-		cmd->sc_pkt		= pkt;
-		cmd->sc_cdb_len		= cmdlen;
-		cmd->sc_scb_len		= statuslen;
-		cmd->sc_priv_len	= tgtlen;
-
-		/* need external space? */
-		if ((cmdlen > sizeof (cmd->sc_pkt_cdb)) ||
-		    (statuslen > sizeof (cmd->sc_scb)) ||
-		    (tgtlen > sizeof (cmd->sc_priv))) {
-			if (scsa1394_cmd_ext_alloc(sp, cmd, kf) !=
-			    DDI_SUCCESS) {
-				kmem_cache_free(sp->s_cmd_cache, cmd);
-				lp->l_stat.stat_err_pkt_kmem_alloc++;
-				return (NULL);
-			}
-		}
+		cmd = pkt->pkt_ha_private;
+		cmd->sc_lun = lp;
+		cmd->sc_pkt = pkt;
+		cmd->sc_orig_cdblen = cmdlen;
+		cmd->sc_task.ts_drv_priv = cmd;
 
 		/* allocate DMA resources for CDB */
 		if (scsa1394_cmd_cdb_dma_alloc(sp, cmd, flags, callback, arg) !=
@@ -1389,11 +1335,8 @@
 		bp_mapout(cmd->sc_bp);
 		cmd->sc_flags &= ~SCSA1394_CMD_DMA_BUF_MAPIN;
 	}
-	if (cmd->sc_flags & SCSA1394_CMD_EXT) {
-		scsa1394_cmd_ext_free(sp, cmd);
-	}
 
-	kmem_cache_free(sp->s_cmd_cache, cmd);
+	scsi_hba_pkt_free(ap, pkt);
 }
 
 static void
@@ -1413,81 +1356,6 @@
 
 /*ARGSUSED*/
 static int
-scsa1394_cmd_cache_constructor(void *buf, void *cdrarg, int kf)
-{
-	scsa1394_cmd_t	*cmd = buf;
-
-	bzero(buf, SCSA1394_CMD_SIZE);
-	cmd->sc_task.ts_drv_priv = cmd;
-
-	return (0);
-}
-
-/*ARGSUSED*/
-static void
-scsa1394_cmd_cache_destructor(void *buf, void *cdrarg)
-{
-}
-
-/*
- * allocate and deallocate external cmd space (ie. not part of scsa1394_cmd_t)
- * for non-standard length cdb, pkt_private, status areas
- */
-static int
-scsa1394_cmd_ext_alloc(scsa1394_state_t *sp, scsa1394_cmd_t *cmd, int kf)
-{
-	struct scsi_pkt	*pkt = cmd->sc_pkt;
-	void		*buf;
-
-	if (cmd->sc_cdb_len > sizeof (cmd->sc_pkt_cdb)) {
-		if ((buf = kmem_zalloc(cmd->sc_cdb_len, kf)) == NULL) {
-			return (DDI_FAILURE);
-		}
-		pkt->pkt_cdbp = buf;
-		cmd->sc_flags |= SCSA1394_CMD_CDB_EXT;
-	}
-
-	if (cmd->sc_scb_len > sizeof (cmd->sc_scb)) {
-		if ((buf = kmem_zalloc(cmd->sc_scb_len, kf)) == NULL) {
-			scsa1394_cmd_ext_free(sp, cmd);
-			return (DDI_FAILURE);
-		}
-		pkt->pkt_scbp = buf;
-		cmd->sc_flags |= SCSA1394_CMD_SCB_EXT;
-	}
-
-	if (cmd->sc_priv_len > sizeof (cmd->sc_priv)) {
-		if ((buf = kmem_zalloc(cmd->sc_priv_len, kf)) == NULL) {
-			scsa1394_cmd_ext_free(sp, cmd);
-			return (DDI_FAILURE);
-		}
-		pkt->pkt_private = buf;
-		cmd->sc_flags |= SCSA1394_CMD_PRIV_EXT;
-	}
-
-	return (DDI_SUCCESS);
-}
-
-/*ARGSUSED*/
-static void
-scsa1394_cmd_ext_free(scsa1394_state_t *sp, scsa1394_cmd_t *cmd)
-{
-	struct scsi_pkt	*pkt = cmd->sc_pkt;
-
-	if (cmd->sc_flags & SCSA1394_CMD_CDB_EXT) {
-		kmem_free(pkt->pkt_cdbp, cmd->sc_cdb_len);
-	}
-	if (cmd->sc_flags & SCSA1394_CMD_SCB_EXT) {
-		kmem_free(pkt->pkt_scbp, cmd->sc_scb_len);
-	}
-	if (cmd->sc_flags & SCSA1394_CMD_PRIV_EXT) {
-		kmem_free(pkt->pkt_private, cmd->sc_priv_len);
-	}
-	cmd->sc_flags &= ~SCSA1394_CMD_EXT;
-}
-
-/*ARGSUSED*/
-static int
 scsa1394_cmd_cdb_dma_alloc(scsa1394_state_t *sp, scsa1394_cmd_t *cmd,
     int flags, int (*callback)(), caddr_t arg)
 {
@@ -2041,8 +1909,6 @@
 static void
 scsa1394_cmd_fill_cdb(scsa1394_lun_t *lp, scsa1394_cmd_t *cmd)
 {
-	cmd->sc_cdb_actual_len = cmd->sc_cdb_len;
-
 	mutex_enter(&lp->l_mutex);
 
 	switch (lp->l_dtype_orig) {
@@ -2080,13 +1946,13 @@
 		lba = SCSA1394_LBA_6BYTE(pkt);
 		len = SCSA1394_LEN_6BYTE(pkt);
 		opcode = SCMD_READ_G1;
-		cmd->sc_cdb_actual_len = CDB_GROUP1;
+		cmd->sc_orig_cdblen = CDB_GROUP1;
 		break;
 	case SCMD_WRITE:
 		lba = SCSA1394_LBA_6BYTE(pkt);
 		len = SCSA1394_LEN_6BYTE(pkt);
 		opcode = SCMD_WRITE_G1;
-		cmd->sc_cdb_actual_len = CDB_GROUP1;
+		cmd->sc_orig_cdblen = CDB_GROUP1;
 		break;
 	case SCMD_READ_G1:
 	case SCMD_READ_LONG:
@@ -2145,18 +2011,13 @@
 		 * Build new cdb from scatch.
 		 * The lba and length fields is updated below.
 		 */
-		bzero(cmd->sc_cdb, cmd->sc_cdb_actual_len);
+		bzero(pkt->pkt_cdbp, cmd->sc_orig_cdblen);
 		break;
 	default:
-		/*
-		 * Copy the non lba/len fields.
-		 * The lba and length fields is updated below.
-		 */
-		bcopy(pkt->pkt_cdbp, cmd->sc_cdb, cmd->sc_cdb_actual_len);
 		break;
 	}
 
-	cmd->sc_cdb[0] = (uchar_t)opcode;
+	pkt->pkt_cdbp[0] = (uchar_t)opcode;
 	scsa1394_cmd_fill_cdb_lba(cmd, lba);
 	switch (opcode) {
 	case SCMD_READ_CD:
@@ -2176,14 +2037,10 @@
 static void
 scsa1394_cmd_fill_cdb_other(scsa1394_lun_t *lp, scsa1394_cmd_t *cmd)
 {
-	struct scsi_pkt	*pkt = CMD2PKT(cmd);
-
 	cmd->sc_xfer_bytes = cmd->sc_win_len;
 	cmd->sc_xfer_blks = cmd->sc_xfer_bytes / lp->l_lba_size;
 	cmd->sc_total_blks = cmd->sc_xfer_blks;
 	cmd->sc_lba = 0;
-
-	bcopy(pkt->pkt_cdbp, cmd->sc_cdb, cmd->sc_cdb_len);
 }
 
 /*
@@ -2192,35 +2049,43 @@
 static void
 scsa1394_cmd_fill_cdb_len(scsa1394_cmd_t *cmd, int len)
 {
-	cmd->sc_cdb[7] = len >> 8;
-	cmd->sc_cdb[8] = (uchar_t)len;
+	struct scsi_pkt	*pkt = CMD2PKT(cmd);
+
+	pkt->pkt_cdbp[7] = len >> 8;
+	pkt->pkt_cdbp[8] = (uchar_t)len;
 }
 
 static void
 scsa1394_cmd_fill_cdb_lba(scsa1394_cmd_t *cmd, int lba)
 {
-	cmd->sc_cdb[2] = lba >> 24;
-	cmd->sc_cdb[3] = lba >> 16;
-	cmd->sc_cdb[4] = lba >> 8;
-	cmd->sc_cdb[5] = (uchar_t)lba;
+	struct scsi_pkt	*pkt = CMD2PKT(cmd);
+
+	pkt->pkt_cdbp[2] = lba >> 24;
+	pkt->pkt_cdbp[3] = lba >> 16;
+	pkt->pkt_cdbp[4] = lba >> 8;
+	pkt->pkt_cdbp[5] = (uchar_t)lba;
 	cmd->sc_lba = lba;
 }
 
 static void
 scsa1394_cmd_fill_12byte_cdb_len(scsa1394_cmd_t *cmd, int len)
 {
-	cmd->sc_cdb[6] = len >> 24;
-	cmd->sc_cdb[7] = len >> 16;
-	cmd->sc_cdb[8] = len >> 8;
-	cmd->sc_cdb[9] = (uchar_t)len;
+	struct scsi_pkt	*pkt = CMD2PKT(cmd);
+
+	pkt->pkt_cdbp[6] = len >> 24;
+	pkt->pkt_cdbp[7] = len >> 16;
+	pkt->pkt_cdbp[8] = len >> 8;
+	pkt->pkt_cdbp[9] = (uchar_t)len;
 }
 
 static void
 scsa1394_cmd_fill_read_cd_cdb_len(scsa1394_cmd_t *cmd, int len)
 {
-	cmd->sc_cdb[6] = len >> 16;
-	cmd->sc_cdb[7] = len >> 8;
-	cmd->sc_cdb[8] = (uchar_t)len;
+	struct scsi_pkt	*pkt = CMD2PKT(cmd);
+
+	pkt->pkt_cdbp[6] = len >> 16;
+	pkt->pkt_cdbp[7] = len >> 8;
+	pkt->pkt_cdbp[8] = (uchar_t)len;
 }
 
 /*
@@ -2448,7 +2313,7 @@
 		len = scsa1394_symbios_size_max / cmd->sc_blk_size;
 	}
 
-	switch (cmd->sc_cdb[0]) {
+	switch (cmd->sc_pkt->pkt_cdbp[0]) {
 	case SCMD_READ_CD:
 		scsa1394_cmd_fill_read_cd_cdb_len(cmd, len);
 		break;
--- old/usr/src/uts/common/io/1394/targets/scsa1394/sbp2_driver.c	2013-12-01 10:18:22.543856061 -0500
+++ new/usr/src/uts/common/io/1394/targets/scsa1394/sbp2_driver.c	2013-12-01 10:18:22.568830871 -0500
@@ -557,7 +557,7 @@
 	bzero(orb->co_cdb, sizeof (orb->co_cdb));
 
 	/* CDB */
-	bcopy(cmd->sc_cdb, orb->co_cdb, cmd->sc_cdb_actual_len);
+	bcopy(cmd->sc_pkt->pkt_cdbp, orb->co_cdb, cmd->sc_orig_cdblen);
 
 	/*
 	 * ORB parameters
@@ -825,7 +825,7 @@
 		/* save the command */
 		p = &lp->l_stat.stat_cmd_last_fail[
 		    lp->l_stat.stat_cmd_last_fail_idx][0];
-		bcopy(&pkt->pkt_cdbp[0], p, min(cmd->sc_cdb_len, 16));
+		bcopy(&pkt->pkt_cdbp[0], p, min(cmd->sc_pkt->pkt_cdblen, 16));
 		*(clock_t *)&p[2] = ddi_get_lbolt();
 		lp->l_stat.stat_cmd_last_fail_idx =
 		    (lp->l_stat.stat_cmd_last_fail_idx + 1) %
--- old/usr/src/uts/common/sys/1394/targets/scsa1394/cmd.h	2013-12-01 10:18:25.855050598 -0500
+++ new/usr/src/uts/common/sys/1394/targets/scsa1394/cmd.h	2013-12-01 10:18:25.880749224 -0500
@@ -26,8 +26,6 @@
 #ifndef	_SYS_1394_TARGETS_SCSA1394_CMD_H
 #define	_SYS_1394_TARGETS_SCSA1394_CMD_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * scsa1394 command
  */
@@ -40,14 +38,6 @@
 extern "C" {
 #endif
 
-/* preferred pkt_private length in 64-bit quantities */
-#ifdef  _LP64
-#define	SCSA1394_CMD_PRIV_SIZE	2
-#else /* _ILP32 */
-#define	SCSA1394_CMD_PRIV_SIZE	1
-#endif
-#define	SCSA1394_CMD_PRIV_LEN   (SCSA1394_CMD_PRIV_SIZE * sizeof (uint64_t))
-
 /* entry describing a page table segment */
 typedef struct scsa1394_cmd_seg {
 	size_t			ss_len;
@@ -64,14 +54,7 @@
 	int			sc_flags;	/* command flags */
 	struct buf		*sc_bp;		/* data buffer */
 	struct scsi_pkt		*sc_pkt;	/* corresponding scsi pkt */
-	size_t			sc_cdb_len;
-	size_t			sc_cdb_actual_len;
-	size_t			sc_scb_len;
-	size_t			sc_priv_len;
-	uchar_t			sc_cdb[SCSI_CDB_SIZE];
-	uchar_t			sc_pkt_cdb[SCSI_CDB_SIZE];
-	struct scsi_arq_status	sc_scb;
-	uint64_t		sc_priv[SCSA1394_CMD_PRIV_SIZE];
+	size_t			sc_orig_cdblen;
 	clock_t			sc_start_time;
 	int			sc_timeout;
 
@@ -109,19 +92,13 @@
 	int			sc_blk_size;	/* xfer block size */
 	size_t			sc_total_blks;	/* total xfer blocks */
 	size_t			sc_resid_blks;	/* blocks left */
-
-	struct scsi_pkt		sc_scsi_pkt;	/* must be last */
-						/* embedded SCSI packet */
-						/* ... scsi_pkt_size() */
 } scsa1394_cmd_t;
-#define	SCSA1394_CMD_SIZE	(sizeof (struct scsa1394_cmd) - \
-				sizeof (struct scsi_pkt) + scsi_pkt_size())
 
 _NOTE(SCHEME_PROTECTS_DATA("unique per task", { scsa1394_cmd scsa1394_cmd_seg
     scsi_pkt scsi_inquiry scsi_extended_sense scsi_cdb scsi_arq_status }))
 
 #define	PKT2CMD(pktp)	((scsa1394_cmd_t *)((pktp)->pkt_ha_private))
-#define	CMD2PKT(cmdp)	((struct scsi_pkt *)((cmdp)->sc_pkt))
+#define	CMD2PKT(cmdp)	((cmdp)->sc_pkt)
 #define	TASK2CMD(task)	((scsa1394_cmd_t *)(task)->ts_drv_priv)
 #define	CMD2TASK(cmdp)	((sbp2_task_t *)&(cmdp)->sc_task)
 
@@ -134,13 +111,6 @@
 
 /* flags */
 enum {
-	SCSA1394_CMD_CDB_EXT		= 0x0001,
-	SCSA1394_CMD_PRIV_EXT		= 0x0002,
-	SCSA1394_CMD_SCB_EXT		= 0x0004,
-	SCSA1394_CMD_EXT		= (SCSA1394_CMD_CDB_EXT |
-					    SCSA1394_CMD_PRIV_EXT |
-					    SCSA1394_CMD_SCB_EXT),
-
 	SCSA1394_CMD_DMA_CDB_VALID	= 0x0008,
 	SCSA1394_CMD_DMA_BUF_BIND_VALID	= 0x0010,
 	SCSA1394_CMD_DMA_BUF_PT_VALID	= 0x0020,
--- old/usr/src/uts/common/sys/1394/targets/scsa1394/impl.h	2013-12-01 10:18:29.133733893 -0500
+++ new/usr/src/uts/common/sys/1394/targets/scsa1394/impl.h	2013-12-01 10:18:29.158616251 -0500
@@ -26,8 +26,6 @@
 #ifndef	_SYS_1394_TARGETS_SCSA1394_IMPL_H
 #define	_SYS_1394_TARGETS_SCSA1394_IMPL_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 /*
  * scsa1394 definitions
  */
@@ -187,7 +185,6 @@
 	sbp2_cfgrom_t		*s_cfgrom;	/* Config ROM */
 	int			s_nluns;	/* # of logical units */
 	scsa1394_lun_t		*s_lun;		/* logical units */
-	kmem_cache_t		*s_cmd_cache;	/* command kmem cache */
 	ddi_taskq_t		*s_taskq;	/* common taskq for all luns */
 	boolean_t		s_symbios;	/* need Symbios workaround? */
 	boolean_t		s_disconnect_warned; /* disconnect warning */
