xref: /titanic_50/usr/src/lib/sun_fc/common/Handle.h (revision eab227978ccdaa5a7cc9fd92ace768915dae3a2b)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_HANDLE_H
27 #define	_HANDLE_H
28 
29 
30 
31 // Forward Declarations
32 class Handle;
33 class HandlePort;
34 
35 #include "Lockable.h"
36 #include "HBA.h"
37 #include "HandlePort.h"
38 #include <map>
39 #include <hbaapi.h>
40 #include <hbaapi-sun.h>
41 
42 
43 /**
44  * @memo	    Represents an open HBA port
45  *
46  * @doc		    This class represents an open HBA.  However,
47  *		    what we really care about is the HBA port's underneath.
48  *		    So, we also track HandlePorts internally.
49  */
50 class Handle : public Lockable {
51 public:
52     enum MODE { INITIATOR, TARGET };
53     Handle(HBA *hba); // Generate ID, and add to vector
54     //    Handle(HBA *hba, MODE m); // Generate ID based on target or initiator mode
55     ~Handle(); // Free and remove from vector
56 
57     static Handle*	    findHandle(HBA_HANDLE index);
58     static Handle*	    findHandle(uint64_t wwn);
59     static void		    closeHandle(HBA_HANDLE index);
60 
61     HBA_HANDLE		    getHandle();
62 
63     bool		    operator==(Handle comp);
64 
65     HBA*		    getHBA() { return (hba); }
66     HandlePort*		    getHandlePortByIndex(int index);
67     HandlePort*		    getHandlePort(uint64_t wwn);
68     MODE		    getMode() { return (modeVal); };
69     void		    refresh();
70 
71     HBA_ADAPTERATTRIBUTES	    getHBAAttributes();
72     int				    doForceLip();
73     HBA_ADAPTERATTRIBUTES	    npivGetHBAAttributes();
74     HBA_PORTATTRIBUTES		    getPortAttributes(uint64_t wwn);
75 
76 private:
77     HBA				    *hba;
78     HBA_HANDLE			    id;
79     MODE			    modeVal;
80     static pthread_mutex_t	    staticLock;
81 
82     static HBA_HANDLE		    prevOpen;
83     static HBA_HANDLE		    prevTgtOpen;
84     static std::map<HBA_HANDLE, Handle*>    openHandles;
85     std::map<uint64_t, HandlePort*>	    portHandles;
86 };
87 
88 #endif /* _HANDLE_H */
89