xref: /onnv-gate/usr/src/uts/common/sys/scsi/targets/sgendef.h (revision 6316:40d5384cc8b2)
12518Sstevel /*
22518Sstevel  * CDDL HEADER START
32518Sstevel  *
42518Sstevel  * The contents of this file are subject to the terms of the
52518Sstevel  * Common Development and Distribution License (the "License").
62518Sstevel  * You may not use this file except in compliance with the License.
72518Sstevel  *
82518Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92518Sstevel  * or http://www.opensolaris.org/os/licensing.
102518Sstevel  * See the License for the specific language governing permissions
112518Sstevel  * and limitations under the License.
122518Sstevel  *
132518Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
142518Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152518Sstevel  * If applicable, add the following below this CDDL HEADER, with the
162518Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
172518Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
182518Sstevel  *
192518Sstevel  * CDDL HEADER END
202518Sstevel  */
212518Sstevel 
222518Sstevel /*
23*6316Seschrock  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
242518Sstevel  * Use is subject to license terms.
252518Sstevel  */
262518Sstevel 
272518Sstevel /*
282518Sstevel  * Copyright Siemens 1999
292518Sstevel  * All rights reserved.
302518Sstevel  */
312518Sstevel 
322518Sstevel #ifndef _SYS_SCSI_TARGETS_SGENDEF_H
332518Sstevel #define	_SYS_SCSI_TARGETS_SGENDEF_H
342518Sstevel 
352518Sstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
362518Sstevel 
372518Sstevel #include <sys/types.h>
382518Sstevel #include <sys/kstat.h>
392518Sstevel #include <sys/condvar.h>
402518Sstevel #include <sys/mutex.h>
412518Sstevel #include <sys/buf.h>
422518Sstevel #include <sys/scsi/scsi.h>
432518Sstevel 
442518Sstevel #ifdef	__cplusplus
452518Sstevel extern "C" {
462518Sstevel #endif
472518Sstevel 
482518Sstevel #define	SGEN_IOC		(('S' << 16) | ('G' << 8))
492518Sstevel #define	SGEN_IOC_READY		(SGEN_IOC | 0x01)
502518Sstevel #define	SGEN_IOC_DIAG		(SGEN_IOC | 0x02)
512518Sstevel 
522518Sstevel #if defined(_KERNEL)
532518Sstevel 
542518Sstevel #define	SGEN_DIAG1		((1 << 8) | CE_CONT)
552518Sstevel #define	SGEN_DIAG2		((2 << 8) | CE_CONT)
562518Sstevel #define	SGEN_DIAG3		((3 << 8) | CE_CONT)
572518Sstevel 
582518Sstevel struct sgen_errstats {
592518Sstevel 	kstat_named_t sgen_trans_err;	/* error trying to transport pkt */
602518Sstevel 	kstat_named_t sgen_restart;	/* command restart attempted */
612518Sstevel 	kstat_named_t sgen_incmp_err;	/* command failed to complete */
622518Sstevel 	kstat_named_t sgen_autosen_rcv;	/* autosense occurred */
632518Sstevel 	kstat_named_t sgen_autosen_bad;	/* autosense data looks malformed */
642518Sstevel 	kstat_named_t sgen_sense_rcv;	/* sense fetch occurred */
652518Sstevel 	kstat_named_t sgen_sense_bad;	/* sense data looks malformed */
662518Sstevel 	kstat_named_t sgen_recov_err;	/* sense key is KEY_RECOVERABLE */
672518Sstevel 	kstat_named_t sgen_nosen_err;	/* sense key is KEY_NO_SENSE */
682518Sstevel 	kstat_named_t sgen_unrecov_err;	/* sense key indicates other err */
692518Sstevel };
702518Sstevel 
712518Sstevel typedef struct sgen_state {
722518Sstevel 	struct scsi_device *sgen_scsidev;	/* pointer to scsi_device */
732518Sstevel 	struct uscsi_cmd *sgen_ucmd;		/* uscsi command struct */
742518Sstevel 	struct buf *sgen_cmdbuf;		/* xfer buffer */
752518Sstevel 	struct scsi_pkt *sgen_cmdpkt;		/* scsi packet for command */
762518Sstevel 	kcondvar_t sgen_cmdbuf_cv;		/* cv for cmdbuf */
772518Sstevel 	int sgen_flags;				/* see SGEN_FL_* */
782518Sstevel 	struct scsi_pkt *sgen_rqspkt;		/* request sense packet */
792518Sstevel 	struct buf *sgen_rqsbuf;		/* request sense xfer buffer */
802518Sstevel 	char *sgen_rqs_sen;			/* sense buffer */
812518Sstevel 	int sgen_arq_enabled;			/* auto request sense enabled */
822518Sstevel 	int sgen_diag;				/* diagnostic output level */
832518Sstevel 	timeout_id_t sgen_restart_timeid;	/* timeout for sgen_restart */
842518Sstevel 	kstat_t *sgen_kstats;			/* for error statistics */
852518Sstevel } sgen_state_t;
862518Sstevel 
872518Sstevel /*
882518Sstevel  * Convenience accessors for sgen_state_t.
892518Sstevel  */
902518Sstevel #define	sgen_mutex sgen_scsidev->sd_mutex
912518Sstevel #define	sgen_devinfo sgen_scsidev->sd_dev
922518Sstevel #define	sgen_scsiaddr sgen_scsidev->sd_address
932518Sstevel #define	sgen_sense sgen_scsidev->sd_sense
942518Sstevel 
952518Sstevel /*
962518Sstevel  * sgen_flags accessors/mutators
972518Sstevel  */
982518Sstevel #define	SGEN_FL_OPEN	0x01	/* instance is open */
992518Sstevel #define	SGEN_FL_SUSP	0x02	/* instance suspended */
1002518Sstevel #define	SGEN_FL_BUSY	0x04	/* command buffer busy */
101*6316Seschrock #define	SGEN_FL_EXCL	0x08	/* exclusive open */
1022518Sstevel 
1032518Sstevel #define	SGEN_SET_OPEN(stp) \
1042518Sstevel 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_OPEN)
1052518Sstevel #define	SGEN_CLR_OPEN(stp) \
1062518Sstevel 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_OPEN)
1072518Sstevel #define	SGEN_IS_OPEN(stp) \
1082518Sstevel 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_OPEN) == SGEN_FL_OPEN)
1092518Sstevel 
1102518Sstevel #define	SGEN_SET_SUSP(stp) \
1112518Sstevel 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_SUSP)
1122518Sstevel #define	SGEN_CLR_SUSP(stp) \
1132518Sstevel 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_SUSP)
1142518Sstevel #define	SGEN_IS_SUSP(stp) \
1152518Sstevel 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_SUSP) == SGEN_FL_SUSP)
1162518Sstevel 
1172518Sstevel #define	SGEN_SET_BUSY(stp) \
1182518Sstevel 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_BUSY)
1192518Sstevel #define	SGEN_CLR_BUSY(stp) \
1202518Sstevel 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_BUSY)
1212518Sstevel #define	SGEN_IS_BUSY(stp) \
1222518Sstevel 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_BUSY) == SGEN_FL_BUSY)
1232518Sstevel 
124*6316Seschrock #define	SGEN_SET_EXCL(stp) \
125*6316Seschrock 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_EXCL)
126*6316Seschrock #define	SGEN_CLR_EXCL(stp) \
127*6316Seschrock 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_EXCL)
128*6316Seschrock #define	SGEN_IS_EXCL(stp) \
129*6316Seschrock 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_EXCL) == SGEN_FL_EXCL)
130*6316Seschrock 
1312518Sstevel /*
1322518Sstevel  * These structures form the driver's database of binding information.
1332518Sstevel  * Inquiry strings and device types from the inquiry-config-list and
1342518Sstevel  * device-type-config-list properties are stored.
1352518Sstevel  */
1362518Sstevel typedef struct sgen_inq_node {
1372518Sstevel 	char *node_vendor;			/* up to 8 character vendor */
1382518Sstevel 	char *node_product;			/* up to 16 character product */
1392518Sstevel 	struct sgen_inq_node *node_next;
1402518Sstevel } sgen_inq_node_t;
1412518Sstevel 
1422518Sstevel typedef struct sgen_type_node {
1432518Sstevel 	uchar_t node_type;			/* SCSI device type */
1442518Sstevel 	struct sgen_type_node *node_next;
1452518Sstevel } sgen_type_node_t;
1462518Sstevel 
1472518Sstevel struct sgen_binddb {
1482518Sstevel 	int sdb_init;				/* has this been initialized? */
1492518Sstevel 	kmutex_t sdb_lock;			/* protects this structure */
1502518Sstevel 	sgen_inq_node_t *sdb_inq_nodes;		/* inquiry binding nodes */
1512518Sstevel 	sgen_type_node_t *sdb_type_nodes;	/* dev-type binding nodes */
1522518Sstevel };
1532518Sstevel 
1542518Sstevel #define	SGEN_ESTIMATED_NUM_DEVS	4		/* for soft-state allocation */
1552518Sstevel 
1562518Sstevel /*
1572518Sstevel  * Time to wait before a retry for commands returning Busy Status
1582518Sstevel  */
1592518Sstevel #define	SGEN_BSY_TIMEOUT	(drv_usectohz(5 * 1000000))
1602518Sstevel #define	SGEN_IO_TIME		60		/* seconds */
1612518Sstevel 
1622518Sstevel /*
1632518Sstevel  * sgen_callback action codes
1642518Sstevel  */
1652518Sstevel #define	COMMAND_DONE		0	/* command completed, biodone it */
1662518Sstevel #define	COMMAND_DONE_ERROR	1	/* command completed, indicate error */
1672518Sstevel #define	FETCH_SENSE		2	/* CHECK CONDITION, so initiate sense */
1682518Sstevel 					/* fetch */
1692518Sstevel 
1702518Sstevel #define	SET_BP_ERROR(bp, err)	bioerror(bp, err);
1712518Sstevel 
1722518Sstevel #endif /* defined(_KERNEL) */
1732518Sstevel 
1742518Sstevel #ifdef	__cplusplus
1752518Sstevel }
1762518Sstevel #endif
1772518Sstevel 
1782518Sstevel #endif	/* _SYS_SCSI_TARGETS_SGENDEF_H */
179