17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*f5488aa8Sbharding  * Common Development and Distribution License (the "License").
6*f5488aa8Sbharding  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*f5488aa8Sbharding  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_1394_TARGETS_SCSA1394_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_1394_TARGETS_SCSA1394_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * scsa1394 definitions
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <sys/1394/t1394.h>
367c478bd9Sstevel@tonic-gate #include <sys/sbp2/driver.h>
377c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi.h>
387c478bd9Sstevel@tonic-gate #include <sys/cdio.h>
397c478bd9Sstevel@tonic-gate #include <sys/1394/targets/scsa1394/cmd.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * each lun uses a worker thread for various deferred processing
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate typedef enum {
497c478bd9Sstevel@tonic-gate 	SCSA1394_THR_INIT,			/* initial state */
507c478bd9Sstevel@tonic-gate 	SCSA1394_THR_RUN,			/* thread is running */
517c478bd9Sstevel@tonic-gate 	SCSA1394_THR_EXIT			/* thread exited */
527c478bd9Sstevel@tonic-gate } scsa1394_thr_state_t;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate /* thread requests */
557c478bd9Sstevel@tonic-gate enum {
567c478bd9Sstevel@tonic-gate 	SCSA1394_THREQ_EXIT		= 0x1,	/* thread has to exit */
577c478bd9Sstevel@tonic-gate 	SCSA1394_THREQ_TASK_STATUS	= 0x2,	/* task status received */
587c478bd9Sstevel@tonic-gate 	SCSA1394_THREQ_NUDGE		= 0x4,	/* nudge SBP-2 layer */
597c478bd9Sstevel@tonic-gate 	SCSA1394_THREQ_BUS_RESET	= 0x8,
607c478bd9Sstevel@tonic-gate 	SCSA1394_THREQ_DISCONNECT	= 0x10,
617c478bd9Sstevel@tonic-gate 	SCSA1394_THREQ_RECONNECT	= 0x20
627c478bd9Sstevel@tonic-gate };
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate typedef struct scsa1394_thread {
657c478bd9Sstevel@tonic-gate 	void			(*thr_func)(void *);	/* function to be run */
667c478bd9Sstevel@tonic-gate 	void			*thr_arg;	/* function argument */
677c478bd9Sstevel@tonic-gate 	struct scsa1394_lun	*thr_lun;	/* lun we belong to */
687c478bd9Sstevel@tonic-gate 	scsa1394_thr_state_t	thr_state;	/* state */
697c478bd9Sstevel@tonic-gate 	kcondvar_t		thr_cv;		/* cv for request wait */
707c478bd9Sstevel@tonic-gate 	int			thr_req;	/* request mask */
717c478bd9Sstevel@tonic-gate } scsa1394_thread_t;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /* 1394 device state */
757c478bd9Sstevel@tonic-gate typedef enum {
767c478bd9Sstevel@tonic-gate 	SCSA1394_DEV_INIT		= 0,
777c478bd9Sstevel@tonic-gate 	SCSA1394_DEV_ONLINE,
787c478bd9Sstevel@tonic-gate 	SCSA1394_DEV_BUS_RESET,
79*f5488aa8Sbharding 	SCSA1394_DEV_DISCONNECTED,
80*f5488aa8Sbharding 	SCSA1394_DEV_PWRED_DOWN,
81*f5488aa8Sbharding 	SCSA1394_DEV_SUSPENDED
827c478bd9Sstevel@tonic-gate } scsa1394_dev_state_t;
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate enum { SCSA1394_STAT_NCMD_LAST = 8 };
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /* per-lun statistics */
877c478bd9Sstevel@tonic-gate typedef struct scsa1394_lun_stat {
887c478bd9Sstevel@tonic-gate 	/*
897c478bd9Sstevel@tonic-gate 	 * ring buffer of the last N failed commands. stat_cmd_fail_last_idx
907c478bd9Sstevel@tonic-gate 	 * is an index into stat_cmd_fail_last the array and points to the
917c478bd9Sstevel@tonic-gate 	 * entry to be written next. The first 16 bytes are CDB bytes,
927c478bd9Sstevel@tonic-gate 	 * the last 8 bytes are a timestamp (lbolt).
937c478bd9Sstevel@tonic-gate 	 */
947c478bd9Sstevel@tonic-gate 	uint64_t		stat_cmd_last_fail[SCSA1394_STAT_NCMD_LAST][3];
957c478bd9Sstevel@tonic-gate 	int			stat_cmd_last_fail_idx;
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate 	uint_t			stat_cmd_cnt;	/* # of commands submitted */
987c478bd9Sstevel@tonic-gate 	uint_t			stat_cmd_buf_max_nsegs;
99f2b7ce3eSartem 	uint_t			stat_cmd_buf_dma_partial;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	/*
1027c478bd9Sstevel@tonic-gate 	 * errors
1037c478bd9Sstevel@tonic-gate 	 */
1047c478bd9Sstevel@tonic-gate 	uint_t			stat_err_pkt_kmem_alloc;
1057c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_cdb_dmem_alloc;
1067c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_cdb_dbind;
1077c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_cdb_addr_alloc;
1087c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_buf_dbind;
1097c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_buf_addr_alloc;
1107c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_pt_kmem_alloc;
1117c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_pt_dmem_alloc;
1127c478bd9Sstevel@tonic-gate 	uint_t			stat_err_cmd_pt_addr_alloc;
1137c478bd9Sstevel@tonic-gate 	uint_t			stat_err_status_tran_err;
1147c478bd9Sstevel@tonic-gate 	uint_t			stat_err_status_conv;
1157c478bd9Sstevel@tonic-gate 	uint_t			stat_err_status_resp;
1167c478bd9Sstevel@tonic-gate } scsa1394_lun_stat_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /* logical unit */
1197c478bd9Sstevel@tonic-gate typedef struct scsa1394_lun {
1207c478bd9Sstevel@tonic-gate 	kmutex_t		l_mutex;	/* structure lock */
1217c478bd9Sstevel@tonic-gate 	struct scsa1394_state	*l_sp;		/* soft state */
1227c478bd9Sstevel@tonic-gate 	sbp2_lun_t		*l_lun;		/* SBP2 lun */
1237c478bd9Sstevel@tonic-gate 	sbp2_ses_t		*l_ses;		/* login session */
1247c478bd9Sstevel@tonic-gate 	dev_info_t		*l_cdip;	/* child devinfo */
1257c478bd9Sstevel@tonic-gate 	scsa1394_thread_t	l_worker_thread; /* worker thread */
1267c478bd9Sstevel@tonic-gate 	ddi_softintr_t		l_softintr_id;	/* soft interrupt */
1277c478bd9Sstevel@tonic-gate 	boolean_t		l_softintr_triggered; /* trigger indicator */
1287c478bd9Sstevel@tonic-gate 	int			l_softintr_req;	/* soft intr request mask */
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	/* workarounds */
1317c478bd9Sstevel@tonic-gate 	int			l_lba_size;	/* LBA size */
1327c478bd9Sstevel@tonic-gate 	int			l_dtype_orig;	/* original DTYPE value */
1337c478bd9Sstevel@tonic-gate 	int			l_rmb_orig;	/* original RMB value */
1347c478bd9Sstevel@tonic-gate 	int			l_start_stop_fail_cnt; /* start/stop failures */
1357c478bd9Sstevel@tonic-gate 	boolean_t		l_start_stop_fake; /* fake start/stop unit */
1367c478bd9Sstevel@tonic-gate 	int			l_mode_sense_fail_cnt; /* mode sense failures */
1377c478bd9Sstevel@tonic-gate 	boolean_t		l_mode_sense_fake; /* fake mode sense command */
1387c478bd9Sstevel@tonic-gate 	boolean_t		l_nosup_tur;
1397c478bd9Sstevel@tonic-gate 	boolean_t		l_nosup_start_stop;
1407c478bd9Sstevel@tonic-gate 	boolean_t		l_nosup_inquiry;
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	struct scsi_inquiry	l_fake_inq;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	scsa1394_lun_stat_t	l_stat;		/* statistics */
1457c478bd9Sstevel@tonic-gate } scsa1394_lun_t;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsa1394_lun::l_mutex, scsa1394_lun))
1487c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa1394_lun::{
1497c478bd9Sstevel@tonic-gate     l_sp l_lun l_ses l_cdip l_worker_thread l_softintr_id
1507c478bd9Sstevel@tonic-gate     l_nosup_tur l_nosup_start_stop l_nosup_inquiry }))
1517c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("statistics", scsa1394_lun::l_stat))
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /* l_softintr_req */
1547c478bd9Sstevel@tonic-gate enum {
1557c478bd9Sstevel@tonic-gate 	SCSA1394_SOFTINTR_STATUS_RCVD	= 0x1,	/* task status received */
1567c478bd9Sstevel@tonic-gate 	SCSA1394_SOFTINTR_RECONNECT	= 0x2	/* perform reconnect */
1577c478bd9Sstevel@tonic-gate };
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /* per-instance statistics */
1607c478bd9Sstevel@tonic-gate typedef struct scsa1394_inst_stat {
1617c478bd9Sstevel@tonic-gate 	uint_t			stat_bus_reset_cnt;
1627c478bd9Sstevel@tonic-gate 	uint_t			stat_disconnect_cnt;
1637c478bd9Sstevel@tonic-gate 	uint_t			stat_reconnect_cnt;
1647c478bd9Sstevel@tonic-gate 	/*
1657c478bd9Sstevel@tonic-gate 	 * errors
1667c478bd9Sstevel@tonic-gate 	 */
1677c478bd9Sstevel@tonic-gate } scsa1394_inst_stat_t;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /* per-instance soft state structure */
1707c478bd9Sstevel@tonic-gate typedef struct scsa1394_state {
1717c478bd9Sstevel@tonic-gate 	kmutex_t		s_mutex;	/* structure mutex */
1727c478bd9Sstevel@tonic-gate 	dev_info_t		*s_dip;		/* device information */
1737c478bd9Sstevel@tonic-gate 	int			s_instance;	/* instance number */
1747c478bd9Sstevel@tonic-gate 	scsa1394_dev_state_t	s_dev_state;	/* device state */
1757c478bd9Sstevel@tonic-gate 	t1394_handle_t		s_t1394_hdl;	/* 1394 handle */
1767c478bd9Sstevel@tonic-gate 	t1394_attachinfo_t	s_attachinfo;	/* 1394 attach info */
1777c478bd9Sstevel@tonic-gate 	t1394_targetinfo_t	s_targetinfo;	/* 1394 target info */
1787c478bd9Sstevel@tonic-gate 	ddi_callback_id_t	s_reset_cb_id;	/* reset event cb id */
1797c478bd9Sstevel@tonic-gate 	ddi_callback_id_t	s_remove_cb_id;	/* remove event cb id */
1807c478bd9Sstevel@tonic-gate 	ddi_callback_id_t	s_insert_cb_id;	/* insert event cb id */
1817c478bd9Sstevel@tonic-gate 	boolean_t		s_event_entered; /* event serialization */
1827c478bd9Sstevel@tonic-gate 	kcondvar_t		s_event_cv;	/* event serialization cv */
1837c478bd9Sstevel@tonic-gate 	ddi_dma_attr_t		s_buf_dma_attr;	/* data buffer DMA attrs */
1847c478bd9Sstevel@tonic-gate 	ddi_dma_attr_t		s_pt_dma_attr;	/* page table DMA attrs */
1857c478bd9Sstevel@tonic-gate 	scsi_hba_tran_t		*s_tran;	/* SCSA HBA tran structure */
1867c478bd9Sstevel@tonic-gate 	sbp2_tgt_t		*s_tgt;		/* SBP-2 target */
1877c478bd9Sstevel@tonic-gate 	sbp2_cfgrom_t		*s_cfgrom;	/* Config ROM */
1887c478bd9Sstevel@tonic-gate 	int			s_nluns;	/* # of logical units */
1897c478bd9Sstevel@tonic-gate 	scsa1394_lun_t		*s_lun;		/* logical units */
1907c478bd9Sstevel@tonic-gate 	kmem_cache_t		*s_cmd_cache;	/* command kmem cache */
1917c478bd9Sstevel@tonic-gate 	ddi_taskq_t		*s_taskq;	/* common taskq for all luns */
1927c478bd9Sstevel@tonic-gate 	boolean_t		s_symbios;	/* need Symbios workaround? */
1937c478bd9Sstevel@tonic-gate 	boolean_t		s_disconnect_warned; /* disconnect warning */
1947c478bd9Sstevel@tonic-gate 	size_t			s_totalsec;	/* total sectors */
1957c478bd9Sstevel@tonic-gate 	size_t			s_secsz;	/* sector size */
1967c478bd9Sstevel@tonic-gate 	scsa1394_inst_stat_t	s_stat;		/* statistics */
1977c478bd9Sstevel@tonic-gate } scsa1394_state_t;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(scsa1394_state::s_mutex, scsa1394_state))
2007c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("stable data", scsa1394_state::{
2017c478bd9Sstevel@tonic-gate     s_dip s_instance s_t1394_hdl s_attachinfo s_reset_cb_id s_remove_cb_id
2027c478bd9Sstevel@tonic-gate     s_insert_cb_id s_buf_dma_attr s_pt_dma_attr s_tran s_tgt s_cfgrom
2037c478bd9Sstevel@tonic-gate     s_nluns s_lun s_cmd_cache s_taskq s_symbios s_targetinfo
2047c478bd9Sstevel@tonic-gate     s_totalsec s_secsz}))
2057c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("statistics", scsa1394_state::s_stat))
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate _NOTE(LOCK_ORDER(scsa1394_state::s_mutex scsa1394_lun::l_mutex))
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate /* for sbp2_bus_buf.bb_hdl */
2107c478bd9Sstevel@tonic-gate typedef struct scsa1394_bus_buf {
2117c478bd9Sstevel@tonic-gate 	scsa1394_state_t	*sbb_state;	/* soft state */
2127c478bd9Sstevel@tonic-gate 	t1394_addr_handle_t	sbb_addr_hdl;	/* 1394 address handle */
2137c478bd9Sstevel@tonic-gate 	ddi_dma_handle_t	sbb_dma_hdl;	/* DMA handle */
2147c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t	sbb_acc_hdl;	/* access handle */
2157c478bd9Sstevel@tonic-gate } scsa1394_bus_buf_t;
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate _NOTE(SCHEME_PROTECTS_DATA("unique per task", scsa1394_bus_buf))
218d291d9f2Sfrits _NOTE(SCHEME_PROTECTS_DATA("dev_info::devi_lock", dev_info::devi_state))
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate /* various translation macros */
2217c478bd9Sstevel@tonic-gate #define	ADDR2TRAN(ap)	((ap)->a_hba_tran)
2227c478bd9Sstevel@tonic-gate #define	TRAN2STATE(hba)	((scsa1394_state_t *)(hba)->tran_hba_private)
2237c478bd9Sstevel@tonic-gate #define	ADDR2STATE(ap)	(TRAN2STATE(ADDR2TRAN(ap)))
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate #define	SCSA1394_NODEID(sp)	((sp)->s_attachinfo.localinfo.local_nodeID)
2267c478bd9Sstevel@tonic-gate #define	SCSA1394_BUSGEN(sp)	((sp)->s_attachinfo.localinfo.bus_generation)
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate #define	SCSA1394_ORB_SIZE_ROUNDUP(sp, sz) SBP2_ORB_SIZE_ROUNDUP(sp->s_tgt, sz)
2297c478bd9Sstevel@tonic-gate #define	SCSA1394_ADDR_SET(sp, var, addr) \
2307c478bd9Sstevel@tonic-gate     SBP2_ADDR_SET(var, addr, SCSA1394_NODEID(sp))
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /* macros to calculate LBA for 6/10/12-byte commands */
2337c478bd9Sstevel@tonic-gate #define	SCSA1394_LBA_6BYTE(pkt)						\
2347c478bd9Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[1] & 0x1f) << 16) +				\
2357c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 8) + (pkt)->pkt_cdbp[3]
2367c478bd9Sstevel@tonic-gate #define	SCSA1394_LEN_6BYTE(pkt)						\
2377c478bd9Sstevel@tonic-gate 	(pkt)->pkt_cdbp[4]
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate #define	SCSA1394_LEN_10BYTE(pkt)					\
2407c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[7] << 8) + (pkt)->pkt_cdbp[8]
2417c478bd9Sstevel@tonic-gate #define	SCSA1394_LBA_10BYTE(pkt)					\
2427c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) + 	\
2437c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate #define	SCSA1394_LEN_12BYTE(pkt)					\
2467c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[6] << 24) + ((pkt)->pkt_cdbp[7] << 16) +	\
2477c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[8] << 8) +  (pkt)->pkt_cdbp[9]
2487c478bd9Sstevel@tonic-gate #define	SCSA1394_LBA_12BYTE(pkt)					\
2497c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[2] << 24) + ((pkt)->pkt_cdbp[3] << 16) +	\
2507c478bd9Sstevel@tonic-gate 	((pkt)->pkt_cdbp[4] << 8) +  (pkt)->pkt_cdbp[5]
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /* macro to calculate LEN for SCMD_READ_CD command */
2537c478bd9Sstevel@tonic-gate #define	SCSA1394_LEN_READ_CD(pkt)					\
2547c478bd9Sstevel@tonic-gate 	(((pkt)->pkt_cdbp[6] << 16) + ((pkt)->pkt_cdbp[7] << 8) +	\
2557c478bd9Sstevel@tonic-gate 	(pkt)->pkt_cdbp[8])
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /* calculate block size for CD-RW writes */
2587c478bd9Sstevel@tonic-gate #define	SCSA1394_CDRW_BLKSZ(bcount, len)	((bcount) / (len))
2597c478bd9Sstevel@tonic-gate #define	SCSA1394_VALID_CDRW_BLKSZ(blksz)				\
2607c478bd9Sstevel@tonic-gate 	(((blksz) == CDROM_BLK_2048) || ((blksz) == CDROM_BLK_2352) ||	\
2617c478bd9Sstevel@tonic-gate 	((blksz) == CDROM_BLK_2336) || ((blksz) == CDROM_BLK_2324))
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate /* black/white list */
2647c478bd9Sstevel@tonic-gate typedef struct scsa1394_bw_list {
2657c478bd9Sstevel@tonic-gate 	int	vid_match;
2667c478bd9Sstevel@tonic-gate 	int	vid;
2677c478bd9Sstevel@tonic-gate } scsa1394_bw_list_t;
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /* match type */
2707c478bd9Sstevel@tonic-gate enum {
2717c478bd9Sstevel@tonic-gate 	SCSA1394_BW_ONE,
2727c478bd9Sstevel@tonic-gate 	SCSA1394_BW_ALL
2737c478bd9Sstevel@tonic-gate };
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate #define	NELEM(a)	(sizeof (a) / sizeof (*(a)))
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate /* misc constants */
2787c478bd9Sstevel@tonic-gate enum {
2797c478bd9Sstevel@tonic-gate 	SCSA1394_COMPAT_MAX		= 1,	/* max @ of compatible names */
2807c478bd9Sstevel@tonic-gate 	SCSA1394_CLEANUP_LEVEL_MAX	= 256,
2817c478bd9Sstevel@tonic-gate 	SCSA1394_START_STOP_FAIL_MAX	= 3,	/* max start/stop failures */
2827c478bd9Sstevel@tonic-gate 	SCSA1394_MODE_SENSE_FAIL_MAX	= 3,	/* max mode sense failures */
2837c478bd9Sstevel@tonic-gate 	SCSA1394_START_STOP_TIMEOUT_MAX	= 30,
2847c478bd9Sstevel@tonic-gate 	SCSA1394_MAPIN_SIZE_MAX		= 512,
2857c478bd9Sstevel@tonic-gate 	SCSA1394_PROBE_TIMEOUT		= 15,	/* in seconds */
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate 	SCSA1394_DTYPE_RBC		= 0x0E
2887c478bd9Sstevel@tonic-gate };
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate /* SBP-2 routines */
2927c478bd9Sstevel@tonic-gate int	scsa1394_sbp2_attach(scsa1394_state_t *);
2937c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_detach(scsa1394_state_t *);
2947c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_fake_inquiry(scsa1394_state_t *, struct scsi_inquiry *);
2957c478bd9Sstevel@tonic-gate int	scsa1394_sbp2_threads_init(scsa1394_state_t *);
2967c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_threads_fini(scsa1394_state_t *);
2977c478bd9Sstevel@tonic-gate int	scsa1394_sbp2_get_lun_type(scsa1394_lun_t *);
2987c478bd9Sstevel@tonic-gate int	scsa1394_sbp2_login(scsa1394_state_t *, int);
2997c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_logout(scsa1394_state_t *, int, boolean_t);
3007c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_req(scsa1394_state_t *, int, int);
3017c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_disconnect(scsa1394_state_t *);
3027c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_seg2pt(scsa1394_lun_t *, scsa1394_cmd_t *);
3037c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_cmd2orb(scsa1394_lun_t *, scsa1394_cmd_t *);
3047c478bd9Sstevel@tonic-gate int	scsa1394_sbp2_start(scsa1394_lun_t *, scsa1394_cmd_t *);
3057c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_nudge(scsa1394_lun_t *);
3067c478bd9Sstevel@tonic-gate int	scsa1394_sbp2_reset(scsa1394_lun_t *, int, scsa1394_cmd_t *);
3077c478bd9Sstevel@tonic-gate void	scsa1394_sbp2_flush_cmds(scsa1394_lun_t *, int, int, int);
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /* HBA public routines */
3117c478bd9Sstevel@tonic-gate int	scsa1394_thr_dispatch(scsa1394_thread_t *);
3127c478bd9Sstevel@tonic-gate void	scsa1394_thr_cancel(scsa1394_thread_t *);
3137c478bd9Sstevel@tonic-gate void	scsa1394_thr_wake(scsa1394_thread_t *, int);
3147c478bd9Sstevel@tonic-gate void	scsa1394_thr_clear_req(scsa1394_thread_t *, int);
3157c478bd9Sstevel@tonic-gate void	scsa1394_cmd_status_proc(scsa1394_lun_t *, scsa1394_cmd_t *);
3167c478bd9Sstevel@tonic-gate boolean_t scsa1394_dev_is_online(scsa1394_state_t *);
317*f5488aa8Sbharding void	scsa1394_sbp2_req_bus_reset(scsa1394_lun_t *);
318*f5488aa8Sbharding void	scsa1394_sbp2_req_reconnect(scsa1394_lun_t *);
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3227c478bd9Sstevel@tonic-gate }
3237c478bd9Sstevel@tonic-gate #endif
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate #endif	/* _SYS_1394_TARGETS_SCSA1394_IMPL_H */
326