xref: /titanic_50/usr/src/lib/libraidcfg/common/raidcfg_spi.h (revision 275c9da86e89f8abf71135cf63d9fc23671b2e60)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_RAIDCFG_SPI_H
28 #define	_SYS_RAIDCFG_SPI_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/types.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Controller capabilities
40  */
41 #define	RAID_CAP_RAID0		1
42 #define	RAID_CAP_RAID1		1 << 1
43 #define	RAID_CAP_RAID1E		1 << 2
44 #define	RAID_CAP_RAID5		1 << 3
45 #define	RAID_CAP_RAID10		1 << 4
46 #define	RAID_CAP_RAID50		1 << 5
47 #define	RAID_CAP_G_HSP		1 << 6
48 #define	RAID_CAP_L_HSP		1 << 7
49 #define	RAID_CAP_DISK_TRANS	1 << 8
50 #define	RAID_CAP_FULL_DISK_ONLY	1 << 9
51 #define	RAID_CAP_SMART_ALLOC	1 << 10
52 #define	RAID_CAP_ARRAY_ALIGN	1 << 11
53 
54 /*
55  * General constants
56  */
57 #define	OBJ_SEPARATOR_BEGIN	-1
58 #define	OBJ_SEPARATOR_END	-2
59 
60 #define	OBJ_ATTR_NONE		-1
61 
62 /*
63  * Array RAID level definition
64  */
65 #define	RAID_LEVEL_0		1
66 #define	RAID_LEVEL_1		2
67 #define	RAID_LEVEL_1E		3
68 #define	RAID_LEVEL_5		4
69 #define	RAID_LEVEL_10		5
70 #define	RAID_LEVEL_50		6
71 
72 /*
73  * Array cache write policy
74  */
75 #define	CACHE_WR_OFF		0
76 #define	CACHE_WR_ON		1
77 
78 /*
79  * Array cache read policy
80  */
81 #define	CACHE_RD_OFF		0
82 #define	CACHE_RD_ON		1
83 
84 /*
85  * Array status
86  */
87 #define	ARRAY_STATE_OPTIMAL	0
88 #define	ARRAY_STATE_DEGRADED	1
89 #define	ARRAY_STATE_FAILED	2
90 #define	ARRAY_STATE_MISSING	3
91 
92 /*
93  * Disk state
94  */
95 #define	DISK_STATE_GOOD		0
96 #define	DISK_STATE_FAILED	1
97 
98 /*
99  * Array part state
100  */
101 #define	ARRAYPART_STATE_GOOD	0
102 #define	ARRAYPART_STATE_MISSED	1
103 
104 /*
105  * Disk segment state
106  */
107 #define	DISKSEG_STATE_GOOD	1
108 #define	DISKSEG_STATE_RESERVED	1 << 1
109 #define	DISKSEG_STATE_DEAD	1 << 2
110 #define	DISKSEG_STATE_NORMAL	1 << 3
111 
112 /*
113  * Controller connection type
114  */
115 #define	TYPE_UNKNOWN		0
116 #define	TYPE_SCSI		1
117 #define	TYPE_SAS		2
118 
119 #define	RAID_TASK_SUSPEND	0
120 #define	RAID_TASK_RESUME	1
121 #define	RAID_TASK_TERMINATE	2
122 
123 #define	HSP_TYPE_GLOBAL		0
124 #define	HSP_TYPE_LOCAL		1
125 
126 /*
127  * Sub-command of set attribute
128  */
129 #define	SET_CACHE_WR_PLY	0
130 #define	SET_CACHE_RD_PLY	1
131 
132 /*
133  * Sub-commands for act method of object
134  */
135 #define	ACT_CONTROLLER_OPEN	0
136 #define	ACT_CONTROLLER_CLOSE	1
137 #define	ACT_CONTROLLER_FLASH_FW	2
138 
139 /*
140  * Some definitions
141  */
142 #define	CONTROLLER_FW_LEN	32
143 #define	CONTROLLER_TYPE_LEN	32
144 
145 #define	DISK_VENDER_LEN		8
146 #define	DISK_PRODUCT_LEN	16
147 #define	DISK_REV_LEN		4
148 
149 #define	RDCFG_PLUGIN_V1		0x10000
150 #define	CFGDIR		"/dev/cfg"
151 #define	MAX_PATH_LEN		255
152 
153 /*
154  * Mininum array part size: 256M
155  */
156 #define	ARRAYPART_MIN_SIZE	(uint64_t)(1 << 28)
157 
158 /*
159  * Return code
160  */
161 #define	SUCCESS			0
162 #define	STD_IOCTL		-1
163 #define	ERR_DRIVER_NOT_FOUND	-2
164 #define	ERR_DRIVER_OPEN		-3
165 #define	ERR_DRIVER_LOCK		-4
166 #define	ERR_DRIVER_CLOSED	-5
167 #define	ERR_DRIVER_ACROSS	-6
168 #define	ERR_ARRAY_LEVEL		-7
169 #define	ERR_ARRAY_SIZE		-8
170 #define	ERR_ARRAY_STRIPE_SIZE	-9
171 #define	ERR_ARRAY_CACHE_POLICY	-10
172 #define	ERR_ARRAY_IN_USE	-11
173 #define	ERR_ARRAY_TASK		-12
174 #define	ERR_ARRAY_CONFIG	-13
175 #define	ERR_ARRAY_DISKNUM	-14
176 #define	ERR_ARRAY_LAYOUT	-15
177 #define	ERR_ARRAY_AMOUNT	-16
178 #define	ERR_DISK_STATE		-17
179 #define	ERR_DISK_SPACE		-18
180 #define	ERR_DISK_SEG_AMOUNT	-19
181 #define	ERR_DISK_NOT_EMPTY	-20
182 #define	ERR_DISK_TASK		-21
183 #define	ERR_TASK_STATE		-22
184 #define	ERR_OP_ILLEGAL		-23
185 #define	ERR_OP_NO_IMPL		-24
186 #define	ERR_OP_FAILED		-25
187 #define	ERR_DEVICE_NOENT	-26
188 #define	ERR_DEVICE_TYPE		-27
189 #define	ERR_DEVICE_DUP		-28
190 #define	ERR_DEVICE_OVERFLOW	-29
191 #define	ERR_DEVICE_UNCLEAN	-30
192 #define	ERR_DEVICE_INVALID	-31
193 #define	ERR_NOMEM		-32
194 #define	ERR_PRIV		-33
195 #define	ERR_PLUGIN		-34
196 
197 /*
198  * Raid object types
199  */
200 typedef enum {
201 	OBJ_TYPE_SYSTEM,
202 	OBJ_TYPE_CONTROLLER,
203 	OBJ_TYPE_ARRAY,
204 	OBJ_TYPE_DISK,
205 	OBJ_TYPE_HSP,
206 	OBJ_TYPE_ARRAY_PART,
207 	OBJ_TYPE_DISK_SEG,
208 	OBJ_TYPE_TASK,
209 	OBJ_TYPE_ALL
210 } raid_obj_type_id_t;
211 
212 /*
213  * Task functions
214  */
215 typedef enum {
216 	TASK_FUNC_UNKNOWN,
217 	TASK_FUNC_INIT,
218 	TASK_FUNC_BUILD,
219 	TASK_FUNC_VERIFY
220 } raidtask_func_t;
221 
222 /*
223  * Task state
224  */
225 typedef enum {
226 	TASK_STATE_UNKNOWN,
227 	TASK_STATE_TERMINATED,
228 	TASK_STATE_FAILED,
229 	TASK_STATE_DONE,
230 	TASK_STATE_RUNNING,
231 	TASK_STATE_SUSPENDED
232 } raidtask_state_t;
233 
234 /*
235  * Attributes of all RAID objects
236  */
237 typedef union {
238 	uint64_t	reserved[3];
239 	struct {
240 		uint64_t	target_id;
241 		uint64_t	lun;
242 	} idl;
243 } array_tag_t;
244 
245 typedef union {
246 	struct {
247 		uint64_t bus;
248 		uint64_t target_id;
249 		uint64_t lun;
250 	} cidl;
251 } disk_tag_t;
252 
253 typedef struct {
254 	uint32_t	controller_id;
255 	uint32_t	max_array_num;
256 	uint32_t	max_seg_per_disk;
257 	uint32_t	connection_type;
258 	uint64_t	capability;
259 	char		fw_version[CONTROLLER_FW_LEN];
260 	char		controller_type[CONTROLLER_TYPE_LEN];
261 } controller_attr_t;
262 
263 typedef struct {
264 	uint32_t	array_id;
265 	uint32_t	state;
266 	array_tag_t	tag;
267 	uint64_t	capacity;
268 	uint32_t	raid_level;
269 	uint32_t	stripe_size;
270 	uint32_t	write_policy;
271 	uint32_t	read_policy;
272 } array_attr_t;
273 
274 typedef struct {
275 	uint32_t	disk_id;
276 	uint32_t	state;
277 	disk_tag_t	tag;
278 	uint64_t	capacity;
279 	char		vendorid[DISK_VENDER_LEN];
280 	char		productid[DISK_PRODUCT_LEN];
281 	char		revision[DISK_REV_LEN];
282 } disk_attr_t;
283 
284 typedef struct {
285 	uint32_t	associated_id;
286 	uint32_t	type;
287 } hsp_attr_t;
288 
289 typedef struct {
290 	uint32_t	disk_id;
291 	uint32_t	state;
292 	uint64_t	offset;
293 	uint64_t	size;
294 } arraypart_attr_t;
295 
296 typedef struct {
297 	uint32_t	seq_no;
298 	uint32_t	state;
299 	uint64_t	offset;
300 	uint64_t	size;
301 } diskseg_attr_t;
302 
303 typedef struct {
304 	uint32_t	task_id;
305 	uint32_t	task_func;
306 	uint32_t	task_state;
307 	uint32_t	progress;
308 } task_attr_t;
309 
310 typedef struct {
311 	uint32_t	array_id;
312 	uint32_t	disk_id;
313 } hsp_relation_t;
314 
315 /*
316  * Structure used to register plug-in modules
317  */
318 typedef	struct raid_lib_type {
319 	uint32_t version;
320 	struct raid_lib_type *next;
321 	void	*lib_handle;
322 	const char	*name;
323 
324 	int (*open_controller)(uint32_t, char **);
325 	int (*close_controller)(uint32_t, char **);
326 	int (*compnum)(uint32_t, uint32_t, raid_obj_type_id_t,
327 		raid_obj_type_id_t);
328 	int (*complist)(uint32_t, uint32_t, raid_obj_type_id_t,
329 		raid_obj_type_id_t, int, void *);
330 	int (*get_attr)(uint32_t, uint32_t, uint32_t, raid_obj_type_id_t,
331 		void *);
332 	int (*set_attr)(uint32_t, uint32_t, uint32_t, uint32_t *, char **);
333 	int (*array_create)(uint32_t, array_attr_t *, int,
334 		arraypart_attr_t *, char **);
335 	int (*array_delete)(uint32_t, uint32_t, char **);
336 	int (*hsp_bind)(uint32_t, uint32_t, hsp_relation_t *, char **);
337 	int (*hsp_unbind)(uint32_t, uint32_t, hsp_relation_t *, char **);
338 	int (*flash_fw)(uint32_t, char *, uint32_t, char **);
339 } raid_lib_t;
340 
341 #ifdef	__cplusplus
342 }
343 #endif
344 
345 #endif	/* _SYS_RAIDCFG_SPI_H */
346