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