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 #include <libdevinfo.h>
34*fcf3ce44SJohn Forte #include <sys/types.h>
35*fcf3ce44SJohn Forte #include <sys/stat.h>
36*fcf3ce44SJohn Forte #include <fcntl.h>
37*fcf3ce44SJohn Forte #include <sys/stat.h>
38*fcf3ce44SJohn Forte 
39*fcf3ce44SJohn Forte 
doDevInfoStuffForIntPort(MP_OID oid)40*fcf3ce44SJohn Forte static MP_STATUS doDevInfoStuffForIntPort(MP_OID oid)
41*fcf3ce44SJohn Forte {
42*fcf3ce44SJohn Forte 	di_node_t root_node	= DI_NODE_NIL;
43*fcf3ce44SJohn Forte 
44*fcf3ce44SJohn Forte 	di_node_t vh_node	= DI_NODE_NIL;
45*fcf3ce44SJohn Forte 	di_node_t ph_node	= DI_NODE_NIL;
46*fcf3ce44SJohn Forte 	di_node_t sv_node	= DI_NODE_NIL;
47*fcf3ce44SJohn Forte 
48*fcf3ce44SJohn Forte 
49*fcf3ce44SJohn Forte 	di_path_t path = DI_PATH_NIL;
50*fcf3ce44SJohn Forte 
51*fcf3ce44SJohn Forte 	struct stat buffer;
52*fcf3ce44SJohn Forte 
53*fcf3ce44SJohn Forte 	int instNum = 0;
54*fcf3ce44SJohn Forte 	int majorNum = 0;
55*fcf3ce44SJohn Forte 
56*fcf3ce44SJohn Forte 	int oidInstNum = 0;
57*fcf3ce44SJohn Forte 	int oidMajorNum = 0;
58*fcf3ce44SJohn Forte 
59*fcf3ce44SJohn Forte 	int found = 0;
60*fcf3ce44SJohn Forte 	int status = -1;
61*fcf3ce44SJohn Forte 
62*fcf3ce44SJohn Forte 
63*fcf3ce44SJohn Forte 	char *pathName  = NULL;
64*fcf3ce44SJohn Forte 	char *minorName = "c";
65*fcf3ce44SJohn Forte 
66*fcf3ce44SJohn Forte 	char fullName[512];
67*fcf3ce44SJohn Forte 
68*fcf3ce44SJohn Forte 
69*fcf3ce44SJohn Forte 
70*fcf3ce44SJohn Forte 
71*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForIntPort()", " - enter");
72*fcf3ce44SJohn Forte 
73*fcf3ce44SJohn Forte 
74*fcf3ce44SJohn Forte 	oidInstNum  = (int)MP_GET_INST_FROM_ID(oid.objectSequenceNumber);
75*fcf3ce44SJohn Forte 	oidMajorNum = (int)MP_GET_MAJOR_FROM_ID(oid.objectSequenceNumber);
76*fcf3ce44SJohn Forte 
77*fcf3ce44SJohn Forte 
78*fcf3ce44SJohn Forte 	root_node = di_init("/", DINFOCACHE);
79*fcf3ce44SJohn Forte 	if (DI_NODE_NIL == root_node) {
80*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForIntPort()",
81*fcf3ce44SJohn Forte 			" - di_init() failed");
82*fcf3ce44SJohn Forte 
83*fcf3ce44SJohn Forte 		return (MP_STATUS_FAILED);
84*fcf3ce44SJohn Forte 	}
85*fcf3ce44SJohn Forte 
86*fcf3ce44SJohn Forte 	vh_node = di_vhci_first_node(root_node);
87*fcf3ce44SJohn Forte 
88*fcf3ce44SJohn Forte 	while (DI_NODE_NIL != vh_node) {
89*fcf3ce44SJohn Forte 		if ((di_driver_name(vh_node) != NULL) &&
90*fcf3ce44SJohn Forte 		    (strncmp(di_driver_name(vh_node), "scsi_vhci", 9) == 0)) {
91*fcf3ce44SJohn Forte 			ph_node = di_phci_first_node(vh_node);
92*fcf3ce44SJohn Forte 			while (DI_NODE_NIL != ph_node) {
93*fcf3ce44SJohn Forte 
94*fcf3ce44SJohn Forte 				instNum  = di_instance(ph_node);
95*fcf3ce44SJohn Forte 				majorNum = di_driver_major(ph_node);
96*fcf3ce44SJohn Forte 
97*fcf3ce44SJohn Forte 				if ((majorNum == oidMajorNum) &&
98*fcf3ce44SJohn Forte 					(instNum == oidInstNum)) {
99*fcf3ce44SJohn Forte 
100*fcf3ce44SJohn Forte 					log(LOG_INFO,
101*fcf3ce44SJohn Forte 					    "doDevInfoStuffForIntPort()",
102*fcf3ce44SJohn Forte 						"got a match");
103*fcf3ce44SJohn Forte 
104*fcf3ce44SJohn Forte 					found = 1;
105*fcf3ce44SJohn Forte 
106*fcf3ce44SJohn Forte 					break;
107*fcf3ce44SJohn Forte 				}
108*fcf3ce44SJohn Forte 
109*fcf3ce44SJohn Forte 				ph_node = di_phci_next_node(ph_node);
110*fcf3ce44SJohn Forte 			}
111*fcf3ce44SJohn Forte 		}
112*fcf3ce44SJohn Forte 
113*fcf3ce44SJohn Forte 		if (found) {
114*fcf3ce44SJohn Forte 
115*fcf3ce44SJohn Forte 			break;
116*fcf3ce44SJohn Forte 		}
117*fcf3ce44SJohn Forte 
118*fcf3ce44SJohn Forte 		vh_node = di_vhci_next_node(vh_node);
119*fcf3ce44SJohn Forte 	}
120*fcf3ce44SJohn Forte 
121*fcf3ce44SJohn Forte 
122*fcf3ce44SJohn Forte 	if (!found) {
123*fcf3ce44SJohn Forte 
124*fcf3ce44SJohn Forte 		di_fini(root_node);
125*fcf3ce44SJohn Forte 
126*fcf3ce44SJohn Forte 		log(LOG_INFO,
127*fcf3ce44SJohn Forte 			"doDevInfoStuffForIntPort()",
128*fcf3ce44SJohn Forte 			" - no match found, error exit");
129*fcf3ce44SJohn Forte 
130*fcf3ce44SJohn Forte 		return (MP_STATUS_OBJECT_NOT_FOUND);
131*fcf3ce44SJohn Forte 	}
132*fcf3ce44SJohn Forte 
133*fcf3ce44SJohn Forte 
134*fcf3ce44SJohn Forte 	path = di_path_next(ph_node, DI_PATH_NIL);
135*fcf3ce44SJohn Forte 
136*fcf3ce44SJohn Forte 	if (DI_PATH_NIL == path) {
137*fcf3ce44SJohn Forte 
138*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForIntPort()",
139*fcf3ce44SJohn Forte 			" - path is DI_PATH_NIL");
140*fcf3ce44SJohn Forte 	}
141*fcf3ce44SJohn Forte 
142*fcf3ce44SJohn Forte 	while (DI_PATH_NIL != path) {
143*fcf3ce44SJohn Forte 
144*fcf3ce44SJohn Forte 		sv_node = di_path_client_node(path);
145*fcf3ce44SJohn Forte 		if (DI_NODE_NIL == sv_node) {
146*fcf3ce44SJohn Forte 
147*fcf3ce44SJohn Forte 			log(LOG_INFO, "doDevInfoStuffForIntPort()",
148*fcf3ce44SJohn Forte 				" - sv_node is DI_NODE_NIL");
149*fcf3ce44SJohn Forte 
150*fcf3ce44SJohn Forte 		} else {
151*fcf3ce44SJohn Forte 
152*fcf3ce44SJohn Forte 			pathName = di_devfs_path(sv_node);
153*fcf3ce44SJohn Forte 			(void) snprintf(fullName, 511, "/devices%s:%s",
154*fcf3ce44SJohn Forte 				pathName, minorName);
155*fcf3ce44SJohn Forte 
156*fcf3ce44SJohn Forte 			(void) di_devfs_path_free(pathName);
157*fcf3ce44SJohn Forte 
158*fcf3ce44SJohn Forte 			status = stat(fullName, &buffer);
159*fcf3ce44SJohn Forte 			if (status < 0) {
160*fcf3ce44SJohn Forte 
161*fcf3ce44SJohn Forte 				log(LOG_INFO,
162*fcf3ce44SJohn Forte 					"doDevInfoStuffForIntPort()",
163*fcf3ce44SJohn Forte 					" - stat() call failed: %d", status);
164*fcf3ce44SJohn Forte 
165*fcf3ce44SJohn Forte 				log(LOG_INFO,
166*fcf3ce44SJohn Forte 				    "doDevInfoStuffForIntPort()",
167*fcf3ce44SJohn Forte 					" - errno: [%d].", errno);
168*fcf3ce44SJohn Forte 
169*fcf3ce44SJohn Forte 				log(LOG_INFO,
170*fcf3ce44SJohn Forte 				    "doDevInfoStuffForIntPort()",
171*fcf3ce44SJohn Forte 					" - strerror(errno): [%s].",
172*fcf3ce44SJohn Forte 					strerror(errno));
173*fcf3ce44SJohn Forte 
174*fcf3ce44SJohn Forte 
175*fcf3ce44SJohn Forte 				di_fini(root_node);
176*fcf3ce44SJohn Forte 
177*fcf3ce44SJohn Forte 				log(LOG_INFO,
178*fcf3ce44SJohn Forte 					"doDevInfoStuffForIntPort()",
179*fcf3ce44SJohn Forte 					" - error exit.");
180*fcf3ce44SJohn Forte 
181*fcf3ce44SJohn Forte 				return (MP_STATUS_FAILED);
182*fcf3ce44SJohn Forte 			}
183*fcf3ce44SJohn Forte 		}
184*fcf3ce44SJohn Forte 
185*fcf3ce44SJohn Forte 		path = di_path_next(ph_node, path);
186*fcf3ce44SJohn Forte 	}
187*fcf3ce44SJohn Forte 
188*fcf3ce44SJohn Forte 
189*fcf3ce44SJohn Forte 	di_fini(root_node);
190*fcf3ce44SJohn Forte 
191*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForIntPort()", " - exit");
192*fcf3ce44SJohn Forte 
193*fcf3ce44SJohn Forte 	return (MP_STATUS_SUCCESS);
194*fcf3ce44SJohn Forte }
195*fcf3ce44SJohn Forte 
196*fcf3ce44SJohn Forte 
doDevInfoStuffForTargetPort(MP_OID oid)197*fcf3ce44SJohn Forte static MP_STATUS doDevInfoStuffForTargetPort(MP_OID oid)
198*fcf3ce44SJohn Forte {
199*fcf3ce44SJohn Forte 	di_node_t root_node	= DI_NODE_NIL;
200*fcf3ce44SJohn Forte 	di_node_t sv_node	= DI_NODE_NIL;
201*fcf3ce44SJohn Forte 	di_node_t child_node = DI_NODE_NIL;
202*fcf3ce44SJohn Forte 
203*fcf3ce44SJohn Forte 	di_path_t path = DI_PATH_NIL;
204*fcf3ce44SJohn Forte 
205*fcf3ce44SJohn Forte 	int match = 0;
206*fcf3ce44SJohn Forte 	int count = 0;
207*fcf3ce44SJohn Forte 	int ioctlStatus = 0;
208*fcf3ce44SJohn Forte 	int status = -1;
209*fcf3ce44SJohn Forte 
210*fcf3ce44SJohn Forte 	struct stat buffer;
211*fcf3ce44SJohn Forte 
212*fcf3ce44SJohn Forte 	char *pathName  = NULL;
213*fcf3ce44SJohn Forte 	char *minorName = "c";
214*fcf3ce44SJohn Forte 
215*fcf3ce44SJohn Forte 	char fullName[512];
216*fcf3ce44SJohn Forte 
217*fcf3ce44SJohn Forte 	uchar_t *targetPort = NULL;
218*fcf3ce44SJohn Forte 
219*fcf3ce44SJohn Forte 	mp_iocdata_t mp_ioctl;
220*fcf3ce44SJohn Forte 
221*fcf3ce44SJohn Forte 	mp_target_port_prop_t tpInfo;
222*fcf3ce44SJohn Forte 
223*fcf3ce44SJohn Forte 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
224*fcf3ce44SJohn Forte 
225*fcf3ce44SJohn Forte 
226*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForTargetPort()", " - enter");
227*fcf3ce44SJohn Forte 
228*fcf3ce44SJohn Forte 
229*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForTargetPort()",
230*fcf3ce44SJohn Forte 		"oid.objectSequenceNumber = %llx",
231*fcf3ce44SJohn Forte 		oid.objectSequenceNumber);
232*fcf3ce44SJohn Forte 
233*fcf3ce44SJohn Forte 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
234*fcf3ce44SJohn Forte 	(void) memset(&tpInfo,   0, sizeof (mp_target_port_prop_t));
235*fcf3ce44SJohn Forte 
236*fcf3ce44SJohn Forte 	mp_ioctl.mp_cmd  = MP_GET_TARGET_PORT_PROP;
237*fcf3ce44SJohn Forte 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
238*fcf3ce44SJohn Forte 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
239*fcf3ce44SJohn Forte 	mp_ioctl.mp_obuf = (caddr_t)&tpInfo;
240*fcf3ce44SJohn Forte 	mp_ioctl.mp_olen = sizeof (mp_target_port_prop_t);
241*fcf3ce44SJohn Forte 	mp_ioctl.mp_xfer = MP_XFER_READ;
242*fcf3ce44SJohn Forte 
243*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForTargetPort()",
244*fcf3ce44SJohn Forte 		"mp_ioctl.mp_cmd (MP_GET_TARGET_PORT_PROP) : %d",
245*fcf3ce44SJohn Forte 		mp_ioctl.mp_cmd);
246*fcf3ce44SJohn Forte 
247*fcf3ce44SJohn Forte 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
248*fcf3ce44SJohn Forte 
249*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForTargetPort()",
250*fcf3ce44SJohn Forte 		" IOCTL call returned: %d", ioctlStatus);
251*fcf3ce44SJohn Forte 
252*fcf3ce44SJohn Forte 	if (ioctlStatus < 0) {
253*fcf3ce44SJohn Forte 		ioctlStatus = errno;
254*fcf3ce44SJohn Forte 	}
255*fcf3ce44SJohn Forte 
256*fcf3ce44SJohn Forte 	if (ioctlStatus != 0) {
257*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForTargetPort()",
258*fcf3ce44SJohn Forte 			"IOCTL call failed.  IOCTL error is: %d",
259*fcf3ce44SJohn Forte 			ioctlStatus);
260*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForTargetPort()",
261*fcf3ce44SJohn Forte 			"IOCTL call failed.  IOCTL error is: %s",
262*fcf3ce44SJohn Forte 			strerror(ioctlStatus));
263*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForTargetPort()",
264*fcf3ce44SJohn Forte 			"IOCTL call failed.  mp_ioctl.mp_errno: %x",
265*fcf3ce44SJohn Forte 			mp_ioctl.mp_errno);
266*fcf3ce44SJohn Forte 
267*fcf3ce44SJohn Forte 		if (ENOTSUP == ioctlStatus) {
268*fcf3ce44SJohn Forte 			mpStatus = MP_STATUS_UNSUPPORTED;
269*fcf3ce44SJohn Forte 		} else if (0 == mp_ioctl.mp_errno) {
270*fcf3ce44SJohn Forte 			mpStatus = MP_STATUS_FAILED;
271*fcf3ce44SJohn Forte 		} else {
272*fcf3ce44SJohn Forte 			mpStatus =
273*fcf3ce44SJohn Forte 				getStatus4ErrorCode(mp_ioctl.mp_errno);
274*fcf3ce44SJohn Forte 		}
275*fcf3ce44SJohn Forte 
276*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForTargetPort()",
277*fcf3ce44SJohn Forte 			" - error exit");
278*fcf3ce44SJohn Forte 
279*fcf3ce44SJohn Forte 		return (mpStatus);
280*fcf3ce44SJohn Forte 	}
281*fcf3ce44SJohn Forte 
282*fcf3ce44SJohn Forte 	root_node = di_init("/", DINFOCACHE);
283*fcf3ce44SJohn Forte 
284*fcf3ce44SJohn Forte 	if (DI_NODE_NIL == root_node) {
285*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForTargetPort()",
286*fcf3ce44SJohn Forte 			" - di_init() failed");
287*fcf3ce44SJohn Forte 
288*fcf3ce44SJohn Forte 		return (MP_STATUS_FAILED);
289*fcf3ce44SJohn Forte 	}
290*fcf3ce44SJohn Forte 
291*fcf3ce44SJohn Forte 
292*fcf3ce44SJohn Forte 	sv_node = di_drv_first_node("scsi_vhci", root_node);
293*fcf3ce44SJohn Forte 	if (DI_NODE_NIL == sv_node) {
294*fcf3ce44SJohn Forte 		log(LOG_INFO, "doDevInfoStuffForTargetPort()",
295*fcf3ce44SJohn Forte 			" - di_drv_first_node() failed");
296*fcf3ce44SJohn Forte 
297*fcf3ce44SJohn Forte 		di_fini(root_node);
298*fcf3ce44SJohn Forte 
299*fcf3ce44SJohn Forte 		return (MP_STATUS_FAILED);
300*fcf3ce44SJohn Forte 	}
301*fcf3ce44SJohn Forte 
302*fcf3ce44SJohn Forte 	child_node = di_child_node(sv_node);
303*fcf3ce44SJohn Forte 
304*fcf3ce44SJohn Forte 	while (DI_NODE_NIL != child_node) {
305*fcf3ce44SJohn Forte 
306*fcf3ce44SJohn Forte 		path = di_path_next(child_node, path);
307*fcf3ce44SJohn Forte 
308*fcf3ce44SJohn Forte 		match = 0;
309*fcf3ce44SJohn Forte 
310*fcf3ce44SJohn Forte 		while (DI_PATH_NIL != path) {
311*fcf3ce44SJohn Forte 
312*fcf3ce44SJohn Forte 			count = di_path_prop_lookup_bytes(path,
313*fcf3ce44SJohn Forte 						"target-port",
314*fcf3ce44SJohn Forte 						&targetPort);
315*fcf3ce44SJohn Forte 
316*fcf3ce44SJohn Forte 			if (NULL != targetPort) {
317*fcf3ce44SJohn Forte 
318*fcf3ce44SJohn Forte 				if (0 == memcmp(targetPort,
319*fcf3ce44SJohn Forte 						tpInfo.portName,
320*fcf3ce44SJohn Forte 						count)) {
321*fcf3ce44SJohn Forte 
322*fcf3ce44SJohn Forte 					match = 1;
323*fcf3ce44SJohn Forte 
324*fcf3ce44SJohn Forte 					break;
325*fcf3ce44SJohn Forte 				}
326*fcf3ce44SJohn Forte 			}
327*fcf3ce44SJohn Forte 
328*fcf3ce44SJohn Forte 			path = di_path_next(child_node, path);
329*fcf3ce44SJohn Forte 		}
330*fcf3ce44SJohn Forte 
331*fcf3ce44SJohn Forte 		if (match) {
332*fcf3ce44SJohn Forte 
333*fcf3ce44SJohn Forte 			log(LOG_INFO, "doDevInfoStuffForTargetPort()",
334*fcf3ce44SJohn Forte 				" - got a match");
335*fcf3ce44SJohn Forte 
336*fcf3ce44SJohn Forte 			pathName = di_devfs_path(child_node);
337*fcf3ce44SJohn Forte 
338*fcf3ce44SJohn Forte 			(void) snprintf(fullName, 511, "/devices%s:%s",
339*fcf3ce44SJohn Forte 				pathName, minorName);
340*fcf3ce44SJohn Forte 
341*fcf3ce44SJohn Forte 			(void) di_devfs_path_free(pathName);
342*fcf3ce44SJohn Forte 
343*fcf3ce44SJohn Forte 			status = stat(fullName, &buffer);
344*fcf3ce44SJohn Forte 			if (status < 0) {
345*fcf3ce44SJohn Forte 
346*fcf3ce44SJohn Forte 				log(LOG_INFO,
347*fcf3ce44SJohn Forte 					"doDevInfoStuffForTargetPort()",
348*fcf3ce44SJohn Forte 					" - stat() call failed: %d", status);
349*fcf3ce44SJohn Forte 
350*fcf3ce44SJohn Forte 				log(LOG_INFO,
351*fcf3ce44SJohn Forte 				    "doDevInfoStuffForTargetPort()",
352*fcf3ce44SJohn Forte 					" - errno: [%d].", errno);
353*fcf3ce44SJohn Forte 
354*fcf3ce44SJohn Forte 				log(LOG_INFO,
355*fcf3ce44SJohn Forte 				    "doDevInfoStuffForTargetPort()",
356*fcf3ce44SJohn Forte 					" - strerror(errno): [%s].",
357*fcf3ce44SJohn Forte 					strerror(errno));
358*fcf3ce44SJohn Forte 
359*fcf3ce44SJohn Forte 
360*fcf3ce44SJohn Forte 				di_fini(root_node);
361*fcf3ce44SJohn Forte 
362*fcf3ce44SJohn Forte 				log(LOG_INFO,
363*fcf3ce44SJohn Forte 					"doDevInfoStuffForTargetPort()",
364*fcf3ce44SJohn Forte 					" - error exit.");
365*fcf3ce44SJohn Forte 
366*fcf3ce44SJohn Forte 				return (MP_STATUS_FAILED);
367*fcf3ce44SJohn Forte 			}
368*fcf3ce44SJohn Forte 		}
369*fcf3ce44SJohn Forte 
370*fcf3ce44SJohn Forte 		child_node = di_sibling_node(child_node);
371*fcf3ce44SJohn Forte 	}
372*fcf3ce44SJohn Forte 
373*fcf3ce44SJohn Forte 
374*fcf3ce44SJohn Forte 	di_fini(root_node);
375*fcf3ce44SJohn Forte 
376*fcf3ce44SJohn Forte 	log(LOG_INFO, "doDevInfoStuffForTargetPort()", " - exit");
377*fcf3ce44SJohn Forte 
378*fcf3ce44SJohn Forte 	return (MP_STATUS_SUCCESS);
379*fcf3ce44SJohn Forte }
380*fcf3ce44SJohn Forte 
381*fcf3ce44SJohn Forte 
382*fcf3ce44SJohn Forte 
383*fcf3ce44SJohn Forte MP_STATUS
MP_GetAssociatedPathOidList(MP_OID oid,MP_OID_LIST ** ppList)384*fcf3ce44SJohn Forte MP_GetAssociatedPathOidList(MP_OID oid, MP_OID_LIST **ppList)
385*fcf3ce44SJohn Forte {
386*fcf3ce44SJohn Forte 	mp_iocdata_t mp_ioctl;
387*fcf3ce44SJohn Forte 
388*fcf3ce44SJohn Forte 	uint64_t *objList = NULL;
389*fcf3ce44SJohn Forte 
390*fcf3ce44SJohn Forte 	int numOBJ = 0;
391*fcf3ce44SJohn Forte 	int i = 0;
392*fcf3ce44SJohn Forte 	int ioctlStatus = 0;
393*fcf3ce44SJohn Forte 
394*fcf3ce44SJohn Forte 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
395*fcf3ce44SJohn Forte 
396*fcf3ce44SJohn Forte 	int request = MP_GET_PATH_LIST_FOR_MP_LU;
397*fcf3ce44SJohn Forte 
398*fcf3ce44SJohn Forte 
399*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()", " - enter");
400*fcf3ce44SJohn Forte 
401*fcf3ce44SJohn Forte 
402*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
403*fcf3ce44SJohn Forte 		" set default request to MP_GET_PATH_LIST_FOR_MP_LU");
404*fcf3ce44SJohn Forte 
405*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
406*fcf3ce44SJohn Forte 		"oid.objectSequenceNumber = %llx",
407*fcf3ce44SJohn Forte 		oid.objectSequenceNumber);
408*fcf3ce44SJohn Forte 
409*fcf3ce44SJohn Forte 
410*fcf3ce44SJohn Forte 	if (g_scsi_vhci_fd < 0) {
411*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
412*fcf3ce44SJohn Forte 		    "invalid driver file handle");
413*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()", " - error exit");
414*fcf3ce44SJohn Forte 		return (MP_STATUS_FAILED);
415*fcf3ce44SJohn Forte 	}
416*fcf3ce44SJohn Forte 
417*fcf3ce44SJohn Forte 	if (MP_OBJECT_TYPE_INITIATOR_PORT == oid.objectType) {
418*fcf3ce44SJohn Forte 		request = MP_GET_PATH_LIST_FOR_INIT_PORT;
419*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
420*fcf3ce44SJohn Forte 			" set request to MP_GET_PATH_LIST_FOR_INIT_PORT");
421*fcf3ce44SJohn Forte 
422*fcf3ce44SJohn Forte 		mpStatus = doDevInfoStuffForIntPort(oid);
423*fcf3ce44SJohn Forte 		if (MP_STATUS_SUCCESS != mpStatus) {
424*fcf3ce44SJohn Forte 
425*fcf3ce44SJohn Forte 			return (mpStatus);
426*fcf3ce44SJohn Forte 		}
427*fcf3ce44SJohn Forte 	} else if (MP_OBJECT_TYPE_TARGET_PORT == oid.objectType) {
428*fcf3ce44SJohn Forte 		request = MP_GET_PATH_LIST_FOR_TARGET_PORT;
429*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
430*fcf3ce44SJohn Forte 			" set request to MP_GET_PATH_LIST_FOR_TARGET_PORT");
431*fcf3ce44SJohn Forte 
432*fcf3ce44SJohn Forte 		mpStatus = doDevInfoStuffForTargetPort(oid);
433*fcf3ce44SJohn Forte 		if (MP_STATUS_SUCCESS != mpStatus) {
434*fcf3ce44SJohn Forte 
435*fcf3ce44SJohn Forte 			return (mpStatus);
436*fcf3ce44SJohn Forte 		}
437*fcf3ce44SJohn Forte 	}
438*fcf3ce44SJohn Forte 
439*fcf3ce44SJohn Forte 	objList = (uint64_t *)calloc(1, DEFAULT_BUFFER_SIZE_PATH_LIST);
440*fcf3ce44SJohn Forte 	if (NULL == objList) {
441*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
442*fcf3ce44SJohn Forte 			"no memory for objList(1)");
443*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
444*fcf3ce44SJohn Forte 			" - error exit");
445*fcf3ce44SJohn Forte 		return (MP_STATUS_INSUFFICIENT_MEMORY);
446*fcf3ce44SJohn Forte 	}
447*fcf3ce44SJohn Forte 
448*fcf3ce44SJohn Forte 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
449*fcf3ce44SJohn Forte 
450*fcf3ce44SJohn Forte 	mp_ioctl.mp_cmd  = request;
451*fcf3ce44SJohn Forte 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
452*fcf3ce44SJohn Forte 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
453*fcf3ce44SJohn Forte 	mp_ioctl.mp_obuf = (caddr_t)objList;
454*fcf3ce44SJohn Forte 	mp_ioctl.mp_olen = DEFAULT_BUFFER_SIZE_PATH_LIST;
455*fcf3ce44SJohn Forte 	mp_ioctl.mp_xfer = MP_XFER_READ;
456*fcf3ce44SJohn Forte 
457*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
458*fcf3ce44SJohn Forte 		"mp_ioctl.mp_cmd : %d", mp_ioctl.mp_cmd);
459*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
460*fcf3ce44SJohn Forte 		"mp_ioctl.mp_obuf: %x", mp_ioctl.mp_obuf);
461*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
462*fcf3ce44SJohn Forte 		"mp_ioctl.mp_olen: %d", mp_ioctl.mp_olen);
463*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
464*fcf3ce44SJohn Forte 		"mp_ioctl.mp_xfer: %d (MP_XFER_READ)",
465*fcf3ce44SJohn Forte 		mp_ioctl.mp_xfer);
466*fcf3ce44SJohn Forte 
467*fcf3ce44SJohn Forte 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
468*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
469*fcf3ce44SJohn Forte 		"ioctl call returned ioctlStatus: %d",
470*fcf3ce44SJohn Forte 		ioctlStatus);
471*fcf3ce44SJohn Forte 
472*fcf3ce44SJohn Forte 	if (ioctlStatus < 0) {
473*fcf3ce44SJohn Forte 		ioctlStatus = errno;
474*fcf3ce44SJohn Forte 	}
475*fcf3ce44SJohn Forte 
476*fcf3ce44SJohn Forte 	if ((ioctlStatus != 0) && (MP_MORE_DATA != mp_ioctl.mp_errno)) {
477*fcf3ce44SJohn Forte 
478*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
479*fcf3ce44SJohn Forte 		    "IOCTL call failed.  IOCTL error is: %d",
480*fcf3ce44SJohn Forte 			ioctlStatus);
481*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
482*fcf3ce44SJohn Forte 		    "IOCTL call failed.  IOCTL error is: %s",
483*fcf3ce44SJohn Forte 			strerror(ioctlStatus));
484*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
485*fcf3ce44SJohn Forte 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
486*fcf3ce44SJohn Forte 			mp_ioctl.mp_errno);
487*fcf3ce44SJohn Forte 
488*fcf3ce44SJohn Forte 
489*fcf3ce44SJohn Forte 		free(objList);
490*fcf3ce44SJohn Forte 
491*fcf3ce44SJohn Forte 		if (ENOTSUP == ioctlStatus) {
492*fcf3ce44SJohn Forte 			mpStatus = MP_STATUS_UNSUPPORTED;
493*fcf3ce44SJohn Forte 		} else if (0 == mp_ioctl.mp_errno) {
494*fcf3ce44SJohn Forte 			mpStatus = MP_STATUS_FAILED;
495*fcf3ce44SJohn Forte 		} else {
496*fcf3ce44SJohn Forte 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
497*fcf3ce44SJohn Forte 		}
498*fcf3ce44SJohn Forte 
499*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
500*fcf3ce44SJohn Forte 			" - error exit");
501*fcf3ce44SJohn Forte 
502*fcf3ce44SJohn Forte 		return (mpStatus);
503*fcf3ce44SJohn Forte 	}
504*fcf3ce44SJohn Forte 
505*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
506*fcf3ce44SJohn Forte 		" - mp_ioctl.mp_alen : %d",
507*fcf3ce44SJohn Forte 		mp_ioctl.mp_alen);
508*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
509*fcf3ce44SJohn Forte 		" - sizeof (uint64_t): %d",
510*fcf3ce44SJohn Forte 		sizeof (uint64_t));
511*fcf3ce44SJohn Forte 
512*fcf3ce44SJohn Forte 	numOBJ = mp_ioctl.mp_alen / sizeof (uint64_t);
513*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
514*fcf3ce44SJohn Forte 	    "Length of list: %d", numOBJ);
515*fcf3ce44SJohn Forte 
516*fcf3ce44SJohn Forte 	if (numOBJ < 1) {
517*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
518*fcf3ce44SJohn Forte 			"driver returned empty list.");
519*fcf3ce44SJohn Forte 
520*fcf3ce44SJohn Forte 		free(objList);
521*fcf3ce44SJohn Forte 
522*fcf3ce44SJohn Forte 		*ppList = createOidList(1);
523*fcf3ce44SJohn Forte 		if (NULL == *ppList) {
524*fcf3ce44SJohn Forte 			log(LOG_INFO,
525*fcf3ce44SJohn Forte 				"MP_GetAssociatedPathOidList()",
526*fcf3ce44SJohn Forte 				"no memory for MP_OID_LIST");
527*fcf3ce44SJohn Forte 			log(LOG_INFO,
528*fcf3ce44SJohn Forte 				"MP_GetAssociatedPathOidList()",
529*fcf3ce44SJohn Forte 				" - error exit");
530*fcf3ce44SJohn Forte 			return (MP_STATUS_INSUFFICIENT_MEMORY);
531*fcf3ce44SJohn Forte 		}
532*fcf3ce44SJohn Forte 
533*fcf3ce44SJohn Forte 		return (MP_STATUS_SUCCESS);
534*fcf3ce44SJohn Forte 	}
535*fcf3ce44SJohn Forte 
536*fcf3ce44SJohn Forte 	if (mp_ioctl.mp_alen > DEFAULT_BUFFER_SIZE_PATH_LIST) {
537*fcf3ce44SJohn Forte 
538*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
539*fcf3ce44SJohn Forte 			"buffer size too small, need : %d",
540*fcf3ce44SJohn Forte 			mp_ioctl.mp_alen);
541*fcf3ce44SJohn Forte 
542*fcf3ce44SJohn Forte 		free(objList);
543*fcf3ce44SJohn Forte 
544*fcf3ce44SJohn Forte 		objList = (uint64_t *)calloc(1, numOBJ * sizeof (uint64_t));
545*fcf3ce44SJohn Forte 		if (NULL == objList) {
546*fcf3ce44SJohn Forte 			log(LOG_INFO, "MP_GetAssociatedPathOidList()",
547*fcf3ce44SJohn Forte 				"no memory for objList(2)");
548*fcf3ce44SJohn Forte 			log(LOG_INFO, "MP_GetAssociatedPathOidList()",
549*fcf3ce44SJohn Forte 				" - error exit");
550*fcf3ce44SJohn Forte 			return (MP_STATUS_INSUFFICIENT_MEMORY);
551*fcf3ce44SJohn Forte 		}
552*fcf3ce44SJohn Forte 
553*fcf3ce44SJohn Forte 		(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
554*fcf3ce44SJohn Forte 
555*fcf3ce44SJohn Forte 		mp_ioctl.mp_cmd  = request;
556*fcf3ce44SJohn Forte 		mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
557*fcf3ce44SJohn Forte 		mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
558*fcf3ce44SJohn Forte 		mp_ioctl.mp_obuf = (caddr_t)objList;
559*fcf3ce44SJohn Forte 		mp_ioctl.mp_olen = numOBJ * sizeof (uint64_t);
560*fcf3ce44SJohn Forte 		mp_ioctl.mp_xfer = MP_XFER_READ;
561*fcf3ce44SJohn Forte 
562*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
563*fcf3ce44SJohn Forte 			"mp_ioctl.mp_cmd : %d", mp_ioctl.mp_cmd);
564*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
565*fcf3ce44SJohn Forte 			"mp_ioctl.mp_obuf: %x", mp_ioctl.mp_obuf);
566*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
567*fcf3ce44SJohn Forte 			"mp_ioctl.mp_olen: %d", mp_ioctl.mp_olen);
568*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
569*fcf3ce44SJohn Forte 			"mp_ioctl.mp_xfer: %d (MP_XFER_READ)",
570*fcf3ce44SJohn Forte 			mp_ioctl.mp_xfer);
571*fcf3ce44SJohn Forte 
572*fcf3ce44SJohn Forte 
573*fcf3ce44SJohn Forte 		ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
574*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
575*fcf3ce44SJohn Forte 			"ioctl call returned ioctlStatus: %d",
576*fcf3ce44SJohn Forte 			ioctlStatus);
577*fcf3ce44SJohn Forte 
578*fcf3ce44SJohn Forte 		if (ioctlStatus < 0) {
579*fcf3ce44SJohn Forte 			ioctlStatus = errno;
580*fcf3ce44SJohn Forte 		}
581*fcf3ce44SJohn Forte 
582*fcf3ce44SJohn Forte 		if (ioctlStatus != 0) {
583*fcf3ce44SJohn Forte 
584*fcf3ce44SJohn Forte 			log(LOG_INFO, "MP_GetAssociatedPathOidList()",
585*fcf3ce44SJohn Forte 				"IOCTL call failed.  IOCTL error is: %d",
586*fcf3ce44SJohn Forte 				ioctlStatus);
587*fcf3ce44SJohn Forte 			log(LOG_INFO, "MP_GetAssociatedPathOidList()",
588*fcf3ce44SJohn Forte 				"IOCTL call failed.  IOCTL error is: %s",
589*fcf3ce44SJohn Forte 				strerror(ioctlStatus));
590*fcf3ce44SJohn Forte 			log(LOG_INFO, "MP_GetAssociatedPathOidList()",
591*fcf3ce44SJohn Forte 				"IOCTL call failed.  mp_ioctl.mp_errno: %x",
592*fcf3ce44SJohn Forte 				mp_ioctl.mp_errno);
593*fcf3ce44SJohn Forte 
594*fcf3ce44SJohn Forte 
595*fcf3ce44SJohn Forte 			free(objList);
596*fcf3ce44SJohn Forte 
597*fcf3ce44SJohn Forte 			if (ENOTSUP == ioctlStatus) {
598*fcf3ce44SJohn Forte 				mpStatus = MP_STATUS_UNSUPPORTED;
599*fcf3ce44SJohn Forte 			} else if (0 == mp_ioctl.mp_errno) {
600*fcf3ce44SJohn Forte 				mpStatus = MP_STATUS_FAILED;
601*fcf3ce44SJohn Forte 			} else {
602*fcf3ce44SJohn Forte 				mpStatus =
603*fcf3ce44SJohn Forte 					getStatus4ErrorCode(mp_ioctl.mp_errno);
604*fcf3ce44SJohn Forte 			}
605*fcf3ce44SJohn Forte 
606*fcf3ce44SJohn Forte 			log(LOG_INFO, "MP_GetAssociatedPathOidList()",
607*fcf3ce44SJohn Forte 				" - error exit");
608*fcf3ce44SJohn Forte 
609*fcf3ce44SJohn Forte 			return (mpStatus);
610*fcf3ce44SJohn Forte 		}
611*fcf3ce44SJohn Forte 	}
612*fcf3ce44SJohn Forte 
613*fcf3ce44SJohn Forte 
614*fcf3ce44SJohn Forte 	*ppList = createOidList(numOBJ);
615*fcf3ce44SJohn Forte 	if (NULL == *ppList) {
616*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
617*fcf3ce44SJohn Forte 			"no memory for *ppList");
618*fcf3ce44SJohn Forte 		free(objList);
619*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
620*fcf3ce44SJohn Forte 			" - error exit");
621*fcf3ce44SJohn Forte 		return (MP_STATUS_INSUFFICIENT_MEMORY);
622*fcf3ce44SJohn Forte 	}
623*fcf3ce44SJohn Forte 
624*fcf3ce44SJohn Forte 	(*ppList)->oidCount = numOBJ;
625*fcf3ce44SJohn Forte 
626*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()",
627*fcf3ce44SJohn Forte 		"(*ppList)->oidCount = %d",
628*fcf3ce44SJohn Forte 		(*ppList)->oidCount);
629*fcf3ce44SJohn Forte 
630*fcf3ce44SJohn Forte 	for (i = 0; i < numOBJ; i++) {
631*fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectType = MP_OBJECT_TYPE_PATH_LU;
632*fcf3ce44SJohn Forte 		(*ppList)->oids[i].ownerId = g_pluginOwnerID;
633*fcf3ce44SJohn Forte 		(*ppList)->oids[i].objectSequenceNumber = objList[i];
634*fcf3ce44SJohn Forte 
635*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
636*fcf3ce44SJohn Forte 			"(*ppList)->oids[%d].objectType           = %d",
637*fcf3ce44SJohn Forte 			i, (*ppList)->oids[i].objectType);
638*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
639*fcf3ce44SJohn Forte 			"(*ppList)->oids[%d].ownerId              = %d",
640*fcf3ce44SJohn Forte 			i, (*ppList)->oids[i].ownerId);
641*fcf3ce44SJohn Forte 		log(LOG_INFO, "MP_GetAssociatedPathOidList()",
642*fcf3ce44SJohn Forte 			"(*ppList)->oids[%d].objectSequenceNumber = %llx",
643*fcf3ce44SJohn Forte 			i, (*ppList)->oids[i].objectSequenceNumber);
644*fcf3ce44SJohn Forte 	}
645*fcf3ce44SJohn Forte 
646*fcf3ce44SJohn Forte 	free(objList);
647*fcf3ce44SJohn Forte 
648*fcf3ce44SJohn Forte 
649*fcf3ce44SJohn Forte 	log(LOG_INFO, "MP_GetAssociatedPathOidList()", " - exit");
650*fcf3ce44SJohn Forte 
651*fcf3ce44SJohn Forte 	return (MP_STATUS_SUCCESS);
652*fcf3ce44SJohn Forte }
653