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 2005 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_SCSI_ADAPTERS_MPAPI_IMPL_H
27 #define	_SYS_SCSI_ADAPTERS_MPAPI_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/sunmdi.h>
32 #include <sys/sunddi.h>
33 #include <sys/mdi_impldefs.h>
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #if !defined(_BIT_FIELDS_LTOH) && !defined(_BIT_FIELDS_HTOL)
40 #error  One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
41 #endif  /* _BIT_FIELDS_LTOH */
42 
43 /*
44  * All the structures (except mp_iocdata_t) are 64-bit aligned (padded,
45  * where necessary) to facilitate the use of the same structure for
46  * handling ioctl calls made by both 32-bit and 64-bit applications.
47  * There are no pointers to other structures inside these structures
48  * as copyout to user land may not produce desired result.
49  * The caddr_t structure is kept at the end due to the undeterminstic
50  * size it could accrue to its parent structure.
51  */
52 
53 /* Structure for MP_PLUGIN_PROPERTIES */
54 
55 typedef struct mp_driver_prop {
56 	char		driverVersion[256];
57 	uint32_t	supportedLoadBalanceTypes;
58 	boolean_t	canSetTPGAccess;
59 	boolean_t	canOverridePaths;
60 	boolean_t	exposesPathDeviceFiles;
61 	char		deviceFileNamespace[256];
62 	uint32_t	onlySupportsSpecifiedProducts;
63 	uint32_t	maximumWeight;
64 	uint32_t	failbackPollingRateMax;
65 	uint32_t	currentFailbackPollingRate;
66 	uint32_t	autoFailbackSupport;
67 	uint32_t	autoFailbackEnabled;
68 	uint32_t	defaultLoadBalanceType;
69 	uint32_t	probingPollingRateMax;
70 	uint32_t	currentProbingPollingRate;
71 	uint32_t	autoProbingSupport;
72 	uint32_t	autoProbingEnabled;
73 	uint32_t	proprietaryPropSize;
74 	caddr_t		proprietaryProp;
75 } mp_driver_prop_t;
76 
77 
78 /* Size of "proprietaryProp" field */
79 
80 #define	MP_MAX_PROP_BUF_SIZE				1024
81 
82 
83 /* Constants for autoFailbackSupport */
84 
85 /*
86  * Both MP_DRVR_AUTO_FAILBACK_SUPPORT and
87  * MP_DRVR_AUTO_FAILBACK_SUPPORT_LU
88  * can be supported at the same time.
89  */
90 
91 #define	MP_DRVR_AUTO_FAILBACK_SUPPORT_NONE		0
92 #define	MP_DRVR_AUTO_FAILBACK_SUPPORT			(1<<0)
93 #define	MP_DRVR_AUTO_FAILBACK_SUPPORT_LU		(1<<1)
94 
95 
96 /* Constants for defaultLoadBalanceType */
97 
98 #define	MP_DRVR_LOAD_BALANCE_TYPE_UNKNOWN		0
99 #define	MP_DRVR_LOAD_BALANCE_TYPE_ROUNDROBIN		(1<<0)
100 #define	MP_DRVR_LOAD_BALANCE_TYPE_LEASTBLOCKS		(1<<1)
101 #define	MP_DRVR_LOAD_BALANCE_TYPE_LEASTIO		(1<<2)
102 #define	MP_DRVR_LOAD_BALANCE_TYPE_DEVICE_PRODUCT	(1<<3)
103 #define	MP_DRVR_LOAD_BALANCE_TYPE_LBA_REGION		(1<<4)
104 #define	MP_DRVR_LOAD_BALANCE_TYPE_PROPRIETARY1		(1<<16)
105 #define	MP_DRVR_LOAD_BALANCE_TYPE_PROPRIETARY2		(1<<17)
106 
107 
108 /* Constants for autoProbingSupport */
109 
110 /*
111  * Both MP_DRVR_AUTO_PROBING_SUPPORT and
112  * MP_DRVR_AUTO_PROBING_SUPPORT_LU
113  * can be supported at the same time.
114  */
115 
116 #define	MP_DRVR_AUTO_PROBING_SUPPORT_NONE		0
117 #define	MP_DRVR_AUTO_PROBING_SUPPORT			(1<<0)
118 #define	MP_DRVR_AUTO_PROBING_SUPPORT_LU			(1<<1)
119 
120 
121 /* Structures for MP_DEVICE_PRODUCT_PROPERTIES */
122 
123 typedef struct mp_vendor_prod_info {
124 	char	vendor[8];
125 	char	product[16];
126 	char	revision[4];
127 	char	reserved[4]; /* padding for 64bit alignment */
128 } mp_vendor_prod_info_t;
129 
130 typedef struct mp_dev_prod_prop {
131 	struct mp_vendor_prod_info	prodInfo;
132 	uint32_t			supportedLoadBalanceTypes;
133 	uint32_t			reserved; /* 64bit alignment padding */
134 	uint64_t			id;
135 } mp_dev_prod_prop_t;
136 
137 
138 /* Structure for MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES */
139 
140 typedef struct mp_logical_unit_prop {
141 	struct mp_vendor_prod_info	prodInfo;
142 	char				name[256];  /* guid */
143 	uint32_t			nameType;
144 	uint32_t			luGroupID;
145 	char				deviceFileName[256];
146 	uint64_t			id;
147 	boolean_t			asymmetric;
148 	uint32_t			currentLoadBalanceType;
149 	boolean_t			autoFailbackEnabled;
150 	uint32_t			failbackPollingRateMax;
151 	uint32_t			currentFailBackPollingRate;
152 	uint32_t			autoProbingEnabled;
153 	uint32_t			probingPollingRateMax;
154 	uint32_t			currentProbingPollingRate;
155 	uint64_t			overridePathID;
156 	boolean_t			overridePathInUse;
157 	uint32_t			proprietaryPropSize;
158 	caddr_t				proprietaryProp;
159 } mp_logical_unit_prop_t;
160 
161 
162 /* Constants for nameType */
163 
164 #define	MP_DRVR_NAME_TYPE_UNKNOWN		0
165 #define	MP_DRVR_NAME_TYPE_VPD83_TYPE1		1
166 #define	MP_DRVR_NAME_TYPE_VPD83_TYPE2		2
167 #define	MP_DRVR_NAME_TYPE_VPD83_TYPE3		3
168 #define	MP_DRVR_NAME_TYPE_DEVICE_SPECIFIC	4
169 
170 
171 /* Structure for MP_INITIATOR_PORT_PROPERTIES */
172 
173 typedef struct mp_init_port_prop {
174 	char		portID[256];
175 	char		osDeviceFile[256];
176 	uint32_t	portType;
177 	uint32_t	reserved; /* padding for 64bit alignment */
178 	uint64_t	id;
179 } mp_init_port_prop_t;
180 
181 
182 /* Constants for portType */
183 
184 #define	MP_DRVR_TRANSPORT_TYPE_UNKNOWN	0
185 #define	MP_DRVR_TRANSPORT_TYPE_FC	2
186 #define	MP_DRVR_TRANSPORT_TYPE_SPI	3
187 #define	MP_DRVR_TRANSPORT_TYPE_ISCSI	4
188 #define	MP_DRVR_TRANSPORT_TYPE_IFB	5
189 
190 
191 /* Structure for MP_TARGET_PORT_PROPERTIES */
192 
193 typedef struct mp_target_port_prop {
194 	char		portName[256];
195 	uint32_t	relativePortID;
196 	uint32_t	reserved; /* padding for 64bit alignment */
197 	uint64_t	id;
198 } mp_target_port_prop_t;
199 
200 
201 /* Structure for MP_TARGET_PORT_GROUP_PROPERTIES */
202 
203 typedef struct mp_tpg_prop {
204 	uint32_t	accessState;
205 	boolean_t	explicitFailover;
206 	uint32_t	tpgId; /* T10 defined id in report/set TPG */
207 	boolean_t	preferredLuPath;
208 	boolean_t	supportsLuAssignment;
209 	uint32_t	reserved; /* padding for 64bit alignment */
210 	uint64_t	id;
211 } mp_tpg_prop_t;
212 
213 
214 /* Constants for accessState */
215 
216 #define	MP_DRVR_ACCESS_STATE_ACTIVE_OPTIMIZED		0
217 #define	MP_DRVR_ACCESS_STATE_ACTIVE_NONOPTIMIZED	0x1
218 #define	MP_DRVR_ACCESS_STATE_STANDBY			0x2
219 #define	MP_DRVR_ACCESS_STATE_UNAVAILABLE		0x3
220 #define	MP_DRVR_ACCESS_STATE_TRANSITIONING		0xf
221 #define	MP_DRVR_ACCESS_STATE_ACTIVE			0x10
222 
223 
224 /* Structure for MP_PATH_LOGICAL_UNIT_PROPERTIES */
225 
226 typedef struct mp_path_prop {
227 	uint32_t			weight;
228 	uint32_t			pathState;
229 	boolean_t			disabled;
230 	uint32_t			reserved; /* 64bit alignment padding */
231 	uint64_t			id;
232 	struct mp_init_port_prop	initPort;
233 	struct mp_target_port_prop	targetPort;
234 	struct mp_logical_unit_prop	logicalUnit;
235 } mp_path_prop_t;
236 
237 
238 /* Constants for pathState */
239 
240 #define	MP_DRVR_PATH_STATE_ACTIVE		0
241 #define	MP_DRVR_PATH_STATE_PASSIVE		1
242 #define	MP_DRVR_PATH_STATE_PATH_ERR		2
243 #define	MP_DRVR_PATH_STATE_LU_ERR		3
244 #define	MP_DRVR_PATH_STATE_RESERVED		4
245 #define	MP_DRVR_PATH_STATE_REMOVED		5
246 #define	MP_DRVR_PATH_STATE_TRANSITIONING	6
247 #define	MP_DRVR_PATH_STATE_UNKNOWN		7
248 
249 
250 /* Structure for MP_PROPRIETARY_LOAD_BALANCE_PROPERTIES */
251 
252 typedef struct mp_proprietary_loadbalance_prop {
253 	char		name[256];
254 	char		vendorName[256];
255 	uint64_t	id;
256 	uint32_t	typeIndex;
257 	uint32_t	proprietaryPropSize;
258 	caddr_t		proprietaryProp;
259 } mp_proprietary_loadbalance_prop_t;
260 
261 
262 /*
263  * Structure used as input to
264  * MP_ASSIGN_LU_TO_TPG subcmd.
265  */
266 
267 typedef struct mp_lu_tpg_pair {
268 	uint64_t	luId;
269 	uint64_t	tpgId;
270 } mp_lu_tpg_pair_t;
271 
272 
273 /*
274  * Structure used as input to
275  * MP_SET_TPG_ACCESS_STATE subcmd.
276  */
277 
278 typedef struct mp_set_tpg_state_req {
279 	struct mp_lu_tpg_pair	luTpgPair;
280 	uint32_t		desiredState;
281 	uint32_t		reserved; /* padding for 64bit boundary */
282 } mp_set_tpg_state_req_t;
283 
284 
285 /*
286  * Structure for ioctl data
287  */
288 typedef struct mp_iocdata {
289 	uint16_t	mp_xfer;	/* direction */
290 	uint16_t	mp_cmd;		/* sub command */
291 	uint16_t	mp_flags;	/* flags */
292 	uint16_t	mp_cmd_flags;	/* command specific flags */
293 	size_t		mp_ilen;	/* Input buffer length */
294 	caddr_t		mp_ibuf;	/* Input buffer */
295 	size_t		mp_olen;	/* Output buffer length */
296 	caddr_t		mp_obuf;	/* Output buffer */
297 	size_t		mp_alen;	/* Auxiliary buffer length */
298 	caddr_t		mp_abuf;	/* Auxiliary buffer */
299 	int		mp_errno;	/* MPAPI driver internal error code */
300 } mp_iocdata_t;
301 
302 
303 #ifdef _KERNEL
304 
305 #if defined(_SYSCALL32)
306 
307 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
308 #pragma pack(4)
309 #endif
310 
311 /*
312  * Structure for 32-bit ioctl data
313  */
314 
315 typedef struct mp_iocdata32 {
316 	uint16_t	mp_xfer;	/* direction */
317 	uint16_t	mp_cmd;		/* sub command */
318 	uint16_t	mp_flags;	/* flags */
319 	uint16_t	mp_cmd_flags;	/* command specific flags */
320 	uint32_t	mp_ilen;	/* Input buffer length */
321 	caddr32_t	mp_ibuf;	/* Input buffer */
322 	uint32_t	mp_olen;	/* Output buffer length */
323 	caddr32_t	mp_obuf;	/* Output buffer */
324 	uint32_t	mp_alen;	/* Auxiliary buffer length */
325 	caddr32_t	mp_abuf;	/* Auxiliary buffer */
326 	int32_t		mp_errno;	/* MPAPI driver internal error code */
327 } mp_iocdata32_t;
328 
329 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
330 #pragma pack()
331 #endif
332 
333 #endif  /* _SYSCALL32 */
334 
335 #endif /* _KERNEL */
336 
337 
338 /* Constants for MP_XFER */
339 
340 #define	MP_XFER_NONE	0x00
341 #define	MP_XFER_READ	0x01
342 #define	MP_XFER_WRITE	0x02
343 #define	MP_XFER_RW	(MP_XFER_READ | MP_XFER_WRITE)
344 
345 
346 /* Constants for MP_OBJECT_TYPE */
347 
348 #define	MP_OBJECT_TYPE_UNKNOWN			0
349 #define	MP_OBJECT_TYPE_PLUGIN			1
350 #define	MP_OBJECT_TYPE_INITIATOR_PORT		2
351 #define	MP_OBJECT_TYPE_TARGET_PORT		3
352 #define	MP_OBJECT_TYPE_MULTIPATH_LU		4
353 #define	MP_OBJECT_TYPE_PATH_LU			5
354 #define	MP_OBJECT_TYPE_DEVICE_PRODUCT		6
355 #define	MP_OBJECT_TYPE_TARGET_PORT_GROUP	7
356 #define	MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE	8
357 #define	MP_OBJECT_TYPE_LAST_ENTRY 	MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE
358 #define	MP_MAX_OBJECT_TYPE	(MP_OBJECT_TYPE_LAST_ENTRY + 1)
359 
360 
361 /* Constants for MP_CMD */
362 
363 #define	MPAPI_CTL				('m'<<8)
364 #define	MP_CMD					(MPAPI_CTL | 2005)
365 #define	MP_SUB_CMD				('M'<<8)
366 
367 #define	MP_API_SUBCMD_MIN			(MP_SUB_CMD + 0x01)
368 #define	MP_GET_DRIVER_PROP			(MP_SUB_CMD + 0x01)
369 #define	MP_GET_DEV_PROD_LIST			(MP_SUB_CMD + 0x02)
370 #define	MP_GET_DEV_PROD_PROP			(MP_SUB_CMD + 0x03)
371 #define	MP_GET_LU_LIST				(MP_SUB_CMD + 0x04)
372 #define	MP_GET_LU_LIST_FROM_TPG			(MP_SUB_CMD + 0x05)
373 #define	MP_GET_LU_PROP				(MP_SUB_CMD + 0x06)
374 #define	MP_GET_PATH_LIST_FOR_MP_LU		(MP_SUB_CMD + 0x07)
375 #define	MP_GET_PATH_LIST_FOR_INIT_PORT		(MP_SUB_CMD + 0x08)
376 #define	MP_GET_PATH_LIST_FOR_TARGET_PORT	(MP_SUB_CMD + 0x09)
377 #define	MP_GET_PATH_PROP			(MP_SUB_CMD + 0x0a)
378 #define	MP_GET_INIT_PORT_LIST			(MP_SUB_CMD + 0x0b)
379 #define	MP_GET_INIT_PORT_PROP			(MP_SUB_CMD + 0x0c)
380 #define	MP_GET_TARGET_PORT_PROP			(MP_SUB_CMD + 0x0d)
381 #define	MP_GET_TPG_LIST				(MP_SUB_CMD + 0x0e)
382 #define	MP_GET_TPG_PROP				(MP_SUB_CMD + 0x0f)
383 #define	MP_GET_TPG_LIST_FOR_LU			(MP_SUB_CMD + 0x10)
384 #define	MP_GET_TARGET_PORT_LIST_FOR_TPG		(MP_SUB_CMD + 0x11)
385 #define	MP_SET_TPG_ACCESS_STATE			(MP_SUB_CMD + 0x12)
386 #define	MP_ENABLE_AUTO_FAILBACK			(MP_SUB_CMD + 0x13)
387 #define	MP_DISABLE_AUTO_FAILBACK 		(MP_SUB_CMD + 0x14)
388 #define	MP_ENABLE_PATH				(MP_SUB_CMD + 0x15)
389 #define	MP_DISABLE_PATH				(MP_SUB_CMD + 0x16)
390 #define	MP_GET_PROPRIETARY_LOADBALANCE_LIST	(MP_SUB_CMD + 0x17)
391 #define	MP_GET_PROPRIETARY_LOADBALANCE_PROP	(MP_SUB_CMD + 0x18)
392 #define	MP_ASSIGN_LU_TO_TPG			(MP_SUB_CMD + 0x19)
393 #define	MP_API_SUBCMD_MAX			(MP_ASSIGN_LU_TO_TPG)
394 
395 
396 /*
397  * Typical MP API ioctl interface specific Return Values
398  */
399 
400 #define	MP_IOCTL_ERROR_START			0x5533
401 #define	MP_MORE_DATA				(MP_IOCTL_ERROR_START + 1)
402 #define	MP_DRVR_INVALID_ID			(MP_IOCTL_ERROR_START + 2)
403 #define	MP_DRVR_ID_OBSOLETE			(MP_IOCTL_ERROR_START + 3)
404 #define	MP_DRVR_ACCESS_SYMMETRIC		(MP_IOCTL_ERROR_START + 4)
405 #define	MP_DRVR_PATH_UNAVAILABLE		(MP_IOCTL_ERROR_START + 5)
406 #define	MP_DRVR_IDS_NOT_ASSOCIATED		(MP_IOCTL_ERROR_START + 6)
407 #define	MP_DRVR_ILLEGAL_ACCESS_STATE_REQUEST	(MP_IOCTL_ERROR_START + 7)
408 
409 /*
410  * Macros for OID operations
411  */
412 #define	MP_ID_SHIFT4MAJOR		32
413 #define	MP_GET_MAJOR_FROM_ID(id)	((id) >> MP_ID_SHIFT4MAJOR)
414 #define	MP_GET_INST_FROM_ID(id)		((id) & 0x00000000ffffffff)
415 #define	MP_STORE_INST_TO_ID(inst, id)	(((uint64_t)(inst)) | id)
416 #define	MP_STORE_MAJOR_TO_ID(major, id)	\
417 	((((uint64_t)(major)) << MP_ID_SHIFT4MAJOR) | id)
418 
419 /*
420  * Event Class and Sub-Class definitions
421  */
422 #define	EC_SUN_MP			"EC_sun_mp"
423 
424 #define	ESC_SUN_MP_LU_CHANGE		"ESC_sun_mp_lu_change"
425 
426 #define	ESC_SUN_MP_PATH_CHANGE		"ESC_sun_mp_path_change"
427 #define	ESC_SUN_MP_PATH_ADD		"ESC_sun_mp_path_add"
428 #define	ESC_SUN_MP_PATH_REMOVE		"ESC_sun_mp_path_remove"
429 
430 #define	ESC_SUN_MP_INIT_PORT_CHANGE	"ESC_sun_mp_init_port_change"
431 
432 #define	ESC_SUN_MP_TPG_CHANGE		"ESC_sun_mp_tpg_change"
433 #define	ESC_SUN_MP_TPG_ADD		"ESC_sun_mp_tpg_add"
434 #define	ESC_SUN_MP_TPG_REMOVE		"ESC_sun_mp_tpg_remove"
435 
436 #define	ESC_SUN_MP_TARGET_PORT_CHANGE	"ESC_sun_mp_target_port_change"
437 #define	ESC_SUN_MP_TARGET_PORT_ADD	"ESC_sun_mp_target_port_add"
438 #define	ESC_SUN_MP_TARGET_PORT_REMOVE	"ESC_sun_mp_target_port_remove"
439 
440 #define	ESC_SUN_MP_DEV_PROD_CHANGE	"ESC_sun_mp_dev_prod_change"
441 #define	ESC_SUN_MP_DEV_PROD_ADD		"ESC_sun_mp_dev_prod_add"
442 #define	ESC_SUN_MP_DEV_PROD_REMOVE	"ESC_sun_mp_dev_prod_remove"
443 
444 #ifdef __cplusplus
445 }
446 #endif
447 
448 #endif /* _SYS_SCSI_ADAPTERS_MPAPI_IMPL_H */
449