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 "HandleNPIVPort.h"
29 #include "Exceptions.h"
33 #include <sys/types.h>
42 * @memo Construct a new HandleNPIVPort for state tracking
43 * @precondition Handle must be open
44 * @param myHandle The open handle for this HBA
45 * @param myHandlePort The open handle for this HBA Port
46 * @param myHBA The HBA for this port
47 * @param myPort The HBA Port for this npiv port
48 * @param myvPort The NPIV port to open
51 HandleNPIVPort::HandleNPIVPort(Handle
*myHandle
, HandlePort
*myHandlePort
,
52 HBA
*myHBA
, HBAPort
*myPort
, HBANPIVPort
*myvPort
) :
53 handle(myHandle
), handleport(myHandlePort
), hba(myHBA
),
54 port(myPort
), active(false), vport(myvPort
) {
55 Trace
log("HandleNPIVPort::HandleNPIVPort");
59 * @memo Reset the state tracking values for stale index detection
60 * @postcondition The first subsequent call to any index based routine
64 void HandleNPIVPort::refresh() {
65 Trace
log("HandleNPIVPort::refresh");
72 * @memo Validate the current state of the handle port
73 * @exception StaleDataException Thrown if the state has changed
74 * @param newState The new state of the port
77 * @doc After opening a port or refreshing, no state is tracked.
78 * The first time validate is called, the state is recorded.
79 * Subsequent calls will verify that the state is the same.
80 * If the state has changed, the exception will be thrown.
82 void HandleNPIVPort::validate(uint64_t newState
) {
83 Trace
log("HandleNPIVPort::validate");
84 log
.debug("Port %016llx state %016llx",
85 vport
->getPortWWN(), newState
);
88 if (lastState
!= newState
) {
90 throw StaleDataException();
100 * @memo Verify this port has the stated port wwn
101 * @return TRUE if the argument matches this port
102 * @return FALSE if the argument does not match this port
103 * @param portWWN The Port WWN to compare against this port
106 bool HandleNPIVPort::match(uint64_t portWWN
) {
107 Trace
log("HandleNPIVPort::match(wwn)");
109 ret
= (portWWN
== vport
->getPortWWN());
114 * @memo Verify this port is the stated index
115 * @return TRUE if the argument matches this port
116 * @return FALSE if the argument does not match this port
117 * @param index The index value to compare against this port
120 bool HandleNPIVPort::match(int index
) {
121 Trace
log("HandleNPIVPort::match(index)");
122 return (*vport
== *(port
->getPortByIndex(index
)));
126 * @memo Get attributes from this port.
127 * @exception ... underlying exceptions will be thrown
128 * @return The port attributes
130 * @see HandlePort::validate
132 * @doc This routine will perform state validation
134 HBA_NPIVATTRIBUTES
HandleNPIVPort::getPortAttributes() {
135 Trace
log("HandleNPIVPort::getPortAttributes");
137 HBA_NPIVATTRIBUTES attributes
= vport
->getPortAttributes(newState
);