xref: /illumos-gate/usr/src/uts/common/sys/scsi/adapters/mpapi_impl.h (revision bcd524b5c10222cf2a1ef37ac7ea8bf1baa3a2ee)
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 2007 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 
97 /*
98  * Declaration of the MP_LOAD_BALANCE_TYPE constants - should be
99  * the same defines as in mpapi.h
100  */
101 #define	MP_DRVR_LOAD_BALANCE_TYPE_NONE			0
102 #define	MP_DRVR_LOAD_BALANCE_TYPE_UNKNOWN		(1<<0)
103 #define	MP_DRVR_LOAD_BALANCE_TYPE_ROUNDROBIN		(1<<1)
104 #define	MP_DRVR_LOAD_BALANCE_TYPE_LEASTBLOCKS		(1<<2)
105 #define	MP_DRVR_LOAD_BALANCE_TYPE_LEASTIO		(1<<3)
106 #define	MP_DRVR_LOAD_BALANCE_TYPE_DEVICE_PRODUCT	(1<<4)
107 #define	MP_DRVR_LOAD_BALANCE_TYPE_LBA_REGION		(1<<5)
108 #define	MP_DRVR_LOAD_BALANCE_TYPE_FAILOVER_ONLY		(1<<6)
109 /*
110  * Proprietary load balance type should start from 0x10000(1<<16) or greater.
111  * It is exposed through API MP_GetProprietaryLoadBalanceProperties if exists.
112  */
113 #define	MP_DRVR_LOAD_BALANCE_TYPE_PROPRIETARY1		(1<<16)
114 #define	MP_DRVR_LOAD_BALANCE_TYPE_PROPRIETARY2		(1<<17)
115 
116 /* Constants for autoProbingSupport */
117 
118 /*
119  * Both MP_DRVR_AUTO_PROBING_SUPPORT and
120  * MP_DRVR_AUTO_PROBING_SUPPORT_LU
121  * can be supported at the same time.
122  */
123 
124 #define	MP_DRVR_AUTO_PROBING_SUPPORT_NONE		0
125 #define	MP_DRVR_AUTO_PROBING_SUPPORT			(1<<0)
126 #define	MP_DRVR_AUTO_PROBING_SUPPORT_LU			(1<<1)
127 
128 
129 /* Structures for MP_DEVICE_PRODUCT_PROPERTIES */
130 
131 typedef struct mp_vendor_prod_info {
132 	char	vendor[8];
133 	char	product[16];
134 	char	revision[4];
135 	char	reserved[4]; /* padding for 64bit alignment */
136 } mp_vendor_prod_info_t;
137 
138 typedef struct mp_dev_prod_prop {
139 	struct mp_vendor_prod_info	prodInfo;
140 	uint32_t			supportedLoadBalanceTypes;
141 	uint32_t			reserved; /* 64bit alignment padding */
142 	uint64_t			id;
143 } mp_dev_prod_prop_t;
144 
145 
146 /* Structure for MP_MULTIPATH_LOGICAL_UNIT_PROPERTIES */
147 
148 typedef struct mp_logical_unit_prop {
149 	struct mp_vendor_prod_info	prodInfo;
150 	char				name[256];  /* guid */
151 	uint32_t			nameType;
152 	uint32_t			luGroupID;
153 	char				deviceFileName[256];
154 	uint64_t			id;
155 	boolean_t			asymmetric;
156 	uint32_t			currentLoadBalanceType;
157 	boolean_t			autoFailbackEnabled;
158 	uint32_t			failbackPollingRateMax;
159 	uint32_t			currentFailBackPollingRate;
160 	uint32_t			autoProbingEnabled;
161 	uint32_t			probingPollingRateMax;
162 	uint32_t			currentProbingPollingRate;
163 	uint64_t			overridePathID;
164 	boolean_t			overridePathInUse;
165 	uint32_t			proprietaryPropSize;
166 	caddr_t				proprietaryProp;
167 } mp_logical_unit_prop_t;
168 
169 
170 /* Constants for nameType */
171 
172 #define	MP_DRVR_NAME_TYPE_UNKNOWN		0
173 #define	MP_DRVR_NAME_TYPE_VPD83_TYPE1		1
174 #define	MP_DRVR_NAME_TYPE_VPD83_TYPE2		2
175 #define	MP_DRVR_NAME_TYPE_VPD83_TYPE3		3
176 #define	MP_DRVR_NAME_TYPE_DEVICE_SPECIFIC	4
177 
178 
179 /* Structure for MP_INITIATOR_PORT_PROPERTIES */
180 
181 typedef struct mp_init_port_prop {
182 	char		portID[256];
183 	char		osDeviceFile[256];
184 	uint32_t	portType;
185 	uint32_t	reserved; /* padding for 64bit alignment */
186 	uint64_t	id;
187 } mp_init_port_prop_t;
188 
189 
190 /* Constants for portType */
191 
192 #define	MP_DRVR_TRANSPORT_TYPE_UNKNOWN	0
193 #define	MP_DRVR_TRANSPORT_TYPE_FC	2
194 #define	MP_DRVR_TRANSPORT_TYPE_SPI	3
195 #define	MP_DRVR_TRANSPORT_TYPE_ISCSI	4
196 #define	MP_DRVR_TRANSPORT_TYPE_IFB	5
197 
198 
199 /* Structure for MP_TARGET_PORT_PROPERTIES */
200 
201 typedef struct mp_target_port_prop {
202 	char		portName[256];
203 	uint32_t	relativePortID;
204 	uint32_t	reserved; /* padding for 64bit alignment */
205 	uint64_t	id;
206 } mp_target_port_prop_t;
207 
208 
209 /* Structure for MP_TARGET_PORT_GROUP_PROPERTIES */
210 
211 typedef struct mp_tpg_prop {
212 	uint32_t	accessState;
213 	boolean_t	explicitFailover;
214 	uint32_t	tpgId; /* T10 defined id in report/set TPG */
215 	boolean_t	preferredLuPath;
216 	boolean_t	supportsLuAssignment;
217 	uint32_t	reserved; /* padding for 64bit alignment */
218 	uint64_t	id;
219 } mp_tpg_prop_t;
220 
221 
222 /* Constants for accessState */
223 
224 #define	MP_DRVR_ACCESS_STATE_ACTIVE_OPTIMIZED		0
225 #define	MP_DRVR_ACCESS_STATE_ACTIVE_NONOPTIMIZED	0x1
226 #define	MP_DRVR_ACCESS_STATE_STANDBY			0x2
227 #define	MP_DRVR_ACCESS_STATE_UNAVAILABLE		0x3
228 #define	MP_DRVR_ACCESS_STATE_TRANSITIONING		0xf
229 #define	MP_DRVR_ACCESS_STATE_ACTIVE			0x10
230 
231 
232 /* Structure for MP_PATH_LOGICAL_UNIT_PROPERTIES */
233 
234 typedef struct mp_path_prop {
235 	uint32_t			weight;
236 	uint32_t			pathState;
237 	boolean_t			disabled;
238 	uint32_t			reserved; /* 64bit alignment padding */
239 	uint64_t			id;
240 	struct mp_init_port_prop	initPort;
241 	struct mp_target_port_prop	targetPort;
242 	struct mp_logical_unit_prop	logicalUnit;
243 } mp_path_prop_t;
244 
245 
246 /* Constants for pathState */
247 
248 #define	MP_DRVR_PATH_STATE_ACTIVE		0
249 #define	MP_DRVR_PATH_STATE_PASSIVE		1
250 #define	MP_DRVR_PATH_STATE_PATH_ERR		2
251 #define	MP_DRVR_PATH_STATE_LU_ERR		3
252 #define	MP_DRVR_PATH_STATE_RESERVED		4
253 #define	MP_DRVR_PATH_STATE_REMOVED		5
254 #define	MP_DRVR_PATH_STATE_TRANSITIONING	6
255 #define	MP_DRVR_PATH_STATE_UNKNOWN		7
256 
257 
258 /* Structure for MP_PROPRIETARY_LOAD_BALANCE_PROPERTIES */
259 
260 typedef struct mp_proprietary_loadbalance_prop {
261 	char		name[256];
262 	char		vendorName[256];
263 	uint64_t	id;
264 	uint32_t	typeIndex;
265 	uint32_t	proprietaryPropSize;
266 	caddr_t		proprietaryProp;
267 } mp_proprietary_loadbalance_prop_t;
268 
269 
270 /*
271  * Structure used as input to
272  * MP_ASSIGN_LU_TO_TPG subcmd.
273  */
274 
275 typedef struct mp_lu_tpg_pair {
276 	uint64_t	luId;
277 	uint64_t	tpgId;
278 } mp_lu_tpg_pair_t;
279 
280 /* used for uscsi commmands */
281 typedef struct mp_uscsi_cmd {
282 	struct scsi_address	*ap;		/* address of the path */
283 	struct uscsi_cmd	*uscmdp;	/* uscsi command */
284 	struct buf		*cmdbp;		/* original buffer */
285 	struct buf		*rqbp;		/* auto-rqsense packet */
286 	mdi_pathinfo_t		*pip;		/* path information */
287 	int			arq_enabled;	/* auto-rqsense enable flag */
288 }mp_uscsi_cmd_t;
289 
290 /*
291  * Structure used as input to
292  * MP_SET_TPG_ACCESS_STATE subcmd.
293  */
294 
295 typedef struct mp_set_tpg_state_req {
296 	struct mp_lu_tpg_pair	luTpgPair;
297 	uint32_t		desiredState;
298 	uint32_t		reserved; /* padding for 64bit boundary */
299 } mp_set_tpg_state_req_t;
300 
301 
302 /*
303  * Structure for ioctl data
304  */
305 typedef struct mp_iocdata {
306 	uint16_t	mp_xfer;	/* direction */
307 	uint16_t	mp_cmd;		/* sub command */
308 	uint16_t	mp_flags;	/* flags */
309 	uint16_t	mp_cmd_flags;	/* command specific flags */
310 	size_t		mp_ilen;	/* Input buffer length */
311 	caddr_t		mp_ibuf;	/* Input buffer */
312 	size_t		mp_olen;	/* Output buffer length */
313 	caddr_t		mp_obuf;	/* Output buffer */
314 	size_t		mp_alen;	/* Auxiliary buffer length */
315 	caddr_t		mp_abuf;	/* Auxiliary buffer */
316 	int		mp_errno;	/* MPAPI driver internal error code */
317 } mp_iocdata_t;
318 
319 
320 #ifdef _KERNEL
321 
322 #if defined(_SYSCALL32)
323 
324 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
325 #pragma pack(4)
326 #endif
327 
328 /*
329  * Structure for 32-bit ioctl data
330  */
331 
332 typedef struct mp_iocdata32 {
333 	uint16_t	mp_xfer;	/* direction */
334 	uint16_t	mp_cmd;		/* sub command */
335 	uint16_t	mp_flags;	/* flags */
336 	uint16_t	mp_cmd_flags;	/* command specific flags */
337 	uint32_t	mp_ilen;	/* Input buffer length */
338 	caddr32_t	mp_ibuf;	/* Input buffer */
339 	uint32_t	mp_olen;	/* Output buffer length */
340 	caddr32_t	mp_obuf;	/* Output buffer */
341 	uint32_t	mp_alen;	/* Auxiliary buffer length */
342 	caddr32_t	mp_abuf;	/* Auxiliary buffer */
343 	int32_t		mp_errno;	/* MPAPI driver internal error code */
344 } mp_iocdata32_t;
345 
346 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
347 #pragma pack()
348 #endif
349 
350 #endif  /* _SYSCALL32 */
351 
352 #endif /* _KERNEL */
353 
354 
355 /* Constants for MP_XFER */
356 
357 #define	MP_XFER_NONE	0x00
358 #define	MP_XFER_READ	0x01
359 #define	MP_XFER_WRITE	0x02
360 #define	MP_XFER_RW	(MP_XFER_READ | MP_XFER_WRITE)
361 
362 
363 /* Constants for MP_OBJECT_TYPE */
364 
365 #define	MP_OBJECT_TYPE_UNKNOWN			0
366 #define	MP_OBJECT_TYPE_PLUGIN			1
367 #define	MP_OBJECT_TYPE_INITIATOR_PORT		2
368 #define	MP_OBJECT_TYPE_TARGET_PORT		3
369 #define	MP_OBJECT_TYPE_MULTIPATH_LU		4
370 #define	MP_OBJECT_TYPE_PATH_LU			5
371 #define	MP_OBJECT_TYPE_DEVICE_PRODUCT		6
372 #define	MP_OBJECT_TYPE_TARGET_PORT_GROUP	7
373 #define	MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE	8
374 #define	MP_OBJECT_TYPE_LAST_ENTRY 	MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE
375 #define	MP_MAX_OBJECT_TYPE	(MP_OBJECT_TYPE_LAST_ENTRY + 1)
376 
377 
378 /* Constants for MP_CMD */
379 
380 #define	MPAPI_CTL				('m'<<8)
381 #define	MP_CMD					(MPAPI_CTL | 2005)
382 #define	MP_SUB_CMD				('M'<<8)
383 
384 #define	MP_API_SUBCMD_MIN			(MP_SUB_CMD + 0x01)
385 #define	MP_GET_DRIVER_PROP			(MP_SUB_CMD + 0x01)
386 #define	MP_GET_DEV_PROD_LIST			(MP_SUB_CMD + 0x02)
387 #define	MP_GET_DEV_PROD_PROP			(MP_SUB_CMD + 0x03)
388 #define	MP_GET_LU_LIST				(MP_SUB_CMD + 0x04)
389 #define	MP_GET_LU_LIST_FROM_TPG			(MP_SUB_CMD + 0x05)
390 #define	MP_GET_LU_PROP				(MP_SUB_CMD + 0x06)
391 #define	MP_GET_PATH_LIST_FOR_MP_LU		(MP_SUB_CMD + 0x07)
392 #define	MP_GET_PATH_LIST_FOR_INIT_PORT		(MP_SUB_CMD + 0x08)
393 #define	MP_GET_PATH_LIST_FOR_TARGET_PORT	(MP_SUB_CMD + 0x09)
394 #define	MP_GET_PATH_PROP			(MP_SUB_CMD + 0x0a)
395 #define	MP_GET_INIT_PORT_LIST			(MP_SUB_CMD + 0x0b)
396 #define	MP_GET_INIT_PORT_PROP			(MP_SUB_CMD + 0x0c)
397 #define	MP_GET_TARGET_PORT_PROP			(MP_SUB_CMD + 0x0d)
398 #define	MP_GET_TPG_LIST				(MP_SUB_CMD + 0x0e)
399 #define	MP_GET_TPG_PROP				(MP_SUB_CMD + 0x0f)
400 #define	MP_GET_TPG_LIST_FOR_LU			(MP_SUB_CMD + 0x10)
401 #define	MP_GET_TARGET_PORT_LIST_FOR_TPG		(MP_SUB_CMD + 0x11)
402 #define	MP_SET_TPG_ACCESS_STATE			(MP_SUB_CMD + 0x12)
403 #define	MP_ENABLE_AUTO_FAILBACK			(MP_SUB_CMD + 0x13)
404 #define	MP_DISABLE_AUTO_FAILBACK 		(MP_SUB_CMD + 0x14)
405 #define	MP_ENABLE_PATH				(MP_SUB_CMD + 0x15)
406 #define	MP_DISABLE_PATH				(MP_SUB_CMD + 0x16)
407 #define	MP_GET_PROPRIETARY_LOADBALANCE_LIST	(MP_SUB_CMD + 0x17)
408 #define	MP_GET_PROPRIETARY_LOADBALANCE_PROP	(MP_SUB_CMD + 0x18)
409 #define	MP_ASSIGN_LU_TO_TPG			(MP_SUB_CMD + 0x19)
410 #define	MP_SEND_SCSI_CMD			(MP_SUB_CMD + 0x1a)
411 #define	MP_API_SUBCMD_MAX			(MP_SEND_SCSI_CMD)
412 
413 
414 /*
415  * Typical MP API ioctl interface specific Return Values
416  */
417 
418 #define	MP_IOCTL_ERROR_START			0x5533
419 #define	MP_MORE_DATA				(MP_IOCTL_ERROR_START + 1)
420 #define	MP_DRVR_INVALID_ID			(MP_IOCTL_ERROR_START + 2)
421 #define	MP_DRVR_ID_OBSOLETE			(MP_IOCTL_ERROR_START + 3)
422 #define	MP_DRVR_ACCESS_SYMMETRIC		(MP_IOCTL_ERROR_START + 4)
423 #define	MP_DRVR_PATH_UNAVAILABLE		(MP_IOCTL_ERROR_START + 5)
424 #define	MP_DRVR_IDS_NOT_ASSOCIATED		(MP_IOCTL_ERROR_START + 6)
425 #define	MP_DRVR_ILLEGAL_ACCESS_STATE_REQUEST	(MP_IOCTL_ERROR_START + 7)
426 #define	MP_DRVR_IO_ERROR			(MP_IOCTL_ERROR_START + 8)
427 
428 /*
429  * Macros for OID operations
430  */
431 #define	MP_ID_SHIFT4MAJOR		32
432 #define	MP_GET_MAJOR_FROM_ID(id)	((id) >> MP_ID_SHIFT4MAJOR)
433 #define	MP_GET_INST_FROM_ID(id)		((id) & 0x00000000ffffffff)
434 #define	MP_STORE_INST_TO_ID(inst, id)	(((uint64_t)(inst)) | id)
435 #define	MP_STORE_MAJOR_TO_ID(major, id)	\
436 	((((uint64_t)(major)) << MP_ID_SHIFT4MAJOR) | id)
437 
438 /*
439  * Event Class and Sub-Class definitions
440  */
441 #define	EC_SUN_MP			"EC_sun_mp"
442 
443 #define	ESC_SUN_MP_LU_CHANGE		"ESC_sun_mp_lu_change"
444 
445 #define	ESC_SUN_MP_PATH_CHANGE		"ESC_sun_mp_path_change"
446 #define	ESC_SUN_MP_PATH_ADD		"ESC_sun_mp_path_add"
447 #define	ESC_SUN_MP_PATH_REMOVE		"ESC_sun_mp_path_remove"
448 
449 #define	ESC_SUN_MP_INIT_PORT_CHANGE	"ESC_sun_mp_init_port_change"
450 
451 #define	ESC_SUN_MP_TPG_CHANGE		"ESC_sun_mp_tpg_change"
452 #define	ESC_SUN_MP_TPG_ADD		"ESC_sun_mp_tpg_add"
453 #define	ESC_SUN_MP_TPG_REMOVE		"ESC_sun_mp_tpg_remove"
454 
455 #define	ESC_SUN_MP_TARGET_PORT_CHANGE	"ESC_sun_mp_target_port_change"
456 #define	ESC_SUN_MP_TARGET_PORT_ADD	"ESC_sun_mp_target_port_add"
457 #define	ESC_SUN_MP_TARGET_PORT_REMOVE	"ESC_sun_mp_target_port_remove"
458 
459 #define	ESC_SUN_MP_DEV_PROD_CHANGE	"ESC_sun_mp_dev_prod_change"
460 #define	ESC_SUN_MP_DEV_PROD_ADD		"ESC_sun_mp_dev_prod_add"
461 #define	ESC_SUN_MP_DEV_PROD_REMOVE	"ESC_sun_mp_dev_prod_remove"
462 
463 #ifdef __cplusplus
464 }
465 #endif
466 
467 #endif /* _SYS_SCSI_ADAPTERS_MPAPI_IMPL_H */
468