xref: /titanic_52/usr/src/lib/libraidcfg/common/raidcfg_spi.h (revision f3f093f5e1252df53faccba99cf6d2295d6d0d58)
13e4f2897Sjc156560 /*
23e4f2897Sjc156560  * CDDL HEADER START
33e4f2897Sjc156560  *
43e4f2897Sjc156560  * The contents of this file are subject to the terms of the
53e4f2897Sjc156560  * Common Development and Distribution License (the "License").
63e4f2897Sjc156560  * You may not use this file except in compliance with the License.
73e4f2897Sjc156560  *
83e4f2897Sjc156560  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93e4f2897Sjc156560  * or http://www.opensolaris.org/os/licensing.
103e4f2897Sjc156560  * See the License for the specific language governing permissions
113e4f2897Sjc156560  * and limitations under the License.
123e4f2897Sjc156560  *
133e4f2897Sjc156560  * When distributing Covered Code, include this CDDL HEADER in each
143e4f2897Sjc156560  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153e4f2897Sjc156560  * If applicable, add the following below this CDDL HEADER, with the
163e4f2897Sjc156560  * fields enclosed by brackets "[]" replaced with your own identifying
173e4f2897Sjc156560  * information: Portions Copyright [yyyy] [name of copyright owner]
183e4f2897Sjc156560  *
193e4f2897Sjc156560  * CDDL HEADER END
203e4f2897Sjc156560  */
213e4f2897Sjc156560 
223e4f2897Sjc156560 /*
23*f3f093f5SMilan Jurik  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
243e4f2897Sjc156560  * Use is subject to license terms.
253e4f2897Sjc156560  */
263e4f2897Sjc156560 
273e4f2897Sjc156560 #ifndef	_SYS_RAIDCFG_SPI_H
283e4f2897Sjc156560 #define	_SYS_RAIDCFG_SPI_H
293e4f2897Sjc156560 
303e4f2897Sjc156560 #include <sys/types.h>
313e4f2897Sjc156560 
323e4f2897Sjc156560 #ifdef	__cplusplus
333e4f2897Sjc156560 extern "C" {
343e4f2897Sjc156560 #endif
353e4f2897Sjc156560 
363e4f2897Sjc156560 /*
373e4f2897Sjc156560  * Controller capabilities
383e4f2897Sjc156560  */
393e4f2897Sjc156560 #define	RAID_CAP_RAID0		1
403e4f2897Sjc156560 #define	RAID_CAP_RAID1		1 << 1
413e4f2897Sjc156560 #define	RAID_CAP_RAID1E		1 << 2
423e4f2897Sjc156560 #define	RAID_CAP_RAID5		1 << 3
433e4f2897Sjc156560 #define	RAID_CAP_RAID10		1 << 4
443e4f2897Sjc156560 #define	RAID_CAP_RAID50		1 << 5
453e4f2897Sjc156560 #define	RAID_CAP_G_HSP		1 << 6
463e4f2897Sjc156560 #define	RAID_CAP_L_HSP		1 << 7
473e4f2897Sjc156560 #define	RAID_CAP_DISK_TRANS	1 << 8
483e4f2897Sjc156560 #define	RAID_CAP_FULL_DISK_ONLY	1 << 9
493e4f2897Sjc156560 #define	RAID_CAP_SMART_ALLOC	1 << 10
503e4f2897Sjc156560 #define	RAID_CAP_ARRAY_ALIGN	1 << 11
513e4f2897Sjc156560 
523e4f2897Sjc156560 /*
533e4f2897Sjc156560  * General constants
543e4f2897Sjc156560  */
553e4f2897Sjc156560 #define	OBJ_SEPARATOR_BEGIN	-1
563e4f2897Sjc156560 #define	OBJ_SEPARATOR_END	-2
573e4f2897Sjc156560 
583e4f2897Sjc156560 #define	OBJ_ATTR_NONE		-1
593e4f2897Sjc156560 
603e4f2897Sjc156560 /*
613e4f2897Sjc156560  * Array RAID level definition
623e4f2897Sjc156560  */
633e4f2897Sjc156560 #define	RAID_LEVEL_0		1
643e4f2897Sjc156560 #define	RAID_LEVEL_1		2
653e4f2897Sjc156560 #define	RAID_LEVEL_1E		3
663e4f2897Sjc156560 #define	RAID_LEVEL_5		4
673e4f2897Sjc156560 #define	RAID_LEVEL_10		5
683e4f2897Sjc156560 #define	RAID_LEVEL_50		6
693e4f2897Sjc156560 
703e4f2897Sjc156560 /*
713e4f2897Sjc156560  * Array cache write policy
723e4f2897Sjc156560  */
733e4f2897Sjc156560 #define	CACHE_WR_OFF		0
743e4f2897Sjc156560 #define	CACHE_WR_ON		1
753e4f2897Sjc156560 
763e4f2897Sjc156560 /*
773e4f2897Sjc156560  * Array cache read policy
783e4f2897Sjc156560  */
793e4f2897Sjc156560 #define	CACHE_RD_OFF		0
803e4f2897Sjc156560 #define	CACHE_RD_ON		1
813e4f2897Sjc156560 
823e4f2897Sjc156560 /*
83b449fa8aSyw161884  * Array activation action
84b449fa8aSyw161884  */
85b449fa8aSyw161884 #define	ARRAY_ACT_ACTIVATE	0
86b449fa8aSyw161884 
87b449fa8aSyw161884 /*
883e4f2897Sjc156560  * Array status
893e4f2897Sjc156560  */
903e4f2897Sjc156560 #define	ARRAY_STATE_OPTIMAL	0
913e4f2897Sjc156560 #define	ARRAY_STATE_DEGRADED	1
923e4f2897Sjc156560 #define	ARRAY_STATE_FAILED	2
93a6e966d7Szk194757 #define	ARRAY_STATE_MISSING	3
943e4f2897Sjc156560 
953e4f2897Sjc156560 /*
96b449fa8aSyw161884  * Array activation state
97b449fa8aSyw161884  */
98b449fa8aSyw161884 #define	ARRAY_STATE_INACTIVATE	0x8000
99b449fa8aSyw161884 
100b449fa8aSyw161884 /*
1013e4f2897Sjc156560  * Disk state
1023e4f2897Sjc156560  */
1033e4f2897Sjc156560 #define	DISK_STATE_GOOD		0
1043e4f2897Sjc156560 #define	DISK_STATE_FAILED	1
1053e4f2897Sjc156560 
1063e4f2897Sjc156560 /*
1073e4f2897Sjc156560  * Array part state
1083e4f2897Sjc156560  */
1093e4f2897Sjc156560 #define	ARRAYPART_STATE_GOOD	0
1103e4f2897Sjc156560 #define	ARRAYPART_STATE_MISSED	1
1113e4f2897Sjc156560 
1123e4f2897Sjc156560 /*
1133e4f2897Sjc156560  * Disk segment state
1143e4f2897Sjc156560  */
1153e4f2897Sjc156560 #define	DISKSEG_STATE_GOOD	1
1163e4f2897Sjc156560 #define	DISKSEG_STATE_RESERVED	1 << 1
1173e4f2897Sjc156560 #define	DISKSEG_STATE_DEAD	1 << 2
1183e4f2897Sjc156560 #define	DISKSEG_STATE_NORMAL	1 << 3
1193e4f2897Sjc156560 
1203e4f2897Sjc156560 /*
1213e4f2897Sjc156560  * Controller connection type
1223e4f2897Sjc156560  */
1233e4f2897Sjc156560 #define	TYPE_UNKNOWN		0
1243e4f2897Sjc156560 #define	TYPE_SCSI		1
1253e4f2897Sjc156560 #define	TYPE_SAS		2
1263e4f2897Sjc156560 
1273e4f2897Sjc156560 #define	RAID_TASK_SUSPEND	0
1283e4f2897Sjc156560 #define	RAID_TASK_RESUME	1
1293e4f2897Sjc156560 #define	RAID_TASK_TERMINATE	2
1303e4f2897Sjc156560 
1313e4f2897Sjc156560 #define	HSP_TYPE_GLOBAL		0
1323e4f2897Sjc156560 #define	HSP_TYPE_LOCAL		1
1333e4f2897Sjc156560 
1343e4f2897Sjc156560 /*
1353e4f2897Sjc156560  * Sub-command of set attribute
1363e4f2897Sjc156560  */
1373e4f2897Sjc156560 #define	SET_CACHE_WR_PLY	0
1383e4f2897Sjc156560 #define	SET_CACHE_RD_PLY	1
139b449fa8aSyw161884 #define	SET_ACTIVATION_PLY	2
1403e4f2897Sjc156560 
1413e4f2897Sjc156560 /*
1423e4f2897Sjc156560  * Sub-commands for act method of object
1433e4f2897Sjc156560  */
1443e4f2897Sjc156560 #define	ACT_CONTROLLER_OPEN	0
1453e4f2897Sjc156560 #define	ACT_CONTROLLER_CLOSE	1
1463e4f2897Sjc156560 #define	ACT_CONTROLLER_FLASH_FW	2
1473e4f2897Sjc156560 
1483e4f2897Sjc156560 /*
1493e4f2897Sjc156560  * Some definitions
1503e4f2897Sjc156560  */
1513e4f2897Sjc156560 #define	CONTROLLER_FW_LEN	32
1523e4f2897Sjc156560 #define	CONTROLLER_TYPE_LEN	32
1533e4f2897Sjc156560 
1543e4f2897Sjc156560 #define	DISK_VENDER_LEN		8
1553e4f2897Sjc156560 #define	DISK_PRODUCT_LEN	16
1563e4f2897Sjc156560 #define	DISK_REV_LEN		4
1573e4f2897Sjc156560 
1583e4f2897Sjc156560 #define	RDCFG_PLUGIN_V1		0x10000
1593e4f2897Sjc156560 #define	CFGDIR		"/dev/cfg"
1603e4f2897Sjc156560 #define	MAX_PATH_LEN		255
1613e4f2897Sjc156560 
1623e4f2897Sjc156560 /*
1633e4f2897Sjc156560  * Mininum array part size: 256M
1643e4f2897Sjc156560  */
1653e4f2897Sjc156560 #define	ARRAYPART_MIN_SIZE	(uint64_t)(1 << 28)
1663e4f2897Sjc156560 
1673e4f2897Sjc156560 /*
1683e4f2897Sjc156560  * Return code
1693e4f2897Sjc156560  */
1703e4f2897Sjc156560 #define	SUCCESS			0
1713e4f2897Sjc156560 #define	STD_IOCTL		-1
1723e4f2897Sjc156560 #define	ERR_DRIVER_NOT_FOUND	-2
1733e4f2897Sjc156560 #define	ERR_DRIVER_OPEN		-3
1743e4f2897Sjc156560 #define	ERR_DRIVER_LOCK		-4
1753e4f2897Sjc156560 #define	ERR_DRIVER_CLOSED	-5
1763e4f2897Sjc156560 #define	ERR_DRIVER_ACROSS	-6
1773e4f2897Sjc156560 #define	ERR_ARRAY_LEVEL		-7
1783e4f2897Sjc156560 #define	ERR_ARRAY_SIZE		-8
1793e4f2897Sjc156560 #define	ERR_ARRAY_STRIPE_SIZE	-9
1803e4f2897Sjc156560 #define	ERR_ARRAY_CACHE_POLICY	-10
1813e4f2897Sjc156560 #define	ERR_ARRAY_IN_USE	-11
1823e4f2897Sjc156560 #define	ERR_ARRAY_TASK		-12
1833e4f2897Sjc156560 #define	ERR_ARRAY_CONFIG	-13
1843e4f2897Sjc156560 #define	ERR_ARRAY_DISKNUM	-14
1853e4f2897Sjc156560 #define	ERR_ARRAY_LAYOUT	-15
1863e4f2897Sjc156560 #define	ERR_ARRAY_AMOUNT	-16
1873e4f2897Sjc156560 #define	ERR_DISK_STATE		-17
1883e4f2897Sjc156560 #define	ERR_DISK_SPACE		-18
1893e4f2897Sjc156560 #define	ERR_DISK_SEG_AMOUNT	-19
1903e4f2897Sjc156560 #define	ERR_DISK_NOT_EMPTY	-20
1913e4f2897Sjc156560 #define	ERR_DISK_TASK		-21
1923e4f2897Sjc156560 #define	ERR_TASK_STATE		-22
1933e4f2897Sjc156560 #define	ERR_OP_ILLEGAL		-23
1943e4f2897Sjc156560 #define	ERR_OP_NO_IMPL		-24
1953e4f2897Sjc156560 #define	ERR_OP_FAILED		-25
1963e4f2897Sjc156560 #define	ERR_DEVICE_NOENT	-26
1973e4f2897Sjc156560 #define	ERR_DEVICE_TYPE		-27
1983e4f2897Sjc156560 #define	ERR_DEVICE_DUP		-28
1993e4f2897Sjc156560 #define	ERR_DEVICE_OVERFLOW	-29
2003e4f2897Sjc156560 #define	ERR_DEVICE_UNCLEAN	-30
2013e4f2897Sjc156560 #define	ERR_DEVICE_INVALID	-31
2023e4f2897Sjc156560 #define	ERR_NOMEM		-32
2033e4f2897Sjc156560 #define	ERR_PRIV		-33
2043e4f2897Sjc156560 #define	ERR_PLUGIN		-34
2053e4f2897Sjc156560 
2063e4f2897Sjc156560 /*
2073e4f2897Sjc156560  * Raid object types
2083e4f2897Sjc156560  */
2093e4f2897Sjc156560 typedef enum {
2103e4f2897Sjc156560 	OBJ_TYPE_SYSTEM,
2113e4f2897Sjc156560 	OBJ_TYPE_CONTROLLER,
2123e4f2897Sjc156560 	OBJ_TYPE_ARRAY,
2133e4f2897Sjc156560 	OBJ_TYPE_DISK,
2143e4f2897Sjc156560 	OBJ_TYPE_HSP,
2153e4f2897Sjc156560 	OBJ_TYPE_ARRAY_PART,
2163e4f2897Sjc156560 	OBJ_TYPE_DISK_SEG,
2173e4f2897Sjc156560 	OBJ_TYPE_TASK,
218b449fa8aSyw161884 	OBJ_TYPE_PROP,
2193e4f2897Sjc156560 	OBJ_TYPE_ALL
2203e4f2897Sjc156560 } raid_obj_type_id_t;
2213e4f2897Sjc156560 
2223e4f2897Sjc156560 /*
2233e4f2897Sjc156560  * Task functions
2243e4f2897Sjc156560  */
2253e4f2897Sjc156560 typedef enum {
2263e4f2897Sjc156560 	TASK_FUNC_UNKNOWN,
2273e4f2897Sjc156560 	TASK_FUNC_INIT,
2283e4f2897Sjc156560 	TASK_FUNC_BUILD,
2293e4f2897Sjc156560 	TASK_FUNC_VERIFY
2303e4f2897Sjc156560 } raidtask_func_t;
2313e4f2897Sjc156560 
2323e4f2897Sjc156560 /*
2333e4f2897Sjc156560  * Task state
2343e4f2897Sjc156560  */
2353e4f2897Sjc156560 typedef enum {
2363e4f2897Sjc156560 	TASK_STATE_UNKNOWN,
2373e4f2897Sjc156560 	TASK_STATE_TERMINATED,
2383e4f2897Sjc156560 	TASK_STATE_FAILED,
2393e4f2897Sjc156560 	TASK_STATE_DONE,
2403e4f2897Sjc156560 	TASK_STATE_RUNNING,
2413e4f2897Sjc156560 	TASK_STATE_SUSPENDED
2423e4f2897Sjc156560 } raidtask_state_t;
2433e4f2897Sjc156560 
2443e4f2897Sjc156560 /*
245b449fa8aSyw161884  * Properties
246b449fa8aSyw161884  */
247b449fa8aSyw161884 typedef	enum {
248b449fa8aSyw161884 	PROP_GUID
249b449fa8aSyw161884 } property_type_t;
250b449fa8aSyw161884 
251b449fa8aSyw161884 /*
2523e4f2897Sjc156560  * Attributes of all RAID objects
2533e4f2897Sjc156560  */
2543e4f2897Sjc156560 typedef union {
2553e4f2897Sjc156560 	uint64_t	reserved[3];
2563e4f2897Sjc156560 	struct {
2573e4f2897Sjc156560 		uint64_t	target_id;
2583e4f2897Sjc156560 		uint64_t	lun;
2593e4f2897Sjc156560 	} idl;
2603e4f2897Sjc156560 } array_tag_t;
2613e4f2897Sjc156560 
2623e4f2897Sjc156560 typedef union {
2633e4f2897Sjc156560 	struct {
2643e4f2897Sjc156560 		uint64_t bus;
2653e4f2897Sjc156560 		uint64_t target_id;
2663e4f2897Sjc156560 		uint64_t lun;
2673e4f2897Sjc156560 	} cidl;
2683e4f2897Sjc156560 } disk_tag_t;
2693e4f2897Sjc156560 
2703e4f2897Sjc156560 typedef struct {
2713e4f2897Sjc156560 	uint32_t	controller_id;
2723e4f2897Sjc156560 	uint32_t	max_array_num;
2733e4f2897Sjc156560 	uint32_t	max_seg_per_disk;
2743e4f2897Sjc156560 	uint32_t	connection_type;
2753e4f2897Sjc156560 	uint64_t	capability;
2763e4f2897Sjc156560 	char		fw_version[CONTROLLER_FW_LEN];
2773e4f2897Sjc156560 	char		controller_type[CONTROLLER_TYPE_LEN];
2783e4f2897Sjc156560 } controller_attr_t;
2793e4f2897Sjc156560 
2803e4f2897Sjc156560 typedef struct {
2813e4f2897Sjc156560 	uint32_t	array_id;
2823e4f2897Sjc156560 	uint32_t	state;
2833e4f2897Sjc156560 	array_tag_t	tag;
2843e4f2897Sjc156560 	uint64_t	capacity;
2853e4f2897Sjc156560 	uint32_t	raid_level;
2863e4f2897Sjc156560 	uint32_t	stripe_size;
2873e4f2897Sjc156560 	uint32_t	write_policy;
2883e4f2897Sjc156560 	uint32_t	read_policy;
2893e4f2897Sjc156560 } array_attr_t;
2903e4f2897Sjc156560 
2913e4f2897Sjc156560 typedef struct {
2923e4f2897Sjc156560 	uint32_t	disk_id;
2933e4f2897Sjc156560 	uint32_t	state;
2943e4f2897Sjc156560 	disk_tag_t	tag;
2953e4f2897Sjc156560 	uint64_t	capacity;
296*f3f093f5SMilan Jurik 
297*f3f093f5SMilan Jurik 	/* ASCII data not terminated by null */
2983e4f2897Sjc156560 	char		vendorid[DISK_VENDER_LEN];
2993e4f2897Sjc156560 	char		productid[DISK_PRODUCT_LEN];
3003e4f2897Sjc156560 	char		revision[DISK_REV_LEN];
3013e4f2897Sjc156560 } disk_attr_t;
3023e4f2897Sjc156560 
3033e4f2897Sjc156560 typedef struct {
3043e4f2897Sjc156560 	uint32_t	associated_id;
3053e4f2897Sjc156560 	uint32_t	type;
3063e4f2897Sjc156560 } hsp_attr_t;
3073e4f2897Sjc156560 
3083e4f2897Sjc156560 typedef struct {
3093e4f2897Sjc156560 	uint32_t	disk_id;
3103e4f2897Sjc156560 	uint32_t	state;
3113e4f2897Sjc156560 	uint64_t	offset;
3123e4f2897Sjc156560 	uint64_t	size;
3133e4f2897Sjc156560 } arraypart_attr_t;
3143e4f2897Sjc156560 
3153e4f2897Sjc156560 typedef struct {
3163e4f2897Sjc156560 	uint32_t	seq_no;
3173e4f2897Sjc156560 	uint32_t	state;
3183e4f2897Sjc156560 	uint64_t	offset;
3193e4f2897Sjc156560 	uint64_t	size;
3203e4f2897Sjc156560 } diskseg_attr_t;
3213e4f2897Sjc156560 
3223e4f2897Sjc156560 typedef struct {
3233e4f2897Sjc156560 	uint32_t	task_id;
3243e4f2897Sjc156560 	uint32_t	task_func;
3253e4f2897Sjc156560 	uint32_t	task_state;
3263e4f2897Sjc156560 	uint32_t	progress;
3273e4f2897Sjc156560 } task_attr_t;
3283e4f2897Sjc156560 
3293e4f2897Sjc156560 typedef struct {
330b449fa8aSyw161884 	uint32_t	prop_id;
331b449fa8aSyw161884 	uint32_t	prop_size;
332b449fa8aSyw161884 	property_type_t	prop_type;
333b449fa8aSyw161884 	char		prop[1];
334b449fa8aSyw161884 } property_attr_t;
335b449fa8aSyw161884 
336b449fa8aSyw161884 typedef struct {
3373e4f2897Sjc156560 	uint32_t	array_id;
3383e4f2897Sjc156560 	uint32_t	disk_id;
3393e4f2897Sjc156560 } hsp_relation_t;
3403e4f2897Sjc156560 
3413e4f2897Sjc156560 /*
3423e4f2897Sjc156560  * Structure used to register plug-in modules
3433e4f2897Sjc156560  */
3443e4f2897Sjc156560 typedef	struct raid_lib_type {
3453e4f2897Sjc156560 	uint32_t version;
3463e4f2897Sjc156560 	struct raid_lib_type *next;
3473e4f2897Sjc156560 	void	*lib_handle;
3483e4f2897Sjc156560 	const char	*name;
3493e4f2897Sjc156560 
3503e4f2897Sjc156560 	int (*open_controller)(uint32_t, char **);
3513e4f2897Sjc156560 	int (*close_controller)(uint32_t, char **);
3523e4f2897Sjc156560 	int (*compnum)(uint32_t, uint32_t, raid_obj_type_id_t,
3533e4f2897Sjc156560 		raid_obj_type_id_t);
3543e4f2897Sjc156560 	int (*complist)(uint32_t, uint32_t, raid_obj_type_id_t,
3553e4f2897Sjc156560 		raid_obj_type_id_t, int, void *);
3563e4f2897Sjc156560 	int (*get_attr)(uint32_t, uint32_t, uint32_t, raid_obj_type_id_t,
3573e4f2897Sjc156560 		void *);
3583e4f2897Sjc156560 	int (*set_attr)(uint32_t, uint32_t, uint32_t, uint32_t *, char **);
3593e4f2897Sjc156560 	int (*array_create)(uint32_t, array_attr_t *, int,
3603e4f2897Sjc156560 		arraypart_attr_t *, char **);
3613e4f2897Sjc156560 	int (*array_delete)(uint32_t, uint32_t, char **);
3625c9d25d2SYu-Bo Ryan Wang 	int (*hsp_bind)(uint32_t, hsp_relation_t *, char **);
3635c9d25d2SYu-Bo Ryan Wang 	int (*hsp_unbind)(uint32_t, hsp_relation_t *, char **);
3643e4f2897Sjc156560 	int (*flash_fw)(uint32_t, char *, uint32_t, char **);
3653e4f2897Sjc156560 } raid_lib_t;
3663e4f2897Sjc156560 
3673e4f2897Sjc156560 #ifdef	__cplusplus
3683e4f2897Sjc156560 }
3693e4f2897Sjc156560 #endif
3703e4f2897Sjc156560 
3713e4f2897Sjc156560 #endif	/* _SYS_RAIDCFG_SPI_H */
372