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