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