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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
28 #include "HandlePort.h"
29 #include "Exceptions.h"
33 #include <sys/types.h>
43 * @memo Construct a new HandlePort for state tracking
44 * @precondition Handle must be open
45 * @param myHandle The open handle for this HBA
46 * @param myHBA The HBA for this port
47 * @param myPort The HBA Port to open
49 HandlePort::HandlePort(Handle
*myHandle
, HBA
*myHBA
, HBAPort
*myPort
) :
50 handle(myHandle
), hba(myHBA
), port(myPort
), active(false) {
51 Trace
log("HandlePort::HandlePort");
55 * @memo Reset the state tracking values for stale index detection
56 * @postcondition The first subsequent call to any index based routine
59 void HandlePort::refresh() {
60 Trace
log("HandlePort::refresh");
67 * @memo Validate the current state of the handle port
68 * @exception StaleDataException Thrown if the state has changed
69 * @param newState The new state of the port
71 * @doc After opening a port or refreshing, no state is tracked.
72 * The first time validate is called, the state is recorded.
73 * Subsequent calls will verify that the state is the same.
74 * If the state has changed, the exception will be thrown.
76 void HandlePort::validate(uint64_t newState
) {
77 Trace
log("HandlePort::validate");
78 log
.debug("Port %016llx state %016llx", port
->getPortWWN(), newState
);
81 if (lastState
!= newState
) {
83 throw StaleDataException();
93 * @memo Verify this port has the stated port wwn
94 * @return TRUE if the argument matches this port
95 * @return FALSE if the argument does not match this port
96 * @param portWWN The Port WWN to compare against this port
98 bool HandlePort::match(uint64_t portWWN
) {
99 Trace
log("HandlePort::match(wwn)");
101 ret
= (portWWN
== port
->getPortWWN());
106 * @memo Verify this port is the stated index
107 * @return TRUE if the argument matches this port
108 * @return FALSE if the argument does not match this port
109 * @param index The index value to compare against this port
111 bool HandlePort::match(int index
) {
112 Trace
log("HandlePort::match(index)");
113 return (*port
== *(hba
->getPortByIndex(index
)));
117 * @memo Get attributes from a discovered port.
118 * @exception ... underlying exceptions will be thrown
119 * @return The discovered port attributes
120 * @param wwn The node or port wwn of the discovered port
122 * @doc This routine will not perform any state validation
124 HBA_PORTATTRIBUTES
HandlePort::getDiscoveredAttributes(uint64_t wwn
) {
125 Trace
log("HandlePort::getDiscoveredAttributes(wwn)");
127 HBA_PORTATTRIBUTES attributes
= port
->getDiscoveredAttributes(
129 // We don't validate when a WWN was used
134 * @memo Get attributes from this port.
135 * @exception ... underlying exceptions will be thrown
136 * @return The port attributes
137 * @see HandlePort::validate
139 * @doc This routine will perform state validation
141 HBA_PORTATTRIBUTES
HandlePort::getPortAttributes() {
142 Trace
log("HandlePort::getPortAttributes");
144 HBA_PORTATTRIBUTES attributes
= port
->getPortAttributes(newState
);
150 * @memo Get attributes from a discovered port.
151 * @exception ... underlying exceptions will be thrown
152 * @return The discovered port attributes
153 * @param discoveredport The index of the discovered port
154 * @see HandlePort::validate
156 * @doc This routine will perform state validation
159 HandlePort::getDiscoveredAttributes(HBA_UINT32 discoveredport
) {
160 Trace
log("HandlePort::getDiscoveredAttributes(index)");
162 HBA_PORTATTRIBUTES attributes
= port
->getDiscoveredAttributes(
163 discoveredport
, newState
);
168 HBA_PORTNPIVATTRIBUTES
HandlePort::getPortNPIVAttributes() {
169 Trace
log("HandlePort::getPortNPIVAttributes");
171 HBA_PORTNPIVATTRIBUTES attributes
= port
->getPortNPIVAttributes(newState
);
176 uint32_t HandlePort::deleteNPIVPort(uint64_t vportwwn
) {
177 Trace
log("HandlePort::deleteNPIVPort");
178 uint32_t ret
= port
->deleteNPIVPort(vportwwn
);
183 uint32_t HandlePort::createNPIVPort(uint64_t vnodewwn
,
184 uint64_t vportwwn
, uint32_t vindex
) {
185 Trace
log("HandlePort::createNPIVPort");
188 vportindex
= port
->createNPIVPort(vnodewwn
, vportwwn
, vindex
);
192 HandleNPIVPort
* HandlePort::getHandleNPIVPortByIndex(int index
) {
193 Trace
log("HandlePort::getHandleNPIVPortByIndex(int index)");
195 HBANPIVPort
* vport
= port
->getPortByIndex(index
);
196 return (getHandleNPIVPort(vport
->getPortWWN()));
199 HandleNPIVPort
* HandlePort::getHandleNPIVPort(uint64_t wwn
) {
200 Trace
log("HandlePort::getHandleNPIVPort");
203 // Check to see if the wwn is in the map
204 if (npivportHandles
.find(wwn
) == npivportHandles
.end()) {
205 // Not found, add a new one
206 HBANPIVPort
* vport
= port
->getPort(wwn
);
207 npivportHandles
[wwn
] = new HandleNPIVPort(handle
, this, hba
, port
, vport
);
209 HandleNPIVPort
*npivportHandle
= npivportHandles
[wwn
];
211 return (npivportHandle
);