xref: /titanic_52/usr/src/uts/common/sys/scsi/targets/sgendef.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
19a016c63Sstevel /*
29a016c63Sstevel  * CDDL HEADER START
39a016c63Sstevel  *
49a016c63Sstevel  * The contents of this file are subject to the terms of the
59a016c63Sstevel  * Common Development and Distribution License (the "License").
69a016c63Sstevel  * You may not use this file except in compliance with the License.
79a016c63Sstevel  *
89a016c63Sstevel  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99a016c63Sstevel  * or http://www.opensolaris.org/os/licensing.
109a016c63Sstevel  * See the License for the specific language governing permissions
119a016c63Sstevel  * and limitations under the License.
129a016c63Sstevel  *
139a016c63Sstevel  * When distributing Covered Code, include this CDDL HEADER in each
149a016c63Sstevel  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159a016c63Sstevel  * If applicable, add the following below this CDDL HEADER, with the
169a016c63Sstevel  * fields enclosed by brackets "[]" replaced with your own identifying
179a016c63Sstevel  * information: Portions Copyright [yyyy] [name of copyright owner]
189a016c63Sstevel  *
199a016c63Sstevel  * CDDL HEADER END
209a016c63Sstevel  */
219a016c63Sstevel 
229a016c63Sstevel /*
23*275c9da8Seschrock  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
249a016c63Sstevel  * Use is subject to license terms.
259a016c63Sstevel  */
269a016c63Sstevel 
279a016c63Sstevel /*
289a016c63Sstevel  * Copyright Siemens 1999
299a016c63Sstevel  * All rights reserved.
309a016c63Sstevel  */
319a016c63Sstevel 
329a016c63Sstevel #ifndef _SYS_SCSI_TARGETS_SGENDEF_H
339a016c63Sstevel #define	_SYS_SCSI_TARGETS_SGENDEF_H
349a016c63Sstevel 
359a016c63Sstevel #pragma ident	"%Z%%M%	%I%	%E% SMI"
369a016c63Sstevel 
379a016c63Sstevel #include <sys/types.h>
389a016c63Sstevel #include <sys/kstat.h>
399a016c63Sstevel #include <sys/condvar.h>
409a016c63Sstevel #include <sys/mutex.h>
419a016c63Sstevel #include <sys/buf.h>
429a016c63Sstevel #include <sys/scsi/scsi.h>
439a016c63Sstevel 
449a016c63Sstevel #ifdef	__cplusplus
459a016c63Sstevel extern "C" {
469a016c63Sstevel #endif
479a016c63Sstevel 
489a016c63Sstevel #define	SGEN_IOC		(('S' << 16) | ('G' << 8))
499a016c63Sstevel #define	SGEN_IOC_READY		(SGEN_IOC | 0x01)
509a016c63Sstevel #define	SGEN_IOC_DIAG		(SGEN_IOC | 0x02)
519a016c63Sstevel 
529a016c63Sstevel #if defined(_KERNEL)
539a016c63Sstevel 
549a016c63Sstevel #define	SGEN_DIAG1		((1 << 8) | CE_CONT)
559a016c63Sstevel #define	SGEN_DIAG2		((2 << 8) | CE_CONT)
569a016c63Sstevel #define	SGEN_DIAG3		((3 << 8) | CE_CONT)
579a016c63Sstevel 
589a016c63Sstevel struct sgen_errstats {
599a016c63Sstevel 	kstat_named_t sgen_trans_err;	/* error trying to transport pkt */
609a016c63Sstevel 	kstat_named_t sgen_restart;	/* command restart attempted */
619a016c63Sstevel 	kstat_named_t sgen_incmp_err;	/* command failed to complete */
629a016c63Sstevel 	kstat_named_t sgen_autosen_rcv;	/* autosense occurred */
639a016c63Sstevel 	kstat_named_t sgen_autosen_bad;	/* autosense data looks malformed */
649a016c63Sstevel 	kstat_named_t sgen_sense_rcv;	/* sense fetch occurred */
659a016c63Sstevel 	kstat_named_t sgen_sense_bad;	/* sense data looks malformed */
669a016c63Sstevel 	kstat_named_t sgen_recov_err;	/* sense key is KEY_RECOVERABLE */
679a016c63Sstevel 	kstat_named_t sgen_nosen_err;	/* sense key is KEY_NO_SENSE */
689a016c63Sstevel 	kstat_named_t sgen_unrecov_err;	/* sense key indicates other err */
699a016c63Sstevel };
709a016c63Sstevel 
719a016c63Sstevel typedef struct sgen_state {
729a016c63Sstevel 	struct scsi_device *sgen_scsidev;	/* pointer to scsi_device */
739a016c63Sstevel 	struct uscsi_cmd *sgen_ucmd;		/* uscsi command struct */
749a016c63Sstevel 	struct buf *sgen_cmdbuf;		/* xfer buffer */
759a016c63Sstevel 	struct scsi_pkt *sgen_cmdpkt;		/* scsi packet for command */
769a016c63Sstevel 	kcondvar_t sgen_cmdbuf_cv;		/* cv for cmdbuf */
779a016c63Sstevel 	int sgen_flags;				/* see SGEN_FL_* */
789a016c63Sstevel 	struct scsi_pkt *sgen_rqspkt;		/* request sense packet */
799a016c63Sstevel 	struct buf *sgen_rqsbuf;		/* request sense xfer buffer */
809a016c63Sstevel 	char *sgen_rqs_sen;			/* sense buffer */
819a016c63Sstevel 	int sgen_arq_enabled;			/* auto request sense enabled */
829a016c63Sstevel 	int sgen_diag;				/* diagnostic output level */
839a016c63Sstevel 	timeout_id_t sgen_restart_timeid;	/* timeout for sgen_restart */
849a016c63Sstevel 	kstat_t *sgen_kstats;			/* for error statistics */
859a016c63Sstevel } sgen_state_t;
869a016c63Sstevel 
879a016c63Sstevel /*
889a016c63Sstevel  * Convenience accessors for sgen_state_t.
899a016c63Sstevel  */
909a016c63Sstevel #define	sgen_mutex sgen_scsidev->sd_mutex
919a016c63Sstevel #define	sgen_devinfo sgen_scsidev->sd_dev
929a016c63Sstevel #define	sgen_scsiaddr sgen_scsidev->sd_address
939a016c63Sstevel #define	sgen_sense sgen_scsidev->sd_sense
949a016c63Sstevel 
959a016c63Sstevel /*
969a016c63Sstevel  * sgen_flags accessors/mutators
979a016c63Sstevel  */
989a016c63Sstevel #define	SGEN_FL_OPEN	0x01	/* instance is open */
999a016c63Sstevel #define	SGEN_FL_SUSP	0x02	/* instance suspended */
1009a016c63Sstevel #define	SGEN_FL_BUSY	0x04	/* command buffer busy */
101*275c9da8Seschrock #define	SGEN_FL_EXCL	0x08	/* exclusive open */
1029a016c63Sstevel 
1039a016c63Sstevel #define	SGEN_SET_OPEN(stp) \
1049a016c63Sstevel 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_OPEN)
1059a016c63Sstevel #define	SGEN_CLR_OPEN(stp) \
1069a016c63Sstevel 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_OPEN)
1079a016c63Sstevel #define	SGEN_IS_OPEN(stp) \
1089a016c63Sstevel 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_OPEN) == SGEN_FL_OPEN)
1099a016c63Sstevel 
1109a016c63Sstevel #define	SGEN_SET_SUSP(stp) \
1119a016c63Sstevel 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_SUSP)
1129a016c63Sstevel #define	SGEN_CLR_SUSP(stp) \
1139a016c63Sstevel 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_SUSP)
1149a016c63Sstevel #define	SGEN_IS_SUSP(stp) \
1159a016c63Sstevel 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_SUSP) == SGEN_FL_SUSP)
1169a016c63Sstevel 
1179a016c63Sstevel #define	SGEN_SET_BUSY(stp) \
1189a016c63Sstevel 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_BUSY)
1199a016c63Sstevel #define	SGEN_CLR_BUSY(stp) \
1209a016c63Sstevel 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_BUSY)
1219a016c63Sstevel #define	SGEN_IS_BUSY(stp) \
1229a016c63Sstevel 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_BUSY) == SGEN_FL_BUSY)
1239a016c63Sstevel 
124*275c9da8Seschrock #define	SGEN_SET_EXCL(stp) \
125*275c9da8Seschrock 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_EXCL)
126*275c9da8Seschrock #define	SGEN_CLR_EXCL(stp) \
127*275c9da8Seschrock 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_EXCL)
128*275c9da8Seschrock #define	SGEN_IS_EXCL(stp) \
129*275c9da8Seschrock 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_EXCL) == SGEN_FL_EXCL)
130*275c9da8Seschrock 
1319a016c63Sstevel /*
1329a016c63Sstevel  * These structures form the driver's database of binding information.
1339a016c63Sstevel  * Inquiry strings and device types from the inquiry-config-list and
1349a016c63Sstevel  * device-type-config-list properties are stored.
1359a016c63Sstevel  */
1369a016c63Sstevel typedef struct sgen_inq_node {
1379a016c63Sstevel 	char *node_vendor;			/* up to 8 character vendor */
1389a016c63Sstevel 	char *node_product;			/* up to 16 character product */
1399a016c63Sstevel 	struct sgen_inq_node *node_next;
1409a016c63Sstevel } sgen_inq_node_t;
1419a016c63Sstevel 
1429a016c63Sstevel typedef struct sgen_type_node {
1439a016c63Sstevel 	uchar_t node_type;			/* SCSI device type */
1449a016c63Sstevel 	struct sgen_type_node *node_next;
1459a016c63Sstevel } sgen_type_node_t;
1469a016c63Sstevel 
1479a016c63Sstevel struct sgen_binddb {
1489a016c63Sstevel 	int sdb_init;				/* has this been initialized? */
1499a016c63Sstevel 	kmutex_t sdb_lock;			/* protects this structure */
1509a016c63Sstevel 	sgen_inq_node_t *sdb_inq_nodes;		/* inquiry binding nodes */
1519a016c63Sstevel 	sgen_type_node_t *sdb_type_nodes;	/* dev-type binding nodes */
1529a016c63Sstevel };
1539a016c63Sstevel 
1549a016c63Sstevel #define	SGEN_ESTIMATED_NUM_DEVS	4		/* for soft-state allocation */
1559a016c63Sstevel 
1569a016c63Sstevel /*
1579a016c63Sstevel  * Time to wait before a retry for commands returning Busy Status
1589a016c63Sstevel  */
1599a016c63Sstevel #define	SGEN_BSY_TIMEOUT	(drv_usectohz(5 * 1000000))
1609a016c63Sstevel #define	SGEN_IO_TIME		60		/* seconds */
1619a016c63Sstevel 
1629a016c63Sstevel /*
1639a016c63Sstevel  * sgen_callback action codes
1649a016c63Sstevel  */
1659a016c63Sstevel #define	COMMAND_DONE		0	/* command completed, biodone it */
1669a016c63Sstevel #define	COMMAND_DONE_ERROR	1	/* command completed, indicate error */
1679a016c63Sstevel #define	FETCH_SENSE		2	/* CHECK CONDITION, so initiate sense */
1689a016c63Sstevel 					/* fetch */
1699a016c63Sstevel 
1709a016c63Sstevel #define	SET_BP_ERROR(bp, err)	bioerror(bp, err);
1719a016c63Sstevel 
1729a016c63Sstevel #endif /* defined(_KERNEL) */
1739a016c63Sstevel 
1749a016c63Sstevel #ifdef	__cplusplus
1759a016c63Sstevel }
1769a016c63Sstevel #endif
1779a016c63Sstevel 
1789a016c63Sstevel #endif	/* _SYS_SCSI_TARGETS_SGENDEF_H */
179