xref: /titanic_44/usr/src/lib/libstmf/common/libstmf.h (revision 2d6b5ea734bb47d251c82670646fde46af15fd69)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_LIBSTMF_H
27 #define	_LIBSTMF_H
28 
29 #include <time.h>
30 #include <sys/param.h>
31 #include <libnvpair.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 /* Constants and Types */
38 
39 /* LU and Local Port states */
40 #define	STMF_LOGICAL_UNIT_OFFLINE	0
41 #define	STMF_LOGICAL_UNIT_OFFLINING	1
42 #define	STMF_LOGICAL_UNIT_ONLINE	2
43 #define	STMF_LOGICAL_UNIT_ONLINING	3
44 #define	STMF_LOGICAL_UNIT_UNREGISTERED	4
45 #define	STMF_TARGET_PORT_OFFLINE	5
46 #define	STMF_TARGET_PORT_OFFLINING	6
47 #define	STMF_TARGET_PORT_ONLINE		7
48 #define	STMF_TARGET_PORT_ONLINING	8
49 #define	STMF_SERVICE_STATE_ONLINE	9
50 #define	STMF_SERVICE_STATE_OFFLINE	10
51 #define	STMF_SERVICE_STATE_ONLINING	11
52 #define	STMF_SERVICE_STATE_OFFLINING	12
53 #define	STMF_SERVICE_STATE_UNKNOWN	13
54 #define	STMF_CONFIG_STATE_NONE		14
55 #define	STMF_CONFIG_STATE_INIT		15
56 #define	STMF_CONFIG_STATE_INIT_DONE	16
57 #define	STMF_CONFIG_STATE_UNKNOWN	17
58 
59 #define	STMF_IDENT_LENGTH   255
60 
61 /* API status return values */
62 #define	STMF_STATUS_SUCCESS	    0x0000
63 #define	STMF_STATUS_ERROR	    0x8000
64 #define	STMF_ERROR_BUSY			(STMF_STATUS_ERROR | 0x01)
65 #define	STMF_ERROR_NOT_FOUND		(STMF_STATUS_ERROR | 0x02)
66 #define	STMF_ERROR_MEMBER_NOT_FOUND	(STMF_STATUS_ERROR | 0x03)
67 #define	STMF_ERROR_GROUP_NOT_FOUND	(STMF_STATUS_ERROR | 0x04)
68 #define	STMF_ERROR_PERM			(STMF_STATUS_ERROR | 0x05)
69 #define	STMF_ERROR_NOMEM		(STMF_STATUS_ERROR | 0x06)
70 #define	STMF_ERROR_INVALID_ARG		(STMF_STATUS_ERROR | 0x07)
71 #define	STMF_ERROR_EXISTS		(STMF_STATUS_ERROR | 0x08)
72 #define	STMF_ERROR_SERVICE_NOT_FOUND	(STMF_STATUS_ERROR | 0x09)
73 #define	STMF_ERROR_SERVICE_ONLINE	(STMF_STATUS_ERROR | 0x0a)
74 #define	STMF_ERROR_SERVICE_OFFLINE	(STMF_STATUS_ERROR | 0x0b)
75 #define	STMF_ERROR_GROUP_IN_USE		(STMF_STATUS_ERROR | 0x0c)
76 #define	STMF_ERROR_LUN_IN_USE		(STMF_STATUS_ERROR | 0x0d)
77 #define	STMF_ERROR_VE_CONFLICT		(STMF_STATUS_ERROR | 0x0e)
78 #define	STMF_ERROR_CONFIG_NONE		(STMF_STATUS_ERROR | 0x0f)
79 #define	STMF_ERROR_SERVICE_DATA_VERSION (STMF_STATUS_ERROR | 0x10)
80 #define	STMF_ERROR_INVALID_HG		(STMF_STATUS_ERROR | 0x11)
81 #define	STMF_ERROR_INVALID_TG		(STMF_STATUS_ERROR | 0x12)
82 #define	STMF_ERROR_PROV_DATA_STALE	(STMF_STATUS_ERROR | 0x13)
83 
84 /* Initiator Name Types */
85 #define	STMF_FC_PORT_WWN	    1
86 #define	STMF_ISCSI_NAME		    2
87 
88 /* protected data flag for provider store */
89 #define	STMF_PROTECTED_DATA	0x0001
90 
91 /* provider types */
92 #define	STMF_LU_PROVIDER_TYPE	1
93 #define	STMF_PORT_PROVIDER_TYPE	2
94 
95 
96 /* devid code set and name types */
97 #define	EUI_64_TYPE	2
98 #define	NAA_TYPE	3
99 #define	SCSI_NAME_TYPE	8
100 
101 #define	BINARY_CODE_SET	1
102 #define	ASCII_CODE_SET	2
103 #define	UTF_8_CODE_SET	3
104 
105 typedef enum _stmfProtocol
106 {
107 	STMF_PROTOCOL_FIBRE_CHANNEL =	0,
108 	STMF_PROTOCOL_ISCSI =		1,
109 	STMF_PROTOCOL_SAS =		2
110 } stmfProtocol;
111 
112 
113 typedef struct _stmfGuid
114 {
115 	uchar_t	guid[16];
116 } stmfGuid;
117 
118 typedef struct _stmfGuidList
119 {
120 	uint32_t cnt;
121 	stmfGuid guid[1];
122 } stmfGuidList;
123 
124 typedef struct _stmfState
125 {
126 	int operationalState;
127 	int configState;
128 } stmfState;
129 
130 typedef struct _stmfDevid
131 {
132 	uint8_t identLength;	/* length of ident */
133 	uint8_t	ident[STMF_IDENT_LENGTH]; /* SCSI name string ident */
134 } stmfDevid;
135 
136 typedef struct _stmfDevidList
137 {
138 	uint32_t cnt;
139 	stmfDevid devid[1];
140 } stmfDevidList;
141 
142 typedef char stmfGroupName[256];
143 typedef char stmfProviderName[256];
144 
145 typedef struct _stmfGroupList
146 {
147 	uint32_t cnt;
148 	stmfGroupName name[1];
149 } stmfGroupList;
150 
151 typedef struct _stmfProvider
152 {
153 	int providerType;
154 	stmfProviderName name;
155 } stmfProvider;
156 
157 typedef struct _stmfProviderList
158 {
159 	uint32_t cnt;
160 	stmfProvider provider[1];
161 } stmfProviderList;
162 
163 typedef struct _stmfSession
164 {
165 	stmfDevid initiator;
166 	char alias[256];
167 	time_t creationTime;
168 } stmfSession;
169 
170 typedef struct _stmfSessionList
171 {
172 	uint32_t cnt;
173 	stmfSession session[1];
174 } stmfSessionList;
175 
176 
177 typedef struct _stmfViewEntry
178 {
179 	boolean_t	veIndexValid;	/* if B_TRUE, veIndex is valid value */
180 	uint32_t	veIndex;	/* View Entry index */
181 	boolean_t	allHosts;	/* all initiator ports */
182 	stmfGroupName   hostGroup;	/* Host Group Name */
183 	boolean_t	allTargets;	/* B_TRUE = targetGroup is invalid */
184 	stmfGroupName	targetGroup;	/* Target Group Name */
185 	boolean_t	luNbrValid;	/* if B_TRUE, luNbr is a valid value */
186 	uchar_t		luNbr[8];	/* LU number for this view entry */
187 } stmfViewEntry;
188 
189 typedef struct _stmfViewEntryList
190 {
191 	uint32_t cnt;
192 	stmfViewEntry ve[1];
193 } stmfViewEntryList;
194 
195 typedef struct _stmfViewEntryProperties
196 {
197 	stmfGuid	associatedLogicalUnitGuid;
198 	stmfViewEntry	viewEntry;
199 } stmfViewEntryProperties;
200 
201 typedef struct _stmfGroupProperties
202 {
203 	uint32_t	cnt;
204 	stmfDevid	name[1];
205 } stmfGroupProperties;
206 
207 typedef struct _stmfTargetProperties
208 {
209 	stmfProviderName providerName;
210 	char		 alias[256];
211 	uint16_t	 status;
212 	stmfProtocol	 protocol;
213 	stmfDevid	 devid;
214 } stmfTargetProperties;
215 
216 typedef struct _stmfLogicalUnitProperties
217 {
218 	char	    alias[256];
219 	uchar_t	    vendor[8];
220 	uchar_t	    product[16];
221 	uchar_t	    revision[4];
222 	uint32_t    status;
223 	char	    providerName[256];
224 	stmfGuid    luid;
225 } stmfLogicalUnitProperties;
226 
227 typedef struct _stmfLogicalUnitProviderProperties
228 {
229 	char	    providerName[MAXPATHLEN];
230 	uint32_t    instance;
231 	uint32_t    status;
232 	uchar_t	    rsvd[64];
233 } stmfLogicalUnitProviderProperties;
234 
235 typedef struct _stmfLocalPortProviderProperties
236 {
237 	char	    providerName[MAXPATHLEN];
238 	uint32_t    instance;
239 	uint32_t    status;
240 	uchar_t	    rsvd[64];
241 } stmfLocalPortProviderProperties;
242 
243 
244 /* API prototypes */
245 int stmfAddToHostGroup(stmfGroupName *hostGroupName, stmfDevid *name);
246 int stmfAddToTargetGroup(stmfGroupName *targetGroupName, stmfDevid *targetName);
247 int stmfAddViewEntry(stmfGuid *lu, stmfViewEntry *viewEntry);
248 int stmfClearProviderData(char *providerName, int providerType);
249 int stmfCreateHostGroup(stmfGroupName *hostGroupName);
250 int stmfCreateTargetGroup(stmfGroupName *targetGroupName);
251 int stmfDeleteHostGroup(stmfGroupName *hostGroupName);
252 int stmfDeleteTargetGroup(stmfGroupName *targetGroupName);
253 int stmfDevidFromIscsiName(char *iscsiName, stmfDevid *devid);
254 int stmfDevidFromWwn(uchar_t wwn[8], stmfDevid *devid);
255 void stmfFreeMemory(void *);
256 int stmfGetHostGroupList(stmfGroupList **initiatorGroupList);
257 int stmfGetHostGroupMembers(stmfGroupName *hostGroupName,
258     stmfGroupProperties **groupProperties);
259 int stmfGetLocalPortProviderList(stmfProviderList **localPortProviderList);
260 int stmfGetLocalPortProviderProperties(stmfProviderName *providerName,
261     stmfLocalPortProviderProperties *providerProperties);
262 int stmfGetLogicalUnitList(stmfGuidList **logicalUnitList);
263 int stmfGetLogicalUnitProperties(stmfGuid *logicalUnit,
264     stmfLogicalUnitProperties *logicalUnitProps);
265 int stmfGetLogicalUnitProviderList(stmfProviderList **logicalUnitProviderList);
266 int stmfGetLogicalUnitProviderProperties(stmfProviderName *providerName,
267     stmfLogicalUnitProviderProperties *providerProperties);
268 int stmfGetProviderData(char *providerName, nvlist_t **nvl, int providerType);
269 int stmfGetProviderDataProt(char *providerName, nvlist_t **nvl,
270     int providerType, uint64_t *setToken);
271 int stmfGetSessionList(stmfDevid *target, stmfSessionList **sessionList);
272 int stmfGetState(stmfState *);
273 int stmfGetTargetGroupList(stmfGroupList **targetGroupList);
274 int stmfGetTargetGroupMembers(stmfGroupName *targetGroupName,
275     stmfGroupProperties **groupProperties);
276 int stmfGetTargetList(stmfDevidList **targetList);
277 int stmfGetTargetProperties(stmfDevid *target,
278     stmfTargetProperties *targetProps);
279 int stmfGetViewEntryList(stmfGuid *lu, stmfViewEntryList **viewEntryList);
280 int stmfLoadConfig(void);
281 int stmfOffline(void);
282 int stmfOfflineTarget(stmfDevid *devid);
283 int stmfOfflineLogicalUnit(stmfGuid *logicalUnit);
284 int stmfOnline(void);
285 int stmfOnlineTarget(stmfDevid *devid);
286 int stmfOnlineLogicalUnit(stmfGuid *logicalUnit);
287 int stmfRemoveFromHostGroup(stmfGroupName *hostGroupName,
288     stmfDevid *initiatorName);
289 int stmfRemoveFromTargetGroup(stmfGroupName *targetGroupName,
290     stmfDevid *targetName);
291 int stmfRemoveViewEntry(stmfGuid *lu, uint32_t viewEntryIndex);
292 int stmfSetProviderData(char *providerName, nvlist_t *nvl, int providerType);
293 int stmfSetProviderDataProt(char *providerName, nvlist_t *nvl,
294     int providerType, uint64_t *setToken);
295 
296 #ifdef	__cplusplus
297 }
298 #endif
299 
300 #endif	/* _LIBSTMF_H */
301