xref: /titanic_51/usr/src/lib/sun_fc/common/sun_fc.h (revision 1886f67eb9de99edbcda88765f2c603a30c87fc2)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SUN_FC_H
27 #define	_SUN_FC_H
28 
29 
30 
31 #include <hbaapi.h>
32 #include <vendorhbaapi.h>
33 
34 #define HR_SECOND	1000000000
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 
41 // Public External routines
42 extern HBA_STATUS HBA_RegisterLibrary(PHBA_ENTRYPOINTS);
43 extern HBA_UINT32 Sun_fcGetVersion();
44 extern HBA_STATUS Sun_fcLoadLibrary();
45 extern HBA_STATUS Sun_fcFreeLibrary();
46 extern HBA_UINT32 Sun_fcGetNumberOfAdapters();
47 extern HBA_STATUS Sun_fcGetAdapterName(HBA_UINT32, char *);
48 extern HBA_HANDLE Sun_fcOpenAdapter(char *);
49 extern void Sun_fcCloseAdapter(HBA_HANDLE);
50 extern HBA_STATUS Sun_fcGetAdapterAttributes(HBA_HANDLE,
51     PHBA_ADAPTERATTRIBUTES);
52 extern HBA_STATUS Sun_fcGetAdapterPortAttributes(HBA_HANDLE, HBA_UINT32,
53     PHBA_PORTATTRIBUTES);
54 extern HBA_STATUS Sun_fcGetPortStatistics(HBA_HANDLE, HBA_UINT32,
55     PHBA_PORTSTATISTICS);
56 extern HBA_STATUS Sun_fcGetDiscoveredPortAttributes(HBA_HANDLE, HBA_UINT32,
57     HBA_UINT32, PHBA_PORTATTRIBUTES);
58 extern HBA_STATUS Sun_fcGetPortAttributesByWWN(HBA_HANDLE, HBA_WWN,
59     PHBA_PORTATTRIBUTES);
60 extern HBA_STATUS Sun_fcSendCTPassThru(HBA_HANDLE, void *, HBA_UINT32, void *,
61     HBA_UINT32);
62 extern void Sun_fcRefreshInformation(HBA_HANDLE);
63 extern void Sun_fcResetStatistics(HBA_HANDLE handle, HBA_UINT32 port);
64 extern HBA_STATUS Sun_fcGetFcpTargetMapping(HBA_HANDLE, PHBA_FCPTARGETMAPPING);
65 extern HBA_STATUS Sun_fcGetFcpPersistentBinding(HBA_HANDLE, PHBA_FCPBINDING);
66 extern HBA_STATUS Sun_fcGetEventBuffer(HBA_HANDLE, PHBA_EVENTINFO,
67     HBA_UINT32 *);
68 extern HBA_STATUS Sun_fcSetRNIDMgmtInfo(HBA_HANDLE, HBA_MGMTINFO);
69 extern HBA_STATUS Sun_fcGetRNIDMgmtInfo(HBA_HANDLE, PHBA_MGMTINFO);
70 extern HBA_STATUS Sun_fcSendRNID(HBA_HANDLE, HBA_WWN, HBA_WWNTYPE,
71     void *, HBA_UINT32 *);
72 extern HBA_STATUS Sun_fcSendScsiInquiry(HBA_HANDLE, HBA_WWN, HBA_UINT64,
73     HBA_UINT8, HBA_UINT32, void *, HBA_UINT32, void *, HBA_UINT32);
74 extern HBA_STATUS Sun_fcSendReportLUNs(HBA_HANDLE, HBA_WWN, void *, HBA_UINT32,
75     void *, HBA_UINT32);
76 extern HBA_STATUS Sun_fcSendReadCapacity(HBA_HANDLE, HBA_WWN, HBA_UINT64,
77     void *, HBA_UINT32, void *, HBA_UINT32);
78 
79 // V2 external routines
80 extern HBA_STATUS Sun_fcOpenAdapterByWWN(HBA_HANDLE *, HBA_WWN);
81 extern HBA_STATUS Sun_fcGetFcpTargetMappingV2(HBA_HANDLE, HBA_WWN,
82     HBA_FCPTARGETMAPPINGV2 *);
83 extern HBA_STATUS Sun_fcSendCTPassThruV2(HBA_HANDLE, HBA_WWN, void *,
84     HBA_UINT32, void *, HBA_UINT32 *);
85 extern void Sun_fcRefreshAdapterConfiguration(void);
86 extern HBA_STATUS Sun_fcGetBindingCapability(HBA_HANDLE, HBA_WWN,
87     HBA_BIND_CAPABILITY *);
88 extern HBA_STATUS Sun_fcGetBindingSupport(HBA_HANDLE, HBA_WWN,
89     HBA_BIND_CAPABILITY *);
90 extern HBA_STATUS Sun_fcSetBindingSupport(HBA_HANDLE, HBA_WWN,
91     HBA_BIND_CAPABILITY);
92 extern HBA_STATUS Sun_fcSetPersistentBindingV2(HBA_HANDLE, HBA_WWN,
93     const HBA_FCPBINDING2 *);
94 extern HBA_STATUS Sun_fcGetPersistentBindingV2(HBA_HANDLE, HBA_WWN,
95     HBA_FCPBINDING2 *);
96 extern HBA_STATUS Sun_fcRemovePersistentBinding(HBA_HANDLE, HBA_WWN,
97     const HBA_FCPBINDING2 *);
98 extern HBA_STATUS Sun_fcRemoveAllPersistentBindings(HBA_HANDLE, HBA_WWN);
99 extern HBA_STATUS Sun_fcSendRNIDV2(HBA_HANDLE, HBA_WWN, HBA_WWN, HBA_UINT32,
100     HBA_UINT32, void *, HBA_UINT32*);
101 extern HBA_STATUS Sun_fcScsiInquiryV2(HBA_HANDLE, HBA_WWN, HBA_WWN, HBA_UINT64,
102     HBA_UINT8, HBA_UINT8, void *, HBA_UINT32 *, HBA_UINT8 *, void *,
103     HBA_UINT32 *);
104 extern HBA_STATUS Sun_fcScsiReportLUNsV2(HBA_HANDLE, HBA_WWN, HBA_WWN, void *,
105     HBA_UINT32 *, HBA_UINT8 *, void *, HBA_UINT32 *);
106 extern HBA_STATUS Sun_fcScsiReadCapacityV2(HBA_HANDLE, HBA_WWN, HBA_WWN,
107     HBA_UINT64, void *, HBA_UINT32 *, HBA_UINT8 *, void *, HBA_UINT32 *);
108 extern HBA_UINT32 Sun_fcGetVendorLibraryAttributes(HBA_LIBRARYATTRIBUTES *);
109 extern HBA_STATUS Sun_fcRemoveCallback(HBA_CALLBACKHANDLE);
110 extern HBA_STATUS Sun_fcRegisterForAdapterAddEvents(void (*)(void *, HBA_WWN,
111     HBA_UINT32), void *, HBA_CALLBACKHANDLE *);
112 extern HBA_STATUS Sun_fcRegisterForAdapterEvents(void (*)(void *, HBA_WWN,
113     HBA_UINT32), void *, HBA_HANDLE, HBA_CALLBACKHANDLE *);
114 extern HBA_STATUS Sun_fcRegisterForAdapterPortEvents(void (*)(void *, HBA_WWN,
115     HBA_UINT32, HBA_UINT32), void *, HBA_HANDLE, HBA_WWN, HBA_CALLBACKHANDLE *);
116 extern HBA_STATUS Sun_fcRegisterForAdapterPortStatEvents(void (*)(void *,
117 	    HBA_WWN, HBA_UINT32), void *, HBA_HANDLE, HBA_WWN,
118     HBA_PORTSTATISTICS, HBA_UINT32, HBA_CALLBACKHANDLE *);
119 extern HBA_STATUS Sun_fcRegisterForTargetEvents(void (*)(void *, HBA_WWN,
120 	    HBA_WWN, HBA_UINT32), void *, HBA_HANDLE, HBA_WWN, HBA_WWN,
121     HBA_CALLBACKHANDLE *, HBA_UINT32);
122 extern HBA_STATUS Sun_fcRegisterForLinkEvents(void (*)(void *, HBA_WWN,
123     HBA_UINT32, void *, HBA_UINT32), void *, void *, HBA_UINT32, HBA_HANDLE,
124     HBA_CALLBACKHANDLE *);
125 extern HBA_STATUS Sun_fcSendRLS(HBA_HANDLE, HBA_WWN, HBA_WWN,
126     void *, HBA_UINT32 *);
127 extern HBA_STATUS Sun_fcSendRPL(HBA_HANDLE, HBA_WWN, HBA_WWN, HBA_UINT32,
128     HBA_UINT32, void *, HBA_UINT32 *);
129 extern HBA_STATUS Sun_fcSendRPS(HBA_HANDLE, HBA_WWN, HBA_WWN, HBA_UINT32,
130     HBA_WWN, HBA_UINT32, void *, HBA_UINT32 *);
131 extern HBA_STATUS Sun_fcSendSRL(HBA_HANDLE, HBA_WWN, HBA_WWN, HBA_UINT32,
132     void *, HBA_UINT32 *);
133 extern HBA_STATUS Sun_fcSendLIRR(HBA_HANDLE, HBA_WWN, HBA_WWN, HBA_UINT8,
134     HBA_UINT8, void *, HBA_UINT32 *);
135 extern HBA_STATUS Sun_fcGetFC4Statistics(HBA_HANDLE, HBA_WWN, HBA_UINT8,
136     HBA_FC4STATISTICS *);
137 extern HBA_STATUS Sun_fcGetFCPStatistics(HBA_HANDLE, const HBA_SCSIID *,
138     HBA_FC4STATISTICS *);
139 
140 #ifdef	__cplusplus
141 }
142 #endif
143 
144 #include <sys/types.h>
145 #include <netinet/in.h>
146 #include <inttypes.h>
147 #ifdef _BIG_ENDIAN
148 #define htonll(x)   (x)
149 #define ntohll(x)   (x)
150 #else
151 #define htonll(x)   ((((uint64_t)htonl(x)) << 32) + htonl(x >> 32))
152 #define ntohll(x)   ((((uint64_t)ntohl(x)) << 32) + ntohl(x >> 32))
153 #endif
154 
155 
156 
157 #include <string.h>
158 inline u_longlong_t
159 wwnConversion(uchar_t *wwn) {
160 	u_longlong_t tmp;
161 	memcpy(&tmp, wwn, sizeof (u_longlong_t));
162 	return (ntohll(tmp));
163 }
164 
165 #ifndef SCMD_REPORT_LUNS
166 #define	    SCMD_REPORT_LUNS       0xA0
167 #endif
168 
169 
170 
171 #endif /* _SUN_FC_H */
172