xref: /titanic_50/usr/src/lib/libraidcfg/common/raidcfg_spi.h (revision e07d9cb85217949d497b02d7211de8a197d2f2eb)
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 2007 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 
91 /*
92  * Disk state
93  */
94 #define	DISK_STATE_GOOD		0
95 #define	DISK_STATE_FAILED	1
96 
97 /*
98  * Array part state
99  */
100 #define	ARRAYPART_STATE_GOOD	0
101 #define	ARRAYPART_STATE_MISSED	1
102 
103 /*
104  * Disk segment state
105  */
106 #define	DISKSEG_STATE_GOOD	1
107 #define	DISKSEG_STATE_RESERVED	1 << 1
108 #define	DISKSEG_STATE_DEAD	1 << 2
109 #define	DISKSEG_STATE_NORMAL	1 << 3
110 
111 /*
112  * Controller connection type
113  */
114 #define	TYPE_UNKNOWN		0
115 #define	TYPE_SCSI		1
116 #define	TYPE_SAS		2
117 
118 #define	RAID_TASK_SUSPEND	0
119 #define	RAID_TASK_RESUME	1
120 #define	RAID_TASK_TERMINATE	2
121 
122 #define	HSP_TYPE_GLOBAL		0
123 #define	HSP_TYPE_LOCAL		1
124 
125 /*
126  * Sub-command of set attribute
127  */
128 #define	SET_CACHE_WR_PLY	0
129 #define	SET_CACHE_RD_PLY	1
130 
131 /*
132  * Sub-commands for act method of object
133  */
134 #define	ACT_CONTROLLER_OPEN	0
135 #define	ACT_CONTROLLER_CLOSE	1
136 #define	ACT_CONTROLLER_FLASH_FW	2
137 
138 /*
139  * Some definitions
140  */
141 #define	CONTROLLER_FW_LEN	32
142 #define	CONTROLLER_TYPE_LEN	32
143 
144 #define	DISK_VENDER_LEN		8
145 #define	DISK_PRODUCT_LEN	16
146 #define	DISK_REV_LEN		4
147 
148 #define	DISK_ID(c, id, l)	((c) << 7 | (l) << 4 | (id))
149 #define	BUS(disk_id)		((disk_id) >> 7)
150 #define	TARGET(disk_id)		((disk_id) & 0xf)
151 #define	LUN(disk_id)		(((disk_id) >> 4) & 0x7)
152 
153 #define	ARRAY_ID(id, l)		((l) << 16 | (id))
154 #define	ARRAY_TARGET(array_id)	((array_id) & 0xffff)
155 #define	ARRAY_LUN(array_id)	((array_id) >> 16)
156 
157 #define	RDCFG_PLUGIN_V1		0x10000
158 #define	CFGDIR		"/dev/cfg"
159 #define	MAX_PATH_LEN		255
160 
161 /*
162  * Mininum array part size: 256M
163  */
164 #define	ARRAYPART_MIN_SIZE	(uint64_t)(1 << 28)
165 
166 /*
167  * Return code
168  */
169 #define	SUCCESS			0
170 #define	STD_IOCTL		-1
171 #define	ERR_DRIVER_NOT_FOUND	-2
172 #define	ERR_DRIVER_OPEN		-3
173 #define	ERR_DRIVER_LOCK		-4
174 #define	ERR_DRIVER_CLOSED	-5
175 #define	ERR_DRIVER_ACROSS	-6
176 #define	ERR_ARRAY_LEVEL		-7
177 #define	ERR_ARRAY_SIZE		-8
178 #define	ERR_ARRAY_STRIPE_SIZE	-9
179 #define	ERR_ARRAY_CACHE_POLICY	-10
180 #define	ERR_ARRAY_IN_USE	-11
181 #define	ERR_ARRAY_TASK		-12
182 #define	ERR_ARRAY_CONFIG	-13
183 #define	ERR_ARRAY_DISKNUM	-14
184 #define	ERR_ARRAY_LAYOUT	-15
185 #define	ERR_ARRAY_AMOUNT	-16
186 #define	ERR_DISK_STATE		-17
187 #define	ERR_DISK_SPACE		-18
188 #define	ERR_DISK_SEG_AMOUNT	-19
189 #define	ERR_DISK_NOT_EMPTY	-20
190 #define	ERR_DISK_TASK		-21
191 #define	ERR_TASK_STATE		-22
192 #define	ERR_OP_ILLEGAL		-23
193 #define	ERR_OP_NO_IMPL		-24
194 #define	ERR_OP_FAILED		-25
195 #define	ERR_DEVICE_NOENT	-26
196 #define	ERR_DEVICE_TYPE		-27
197 #define	ERR_DEVICE_DUP		-28
198 #define	ERR_DEVICE_OVERFLOW	-29
199 #define	ERR_DEVICE_UNCLEAN	-30
200 #define	ERR_DEVICE_INVALID	-31
201 #define	ERR_NOMEM		-32
202 #define	ERR_PRIV		-33
203 #define	ERR_PLUGIN		-34
204 
205 /*
206  * Raid object types
207  */
208 typedef enum {
209 	OBJ_TYPE_SYSTEM,
210 	OBJ_TYPE_CONTROLLER,
211 	OBJ_TYPE_ARRAY,
212 	OBJ_TYPE_DISK,
213 	OBJ_TYPE_HSP,
214 	OBJ_TYPE_ARRAY_PART,
215 	OBJ_TYPE_DISK_SEG,
216 	OBJ_TYPE_TASK,
217 	OBJ_TYPE_ALL
218 } raid_obj_type_id_t;
219 
220 /*
221  * Task functions
222  */
223 typedef enum {
224 	TASK_FUNC_UNKNOWN,
225 	TASK_FUNC_INIT,
226 	TASK_FUNC_BUILD,
227 	TASK_FUNC_VERIFY
228 } raidtask_func_t;
229 
230 /*
231  * Task state
232  */
233 typedef enum {
234 	TASK_STATE_UNKNOWN,
235 	TASK_STATE_TERMINATED,
236 	TASK_STATE_FAILED,
237 	TASK_STATE_DONE,
238 	TASK_STATE_RUNNING,
239 	TASK_STATE_SUSPENDED
240 } raidtask_state_t;
241 
242 /*
243  * Attributes of all RAID objects
244  */
245 typedef union {
246 	uint64_t	reserved[3];
247 	struct {
248 		uint64_t	target_id;
249 		uint64_t	lun;
250 	} idl;
251 } array_tag_t;
252 
253 typedef union {
254 	struct {
255 		uint64_t bus;
256 		uint64_t target_id;
257 		uint64_t lun;
258 	} cidl;
259 } disk_tag_t;
260 
261 typedef struct {
262 	uint32_t	controller_id;
263 	uint32_t	max_array_num;
264 	uint32_t	max_seg_per_disk;
265 	uint32_t	connection_type;
266 	uint64_t	capability;
267 	char		fw_version[CONTROLLER_FW_LEN];
268 	char		controller_type[CONTROLLER_TYPE_LEN];
269 } controller_attr_t;
270 
271 typedef struct {
272 	uint32_t	array_id;
273 	uint32_t	state;
274 	array_tag_t	tag;
275 	uint64_t	capacity;
276 	uint32_t	raid_level;
277 	uint32_t	stripe_size;
278 	uint32_t	write_policy;
279 	uint32_t	read_policy;
280 } array_attr_t;
281 
282 typedef struct {
283 	uint32_t	disk_id;
284 	uint32_t	state;
285 	disk_tag_t	tag;
286 	uint64_t	capacity;
287 	char		vendorid[DISK_VENDER_LEN];
288 	char		productid[DISK_PRODUCT_LEN];
289 	char		revision[DISK_REV_LEN];
290 } disk_attr_t;
291 
292 typedef struct {
293 	uint32_t	associated_id;
294 	uint32_t	type;
295 } hsp_attr_t;
296 
297 typedef struct {
298 	uint32_t	disk_id;
299 	uint32_t	state;
300 	uint64_t	offset;
301 	uint64_t	size;
302 } arraypart_attr_t;
303 
304 typedef struct {
305 	uint32_t	seq_no;
306 	uint32_t	state;
307 	uint64_t	offset;
308 	uint64_t	size;
309 } diskseg_attr_t;
310 
311 typedef struct {
312 	uint32_t	task_id;
313 	uint32_t	task_func;
314 	uint32_t	task_state;
315 	uint32_t	progress;
316 } task_attr_t;
317 
318 typedef struct {
319 	uint32_t	array_id;
320 	uint32_t	disk_id;
321 } hsp_relation_t;
322 
323 /*
324  * Structure used to register plug-in modules
325  */
326 typedef	struct raid_lib_type {
327 	uint32_t version;
328 	struct raid_lib_type *next;
329 	void	*lib_handle;
330 	const char	*name;
331 
332 	int (*open_controller)(uint32_t, char **);
333 	int (*close_controller)(uint32_t, char **);
334 	int (*compnum)(uint32_t, uint32_t, raid_obj_type_id_t,
335 		raid_obj_type_id_t);
336 	int (*complist)(uint32_t, uint32_t, raid_obj_type_id_t,
337 		raid_obj_type_id_t, int, void *);
338 	int (*get_attr)(uint32_t, uint32_t, uint32_t, raid_obj_type_id_t,
339 		void *);
340 	int (*set_attr)(uint32_t, uint32_t, uint32_t, uint32_t *, char **);
341 	int (*array_create)(uint32_t, array_attr_t *, int,
342 		arraypart_attr_t *, char **);
343 	int (*array_delete)(uint32_t, uint32_t, char **);
344 	int (*hsp_bind)(uint32_t, uint32_t, hsp_relation_t *, char **);
345 	int (*hsp_unbind)(uint32_t, uint32_t, hsp_relation_t *, char **);
346 	int (*flash_fw)(uint32_t, char *, uint32_t, char **);
347 } raid_lib_t;
348 
349 #ifdef	__cplusplus
350 }
351 #endif
352 
353 #endif	/* _SYS_RAIDCFG_SPI_H */
354