1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #include <syslog.h>
27*fcf3ce44SJohn Forte #include <errno.h>
28*fcf3ce44SJohn Forte #include <unistd.h>
29*fcf3ce44SJohn Forte #include <stropts.h>
30*fcf3ce44SJohn Forte 
31*fcf3ce44SJohn Forte #include "mp_utils.h"
32*fcf3ce44SJohn Forte 
33*fcf3ce44SJohn Forte 
34*fcf3ce44SJohn Forte MP_STATUS
MP_GetProprietaryLoadBalanceOidListPlugin(MP_OID_LIST ** ppList)35*fcf3ce44SJohn Forte MP_GetProprietaryLoadBalanceOidListPlugin(MP_OID_LIST **ppList)
36*fcf3ce44SJohn Forte {
37*fcf3ce44SJohn Forte 	mp_iocdata_t mp_ioctl;
38*fcf3ce44SJohn Forte 
39*fcf3ce44SJohn Forte 	uint64_t *objList = NULL;
40*fcf3ce44SJohn Forte 
41*fcf3ce44SJohn Forte 	int numOBJ = 0;
42*fcf3ce44SJohn Forte 	int i = 0;
43*fcf3ce44SJohn Forte 	int ioctlStatus = 0;
44*fcf3ce44SJohn Forte 
45*fcf3ce44SJohn Forte 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
46*fcf3ce44SJohn Forte 
47*fcf3ce44SJohn Forte 
48*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
49*fcf3ce44SJohn Forte 		" - enter");
50*fcf3ce44SJohn Forte 
51*fcf3ce44SJohn Forte 
52*fcf3ce44SJohn Forte 	if (g_scsi_vhci_fd < 0) {
53*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
54*fcf3ce44SJohn Forte 		    "invalid driver file handle");
55*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
56*fcf3ce44SJohn Forte 			" - error exit");
57*fcf3ce44SJohn Forte 		return (MP_STATUS_FAILED);
58*fcf3ce44SJohn Forte 	}
59*fcf3ce44SJohn Forte 
60*fcf3ce44SJohn Forte 	objList = (uint64_t *)calloc(1, DEFAULT_BUFFER_SIZE_LOADBALANCE);
61*fcf3ce44SJohn Forte 	if (NULL == objList) {
62*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
63*fcf3ce44SJohn Forte 			"no memory for objList(1)");
64*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
65*fcf3ce44SJohn Forte 			" - error exit");
66*fcf3ce44SJohn Forte 		return (MP_STATUS_INSUFFICIENT_MEMORY);
67*fcf3ce44SJohn Forte 	}
68*fcf3ce44SJohn Forte 
69*fcf3ce44SJohn Forte 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
70*fcf3ce44SJohn Forte 
71*fcf3ce44SJohn Forte 	mp_ioctl.mp_cmd  = MP_GET_PROPRIETARY_LOADBALANCE_LIST;
72*fcf3ce44SJohn Forte 	mp_ioctl.mp_obuf = (caddr_t)objList;
73*fcf3ce44SJohn Forte 	mp_ioctl.mp_olen = DEFAULT_BUFFER_SIZE_LOADBALANCE;
74*fcf3ce44SJohn Forte 	mp_ioctl.mp_xfer = MP_XFER_READ;
75*fcf3ce44SJohn Forte 
76*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
77*fcf3ce44SJohn Forte 		"mp_ioctl.mp_cmd : %d", mp_ioctl.mp_cmd);
78*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
79*fcf3ce44SJohn Forte 		"mp_ioctl.mp_obuf: %x", mp_ioctl.mp_obuf);
80*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
81*fcf3ce44SJohn Forte 		"mp_ioctl.mp_olen: %d", mp_ioctl.mp_olen);
82*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
83*fcf3ce44SJohn Forte 		"mp_ioctl.mp_xfer: %d (MP_XFER_READ)",
84*fcf3ce44SJohn Forte 		mp_ioctl.mp_xfer);
85*fcf3ce44SJohn Forte 
86*fcf3ce44SJohn Forte 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
87*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetInitiatorPortOidListPlugin()",
88*fcf3ce44SJohn Forte 		"ioctl call returned ioctlStatus: %d",
89*fcf3ce44SJohn Forte 		ioctlStatus);
90*fcf3ce44SJohn Forte 
91*fcf3ce44SJohn Forte 	if (ioctlStatus < 0) {
92*fcf3ce44SJohn Forte 		ioctlStatus = errno;
93*fcf3ce44SJohn Forte 	}
94*fcf3ce44SJohn Forte 
95*fcf3ce44SJohn Forte 	if ((ioctlStatus != 0) && (MP_MORE_DATA != mp_ioctl.mp_errno)) {
96*fcf3ce44SJohn Forte 
97*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
98*fcf3ce44SJohn Forte 		    "IOCTL call failed.  IOCTL error is: %d",
99*fcf3ce44SJohn Forte 			ioctlStatus);
100*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
101*fcf3ce44SJohn Forte 		    "IOCTL call failed.  IOCTL error is: %s",
102*fcf3ce44SJohn Forte 			strerror(ioctlStatus));
103*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
104*fcf3ce44SJohn Forte 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
105*fcf3ce44SJohn Forte 			mp_ioctl.mp_errno);
106*fcf3ce44SJohn Forte 
107*fcf3ce44SJohn Forte 
108*fcf3ce44SJohn Forte 		free(objList);
109*fcf3ce44SJohn Forte 
110*fcf3ce44SJohn Forte 		if (ENOTSUP == ioctlStatus) {
111*fcf3ce44SJohn Forte 			mpStatus = MP_STATUS_UNSUPPORTED;
112*fcf3ce44SJohn Forte 		} else if (0 == mp_ioctl.mp_errno) {
113*fcf3ce44SJohn Forte 			mpStatus = MP_STATUS_FAILED;
114*fcf3ce44SJohn Forte 		} else {
115*fcf3ce44SJohn Forte 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
116*fcf3ce44SJohn Forte 		}
117*fcf3ce44SJohn Forte 
118*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
119*fcf3ce44SJohn Forte 			" - error exit");
120*fcf3ce44SJohn Forte 
121*fcf3ce44SJohn Forte 		return (mpStatus);
122*fcf3ce44SJohn Forte 	}
123*fcf3ce44SJohn Forte 
124*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
125*fcf3ce44SJohn Forte 		" - mp_ioctl.mp_alen : %d",
126*fcf3ce44SJohn Forte 		mp_ioctl.mp_alen);
127*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
128*fcf3ce44SJohn Forte 		" - sizeof (uint64_t): %d",
129*fcf3ce44SJohn Forte 		sizeof (uint64_t));
130*fcf3ce44SJohn Forte 
131*fcf3ce44SJohn Forte 	numOBJ = mp_ioctl.mp_alen / sizeof (uint64_t);
132*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
133*fcf3ce44SJohn Forte 	    "Length of list: %d", numOBJ);
134*fcf3ce44SJohn Forte 
135*fcf3ce44SJohn Forte 	if (numOBJ < 1) {
136*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
137*fcf3ce44SJohn Forte 			"driver returned empty list.");
138*fcf3ce44SJohn Forte 
139*fcf3ce44SJohn Forte 		free(objList);
140*fcf3ce44SJohn Forte 
141*fcf3ce44SJohn Forte 		*ppList = createOidList(1);
142*fcf3ce44SJohn Forte 		if (NULL == *ppList) {
143*fcf3ce44SJohn Forte 			log(LOG_INFO,
144*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
145*fcf3ce44SJohn Forte 				"no memory for MP_OID_LIST");
146*fcf3ce44SJohn Forte 			log(LOG_INFO,
147*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
148*fcf3ce44SJohn Forte 				" - error exit");
149*fcf3ce44SJohn Forte 			return (MP_STATUS_INSUFFICIENT_MEMORY);
150*fcf3ce44SJohn Forte 		}
151*fcf3ce44SJohn Forte 
152*fcf3ce44SJohn Forte 		return (MP_STATUS_SUCCESS);
153*fcf3ce44SJohn Forte 	}
154*fcf3ce44SJohn Forte 
155*fcf3ce44SJohn Forte 	if (mp_ioctl.mp_alen > DEFAULT_BUFFER_SIZE_LOADBALANCE) {
156*fcf3ce44SJohn Forte 
157*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
158*fcf3ce44SJohn Forte 			"buffer size too small, need : %d",
159*fcf3ce44SJohn Forte 			mp_ioctl.mp_alen);
160*fcf3ce44SJohn Forte 
161*fcf3ce44SJohn Forte 		free(objList);
162*fcf3ce44SJohn Forte 
163*fcf3ce44SJohn Forte 		objList = (uint64_t *)calloc(1, numOBJ * sizeof (uint64_t));
164*fcf3ce44SJohn Forte 		if (NULL == objList) {
165*fcf3ce44SJohn Forte 			log(LOG_INFO,
166*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
167*fcf3ce44SJohn Forte 				"no memory for objList(2)");
168*fcf3ce44SJohn Forte 			log(LOG_INFO,
169*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
170*fcf3ce44SJohn Forte 				" - error exit");
171*fcf3ce44SJohn Forte 			return (MP_STATUS_INSUFFICIENT_MEMORY);
172*fcf3ce44SJohn Forte 		}
173*fcf3ce44SJohn Forte 
174*fcf3ce44SJohn Forte 		(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
175*fcf3ce44SJohn Forte 
176*fcf3ce44SJohn Forte 		mp_ioctl.mp_cmd  = MP_GET_PROPRIETARY_LOADBALANCE_LIST;
177*fcf3ce44SJohn Forte 		mp_ioctl.mp_obuf = (caddr_t)objList;
178*fcf3ce44SJohn Forte 		mp_ioctl.mp_olen = numOBJ * sizeof (uint64_t);
179*fcf3ce44SJohn Forte 		mp_ioctl.mp_xfer = MP_XFER_READ;
180*fcf3ce44SJohn Forte 
181*fcf3ce44SJohn Forte 		log(LOG_INFO,
182*fcf3ce44SJohn Forte 			"MP_GetProprietaryLoadBalanceOidListPlugin()",
183*fcf3ce44SJohn Forte 			"mp_ioctl.mp_cmd : %d", mp_ioctl.mp_cmd);
184*fcf3ce44SJohn Forte 		log(LOG_INFO,
185*fcf3ce44SJohn Forte 			"MP_GetProprietaryLoadBalanceOidListPlugin()",
186*fcf3ce44SJohn Forte 			"mp_ioctl.mp_obuf: %x", mp_ioctl.mp_obuf);
187*fcf3ce44SJohn Forte 		log(LOG_INFO,
188*fcf3ce44SJohn Forte 			"MP_GetProprietaryLoadBalanceOidListPlugin()",
189*fcf3ce44SJohn Forte 			"mp_ioctl.mp_olen: %d", mp_ioctl.mp_olen);
190*fcf3ce44SJohn Forte 		log(LOG_INFO,
191*fcf3ce44SJohn Forte 			"MP_GetProprietaryLoadBalanceOidListPlugin()",
192*fcf3ce44SJohn Forte 			"mp_ioctl.mp_xfer: %d (MP_XFER_READ)",
193*fcf3ce44SJohn Forte 			mp_ioctl.mp_xfer);
194*fcf3ce44SJohn Forte 
195*fcf3ce44SJohn Forte 
196*fcf3ce44SJohn Forte 		ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
197*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
198*fcf3ce44SJohn Forte 			"ioctl call returned ioctlStatus: %d",
199*fcf3ce44SJohn Forte 			ioctlStatus);
200*fcf3ce44SJohn Forte 
201*fcf3ce44SJohn Forte 		if (ioctlStatus < 0) {
202*fcf3ce44SJohn Forte 			ioctlStatus = errno;
203*fcf3ce44SJohn Forte 		}
204*fcf3ce44SJohn Forte 
205*fcf3ce44SJohn Forte 		if (ioctlStatus != 0) {
206*fcf3ce44SJohn Forte 
207*fcf3ce44SJohn Forte 			log(LOG_INFO,
208*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
209*fcf3ce44SJohn Forte 				"IOCTL call failed.  IOCTL error is: %d",
210*fcf3ce44SJohn Forte 				ioctlStatus);
211*fcf3ce44SJohn Forte 			log(LOG_INFO,
212*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
213*fcf3ce44SJohn Forte 				"IOCTL call failed.  IOCTL error is: %s",
214*fcf3ce44SJohn Forte 				strerror(ioctlStatus));
215*fcf3ce44SJohn Forte 			log(LOG_INFO,
216*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
217*fcf3ce44SJohn Forte 				"IOCTL call failed.  mp_ioctl.mp_errno: %x",
218*fcf3ce44SJohn Forte 				mp_ioctl.mp_errno);
219*fcf3ce44SJohn Forte 
220*fcf3ce44SJohn Forte 
221*fcf3ce44SJohn Forte 			free(objList);
222*fcf3ce44SJohn Forte 
223*fcf3ce44SJohn Forte 			if (ENOTSUP == ioctlStatus) {
224*fcf3ce44SJohn Forte 				mpStatus = MP_STATUS_UNSUPPORTED;
225*fcf3ce44SJohn Forte 			} else if (0 == mp_ioctl.mp_errno) {
226*fcf3ce44SJohn Forte 				mpStatus = MP_STATUS_FAILED;
227*fcf3ce44SJohn Forte 			} else {
228*fcf3ce44SJohn Forte 				mpStatus =
229*fcf3ce44SJohn Forte 					getStatus4ErrorCode(mp_ioctl.mp_errno);
230*fcf3ce44SJohn Forte 			}
231*fcf3ce44SJohn Forte 
232*fcf3ce44SJohn Forte 			log(LOG_INFO,
233*fcf3ce44SJohn Forte 				"MP_GetProprietaryLoadBalanceOidListPlugin()",
234*fcf3ce44SJohn Forte 				" - error exit");
235*fcf3ce44SJohn Forte 
236*fcf3ce44SJohn Forte 			return (mpStatus);
237*fcf3ce44SJohn Forte 		}
238*fcf3ce44SJohn Forte 	}
239*fcf3ce44SJohn Forte 
240*fcf3ce44SJohn Forte 
241*fcf3ce44SJohn Forte 	*ppList = createOidList(numOBJ);
242*fcf3ce44SJohn Forte 	if (NULL == *ppList) {
243*fcf3ce44SJohn Forte 		log(LOG_INFO,
244*fcf3ce44SJohn Forte 			"MP_GetProprietaryLoadBalanceOidListPlugin()",
245*fcf3ce44SJohn Forte 			"no memory for *ppList");
246*fcf3ce44SJohn Forte 		free(objList);
247*fcf3ce44SJohn Forte 		log(LOG_INFO,
248*fcf3ce44SJohn Forte 			"MP_GetProprietaryLoadBalanceOidListPlugin()",
249*fcf3ce44SJohn Forte 			" - error exit");
250*fcf3ce44SJohn Forte 		return (MP_STATUS_INSUFFICIENT_MEMORY);
251*fcf3ce44SJohn Forte 	}
252*fcf3ce44SJohn Forte 
253*fcf3ce44SJohn Forte 	(*ppList)->oidCount = numOBJ;
254*fcf3ce44SJohn Forte 
255*fcf3ce44SJohn Forte 	log(LOG_INFO,
256*fcf3ce44SJohn Forte 		"MP_GetProprietaryLoadBalanceOidListPlugin()",
257*fcf3ce44SJohn Forte 		"(*ppList)->oidCount = %d",
258*fcf3ce44SJohn Forte 		(*ppList)->oidCount);
259*fcf3ce44SJohn Forte 
260*fcf3ce44SJohn Forte 	for (i = 0; i < numOBJ; i++) {
261*fcf3ce44SJohn Forte 
262*fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectType =
263*fcf3ce44SJohn Forte 			MP_OBJECT_TYPE_PROPRIETARY_LOAD_BALANCE;
264*fcf3ce44SJohn Forte 		(*ppList)->oids[i].ownerId =
265*fcf3ce44SJohn Forte 			g_pluginOwnerID;
266*fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectSequenceNumber =
267*fcf3ce44SJohn Forte 			objList[i];
268*fcf3ce44SJohn Forte 
269*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
270*fcf3ce44SJohn Forte 			"(*ppList)->oids[%d].objectType           = %d",
271*fcf3ce44SJohn Forte 			i, (*ppList)->oids[i].objectType);
272*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
273*fcf3ce44SJohn Forte 			"(*ppList)->oids[%d].ownerId              = %d",
274*fcf3ce44SJohn Forte 			i, (*ppList)->oids[i].ownerId);
275*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
276*fcf3ce44SJohn Forte 			"(*ppList)->oids[%d].objectSequenceNumber = %llx",
277*fcf3ce44SJohn Forte 			i, (*ppList)->oids[i].objectSequenceNumber);
278*fcf3ce44SJohn Forte 	}
279*fcf3ce44SJohn Forte 
280*fcf3ce44SJohn Forte 	free(objList);
281*fcf3ce44SJohn Forte 
282*fcf3ce44SJohn Forte 
283*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetProprietaryLoadBalanceOidListPlugin()",
284*fcf3ce44SJohn Forte 		" - exit");
285*fcf3ce44SJohn Forte 
286*fcf3ce44SJohn Forte 	return (MP_STATUS_SUCCESS);
287*fcf3ce44SJohn Forte }
288