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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <string.h>
27 #include <syslog.h>
28 #include <errno.h>
29 #include <unistd.h>
30 #include <stropts.h>
31 
32 #include "mp_utils.h"
33 
34 
35 
36 MP_STATUS
MP_GetTargetPortProperties(MP_OID oid,MP_TARGET_PORT_PROPERTIES * pProps)37 MP_GetTargetPortProperties(MP_OID oid,
38 	MP_TARGET_PORT_PROPERTIES *pProps)
39 {
40 	mp_iocdata_t		mp_ioctl;
41 	mp_target_port_prop_t	tpInfo;
42 
43 	int ioctlStatus = 0;
44 
45 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
46 
47 
48 
49 	log(LOG_INFO, "MP_GetTargetPortProperties()", " - enter");
50 
51 
52 	log(LOG_INFO, "MP_GetTargetPortProperties()",
53 		"oid.objectSequenceNumber = %llx",
54 		oid.objectSequenceNumber);
55 
56 	if (g_scsi_vhci_fd < 0) {
57 		log(LOG_INFO, "MP_GetTargetPortProperties()",
58 		    "invalid driver file handle");
59 		log(LOG_INFO, "MP_GetTargetPortProperties()", " - error exit");
60 		return (MP_STATUS_FAILED);
61 	}
62 
63 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
64 	(void) memset(&tpInfo,   0, sizeof (mp_target_port_prop_t));
65 
66 	mp_ioctl.mp_cmd  = MP_GET_TARGET_PORT_PROP;
67 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
68 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
69 	mp_ioctl.mp_obuf = (caddr_t)&tpInfo;
70 	mp_ioctl.mp_olen = sizeof (mp_target_port_prop_t);
71 	mp_ioctl.mp_xfer = MP_XFER_READ;
72 
73 	log(LOG_INFO, "MP_GetTargetPortProperties()",
74 		"mp_ioctl.mp_cmd (MP_GET_TARGET_PORT_PROP) : %d",
75 		mp_ioctl.mp_cmd);
76 
77 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
78 
79 	log(LOG_INFO, "MP_GetTargetPortProperties()",
80 		" IOCTL call returned: %d", ioctlStatus);
81 
82 	if (ioctlStatus < 0) {
83 		ioctlStatus = errno;
84 	}
85 
86 	if (ioctlStatus != 0) {
87 		log(LOG_INFO, "MP_GetTargetPortProperties()",
88 		    "IOCTL call failed.  IOCTL error is: %d",
89 			ioctlStatus);
90 		log(LOG_INFO, "MP_GetTargetPortProperties()",
91 		    "IOCTL call failed.  IOCTL error is: %s",
92 			strerror(ioctlStatus));
93 		log(LOG_INFO, "MP_GetTargetPortProperties()",
94 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
95 			mp_ioctl.mp_errno);
96 
97 		if (ENOTSUP == ioctlStatus) {
98 			mpStatus = MP_STATUS_UNSUPPORTED;
99 		} else if (0 == mp_ioctl.mp_errno) {
100 			mpStatus = MP_STATUS_FAILED;
101 		} else {
102 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
103 		}
104 
105 		log(LOG_INFO, "MP_GetTargetPortProperties()",
106 			" - error exit");
107 
108 		return (mpStatus);
109 	}
110 
111 	(void) memset(pProps, 0, sizeof (MP_TARGET_PORT_PROPERTIES));
112 
113 	(void) strncpy(pProps->portID, tpInfo.portName,
114 	    sizeof (pProps->portID));
115 	pProps->relativePortID = tpInfo.relativePortID;
116 
117 
118 	log(LOG_INFO, "MP_GetTargetPortProperties()", " - exit");
119 
120 	return (MP_STATUS_SUCCESS);
121 }
122