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