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