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 "mp_utils.h"
27 
28 #include <string.h>
29 #include <syslog.h>
30 #include <errno.h>
31 #include <unistd.h>
32 #include <stropts.h>
33 
34 
35 /*
36  *	Called by the common layer to request properties for a Device Product
37  */
38 
39 MP_STATUS
MP_GetDeviceProductProperties(MP_OID oid,MP_DEVICE_PRODUCT_PROPERTIES * pProps)40 MP_GetDeviceProductProperties(MP_OID oid, MP_DEVICE_PRODUCT_PROPERTIES *pProps)
41 {
42 	mp_iocdata_t		mp_ioctl;
43 	mp_dev_prod_prop_t	devProdInfo;
44 
45 	int ioctlStatus = 0;
46 
47 	int vendorLength   = 0;
48 	int productLength  = 0;
49 	int revisionLength = 0;
50 
51 	MP_STATUS mpStatus = MP_STATUS_SUCCESS;
52 
53 
54 	log(LOG_INFO, "MP_GetDeviceProductProperties()", " - enter");
55 
56 	log(LOG_INFO, "MP_GetDeviceProductProperties()",
57 		"oid.objectSequenceNumber = %llx",
58 		oid.objectSequenceNumber);
59 
60 	if (g_scsi_vhci_fd < 0) {
61 		log(LOG_INFO, "MP_GetDeviceProductProperties()",
62 		    "invalid driver file handle");
63 		log(LOG_INFO, "MP_GetDeviceProductProperties",
64 			" - error exit");
65 		return (MP_STATUS_FAILED);
66 	}
67 
68 	(void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
69 	(void) memset(&devProdInfo, 0, sizeof (mp_dev_prod_prop_t));
70 
71 	mp_ioctl.mp_cmd  = MP_GET_DEV_PROD_PROP;
72 	mp_ioctl.mp_ibuf = (caddr_t)&oid.objectSequenceNumber;
73 	mp_ioctl.mp_ilen = sizeof (oid.objectSequenceNumber);
74 	mp_ioctl.mp_obuf = (caddr_t)&devProdInfo;
75 	mp_ioctl.mp_olen = sizeof (mp_dev_prod_prop_t);
76 	mp_ioctl.mp_xfer = MP_XFER_READ;
77 
78 	ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
79 
80 	log(LOG_INFO, "MP_GetDeviceProductProperties()",
81 		" IOCTL call returned: %d", ioctlStatus);
82 
83 	if (ioctlStatus < 0) {
84 		ioctlStatus = errno;
85 	}
86 
87 	if (ioctlStatus != 0) {
88 		log(LOG_INFO, "MP_GetDeviceProductProperties()",
89 		    "IOCTL call failed.  IOCTL error is: %d",
90 			ioctlStatus);
91 		log(LOG_INFO, "MP_GetDeviceProductProperties()",
92 		    "IOCTL call failed.  IOCTL error is: %s",
93 			strerror(ioctlStatus));
94 		log(LOG_INFO, "MP_GetDeviceProductProperties()",
95 		    "IOCTL call failed.  mp_ioctl.mp_errno: %x",
96 			mp_ioctl.mp_errno);
97 
98 		if (ENOTSUP == ioctlStatus) {
99 			mpStatus = MP_STATUS_UNSUPPORTED;
100 		} else if (0 == mp_ioctl.mp_errno) {
101 			mpStatus = MP_STATUS_FAILED;
102 		} else {
103 			mpStatus = getStatus4ErrorCode(mp_ioctl.mp_errno);
104 		}
105 
106 		log(LOG_INFO, "MP_GetDeviceProductProperties()",
107 			" - error exit");
108 
109 		return (mpStatus);
110 	}
111 
112 	(void) memset(pProps, 0, sizeof (MP_DEVICE_PRODUCT_PROPERTIES));
113 
114 
115 	vendorLength   = sizeof (pProps->vendor);
116 	productLength  = sizeof (pProps->product);
117 	revisionLength = sizeof (pProps->revision);
118 
119 
120 	(void) strncpy(pProps->vendor,
121 			devProdInfo.prodInfo.vendor,
122 			vendorLength);
123 
124 	(void) strncpy(pProps->product,
125 			devProdInfo.prodInfo.product,
126 			productLength);
127 
128 	(void) strncpy(pProps->revision,
129 			devProdInfo.prodInfo.revision,
130 			revisionLength);
131 
132 	pProps->supportedLoadBalanceTypes =
133 		devProdInfo.supportedLoadBalanceTypes;
134 
135 
136 	log(LOG_INFO, "MP_GetDeviceProductProperties()",
137 		" - exit");
138 
139 	return (MP_STATUS_SUCCESS);
140 }
141