xref: /titanic_41/usr/src/cmd/format/ctlr_scsi.h (revision 1ae0874509b6811fdde1dfd46f0d93fd09867a3f)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_CTLR_SCSI_H
28 #define	_CTLR_SCSI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/buf.h>
37 #include <sys/scsi/scsi.h>
38 #ifdef sparc
39 #include <sys/scsi/targets/sddef.h>
40 #endif
41 
42 
43 /*
44  * Rounded parameter, as returned in Extended Sense information
45  */
46 #define	ROUNDED_PARAMETER	0x37
47 
48 /*
49  * Timeout Value during formatting
50  */
51 #ifndef	SHRT_MAX
52 #define	SHRT_MAX	32767
53 #endif
54 
55 /*
56  * Mode sense/select page header information
57  */
58 struct scsi_ms_header {
59 	struct mode_header	mode_header;
60 	struct block_descriptor	block_descriptor;
61 };
62 
63 /*
64  * Mode Sense Page Control
65  */
66 #define	MODE_SENSE_PC_CURRENT		(0 << 6)
67 #define	MODE_SENSE_PC_CHANGEABLE	(1 << 6)
68 #define	MODE_SENSE_PC_DEFAULT		(2 << 6)
69 #define	MODE_SENSE_PC_SAVED		(3 << 6)
70 
71 /*
72  * Mode Select options
73  */
74 #define	MODE_SELECT_SP			0x01
75 #define	MODE_SELECT_PF			0x10
76 
77 
78 
79 /*
80  * Minimum length of Request Sense data that we can accept
81  */
82 #define	MIN_REQUEST_SENSE_LEN		18
83 
84 /*
85  * "impossible" status value
86  */
87 #define	IMPOSSIBLE_SCSI_STATUS		0xff
88 
89 /*
90  * Convert a three-byte triplet into an int
91  */
92 #define	TRIPLET(u, m, l)	((int)((((u))&0xff<<16) + \
93 				(((m)&0xff)<<8) + (l&0xff)))
94 
95 /*
96  * Define the amount of slop we can tolerate on a SCSI-2 mode sense.
97  * Usually we try to deal with just the common subset between the
98  * the SCSI-2 structure and the CCS structure.  The length of the
99  * data returned can vary between targets, so being tolerant gives
100  * gives us a higher chance of success.
101  */
102 #define	PAGE1_SLOP		5
103 #define	PAGE2_SLOP		6
104 #define	PAGE3_SLOP		3
105 #define	PAGE4_SLOP		8
106 #define	PAGE8_SLOP		8
107 #define	PAGE38_SLOP		8
108 
109 /*
110  * Minimum lengths of a particular SCSI-2 mode sense page that
111  * we can deal with.  We must reject anything less than this.
112  */
113 #define	MIN_PAGE1_LEN		(sizeof (struct mode_err_recov)-PAGE1_SLOP)
114 #define	MIN_PAGE2_LEN		(sizeof (struct mode_disco_reco)-PAGE2_SLOP)
115 #define	MIN_PAGE3_LEN		(sizeof (struct mode_format)-PAGE3_SLOP)
116 #define	MIN_PAGE4_LEN		(sizeof (struct mode_geometry)-PAGE4_SLOP)
117 #define	MIN_PAGE8_LEN		(sizeof (struct mode_cache)-PAGE8_SLOP)
118 #define	MIN_PAGE38_LEN		(sizeof (struct mode_cache_ccs)-PAGE38_SLOP)
119 
120 /*
121  * Macro to extract the length of a mode sense page
122  * as returned by a target.
123  */
124 #define	MODESENSE_PAGE_LEN(p)	(((int)((struct mode_page *)p)->length) + \
125 					sizeof (struct mode_page))
126 
127 /*
128  * Request this number of bytes for all mode senses.  Since the
129  * data returned is self-defining, we can accept anywhere from
130  * the minimum for a particular page, up to this maximum.
131  * Whatever the drive gives us, we return to the drive, delta'ed
132  * by whatever we want to change.
133  */
134 #define	MAX_MODE_SENSE_SIZE		255
135 
136 
137 #ifdef	__STDC__
138 /*
139  *	Local prototypes for ANSI C compilers
140  */
141 #ifdef sparc
142 int	scsi_rdwr(int, int, diskaddr_t, int, caddr_t, int, int *);
143 #endif /* sparc */
144 
145 int	scsi_ex_man(struct defect_list *);
146 int	scsi_ex_cur(struct defect_list *);
147 int	scsi_ex_grown(struct defect_list *);
148 int	uscsi_cmd(int, struct uscsi_cmd *, int);
149 int	uscsi_mode_sense(int, int, int, caddr_t, int,
150 		struct scsi_ms_header *);
151 int	uscsi_mode_select(int, int, int, caddr_t, int,
152 		struct scsi_ms_header *);
153 int	uscsi_inquiry(int, caddr_t, int);
154 int	uscsi_read_capacity(int, struct scsi_capacity_16 *);
155 int	scsi_translate(int, struct scsi_bfi_defect *);
156 int	scsi_dump_mode_sense_pages(int);
157 int	scsi_supported_page(int);
158 int	apply_chg_list(int, int, uchar_t *, uchar_t *, struct chg_list *);
159 int	scsi_format_time(void);
160 
161 #else
162 
163 #ifdef sparc
164 int	scsi_ms_page1();
165 int	scsi_ms_page2();
166 int	scsi_ms_page3();
167 int	scsi_ms_page4();
168 int	scsi_read_defect_data();
169 int	scsi_repair();
170 int	scsi_rdwr();
171 #endif /* sparc */
172 
173 int	scsi_ck_format();
174 int	scsi_ex_man();
175 int	scsi_ex_cur();
176 int	scsi_ex_grown();
177 int	uscsi_cmd();
178 int	uscsi_mode_sense();
179 int	uscsi_mode_select();
180 int	uscsi_inquiry();
181 int	uscsi_read_capacity();
182 int	scsi_translate();
183 int	scsi_dump_mode_sense_pages();
184 int	scsi_supported_page();
185 int	apply_chg_list();
186 int	scsi_format_time();
187 
188 #endif	/* __STDC__ */
189 
190 #ifdef	__cplusplus
191 }
192 #endif
193 
194 #endif	/* _CTLR_SCSI_H */
195