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