xref: /onnv-gate/usr/src/lib/sun_fc/common/HandleNPIVPort.cc (revision 7836:4e95154b5b7a)
1*7836SJohn.Forte@Sun.COM /*
2*7836SJohn.Forte@Sun.COM  * CDDL HEADER START
3*7836SJohn.Forte@Sun.COM  *
4*7836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
5*7836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
6*7836SJohn.Forte@Sun.COM  * You may not use this file except in compliance with the License.
7*7836SJohn.Forte@Sun.COM  *
8*7836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*7836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
11*7836SJohn.Forte@Sun.COM  * and limitations under the License.
12*7836SJohn.Forte@Sun.COM  *
13*7836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*7836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*7836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*7836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*7836SJohn.Forte@Sun.COM  *
19*7836SJohn.Forte@Sun.COM  * CDDL HEADER END
20*7836SJohn.Forte@Sun.COM  */
21*7836SJohn.Forte@Sun.COM /*
22*7836SJohn.Forte@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*7836SJohn.Forte@Sun.COM  * Use is subject to license terms.
24*7836SJohn.Forte@Sun.COM  */
25*7836SJohn.Forte@Sun.COM 
26*7836SJohn.Forte@Sun.COM 
27*7836SJohn.Forte@Sun.COM 
28*7836SJohn.Forte@Sun.COM #include "HandleNPIVPort.h"
29*7836SJohn.Forte@Sun.COM #include "Exceptions.h"
30*7836SJohn.Forte@Sun.COM #include "Trace.h"
31*7836SJohn.Forte@Sun.COM #include <iostream>
32*7836SJohn.Forte@Sun.COM #include <iomanip>
33*7836SJohn.Forte@Sun.COM #include <sys/types.h>
34*7836SJohn.Forte@Sun.COM #include <sys/stat.h>
35*7836SJohn.Forte@Sun.COM #include <fcntl.h>
36*7836SJohn.Forte@Sun.COM #include <unistd.h>
37*7836SJohn.Forte@Sun.COM #include <stropts.h>
38*7836SJohn.Forte@Sun.COM 
39*7836SJohn.Forte@Sun.COM using namespace std;
40*7836SJohn.Forte@Sun.COM 
41*7836SJohn.Forte@Sun.COM /**
42*7836SJohn.Forte@Sun.COM  * @memo            Construct a new HandleNPIVPort for state tracking
43*7836SJohn.Forte@Sun.COM  * @precondition    Handle must be open
44*7836SJohn.Forte@Sun.COM  * @param           myHandle The open handle for this HBA
45*7836SJohn.Forte@Sun.COM  * @param           myHandlePort The open handle for this HBA Port
46*7836SJohn.Forte@Sun.COM  * @param           myHBA The HBA for this port
47*7836SJohn.Forte@Sun.COM  * @param           myPort The HBA Port for this npiv port
48*7836SJohn.Forte@Sun.COM  * @param           myvPort The NPIV port to open
49*7836SJohn.Forte@Sun.COM  * @version         1.2
50*7836SJohn.Forte@Sun.COM  */
HandleNPIVPort(Handle * myHandle,HandlePort * myHandlePort,HBA * myHBA,HBAPort * myPort,HBANPIVPort * myvPort)51*7836SJohn.Forte@Sun.COM HandleNPIVPort::HandleNPIVPort(Handle *myHandle, HandlePort *myHandlePort,
52*7836SJohn.Forte@Sun.COM     HBA *myHBA, HBAPort *myPort, HBANPIVPort *myvPort) :
53*7836SJohn.Forte@Sun.COM     handle(myHandle), handleport(myHandlePort), hba(myHBA),
54*7836SJohn.Forte@Sun.COM     port(myPort), active(false), vport(myvPort) {
55*7836SJohn.Forte@Sun.COM 	Trace log("HandleNPIVPort::HandleNPIVPort");
56*7836SJohn.Forte@Sun.COM }
57*7836SJohn.Forte@Sun.COM 
58*7836SJohn.Forte@Sun.COM /**
59*7836SJohn.Forte@Sun.COM  * @memo            Reset the state tracking values for stale index detection
60*7836SJohn.Forte@Sun.COM  * @postcondition   The first subsequent call to any index based routine
61*7836SJohn.Forte@Sun.COM  *                  will always succed.
62*7836SJohn.Forte@Sun.COM  * @version         1.2
63*7836SJohn.Forte@Sun.COM  */
refresh()64*7836SJohn.Forte@Sun.COM void HandleNPIVPort::refresh() {
65*7836SJohn.Forte@Sun.COM 	Trace log("HandleNPIVPort::refresh");
66*7836SJohn.Forte@Sun.COM 	lock();
67*7836SJohn.Forte@Sun.COM 	active = false;
68*7836SJohn.Forte@Sun.COM 	unlock();
69*7836SJohn.Forte@Sun.COM }
70*7836SJohn.Forte@Sun.COM 
71*7836SJohn.Forte@Sun.COM /**
72*7836SJohn.Forte@Sun.COM  * @memo            Validate the current state of the handle port
73*7836SJohn.Forte@Sun.COM  * @exception       StaleDataException Thrown if the state has changed
74*7836SJohn.Forte@Sun.COM  * @param           newState The new state of the port
75*7836SJohn.Forte@Sun.COM  * @version         1.2
76*7836SJohn.Forte@Sun.COM  *
77*7836SJohn.Forte@Sun.COM  * @doc             After opening a port or refreshing, no state is tracked.
78*7836SJohn.Forte@Sun.COM  *                  The first time validate is called, the state is recorded.
79*7836SJohn.Forte@Sun.COM  *                  Subsequent calls will verify that the state is the same.
80*7836SJohn.Forte@Sun.COM  *                  If the state has changed, the exception will be thrown.
81*7836SJohn.Forte@Sun.COM  */
validate(uint64_t newState)82*7836SJohn.Forte@Sun.COM void HandleNPIVPort::validate(uint64_t newState) {
83*7836SJohn.Forte@Sun.COM 	Trace log("HandleNPIVPort::validate");
84*7836SJohn.Forte@Sun.COM 	log.debug("Port %016llx state %016llx",
85*7836SJohn.Forte@Sun.COM 	    vport->getPortWWN(), newState);
86*7836SJohn.Forte@Sun.COM 	lock();
87*7836SJohn.Forte@Sun.COM 	if (active) {
88*7836SJohn.Forte@Sun.COM 		if (lastState != newState) {
89*7836SJohn.Forte@Sun.COM 			unlock();
90*7836SJohn.Forte@Sun.COM 			throw StaleDataException();
91*7836SJohn.Forte@Sun.COM 		}
92*7836SJohn.Forte@Sun.COM 	} else {
93*7836SJohn.Forte@Sun.COM 		active = true;
94*7836SJohn.Forte@Sun.COM 		lastState = newState;
95*7836SJohn.Forte@Sun.COM 	}
96*7836SJohn.Forte@Sun.COM 	unlock();
97*7836SJohn.Forte@Sun.COM }
98*7836SJohn.Forte@Sun.COM 
99*7836SJohn.Forte@Sun.COM /**
100*7836SJohn.Forte@Sun.COM  * @memo            Verify this port has the stated port wwn
101*7836SJohn.Forte@Sun.COM  * @return          TRUE if the argument matches this port
102*7836SJohn.Forte@Sun.COM  * @return          FALSE if the argument does not match this port
103*7836SJohn.Forte@Sun.COM  * @param           portWWN The Port WWN to compare against this port
104*7836SJohn.Forte@Sun.COM  * @version         1.2
105*7836SJohn.Forte@Sun.COM  */
match(uint64_t portWWN)106*7836SJohn.Forte@Sun.COM bool HandleNPIVPort::match(uint64_t portWWN) {
107*7836SJohn.Forte@Sun.COM 	Trace log("HandleNPIVPort::match(wwn)");
108*7836SJohn.Forte@Sun.COM 	bool ret = false;
109*7836SJohn.Forte@Sun.COM 	ret = (portWWN == vport->getPortWWN());
110*7836SJohn.Forte@Sun.COM 	return (ret);
111*7836SJohn.Forte@Sun.COM }
112*7836SJohn.Forte@Sun.COM 
113*7836SJohn.Forte@Sun.COM /**
114*7836SJohn.Forte@Sun.COM  * @memo            Verify this port is the stated index
115*7836SJohn.Forte@Sun.COM  * @return          TRUE if the argument matches this port
116*7836SJohn.Forte@Sun.COM  * @return          FALSE if the argument does not match this port
117*7836SJohn.Forte@Sun.COM  * @param           index The index value to compare against this port
118*7836SJohn.Forte@Sun.COM  * @version         1.2
119*7836SJohn.Forte@Sun.COM  */
match(int index)120*7836SJohn.Forte@Sun.COM bool HandleNPIVPort::match(int index) {
121*7836SJohn.Forte@Sun.COM 	Trace log("HandleNPIVPort::match(index)");
122*7836SJohn.Forte@Sun.COM 	return (*vport == *(port->getPortByIndex(index)));
123*7836SJohn.Forte@Sun.COM }
124*7836SJohn.Forte@Sun.COM 
125*7836SJohn.Forte@Sun.COM /**
126*7836SJohn.Forte@Sun.COM  * @memo            Get attributes from this port.
127*7836SJohn.Forte@Sun.COM  * @exception       ... underlying exceptions will be thrown
128*7836SJohn.Forte@Sun.COM  * @return          The port attributes
129*7836SJohn.Forte@Sun.COM  * @version         1.2
130*7836SJohn.Forte@Sun.COM  * @see             HandlePort::validate
131*7836SJohn.Forte@Sun.COM  *
132*7836SJohn.Forte@Sun.COM  * @doc             This routine will perform state validation
133*7836SJohn.Forte@Sun.COM  */
getPortAttributes()134*7836SJohn.Forte@Sun.COM HBA_NPIVATTRIBUTES HandleNPIVPort::getPortAttributes() {
135*7836SJohn.Forte@Sun.COM 	Trace log("HandleNPIVPort::getPortAttributes");
136*7836SJohn.Forte@Sun.COM 	uint64_t newState;
137*7836SJohn.Forte@Sun.COM 	HBA_NPIVATTRIBUTES attributes = vport->getPortAttributes(newState);
138*7836SJohn.Forte@Sun.COM 	validate(newState);
139*7836SJohn.Forte@Sun.COM 	return (attributes);
140*7836SJohn.Forte@Sun.COM }
141*7836SJohn.Forte@Sun.COM 
142