xref: /titanic_52/usr/src/uts/common/sys/scsi/targets/sgendef.h (revision 9df258ac654d4990e45ba8bff1661d2d0d3b0d2a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2001 by Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright Siemens 1999
29  * All rights reserved.
30  */
31 
32 #ifndef _SYS_SCSI_TARGETS_SGENDEF_H
33 #define	_SYS_SCSI_TARGETS_SGENDEF_H
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 #include <sys/types.h>
38 #include <sys/kstat.h>
39 #include <sys/condvar.h>
40 #include <sys/mutex.h>
41 #include <sys/buf.h>
42 #include <sys/scsi/scsi.h>
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 #define	SGEN_IOC		(('S' << 16) | ('G' << 8))
49 #define	SGEN_IOC_READY		(SGEN_IOC | 0x01)
50 #define	SGEN_IOC_DIAG		(SGEN_IOC | 0x02)
51 
52 #if defined(_KERNEL)
53 
54 #define	SGEN_DIAG1		((1 << 8) | CE_CONT)
55 #define	SGEN_DIAG2		((2 << 8) | CE_CONT)
56 #define	SGEN_DIAG3		((3 << 8) | CE_CONT)
57 
58 struct sgen_errstats {
59 	kstat_named_t sgen_trans_err;	/* error trying to transport pkt */
60 	kstat_named_t sgen_restart;	/* command restart attempted */
61 	kstat_named_t sgen_incmp_err;	/* command failed to complete */
62 	kstat_named_t sgen_autosen_rcv;	/* autosense occurred */
63 	kstat_named_t sgen_autosen_bad;	/* autosense data looks malformed */
64 	kstat_named_t sgen_sense_rcv;	/* sense fetch occurred */
65 	kstat_named_t sgen_sense_bad;	/* sense data looks malformed */
66 	kstat_named_t sgen_recov_err;	/* sense key is KEY_RECOVERABLE */
67 	kstat_named_t sgen_nosen_err;	/* sense key is KEY_NO_SENSE */
68 	kstat_named_t sgen_unrecov_err;	/* sense key indicates other err */
69 };
70 
71 typedef struct sgen_state {
72 	struct scsi_device *sgen_scsidev;	/* pointer to scsi_device */
73 	struct uscsi_cmd *sgen_ucmd;		/* uscsi command struct */
74 	struct buf *sgen_cmdbuf;		/* xfer buffer */
75 	struct scsi_pkt *sgen_cmdpkt;		/* scsi packet for command */
76 	kcondvar_t sgen_cmdbuf_cv;		/* cv for cmdbuf */
77 	int sgen_flags;				/* see SGEN_FL_* */
78 	struct scsi_pkt *sgen_rqspkt;		/* request sense packet */
79 	struct buf *sgen_rqsbuf;		/* request sense xfer buffer */
80 	char *sgen_rqs_sen;			/* sense buffer */
81 	int sgen_arq_enabled;			/* auto request sense enabled */
82 	int sgen_diag;				/* diagnostic output level */
83 	timeout_id_t sgen_restart_timeid;	/* timeout for sgen_restart */
84 	kstat_t *sgen_kstats;			/* for error statistics */
85 } sgen_state_t;
86 
87 /*
88  * Convenience accessors for sgen_state_t.
89  */
90 #define	sgen_mutex sgen_scsidev->sd_mutex
91 #define	sgen_devinfo sgen_scsidev->sd_dev
92 #define	sgen_scsiaddr sgen_scsidev->sd_address
93 #define	sgen_sense sgen_scsidev->sd_sense
94 
95 /*
96  * sgen_flags accessors/mutators
97  */
98 #define	SGEN_FL_OPEN	0x01	/* instance is open */
99 #define	SGEN_FL_SUSP	0x02	/* instance suspended */
100 #define	SGEN_FL_BUSY	0x04	/* command buffer busy */
101 
102 #define	SGEN_SET_OPEN(stp) \
103 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_OPEN)
104 #define	SGEN_CLR_OPEN(stp) \
105 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_OPEN)
106 #define	SGEN_IS_OPEN(stp) \
107 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_OPEN) == SGEN_FL_OPEN)
108 
109 #define	SGEN_SET_SUSP(stp) \
110 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_SUSP)
111 #define	SGEN_CLR_SUSP(stp) \
112 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_SUSP)
113 #define	SGEN_IS_SUSP(stp) \
114 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_SUSP) == SGEN_FL_SUSP)
115 
116 #define	SGEN_SET_BUSY(stp) \
117 	(((sgen_state_t *)(stp))->sgen_flags |= SGEN_FL_BUSY)
118 #define	SGEN_CLR_BUSY(stp) \
119 	(((sgen_state_t *)(stp))->sgen_flags &= ~SGEN_FL_BUSY)
120 #define	SGEN_IS_BUSY(stp) \
121 	((((sgen_state_t *)(stp))->sgen_flags & SGEN_FL_BUSY) == SGEN_FL_BUSY)
122 
123 /*
124  * These structures form the driver's database of binding information.
125  * Inquiry strings and device types from the inquiry-config-list and
126  * device-type-config-list properties are stored.
127  */
128 typedef struct sgen_inq_node {
129 	char *node_vendor;			/* up to 8 character vendor */
130 	char *node_product;			/* up to 16 character product */
131 	struct sgen_inq_node *node_next;
132 } sgen_inq_node_t;
133 
134 typedef struct sgen_type_node {
135 	uchar_t node_type;			/* SCSI device type */
136 	struct sgen_type_node *node_next;
137 } sgen_type_node_t;
138 
139 struct sgen_binddb {
140 	int sdb_init;				/* has this been initialized? */
141 	kmutex_t sdb_lock;			/* protects this structure */
142 	sgen_inq_node_t *sdb_inq_nodes;		/* inquiry binding nodes */
143 	sgen_type_node_t *sdb_type_nodes;	/* dev-type binding nodes */
144 };
145 
146 #define	SGEN_ESTIMATED_NUM_DEVS	4		/* for soft-state allocation */
147 
148 /*
149  * Time to wait before a retry for commands returning Busy Status
150  */
151 #define	SGEN_BSY_TIMEOUT	(drv_usectohz(5 * 1000000))
152 #define	SGEN_IO_TIME		60		/* seconds */
153 
154 /*
155  * sgen_callback action codes
156  */
157 #define	COMMAND_DONE		0	/* command completed, biodone it */
158 #define	COMMAND_DONE_ERROR	1	/* command completed, indicate error */
159 #define	FETCH_SENSE		2	/* CHECK CONDITION, so initiate sense */
160 					/* fetch */
161 
162 #define	SET_BP_ERROR(bp, err)	bioerror(bp, err);
163 
164 #endif /* defined(_KERNEL) */
165 
166 #ifdef	__cplusplus
167 }
168 #endif
169 
170 #endif	/* _SYS_SCSI_TARGETS_SGENDEF_H */
171