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 <string.h>
27*fcf3ce44SJohn Forte #include <syslog.h>
28*fcf3ce44SJohn Forte #include <errno.h>
29*fcf3ce44SJohn Forte #include <unistd.h>
30*fcf3ce44SJohn Forte #include <stropts.h>
31*fcf3ce44SJohn Forte
32*fcf3ce44SJohn Forte
33*fcf3ce44SJohn Forte #include "mp_utils.h"
34*fcf3ce44SJohn Forte
35*fcf3ce44SJohn Forte
36*fcf3ce44SJohn Forte /*
37*fcf3ce44SJohn Forte * Called by the common layer to request the plugin to set the
38*fcf3ce44SJohn Forte * access state for a list of target port groups.
39*fcf3ce44SJohn Forte */
40*fcf3ce44SJohn Forte
41*fcf3ce44SJohn Forte MP_STATUS
MP_SetTPGAccess(MP_OID oid,MP_UINT32 count,MP_TPG_STATE_PAIR * pTpgStateList)42*fcf3ce44SJohn Forte MP_SetTPGAccess(MP_OID oid, MP_UINT32 count,
43*fcf3ce44SJohn Forte MP_TPG_STATE_PAIR *pTpgStateList)
44*fcf3ce44SJohn Forte {
45*fcf3ce44SJohn Forte
46*fcf3ce44SJohn Forte MP_TPG_STATE_PAIR *head = pTpgStateList;
47*fcf3ce44SJohn Forte
48*fcf3ce44SJohn Forte mp_iocdata_t mp_ioctl;
49*fcf3ce44SJohn Forte mp_set_tpg_state_req_t setTpgStateRequest;
50*fcf3ce44SJohn Forte
51*fcf3ce44SJohn Forte int r = 0;
52*fcf3ce44SJohn Forte
53*fcf3ce44SJohn Forte int ioctlStatus = 0;
54*fcf3ce44SJohn Forte
55*fcf3ce44SJohn Forte MP_STATUS mpStatus = MP_STATUS_SUCCESS;
56*fcf3ce44SJohn Forte
57*fcf3ce44SJohn Forte
58*fcf3ce44SJohn Forte
59*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()", " - enter");
60*fcf3ce44SJohn Forte
61*fcf3ce44SJohn Forte
62*fcf3ce44SJohn Forte if (NULL == pTpgStateList) {
63*fcf3ce44SJohn Forte
64*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
65*fcf3ce44SJohn Forte "pTpgStateList is NULL");
66*fcf3ce44SJohn Forte
67*fcf3ce44SJohn Forte return (MP_STATUS_INVALID_PARAMETER);
68*fcf3ce44SJohn Forte }
69*fcf3ce44SJohn Forte
70*fcf3ce44SJohn Forte
71*fcf3ce44SJohn Forte if (g_scsi_vhci_fd < 0) {
72*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
73*fcf3ce44SJohn Forte "invalid driver file handle");
74*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()", " - error exit");
75*fcf3ce44SJohn Forte return (MP_STATUS_FAILED);
76*fcf3ce44SJohn Forte }
77*fcf3ce44SJohn Forte
78*fcf3ce44SJohn Forte
79*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
80*fcf3ce44SJohn Forte "oid.ownerId = %d",
81*fcf3ce44SJohn Forte oid.ownerId);
82*fcf3ce44SJohn Forte
83*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
84*fcf3ce44SJohn Forte "oid.objectType = %d",
85*fcf3ce44SJohn Forte oid.objectType);
86*fcf3ce44SJohn Forte
87*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
88*fcf3ce44SJohn Forte "oid.objectSequenceNumber = %llx",
89*fcf3ce44SJohn Forte oid.objectSequenceNumber);
90*fcf3ce44SJohn Forte
91*fcf3ce44SJohn Forte
92*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
93*fcf3ce44SJohn Forte "count = %d",
94*fcf3ce44SJohn Forte count);
95*fcf3ce44SJohn Forte
96*fcf3ce44SJohn Forte
97*fcf3ce44SJohn Forte for (r = 0; r < count; r++) {
98*fcf3ce44SJohn Forte
99*fcf3ce44SJohn Forte if (head->tpgOid.ownerId != g_pluginOwnerID) {
100*fcf3ce44SJohn Forte
101*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
102*fcf3ce44SJohn Forte "pTpgStateList->tpgOid.ownerId is not for"
103*fcf3ce44SJohn Forte " this plugin");
104*fcf3ce44SJohn Forte
105*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
106*fcf3ce44SJohn Forte "error exit");
107*fcf3ce44SJohn Forte
108*fcf3ce44SJohn Forte return (MP_STATUS_INVALID_PARAMETER);
109*fcf3ce44SJohn Forte }
110*fcf3ce44SJohn Forte
111*fcf3ce44SJohn Forte if (head->tpgOid.objectType !=
112*fcf3ce44SJohn Forte MP_OBJECT_TYPE_TARGET_PORT_GROUP) {
113*fcf3ce44SJohn Forte
114*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
115*fcf3ce44SJohn Forte "pTpgStateList->tpgOid.objectType is not"
116*fcf3ce44SJohn Forte " MP_OBJECT_TYPE_TARGET_PORT_GROUP");
117*fcf3ce44SJohn Forte
118*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
119*fcf3ce44SJohn Forte "error exit");
120*fcf3ce44SJohn Forte
121*fcf3ce44SJohn Forte return (MP_STATUS_INVALID_PARAMETER);
122*fcf3ce44SJohn Forte }
123*fcf3ce44SJohn Forte
124*fcf3ce44SJohn Forte
125*fcf3ce44SJohn Forte head++;
126*fcf3ce44SJohn Forte }
127*fcf3ce44SJohn Forte
128*fcf3ce44SJohn Forte
129*fcf3ce44SJohn Forte head = pTpgStateList;
130*fcf3ce44SJohn Forte
131*fcf3ce44SJohn Forte for (r = 0; r < count; r++) {
132*fcf3ce44SJohn Forte
133*fcf3ce44SJohn Forte (void) memset(&mp_ioctl, 0, sizeof (mp_iocdata_t));
134*fcf3ce44SJohn Forte (void) memset(&setTpgStateRequest, 0,
135*fcf3ce44SJohn Forte sizeof (mp_set_tpg_state_req_t));
136*fcf3ce44SJohn Forte
137*fcf3ce44SJohn Forte setTpgStateRequest.desiredState
138*fcf3ce44SJohn Forte = head->desiredState;
139*fcf3ce44SJohn Forte setTpgStateRequest.luTpgPair.luId
140*fcf3ce44SJohn Forte = oid.objectSequenceNumber;
141*fcf3ce44SJohn Forte setTpgStateRequest.luTpgPair.tpgId
142*fcf3ce44SJohn Forte = head->tpgOid.objectSequenceNumber;
143*fcf3ce44SJohn Forte
144*fcf3ce44SJohn Forte mp_ioctl.mp_cmd = MP_SET_TPG_ACCESS_STATE;
145*fcf3ce44SJohn Forte mp_ioctl.mp_ibuf = (caddr_t)&setTpgStateRequest;
146*fcf3ce44SJohn Forte mp_ioctl.mp_ilen = sizeof (mp_set_tpg_state_req_t);
147*fcf3ce44SJohn Forte mp_ioctl.mp_xfer = MP_XFER_WRITE;
148*fcf3ce44SJohn Forte
149*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
150*fcf3ce44SJohn Forte "mp_ioctl.mp_cmd (MP_SET_TPG_ACCESS_STATE) : %d",
151*fcf3ce44SJohn Forte mp_ioctl.mp_cmd);
152*fcf3ce44SJohn Forte
153*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
154*fcf3ce44SJohn Forte "setTpgStateRequest.luTpgPair.luId = %llx",
155*fcf3ce44SJohn Forte setTpgStateRequest.luTpgPair.luId);
156*fcf3ce44SJohn Forte
157*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
158*fcf3ce44SJohn Forte "setTpgStateRequest.luTpgPair.tpgId = %llx",
159*fcf3ce44SJohn Forte setTpgStateRequest.luTpgPair.tpgId);
160*fcf3ce44SJohn Forte
161*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
162*fcf3ce44SJohn Forte "setTpgStateRequest.desiredState = %d",
163*fcf3ce44SJohn Forte setTpgStateRequest.desiredState);
164*fcf3ce44SJohn Forte
165*fcf3ce44SJohn Forte ioctlStatus = ioctl(g_scsi_vhci_fd, MP_CMD, &mp_ioctl);
166*fcf3ce44SJohn Forte
167*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
168*fcf3ce44SJohn Forte " IOCTL call returned: %d", ioctlStatus);
169*fcf3ce44SJohn Forte
170*fcf3ce44SJohn Forte if (ioctlStatus < 0) {
171*fcf3ce44SJohn Forte ioctlStatus = errno;
172*fcf3ce44SJohn Forte }
173*fcf3ce44SJohn Forte
174*fcf3ce44SJohn Forte if (ioctlStatus != 0) {
175*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
176*fcf3ce44SJohn Forte "IOCTL call failed. IOCTL error is: %d",
177*fcf3ce44SJohn Forte ioctlStatus);
178*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
179*fcf3ce44SJohn Forte "IOCTL call failed. IOCTL error is: %s",
180*fcf3ce44SJohn Forte strerror(ioctlStatus));
181*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
182*fcf3ce44SJohn Forte "IOCTL call failed. mp_ioctl.mp_errno: %x",
183*fcf3ce44SJohn Forte mp_ioctl.mp_errno);
184*fcf3ce44SJohn Forte
185*fcf3ce44SJohn Forte if (ENOTSUP == ioctlStatus) {
186*fcf3ce44SJohn Forte mpStatus = MP_STATUS_UNSUPPORTED;
187*fcf3ce44SJohn Forte } else if (0 == mp_ioctl.mp_errno) {
188*fcf3ce44SJohn Forte mpStatus = MP_STATUS_FAILED;
189*fcf3ce44SJohn Forte } else {
190*fcf3ce44SJohn Forte mpStatus =
191*fcf3ce44SJohn Forte getStatus4ErrorCode(mp_ioctl.mp_errno);
192*fcf3ce44SJohn Forte }
193*fcf3ce44SJohn Forte
194*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()",
195*fcf3ce44SJohn Forte " - error exit");
196*fcf3ce44SJohn Forte
197*fcf3ce44SJohn Forte return (mpStatus);
198*fcf3ce44SJohn Forte }
199*fcf3ce44SJohn Forte
200*fcf3ce44SJohn Forte head++;
201*fcf3ce44SJohn Forte }
202*fcf3ce44SJohn Forte
203*fcf3ce44SJohn Forte
204*fcf3ce44SJohn Forte log(LOG_INFO, "MP_SetTPGAccess()", " - exit");
205*fcf3ce44SJohn Forte
206*fcf3ce44SJohn Forte return (MP_STATUS_SUCCESS);
207*fcf3ce44SJohn Forte }
208