xref: /titanic_51/usr/src/lib/hbaapi/common/HBAAPILIB.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte /*************************************************************************
2*fcf3ce44SJohn Forte  * Description
3*fcf3ce44SJohn Forte  *	HBAAPILIB.c - Implements a sample common (wrapper) HBA API library
4*fcf3ce44SJohn Forte  *
5*fcf3ce44SJohn Forte  * License:
6*fcf3ce44SJohn Forte  *	The contents of this file are subject to the SNIA Public License
7*fcf3ce44SJohn Forte  *	Version 1.0 (the "License"); you may not use this file except in
8*fcf3ce44SJohn Forte  *	compliance with the License. You may obtain a copy of the License at
9*fcf3ce44SJohn Forte  *
10*fcf3ce44SJohn Forte  *	/http://www.snia.org/English/Resources/Code/OpenSource.html
11*fcf3ce44SJohn Forte  *
12*fcf3ce44SJohn Forte  *	Software distributed under the License is distributed on an "AS IS"
13*fcf3ce44SJohn Forte  *	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14*fcf3ce44SJohn Forte  *	the License for the specific language governing rights and limitations
15*fcf3ce44SJohn Forte  *	under the License.
16*fcf3ce44SJohn Forte  *
17*fcf3ce44SJohn Forte  * The Original Code is  SNIA HBA API Wrapper Library
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * The Initial Developer of the Original Code is:
20*fcf3ce44SJohn Forte  *	Benjamin F. Kuo, Troika Networks, Inc. (benk@troikanetworks.com)
21*fcf3ce44SJohn Forte  *
22*fcf3ce44SJohn Forte  * Contributor(s):
23*fcf3ce44SJohn Forte  *	Tuan Lam, QLogic Corp. (t_lam@qlc.com)
24*fcf3ce44SJohn Forte  *	Dan Willie, Emulex Corp. (Dan.Willie@emulex.com)
25*fcf3ce44SJohn Forte  *	Dixon Hutchinson, Legato Systems, Inc. (dhutchin@legato.com)
26*fcf3ce44SJohn Forte  *	David Dillard, VERITAS Software Corp. (david.dillard@veritas.com)
27*fcf3ce44SJohn Forte  *
28*fcf3ce44SJohn Forte  *************************************************************************
29*fcf3ce44SJohn Forte  */
30*fcf3ce44SJohn Forte 
31*fcf3ce44SJohn Forte #ifdef WIN32
32*fcf3ce44SJohn Forte #include <windows.h>
33*fcf3ce44SJohn Forte #include <string.h>
34*fcf3ce44SJohn Forte /*
35*fcf3ce44SJohn Forte  * Next define forces entry points in the dll to be exported
36*fcf3ce44SJohn Forte  * See hbaapi.h to see what it does.
37*fcf3ce44SJohn Forte  */
38*fcf3ce44SJohn Forte #define HBAAPI_EXPORTS
39*fcf3ce44SJohn Forte #else
40*fcf3ce44SJohn Forte #include <dlfcn.h>
41*fcf3ce44SJohn Forte #include <strings.h>
42*fcf3ce44SJohn Forte #endif
43*fcf3ce44SJohn Forte #include <stdio.h>
44*fcf3ce44SJohn Forte #include <time.h>
45*fcf3ce44SJohn Forte #include "hbaapi.h"
46*fcf3ce44SJohn Forte #include "vendorhbaapi.h"
47*fcf3ce44SJohn Forte #include <stdlib.h>
48*fcf3ce44SJohn Forte #ifdef USESYSLOG
49*fcf3ce44SJohn Forte #include <syslog.h>
50*fcf3ce44SJohn Forte #endif
51*fcf3ce44SJohn Forte 
52*fcf3ce44SJohn Forte /*
53*fcf3ce44SJohn Forte  * LIBRARY_NUM is a shortcut to figure out which library we need to call.
54*fcf3ce44SJohn Forte  *  The top 16 bits of handle are the library index
55*fcf3ce44SJohn Forte  */
56*fcf3ce44SJohn Forte #define LIBRARY_NUM(handle)	((handle)>>16)
57*fcf3ce44SJohn Forte 
58*fcf3ce44SJohn Forte /*
59*fcf3ce44SJohn Forte  * VENDOR_HANDLE turns a global library handle into a vendor specific handle,
60*fcf3ce44SJohn Forte  * with all upper 16 bits set to 0
61*fcf3ce44SJohn Forte  */
62*fcf3ce44SJohn Forte #define VENDOR_HANDLE(handle)	((handle)&0xFFFF)
63*fcf3ce44SJohn Forte 
64*fcf3ce44SJohn Forte #define HBA_HANDLE_FROM_LOCAL(library, vendor) \
65*fcf3ce44SJohn Forte 				(((library)<<16) | ((vendor)&0x0000FFFF))
66*fcf3ce44SJohn Forte 
67*fcf3ce44SJohn Forte int _hbaapi_debuglevel = 0;
68*fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3)
69*fcf3ce44SJohn Forte 
70*fcf3ce44SJohn Forte #if defined(USESYSLOG) && defined(USELOGFILE)
71*fcf3ce44SJohn Forte FILE *_hbaapi_debug_fd = NULL;
72*fcf3ce44SJohn Forte int _hbaapi_sysloginit = 0;
73*fcf3ce44SJohn Forte #undef DEBUG
74*fcf3ce44SJohn Forte #ifdef WIN32
75*fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3)\
76*fcf3ce44SJohn Forte     if ((L) <= _hbaapi_debuglevel) {\
77*fcf3ce44SJohn Forte 	if(_hbaapi_sysloginit == 0) {\
78*fcf3ce44SJohn Forte 	    openlog("HBAAPI", LOG_PID|LOG_ODELAY ,LOG_USER);\
79*fcf3ce44SJohn Forte 	    _hbaapi_sysloginit = 1;\
80*fcf3ce44SJohn Forte 	}\
81*fcf3ce44SJohn Forte 	syslog (LOG_INFO, (STR), (A1), (A2), (A3));\
82*fcf3ce44SJohn Forte 	if(_hbaapi_debug_fd == NULL) {\
83*fcf3ce44SJohn Forte 	    char _logFile[MAX_PATH]; \
84*fcf3ce44SJohn Forte 	    GetTempPath(MAX_PATH, _logFile); \
85*fcf3ce44SJohn Forte 	    strcat(_logFile, "HBAAPI.log"); \
86*fcf3ce44SJohn Forte 	    _hbaapi_debug_fd = fopen(_logFile, "a");\
87*fcf3ce44SJohn Forte 	}\
88*fcf3ce44SJohn Forte         if(_hbaapi_debug_fd != NULL) {\
89*fcf3ce44SJohn Forte 	    fprintf(_hbaapi_debug_fd, (STR ## "\n"), (A1), (A2), (A3));\
90*fcf3ce44SJohn Forte 	}\
91*fcf3ce44SJohn Forte     }
92*fcf3ce44SJohn Forte #else /* WIN32*/
93*fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3)\
94*fcf3ce44SJohn Forte     if ((L) <= _hbaapi_debuglevel) {\
95*fcf3ce44SJohn Forte 	if(_hbaapi_sysloginit == 0) {\
96*fcf3ce44SJohn Forte 	    openlog("HBAAPI", LOG_PID|LOG_ODELAY ,LOG_USER);\
97*fcf3ce44SJohn Forte 	    _hbaapi_sysloginit = 1;\
98*fcf3ce44SJohn Forte 	}\
99*fcf3ce44SJohn Forte 	syslog (LOG_INFO, (STR), (A1), (A2), (A3));\
100*fcf3ce44SJohn Forte 	if(_hbaapi_debug_fd == NULL) {\
101*fcf3ce44SJohn Forte 	    _hbaapi_debug_fd = fopen("/tmp/HBAAPI.log", "a");\
102*fcf3ce44SJohn Forte 	}\
103*fcf3ce44SJohn Forte         if(_hbaapi_debug_fd != NULL) {\
104*fcf3ce44SJohn Forte 	    fprintf(_hbaapi_debug_fd, (STR ## "\n"), (A1), (A2), (A3));\
105*fcf3ce44SJohn Forte 	}\
106*fcf3ce44SJohn Forte     }
107*fcf3ce44SJohn Forte #endif /* WIN32*/
108*fcf3ce44SJohn Forte 
109*fcf3ce44SJohn Forte #else /* Not both USESYSLOG and USELOGFILE */
110*fcf3ce44SJohn Forte #if defined(USESYSLOG)
111*fcf3ce44SJohn Forte int _hbaapi_sysloginit = 0;
112*fcf3ce44SJohn Forte #undef DEBUG
113*fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) \
114*fcf3ce44SJohn Forte     if ((L) <= _hbaapi_debuglevel) {\
115*fcf3ce44SJohn Forte 	if(_hbaapi_sysloginit == 0) {\
116*fcf3ce44SJohn Forte 	    openlog("HBAAPI", LOG_PID|LOG_ODELAY ,LOG_USER);\
117*fcf3ce44SJohn Forte 	    _hbaapi_sysloginit = 1;\
118*fcf3ce44SJohn Forte 	}\
119*fcf3ce44SJohn Forte 	syslog (LOG_INFO, (STR), (A1), (A2), (A3));\
120*fcf3ce44SJohn Forte     }
121*fcf3ce44SJohn Forte #endif /* USESYSLOG */
122*fcf3ce44SJohn Forte #if defined(USELOGFILE)
123*fcf3ce44SJohn Forte FILE *_hbaapi_debug_fd = NULL;
124*fcf3ce44SJohn Forte #undef DEBUG
125*fcf3ce44SJohn Forte #ifdef WIN32
126*fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) \
127*fcf3ce44SJohn Forte     if((L) <= _hbaapi_debuglevel) {\
128*fcf3ce44SJohn Forte 	if(_hbaapi_debug_fd == NULL) {\
129*fcf3ce44SJohn Forte 	    char _logFile[MAX_PATH]; \
130*fcf3ce44SJohn Forte 	    GetTempPath(MAX_PATH, _logFile); \
131*fcf3ce44SJohn Forte 	    strcat(_logFile, "HBAAPI.log"); \
132*fcf3ce44SJohn Forte 	    _hbaapi_debug_fd = fopen(_logFile, "a");\
133*fcf3ce44SJohn Forte         }\
134*fcf3ce44SJohn Forte     }
135*fcf3ce44SJohn Forte #else /* WIN32 */
136*fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) \
137*fcf3ce44SJohn Forte     if((L) <= _hbaapi_debuglevel) {\
138*fcf3ce44SJohn Forte 	if(_hbaapi_debug_fd == NULL) {\
139*fcf3ce44SJohn Forte 	    _hbaapi_debug_fd = fopen("/tmp/HBAAPI.log", "a");\
140*fcf3ce44SJohn Forte 	}\
141*fcf3ce44SJohn Forte 	if(_hbaapi_debug_fd != NULL) { \
142*fcf3ce44SJohn Forte 	    fprintf(_hbaapi_debug_fd, (STR) ## "\n", (A1), (A2), (A3));\
143*fcf3ce44SJohn Forte 	}\
144*fcf3ce44SJohn Forte     }
145*fcf3ce44SJohn Forte #endif /* WIN32 */
146*fcf3ce44SJohn Forte #endif /* USELOGFILE */
147*fcf3ce44SJohn Forte #endif /* Not both USELOGFILE and USESYSLOG */
148*fcf3ce44SJohn Forte 
149*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
150*fcf3ce44SJohn Forte #include <pthread.h>
151*fcf3ce44SJohn Forte /*
152*fcf3ce44SJohn Forte  * When multiple mutex's are grabed, they must be always be grabbed in
153*fcf3ce44SJohn Forte  * the same order, or deadlock can result.  There are three levels
154*fcf3ce44SJohn Forte  * of mutex's involved in this API.  If LL_mutex is grabbed, always grap
155*fcf3ce44SJohn Forte  * it first.  If AL_mutex is grabbed, it may not be grabbed before
156*fcf3ce44SJohn Forte  * LL_mutex.  If grabbed in a multi grab sequence, the mutex's protecting
157*fcf3ce44SJohn Forte  * the callback lists must always be grabbed last and release before calling
158*fcf3ce44SJohn Forte  * a vendor specific library function that might invoke a callback function
159*fcf3ce44SJohn Forte  * on the same thread.
160*fcf3ce44SJohn Forte  */
161*fcf3ce44SJohn Forte #define GRAB_MUTEX(M)			grab_mutex(M)
162*fcf3ce44SJohn Forte #define RELEASE_MUTEX(M)		release_mutex(M)
163*fcf3ce44SJohn Forte #define RELEASE_MUTEX_RETURN(M,RET)	release_mutex(M); return(RET)
164*fcf3ce44SJohn Forte #elif defined (WIN32)
165*fcf3ce44SJohn Forte #define GRAB_MUTEX(m)			EnterCriticalSection(m)
166*fcf3ce44SJohn Forte #define RELEASE_MUTEX(m)		LeaveCriticalSection(m)
167*fcf3ce44SJohn Forte #define RELEASE_MUTEX_RETURN(m, RET)	LeaveCriticalSection(m); return(RET)
168*fcf3ce44SJohn Forte #else
169*fcf3ce44SJohn Forte #define GRAB_MUTEX(M)
170*fcf3ce44SJohn Forte #define RELEASE_MUTEX(M)
171*fcf3ce44SJohn Forte #define RELEASE_MUTEX_RETURN(M,RET)	return(RET)
172*fcf3ce44SJohn Forte #endif
173*fcf3ce44SJohn Forte 
174*fcf3ce44SJohn Forte /*
175*fcf3ce44SJohn Forte  * Vendor library information
176*fcf3ce44SJohn Forte  */
177*fcf3ce44SJohn Forte typedef enum {
178*fcf3ce44SJohn Forte     HBA_LIBRARY_UNKNOWN,
179*fcf3ce44SJohn Forte     HBA_LIBRARY_LOADED,
180*fcf3ce44SJohn Forte     HBA_LIBRARY_NOT_LOADED
181*fcf3ce44SJohn Forte } HBA_LIBRARY_STATUS;
182*fcf3ce44SJohn Forte 
183*fcf3ce44SJohn Forte typedef struct hba_library_info {
184*fcf3ce44SJohn Forte     struct hba_library_info
185*fcf3ce44SJohn Forte 			*next;
186*fcf3ce44SJohn Forte #ifdef WIN32
187*fcf3ce44SJohn Forte     HINSTANCE		hLibrary;		/* Handle to a loaded DLL */
188*fcf3ce44SJohn Forte #else
189*fcf3ce44SJohn Forte     char		*LibraryName;
190*fcf3ce44SJohn Forte     void*		hLibrary;		/* Handle to a loaded DLL */
191*fcf3ce44SJohn Forte #endif
192*fcf3ce44SJohn Forte     char		*LibraryPath;
193*fcf3ce44SJohn Forte     HBA_ENTRYPOINTSV2	functionTable;		/* Function pointers */
194*fcf3ce44SJohn Forte     HBA_LIBRARY_STATUS	status;			/* info on this library */
195*fcf3ce44SJohn Forte     HBA_UINT32		index;
196*fcf3ce44SJohn Forte } HBA_LIBRARY_INFO, *PHBA_LIBRARY_INFO;
197*fcf3ce44SJohn Forte 
198*fcf3ce44SJohn Forte #define ARE_WE_INITED() \
199*fcf3ce44SJohn Forte 	if (_hbaapi_librarylist == NULL) { \
200*fcf3ce44SJohn Forte 		return(HBA_STATUS_ERROR); \
201*fcf3ce44SJohn Forte 	}
202*fcf3ce44SJohn Forte HBA_LIBRARY_INFO *_hbaapi_librarylist = NULL;
203*fcf3ce44SJohn Forte HBA_UINT32 _hbaapi_total_library_count = 0;
204*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
205*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_LL_mutex = PTHREAD_MUTEX_INITIALIZER;
206*fcf3ce44SJohn Forte #elif defined(WIN32)
207*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_LL_mutex;
208*fcf3ce44SJohn Forte #endif
209*fcf3ce44SJohn Forte 
210*fcf3ce44SJohn Forte /*
211*fcf3ce44SJohn Forte  * Individual adapter (hba) information
212*fcf3ce44SJohn Forte  */
213*fcf3ce44SJohn Forte typedef struct hba_adapter_info {
214*fcf3ce44SJohn Forte     struct hba_adapter_info
215*fcf3ce44SJohn Forte 			*next;
216*fcf3ce44SJohn Forte     HBA_STATUS		GNstatus;	/* status from GetAdapterNameFunc */
217*fcf3ce44SJohn Forte     char		*name;
218*fcf3ce44SJohn Forte     HBA_WWN		nodeWWN;
219*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*library;
220*fcf3ce44SJohn Forte     HBA_UINT32		index;
221*fcf3ce44SJohn Forte } HBA_ADAPTER_INFO;
222*fcf3ce44SJohn Forte 
223*fcf3ce44SJohn Forte HBA_ADAPTER_INFO *_hbaapi_adapterlist = NULL;
224*fcf3ce44SJohn Forte HBA_UINT32 _hbaapi_total_adapter_count = 0;
225*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
226*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_AL_mutex = PTHREAD_MUTEX_INITIALIZER;
227*fcf3ce44SJohn Forte #elif defined(WIN32)
228*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_AL_mutex;
229*fcf3ce44SJohn Forte #endif
230*fcf3ce44SJohn Forte 
231*fcf3ce44SJohn Forte /*
232*fcf3ce44SJohn Forte  * Call back registration
233*fcf3ce44SJohn Forte  */
234*fcf3ce44SJohn Forte typedef struct hba_vendorcallback_elem {
235*fcf3ce44SJohn Forte     struct hba_vendorcallback_elem
236*fcf3ce44SJohn Forte 				*next;
237*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE		vendorcbhandle;
238*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO		*lib_info;
239*fcf3ce44SJohn Forte } HBA_VENDORCALLBACK_ELEM;
240*fcf3ce44SJohn Forte 
241*fcf3ce44SJohn Forte /*
242*fcf3ce44SJohn Forte  * Each instance of HBA_ADAPTERCALLBACK_ELEM represents a call to one of
243*fcf3ce44SJohn Forte  * "register" functions that apply to a particular adapter.
244*fcf3ce44SJohn Forte  * HBA_ALLADAPTERSCALLBACK_ELEM is used just for HBA_RegisterForAdapterAddEvents
245*fcf3ce44SJohn Forte  */
246*fcf3ce44SJohn Forte typedef struct hba_adaptercallback_elem {
247*fcf3ce44SJohn Forte     struct hba_adaptercallback_elem
248*fcf3ce44SJohn Forte 			*next;
249*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_info;
250*fcf3ce44SJohn Forte     void		*userdata;
251*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE	vendorcbhandle;
252*fcf3ce44SJohn Forte     void		(*callback)();
253*fcf3ce44SJohn Forte } HBA_ADAPTERCALLBACK_ELEM;
254*fcf3ce44SJohn Forte 
255*fcf3ce44SJohn Forte typedef struct hba_alladapterscallback_elem {
256*fcf3ce44SJohn Forte     struct hba_alladapterscallback_elem
257*fcf3ce44SJohn Forte 				*next;
258*fcf3ce44SJohn Forte     void			*userdata;
259*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM	*vendorhandlelist;
260*fcf3ce44SJohn Forte     void			(*callback)();
261*fcf3ce44SJohn Forte } HBA_ALLADAPTERSCALLBACK_ELEM;
262*fcf3ce44SJohn Forte 
263*fcf3ce44SJohn Forte HBA_ALLADAPTERSCALLBACK_ELEM *_hbaapi_adapteraddevents_callback_list = NULL;
264*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterevents_callback_list = NULL;
265*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterportevents_callback_list = NULL;
266*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterportstatevents_callback_list = NULL;
267*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM *_hbaapi_targetevents_callback_list = NULL;
268*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM *_hbaapi_linkevents_callback_list = NULL;
269*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterdeviceevents_callback_list = NULL;
270*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
271*fcf3ce44SJohn Forte /* mutex's to protect each list */
272*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_AAE_mutex = PTHREAD_MUTEX_INITIALIZER;
273*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_AE_mutex = PTHREAD_MUTEX_INITIALIZER;
274*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_APE_mutex = PTHREAD_MUTEX_INITIALIZER;
275*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_APSE_mutex = PTHREAD_MUTEX_INITIALIZER;
276*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_TE_mutex = PTHREAD_MUTEX_INITIALIZER;
277*fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_LE_mutex = PTHREAD_MUTEX_INITIALIZER;
278*fcf3ce44SJohn Forte #elif defined(WIN32)
279*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_AAE_mutex;
280*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_AE_mutex;
281*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_APE_mutex;
282*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_APSE_mutex;
283*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_TE_mutex;
284*fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_LE_mutex;
285*fcf3ce44SJohn Forte #endif
286*fcf3ce44SJohn Forte 
287*fcf3ce44SJohn Forte HBA_ADAPTERCALLBACK_ELEM **cb_lists_array[] = {
288*fcf3ce44SJohn Forte     &_hbaapi_adapterevents_callback_list,
289*fcf3ce44SJohn Forte     &_hbaapi_adapterportevents_callback_list,
290*fcf3ce44SJohn Forte     &_hbaapi_adapterportstatevents_callback_list,
291*fcf3ce44SJohn Forte     &_hbaapi_targetevents_callback_list,
292*fcf3ce44SJohn Forte     &_hbaapi_linkevents_callback_list,
293*fcf3ce44SJohn Forte     &_hbaapi_adapterdeviceevents_callback_list,
294*fcf3ce44SJohn Forte     NULL};
295*fcf3ce44SJohn Forte 
296*fcf3ce44SJohn Forte /*
297*fcf3ce44SJohn Forte  * Common library internal. Mutex handling
298*fcf3ce44SJohn Forte  */
299*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
300*fcf3ce44SJohn Forte static void
301*fcf3ce44SJohn Forte grab_mutex(pthread_mutex_t *mp) {
302*fcf3ce44SJohn Forte     int ret;
303*fcf3ce44SJohn Forte     if((ret = pthread_mutex_lock(mp)) != 0) {
304*fcf3ce44SJohn Forte 	perror("pthread_mutex_lock - HBAAPI:");
305*fcf3ce44SJohn Forte 	DEBUG(0, "pthread_mutex_lock returned %d", ret, 0, 0);
306*fcf3ce44SJohn Forte     }
307*fcf3ce44SJohn Forte }
308*fcf3ce44SJohn Forte 
309*fcf3ce44SJohn Forte static void
310*fcf3ce44SJohn Forte release_mutex(pthread_mutex_t *mp) {
311*fcf3ce44SJohn Forte     int ret;
312*fcf3ce44SJohn Forte     if((ret = pthread_mutex_unlock(mp)) != 0) {
313*fcf3ce44SJohn Forte 	perror("pthread_mutex_unlock - HBAAPI:");
314*fcf3ce44SJohn Forte 	DEBUG(0, "pthread_mutex_unlock returned %d", ret, 0, 0);
315*fcf3ce44SJohn Forte     }
316*fcf3ce44SJohn Forte }
317*fcf3ce44SJohn Forte #endif
318*fcf3ce44SJohn Forte 
319*fcf3ce44SJohn Forte /*
320*fcf3ce44SJohn Forte  * Common library internal. Check library and return vendorhandle
321*fcf3ce44SJohn Forte  */
322*fcf3ce44SJohn Forte static HBA_STATUS
323*fcf3ce44SJohn Forte HBA_CheckLibrary(HBA_HANDLE handle,
324*fcf3ce44SJohn Forte 		 HBA_LIBRARY_INFO **lib_infopp,
325*fcf3ce44SJohn Forte 		 HBA_HANDLE *vendorhandle) {
326*fcf3ce44SJohn Forte 
327*fcf3ce44SJohn Forte     HBA_UINT32		libraryIndex;
328*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
329*fcf3ce44SJohn Forte 
330*fcf3ce44SJohn Forte     if (vendorhandle == NULL) {
331*fcf3ce44SJohn Forte 	return(HBA_STATUS_ERROR_ARG);
332*fcf3ce44SJohn Forte     }
333*fcf3ce44SJohn Forte     if(_hbaapi_librarylist == NULL) {
334*fcf3ce44SJohn Forte 	return(HBA_STATUS_ERROR);
335*fcf3ce44SJohn Forte     }
336*fcf3ce44SJohn Forte     libraryIndex = LIBRARY_NUM(handle);
337*fcf3ce44SJohn Forte 
338*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex);
339*fcf3ce44SJohn Forte     for(lib_infop = _hbaapi_librarylist;
340*fcf3ce44SJohn Forte 	lib_infop != NULL;
341*fcf3ce44SJohn Forte 	lib_infop = lib_infop->next) {
342*fcf3ce44SJohn Forte 	if(lib_infop->index == libraryIndex) {
343*fcf3ce44SJohn Forte 	    if(lib_infop->status != HBA_LIBRARY_LOADED) {
344*fcf3ce44SJohn Forte 		return HBA_STATUS_ERROR;
345*fcf3ce44SJohn Forte 	    }
346*fcf3ce44SJohn Forte 	    *lib_infopp = lib_infop;
347*fcf3ce44SJohn Forte 	    *vendorhandle = VENDOR_HANDLE(handle);
348*fcf3ce44SJohn Forte 	    /* caller will release the mutex */
349*fcf3ce44SJohn Forte 	    return HBA_STATUS_OK;
350*fcf3ce44SJohn Forte 	}
351*fcf3ce44SJohn Forte     }
352*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INVALID_HANDLE);
353*fcf3ce44SJohn Forte }
354*fcf3ce44SJohn Forte #define CHECKLIBRARY() \
355*fcf3ce44SJohn Forte 	status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);\
356*fcf3ce44SJohn Forte  	if(status != HBA_STATUS_OK) { \
357*fcf3ce44SJohn Forte 	    return(status); \
358*fcf3ce44SJohn Forte  	}
359*fcf3ce44SJohn Forte 
360*fcf3ce44SJohn Forte /*
361*fcf3ce44SJohn Forte  *freevendorhandlelist is called with _hbaapi_LL_mutex already held
362*fcf3ce44SJohn Forte  */
363*fcf3ce44SJohn Forte static void
364*fcf3ce44SJohn Forte freevendorhandlelist(HBA_VENDORCALLBACK_ELEM *vhlist) {
365*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM	*vhlp;
366*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM	*vnext;
367*fcf3ce44SJohn Forte     HBARemoveCallbackFunc	registeredfunc;
368*fcf3ce44SJohn Forte 
369*fcf3ce44SJohn Forte     for(vhlp = vhlist; vhlp != NULL; vhlp = vnext) {
370*fcf3ce44SJohn Forte 	vnext = vhlp->next;
371*fcf3ce44SJohn Forte 	registeredfunc =
372*fcf3ce44SJohn Forte 	    vhlp->lib_info->functionTable.RemoveCallbackHandler;
373*fcf3ce44SJohn Forte 	if(registeredfunc == NULL) {
374*fcf3ce44SJohn Forte 	    continue;
375*fcf3ce44SJohn Forte 	}
376*fcf3ce44SJohn Forte 	(registeredfunc)(vhlp->vendorcbhandle);
377*fcf3ce44SJohn Forte 	free(vhlp);
378*fcf3ce44SJohn Forte     }
379*fcf3ce44SJohn Forte }
380*fcf3ce44SJohn Forte 
381*fcf3ce44SJohn Forte static
382*fcf3ce44SJohn Forte HBA_STATUS
383*fcf3ce44SJohn Forte local_remove_callback(HBA_CALLBACKHANDLE cbhandle) {
384*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM		***listp;
385*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM		**lastp;
386*fcf3ce44SJohn Forte     HBA_ALLADAPTERSCALLBACK_ELEM	**lap;
387*fcf3ce44SJohn Forte     HBA_ALLADAPTERSCALLBACK_ELEM	*allcbp;
388*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM		*cbp;
389*fcf3ce44SJohn Forte     HBARemoveCallbackFunc		registeredfunc;
390*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM		*vhlp;
391*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM		*vnext;
392*fcf3ce44SJohn Forte     int					found;
393*fcf3ce44SJohn Forte     HBA_STATUS				status = HBA_STATUS_ERROR_INVALID_HANDLE;
394*fcf3ce44SJohn Forte 
395*fcf3ce44SJohn Forte 
396*fcf3ce44SJohn Forte     /* search through the simple lists first */
397*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AAE_mutex);
398*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AE_mutex);
399*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_APE_mutex);
400*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_APSE_mutex);
401*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_TE_mutex);
402*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LE_mutex);
403*fcf3ce44SJohn Forte     for(listp = cb_lists_array, found = 0; found == 0, *listp != NULL; listp++) {
404*fcf3ce44SJohn Forte 	lastp = *listp;
405*fcf3ce44SJohn Forte 	for(cbp=**listp; cbp != NULL; cbp = cbp->next) {
406*fcf3ce44SJohn Forte 	    if(cbhandle != (HBA_CALLBACKHANDLE)cbp) {
407*fcf3ce44SJohn Forte 		lastp = &(cbp->next);
408*fcf3ce44SJohn Forte 		continue;
409*fcf3ce44SJohn Forte 	    }
410*fcf3ce44SJohn Forte 	    found = 1;
411*fcf3ce44SJohn Forte 	    registeredfunc = cbp->lib_info->functionTable.RemoveCallbackHandler;
412*fcf3ce44SJohn Forte 	    if(registeredfunc == NULL) {
413*fcf3ce44SJohn Forte 		break;
414*fcf3ce44SJohn Forte 	    }
415*fcf3ce44SJohn Forte 	    (registeredfunc)(cbp->vendorcbhandle);
416*fcf3ce44SJohn Forte 	    *lastp = cbp->next;
417*fcf3ce44SJohn Forte 	    free(cbp);
418*fcf3ce44SJohn Forte 	    break;
419*fcf3ce44SJohn Forte 	}
420*fcf3ce44SJohn Forte     }
421*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_LE_mutex);
422*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_TE_mutex);
423*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_APSE_mutex);
424*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_APE_mutex);
425*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AE_mutex);
426*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AAE_mutex);
427*fcf3ce44SJohn Forte     if(found != 0) {
428*fcf3ce44SJohn Forte 	if(registeredfunc == NULL) {
429*fcf3ce44SJohn Forte 	    return HBA_STATUS_ERROR_NOT_SUPPORTED;
430*fcf3ce44SJohn Forte 	}
431*fcf3ce44SJohn Forte 	return HBA_STATUS_OK;
432*fcf3ce44SJohn Forte     }
433*fcf3ce44SJohn Forte 
434*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AAE_mutex);
435*fcf3ce44SJohn Forte     /* if it wasnt in the simple lists, look in the list for adapteraddevents */
436*fcf3ce44SJohn Forte     lap = &_hbaapi_adapteraddevents_callback_list;
437*fcf3ce44SJohn Forte     for(allcbp = _hbaapi_adapteraddevents_callback_list;
438*fcf3ce44SJohn Forte 	allcbp != NULL;
439*fcf3ce44SJohn Forte 	allcbp = allcbp->next) {
440*fcf3ce44SJohn Forte 	if(cbhandle != (HBA_CALLBACKHANDLE)allcbp) {
441*fcf3ce44SJohn Forte 	    lap = &allcbp->next;
442*fcf3ce44SJohn Forte 	    continue;
443*fcf3ce44SJohn Forte 	}
444*fcf3ce44SJohn Forte 	for(vhlp = allcbp->vendorhandlelist; vhlp != NULL; vhlp = vnext) {
445*fcf3ce44SJohn Forte 	    vnext = vhlp->next;
446*fcf3ce44SJohn Forte 	    registeredfunc =
447*fcf3ce44SJohn Forte 		vhlp->lib_info->functionTable.RemoveCallbackHandler;
448*fcf3ce44SJohn Forte 	    if(registeredfunc == NULL) {
449*fcf3ce44SJohn Forte 		continue;
450*fcf3ce44SJohn Forte 	    }
451*fcf3ce44SJohn Forte 	    (registeredfunc)(vhlp->vendorcbhandle);
452*fcf3ce44SJohn Forte 	    free(vhlp);
453*fcf3ce44SJohn Forte 	}
454*fcf3ce44SJohn Forte 	*lap = allcbp->next;
455*fcf3ce44SJohn Forte 	free(allcbp);
456*fcf3ce44SJohn Forte 	status = HBA_STATUS_OK;
457*fcf3ce44SJohn Forte 	break;
458*fcf3ce44SJohn Forte     }
459*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AAE_mutex);
460*fcf3ce44SJohn Forte     return(status);
461*fcf3ce44SJohn Forte }
462*fcf3ce44SJohn Forte 
463*fcf3ce44SJohn Forte static char wwn_str1[17];
464*fcf3ce44SJohn Forte static char wwn_str2[17];
465*fcf3ce44SJohn Forte static char wwn_str3[17];
466*fcf3ce44SJohn Forte #define WWN2STR1(wwn) WWN2str(wwn_str1, (wwn))
467*fcf3ce44SJohn Forte #define WWN2STR2(wwn) WWN2str(wwn_str2, (wwn))
468*fcf3ce44SJohn Forte #define WWN2STR3(wwn) WWN2str(wwn_str3, (wwn))
469*fcf3ce44SJohn Forte static char *
470*fcf3ce44SJohn Forte WWN2str(char *buf, HBA_WWN *wwn) {
471*fcf3ce44SJohn Forte     int j;
472*fcf3ce44SJohn Forte     unsigned char *pc = (unsigned char *)&(wwn->wwn[0]);
473*fcf3ce44SJohn Forte     buf[0] = '\0';
474*fcf3ce44SJohn Forte     for (j=0; j<16; j+=2) {
475*fcf3ce44SJohn Forte         sprintf(&buf[j], "%02X", (int)*pc++);
476*fcf3ce44SJohn Forte     }
477*fcf3ce44SJohn Forte     return(buf);
478*fcf3ce44SJohn Forte }
479*fcf3ce44SJohn Forte 
480*fcf3ce44SJohn Forte 
481*fcf3ce44SJohn Forte #ifdef WIN32
482*fcf3ce44SJohn Forte BOOL APIENTRY
483*fcf3ce44SJohn Forte DllMain( HANDLE hModule,
484*fcf3ce44SJohn Forte 	 DWORD  ul_reason_for_call,
485*fcf3ce44SJohn Forte 	 LPVOID lpReserved
486*fcf3ce44SJohn Forte     )
487*fcf3ce44SJohn Forte {
488*fcf3ce44SJohn Forte     switch (ul_reason_for_call)
489*fcf3ce44SJohn Forte     {
490*fcf3ce44SJohn Forte     case DLL_PROCESS_ATTACH:
491*fcf3ce44SJohn Forte 	break;
492*fcf3ce44SJohn Forte     case DLL_PROCESS_DETACH:
493*fcf3ce44SJohn Forte 	break;
494*fcf3ce44SJohn Forte     case DLL_THREAD_ATTACH:
495*fcf3ce44SJohn Forte     case DLL_THREAD_DETACH:
496*fcf3ce44SJohn Forte 	break;
497*fcf3ce44SJohn Forte     }
498*fcf3ce44SJohn Forte     return TRUE;
499*fcf3ce44SJohn Forte }
500*fcf3ce44SJohn Forte #endif
501*fcf3ce44SJohn Forte 
502*fcf3ce44SJohn Forte /*
503*fcf3ce44SJohn Forte  * Read in the config file and load all the specified vendor specific
504*fcf3ce44SJohn Forte  * libraries and perform the function registration exercise
505*fcf3ce44SJohn Forte  */
506*fcf3ce44SJohn Forte HBA_STATUS
507*fcf3ce44SJohn Forte HBA_LoadLibrary(void) {
508*fcf3ce44SJohn Forte     HBARegisterLibraryFunc
509*fcf3ce44SJohn Forte 			RegisterFunc;
510*fcf3ce44SJohn Forte     HBARegisterLibraryV2Func
511*fcf3ce44SJohn Forte 			RegisterV2Func;
512*fcf3ce44SJohn Forte     HBALoadLibraryFunc	LoadLibraryFunc;
513*fcf3ce44SJohn Forte     HBAGetVersionFunc	GetVersionFunc;
514*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
515*fcf3ce44SJohn Forte     int			ret;
516*fcf3ce44SJohn Forte #endif
517*fcf3ce44SJohn Forte     HBA_STATUS		status;
518*fcf3ce44SJohn Forte     HBA_UINT32		libversion;
519*fcf3ce44SJohn Forte 
520*fcf3ce44SJohn Forte     /* Open configuration file from known location */
521*fcf3ce44SJohn Forte #ifdef WIN32
522*fcf3ce44SJohn Forte     LONG		lStatus;
523*fcf3ce44SJohn Forte     HKEY		hkSniaHba, hkVendorLib;
524*fcf3ce44SJohn Forte     FILETIME		ftLastWriteTime;
525*fcf3ce44SJohn Forte     TCHAR		cSubKeyName[256];
526*fcf3ce44SJohn Forte     DWORD		i, dwSize, dwType;
527*fcf3ce44SJohn Forte     BYTE		byFileName[MAX_PATH];
528*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
529*fcf3ce44SJohn Forte 
530*fcf3ce44SJohn Forte     if(_hbaapi_librarylist != NULL) {
531*fcf3ce44SJohn Forte 	/* this is an app programming error */
532*fcf3ce44SJohn Forte 	return HBA_STATUS_ERROR;
533*fcf3ce44SJohn Forte     }
534*fcf3ce44SJohn Forte 
535*fcf3ce44SJohn Forte     lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\SNIA\\HBA",
536*fcf3ce44SJohn Forte 			   0, KEY_READ, &hkSniaHba);
537*fcf3ce44SJohn Forte     if (lStatus != ERROR_SUCCESS) {
538*fcf3ce44SJohn Forte 	/* ???Opportunity to send error msg, configuration error */
539*fcf3ce44SJohn Forte 	return HBA_STATUS_ERROR;
540*fcf3ce44SJohn Forte     }
541*fcf3ce44SJohn Forte     /*
542*fcf3ce44SJohn Forte      * Enumerate all the subkeys. These have the form:
543*fcf3ce44SJohn Forte      * HKLM\Software\SNIA\HBA\<Vendor id> - note that we don't care
544*fcf3ce44SJohn Forte      * what the vendor id is
545*fcf3ce44SJohn Forte      */
546*fcf3ce44SJohn Forte     for (i = 0; ; i++) {
547*fcf3ce44SJohn Forte 	dwSize = 255;	/* how big the buffer is */
548*fcf3ce44SJohn Forte 	lStatus = RegEnumKeyEx(hkSniaHba, i,
549*fcf3ce44SJohn Forte 			       (char *)&cSubKeyName, &dwSize, NULL,
550*fcf3ce44SJohn Forte 			       NULL, NULL, &ftLastWriteTime);
551*fcf3ce44SJohn Forte 	if (lStatus == ERROR_NO_MORE_ITEMS) {
552*fcf3ce44SJohn Forte 	    break;	/* we're done */
553*fcf3ce44SJohn Forte 	} else if (lStatus == ERROR_MORE_DATA) { /* buffer not big enough */
554*fcf3ce44SJohn Forte 	    /* do whatever */
555*fcf3ce44SJohn Forte 	    ;
556*fcf3ce44SJohn Forte 	}
557*fcf3ce44SJohn Forte 	/* Now open the subkey that pertains to this vendor's library */
558*fcf3ce44SJohn Forte 	lStatus = RegOpenKeyEx(hkSniaHba, cSubKeyName, 0, KEY_READ,
559*fcf3ce44SJohn Forte 			       &hkVendorLib);
560*fcf3ce44SJohn Forte 	if (lStatus != ERROR_SUCCESS) {
561*fcf3ce44SJohn Forte 	    RegCloseKey(hkSniaHba);
562*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, installation error */
563*fcf3ce44SJohn Forte 	    return HBA_STATUS_ERROR; /* you may want to return something
564*fcf3ce44SJohn Forte 				      * else or keep trying */
565*fcf3ce44SJohn Forte 	}
566*fcf3ce44SJohn Forte 	/* The name of the library is contained in a REG_SZ Value
567*fcf3ce44SJohn Forte 	 * keyed to "LibraryFile" */
568*fcf3ce44SJohn Forte 	dwSize = MAX_PATH;
569*fcf3ce44SJohn Forte 	lStatus = RegQueryValueEx(hkVendorLib, "LibraryFile", NULL, &dwType,
570*fcf3ce44SJohn Forte 				  byFileName, &dwSize);
571*fcf3ce44SJohn Forte 	if (lStatus != ERROR_SUCCESS) {
572*fcf3ce44SJohn Forte 	    RegCloseKey(hkVendorLib);
573*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, installation error */
574*fcf3ce44SJohn Forte 	    continue;
575*fcf3ce44SJohn Forte 	}
576*fcf3ce44SJohn Forte 	lib_infop = (HBA_LIBRARY_INFO *)calloc(1, sizeof(HBA_LIBRARY_INFO));
577*fcf3ce44SJohn Forte 	if(lib_infop == NULL) {
578*fcf3ce44SJohn Forte 	    /* what is the right thing to do in MS land??? */
579*fcf3ce44SJohn Forte 	    RegCloseKey(hkVendorLib);
580*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, installation error */
581*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR);
582*fcf3ce44SJohn Forte 	}
583*fcf3ce44SJohn Forte 	lib_infop->status = HBA_LIBRARY_NOT_LOADED;
584*fcf3ce44SJohn Forte 	lib_infop->next = _hbaapi_librarylist;
585*fcf3ce44SJohn Forte 	lib_infop->index = _hbaapi_total_library_count;
586*fcf3ce44SJohn Forte 	_hbaapi_total_library_count++;
587*fcf3ce44SJohn Forte 	_hbaapi_librarylist = lib_infop;
588*fcf3ce44SJohn Forte 
589*fcf3ce44SJohn Forte 	/* Now I can try to load the library */
590*fcf3ce44SJohn Forte 	lib_infop->hLibrary = LoadLibrary(byFileName);
591*fcf3ce44SJohn Forte 	if (lib_infop->hLibrary == NULL){
592*fcf3ce44SJohn Forte 	    /* printf("unable to load library %s\n", librarypath); */
593*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, installation error */
594*fcf3ce44SJohn Forte 	    goto dud_library;
595*fcf3ce44SJohn Forte 	}
596*fcf3ce44SJohn Forte 	lib_infop->LibraryPath = strdup(byFileName);
597*fcf3ce44SJohn Forte 	DEBUG(1, "HBAAPI loading: %s\n", byFileName, 0, 0);
598*fcf3ce44SJohn Forte 
599*fcf3ce44SJohn Forte 	/* Call the registration function to get the list of pointers */
600*fcf3ce44SJohn Forte 	RegisterV2Func = (HBARegisterLibraryV2Func)
601*fcf3ce44SJohn Forte 	    GetProcAddress(lib_infop->hLibrary, "HBA_RegisterLibraryV2");
602*fcf3ce44SJohn Forte 	if (RegisterV2Func != NULL) {
603*fcf3ce44SJohn Forte 	    /* Load the function pointers directly into
604*fcf3ce44SJohn Forte 	     * the table of functions */
605*fcf3ce44SJohn Forte 	    status = ((RegisterV2Func)(&lib_infop->functionTable));
606*fcf3ce44SJohn Forte 	    if (status != HBA_STATUS_OK) {
607*fcf3ce44SJohn Forte 		/* library not loaded */
608*fcf3ce44SJohn Forte 		/* ???Opportunity to send error msg, library error? */
609*fcf3ce44SJohn Forte 		goto dud_library;
610*fcf3ce44SJohn Forte 	    }
611*fcf3ce44SJohn Forte 	} else {
612*fcf3ce44SJohn Forte 	    /* Maybe the vendor library is only Rev1 */
613*fcf3ce44SJohn Forte 	    RegisterFunc = (HBARegisterLibraryFunc)
614*fcf3ce44SJohn Forte 		GetProcAddress(lib_infop->hLibrary, "HBA_RegisterLibrary");
615*fcf3ce44SJohn Forte 	    if(RegisterFunc == NULL) {
616*fcf3ce44SJohn Forte 		/* ???Opportunity to send error msg, library error? */
617*fcf3ce44SJohn Forte 		goto dud_library;
618*fcf3ce44SJohn Forte 	    }
619*fcf3ce44SJohn Forte 	    /* Load the function points directly into
620*fcf3ce44SJohn Forte 	     * the Rev 2 table of functions */
621*fcf3ce44SJohn Forte 	    status = ((RegisterFunc)(
622*fcf3ce44SJohn Forte 		(HBA_ENTRYPOINTS *)(&lib_infop->functionTable)));
623*fcf3ce44SJohn Forte 	    if (status != HBA_STATUS_OK) {
624*fcf3ce44SJohn Forte 		/* library not loaded */
625*fcf3ce44SJohn Forte 		/* ???Opportunity to send error msg, library error? */
626*fcf3ce44SJohn Forte 		goto dud_library;
627*fcf3ce44SJohn Forte 	    }
628*fcf3ce44SJohn Forte 	}
629*fcf3ce44SJohn Forte 
630*fcf3ce44SJohn Forte 	/* successfully loaded library */
631*fcf3ce44SJohn Forte 	GetVersionFunc = lib_infop->functionTable.GetVersionHandler;
632*fcf3ce44SJohn Forte 	if (GetVersionFunc == NULL) {
633*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, library error? */
634*fcf3ce44SJohn Forte 	    goto dud_library;
635*fcf3ce44SJohn Forte 	}
636*fcf3ce44SJohn Forte 	/* Check the version of this library before loading */
637*fcf3ce44SJohn Forte 	/* Actually... This wrapper is compatible with version 1 */
638*fcf3ce44SJohn Forte 	libversion = ((GetVersionFunc)());
639*fcf3ce44SJohn Forte #ifdef NOTDEF /* save for a later time... when it matters */
640*fcf3ce44SJohn Forte 	if (libversion < HBA_LIBVERSION) {
641*fcf3ce44SJohn Forte 	    goto dud_library;
642*fcf3ce44SJohn Forte 	}
643*fcf3ce44SJohn Forte #endif
644*fcf3ce44SJohn Forte 	LoadLibraryFunc = lib_infop->functionTable.LoadLibraryHandler;
645*fcf3ce44SJohn Forte 	if (LoadLibraryFunc == NULL) {
646*fcf3ce44SJohn Forte 	    /* Hmmm, dont we need to flag this in a realy big way??? */
647*fcf3ce44SJohn Forte 	    /* How about messages to the system event logger ??? */
648*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, library error? */
649*fcf3ce44SJohn Forte 	    goto dud_library;
650*fcf3ce44SJohn Forte 	}
651*fcf3ce44SJohn Forte 	/* Initialize this library */
652*fcf3ce44SJohn Forte 	status = ((LoadLibraryFunc)());
653*fcf3ce44SJohn Forte 	if (status != HBA_STATUS_OK) {
654*fcf3ce44SJohn Forte 	    /* ???Opportunity to send error msg, library error? */
655*fcf3ce44SJohn Forte 	    continue;
656*fcf3ce44SJohn Forte 	}
657*fcf3ce44SJohn Forte 	/* successfully loaded library */
658*fcf3ce44SJohn Forte 	lib_infop->status = HBA_LIBRARY_LOADED;
659*fcf3ce44SJohn Forte 
660*fcf3ce44SJohn Forte     dud_library: /* its also just the end of the loop */
661*fcf3ce44SJohn Forte 	RegCloseKey(hkVendorLib);
662*fcf3ce44SJohn Forte     }
663*fcf3ce44SJohn Forte     RegCloseKey(hkSniaHba);
664*fcf3ce44SJohn Forte 
665*fcf3ce44SJohn Forte #else /* Unix as opposed to Win32 */
666*fcf3ce44SJohn Forte     FILE		*hbaconf;
667*fcf3ce44SJohn Forte     char		fullline[512];		/* line read from HBA.conf */
668*fcf3ce44SJohn Forte     char		*libraryname;		/* Read in from file HBA.conf */
669*fcf3ce44SJohn Forte     char		*librarypath;		/* Read in from file HBA.conf */
670*fcf3ce44SJohn Forte     char		hbaConfFilePath[256];
671*fcf3ce44SJohn Forte     char		*charPtr;
672*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
673*fcf3ce44SJohn Forte 
674*fcf3ce44SJohn Forte     if(_hbaapi_librarylist != NULL) {
675*fcf3ce44SJohn Forte 	fprintf(stderr,
676*fcf3ce44SJohn Forte 		"HBA_LoadLibrary: previously unfreed "
677*fcf3ce44SJohn Forte 		"libraries exist, call HBA_FreeLibrary().\n");
678*fcf3ce44SJohn Forte 	return HBA_STATUS_ERROR;
679*fcf3ce44SJohn Forte     }
680*fcf3ce44SJohn Forte 
681*fcf3ce44SJohn Forte     strcpy(hbaConfFilePath, "/etc/hba.conf");
682*fcf3ce44SJohn Forte 
683*fcf3ce44SJohn Forte     if ((hbaconf = fopen(hbaConfFilePath, "r")) == NULL) {
684*fcf3ce44SJohn Forte 	printf("Cannot open %s\n", hbaConfFilePath);
685*fcf3ce44SJohn Forte 	return HBA_STATUS_ERROR;
686*fcf3ce44SJohn Forte     }
687*fcf3ce44SJohn Forte 
688*fcf3ce44SJohn Forte     /* Read in each line and load library */
689*fcf3ce44SJohn Forte     while ((hbaconf != NULL) && (fgets(fullline, sizeof(fullline), hbaconf))) {
690*fcf3ce44SJohn Forte 	/* Skip the comments... */
691*fcf3ce44SJohn Forte 	if ((fullline[0] == '#') || (fullline[0] == '\n')) {
692*fcf3ce44SJohn Forte 	    continue;
693*fcf3ce44SJohn Forte 	}
694*fcf3ce44SJohn Forte 
695*fcf3ce44SJohn Forte 	/* grab first 'thing' in line (if its there)*/
696*fcf3ce44SJohn Forte 	if((libraryname = strtok(fullline, " \t\n")) != NULL) {
697*fcf3ce44SJohn Forte 	    if(strlen(libraryname) >= 64) {
698*fcf3ce44SJohn Forte 		fprintf(stderr, "Library name(%s) in %s is > 64 characters\n",
699*fcf3ce44SJohn Forte 			libraryname, hbaConfFilePath);
700*fcf3ce44SJohn Forte 	    }
701*fcf3ce44SJohn Forte 	}
702*fcf3ce44SJohn Forte 	/* grab second 'thing' in line (if its there)*/
703*fcf3ce44SJohn Forte 	if((librarypath = strtok(NULL, " \t\n")) != NULL) {
704*fcf3ce44SJohn Forte 	    if(strlen(librarypath) >= 256) {
705*fcf3ce44SJohn Forte 		fprintf(stderr, "Library path(%s) in %s is > 256 characters\n",
706*fcf3ce44SJohn Forte 			librarypath, hbaConfFilePath);
707*fcf3ce44SJohn Forte 	    }
708*fcf3ce44SJohn Forte 	}
709*fcf3ce44SJohn Forte 
710*fcf3ce44SJohn Forte 	/* there should be no more 'things' in the line */
711*fcf3ce44SJohn Forte 	if((charPtr = strtok(NULL, " \n\t")) != NULL) {
712*fcf3ce44SJohn Forte 	    fprintf(stderr, "Extraneous characters (\"%s\") in %s\n",
713*fcf3ce44SJohn Forte 		    charPtr, hbaConfFilePath);
714*fcf3ce44SJohn Forte 	}
715*fcf3ce44SJohn Forte 
716*fcf3ce44SJohn Forte 	/* Continue to the next line if library name or path is invalid */
717*fcf3ce44SJohn Forte 	if (libraryname == NULL ||
718*fcf3ce44SJohn Forte 	    strlen(libraryname) == 0 ||
719*fcf3ce44SJohn Forte 	    librarypath == NULL ||
720*fcf3ce44SJohn Forte 	    (strlen(librarypath) == 0)) {
721*fcf3ce44SJohn Forte 	    continue;
722*fcf3ce44SJohn Forte 	}
723*fcf3ce44SJohn Forte 	/*
724*fcf3ce44SJohn Forte 	 * Special case....
725*fcf3ce44SJohn Forte 	 * Look for loglevel
726*fcf3ce44SJohn Forte 	 */
727*fcf3ce44SJohn Forte 	if(strcmp(libraryname, "debuglevel") == 0) {
728*fcf3ce44SJohn Forte 	    _hbaapi_debuglevel = strtol(librarypath, NULL, 10);
729*fcf3ce44SJohn Forte 	    /* error handling does the right thing automagically */
730*fcf3ce44SJohn Forte 	    continue;
731*fcf3ce44SJohn Forte 	}
732*fcf3ce44SJohn Forte 
733*fcf3ce44SJohn Forte 	lib_infop = (HBA_LIBRARY_INFO *)calloc(1, sizeof(HBA_LIBRARY_INFO));
734*fcf3ce44SJohn Forte 	if(lib_infop == NULL) {
735*fcf3ce44SJohn Forte 	    fprintf(stderr, "HBA_LoadLibrary: out of memeory\n");
736*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR);
737*fcf3ce44SJohn Forte 	}
738*fcf3ce44SJohn Forte 	lib_infop->status = HBA_LIBRARY_NOT_LOADED;
739*fcf3ce44SJohn Forte 	lib_infop->LibraryName = strdup(libraryname);
740*fcf3ce44SJohn Forte 	lib_infop->LibraryPath = strdup(librarypath);
741*fcf3ce44SJohn Forte 	lib_infop->index = _hbaapi_total_library_count;
742*fcf3ce44SJohn Forte 	_hbaapi_total_library_count++;
743*fcf3ce44SJohn Forte 	lib_infop->next = _hbaapi_librarylist;
744*fcf3ce44SJohn Forte 	_hbaapi_librarylist = lib_infop;
745*fcf3ce44SJohn Forte 
746*fcf3ce44SJohn Forte 	/* Load the DLL now */
747*fcf3ce44SJohn Forte 	if((lib_infop->hLibrary = dlopen(librarypath,RTLD_LAZY)) == NULL) {
748*fcf3ce44SJohn Forte 	    /*printf("unable to load library %s\n", librarypath); */
749*fcf3ce44SJohn Forte 	    continue;
750*fcf3ce44SJohn Forte 	}
751*fcf3ce44SJohn Forte 	/* Call the registration function to get the list of pointers */
752*fcf3ce44SJohn Forte 	RegisterV2Func = (HBARegisterLibraryV2Func)
753*fcf3ce44SJohn Forte 	    dlsym(lib_infop->hLibrary, "HBA_RegisterLibraryV2");
754*fcf3ce44SJohn Forte 	if (RegisterV2Func != NULL) {
755*fcf3ce44SJohn Forte 	    /* Load the function points directly into
756*fcf3ce44SJohn Forte 	     * the table of functions */
757*fcf3ce44SJohn Forte 	    status = ((RegisterV2Func)(&lib_infop->functionTable));
758*fcf3ce44SJohn Forte 	    if (status != HBA_STATUS_OK) {
759*fcf3ce44SJohn Forte 		/* library not loaded */
760*fcf3ce44SJohn Forte 		continue;
761*fcf3ce44SJohn Forte 	    }
762*fcf3ce44SJohn Forte 	} else {
763*fcf3ce44SJohn Forte 	    /* Maybe the vendor library is only Rev1 */
764*fcf3ce44SJohn Forte 	    RegisterFunc = (HBARegisterLibraryFunc)
765*fcf3ce44SJohn Forte 		dlsym(lib_infop->hLibrary, "HBA_RegisterLibrary");
766*fcf3ce44SJohn Forte 	    if(RegisterFunc == NULL) {
767*fcf3ce44SJohn Forte 		/* This function is required */
768*fcf3ce44SJohn Forte 		fprintf(stderr,
769*fcf3ce44SJohn Forte 			"HBA_LoadLibrary: vendor specific RegisterLibrary "
770*fcf3ce44SJohn Forte 			"function not found.  lib: %s\n", librarypath);
771*fcf3ce44SJohn Forte 		DEBUG(0, "HBA_LoadLibrary: vendor specific RegisterLibrary "
772*fcf3ce44SJohn Forte 		      "function not found.  lib: %s\n", librarypath, 0, 0);
773*fcf3ce44SJohn Forte 		continue;
774*fcf3ce44SJohn Forte 	    }
775*fcf3ce44SJohn Forte 	    /* Load the function points directly into
776*fcf3ce44SJohn Forte 	     * the table of functions */
777*fcf3ce44SJohn Forte 	    status = ((RegisterFunc)
778*fcf3ce44SJohn Forte 		      ((HBA_ENTRYPOINTS *)(&lib_infop->functionTable)));
779*fcf3ce44SJohn Forte 	    if (status != HBA_STATUS_OK) {
780*fcf3ce44SJohn Forte 		/* library not loaded */
781*fcf3ce44SJohn Forte 		fprintf(stderr,
782*fcf3ce44SJohn Forte 			"HBA_LoadLibrary: vendor specific RegisterLibrary "
783*fcf3ce44SJohn Forte 			"function encountered an error.  lib: %s\n", librarypath);
784*fcf3ce44SJohn Forte 		DEBUG(0, "HBA_LoadLibrary: vendor specific RegisterLibrary "
785*fcf3ce44SJohn Forte 		      "function encountered an error. lib: %s\n", librarypath, 0, 0);
786*fcf3ce44SJohn Forte 		continue;
787*fcf3ce44SJohn Forte 	    }
788*fcf3ce44SJohn Forte 	}
789*fcf3ce44SJohn Forte 
790*fcf3ce44SJohn Forte 	/* successfully loaded library */
791*fcf3ce44SJohn Forte 	if((GetVersionFunc = lib_infop->functionTable.GetVersionHandler)
792*fcf3ce44SJohn Forte 	   == NULL) {
793*fcf3ce44SJohn Forte 	    continue;
794*fcf3ce44SJohn Forte 	}
795*fcf3ce44SJohn Forte 	libversion = ((GetVersionFunc)());
796*fcf3ce44SJohn Forte 	/* Check the version of this library before loading */
797*fcf3ce44SJohn Forte 	/* Actually... This wrapper is compatible with version 1 */
798*fcf3ce44SJohn Forte #ifdef NOTDEF /* save for a later time... when it matters */
799*fcf3ce44SJohn Forte 	if(libversion < HBA_LIBVERSION) {
800*fcf3ce44SJohn Forte 	    printf("Library version mismatch. Got %d expected %d.\n",
801*fcf3ce44SJohn Forte 		   libversion, HBA_LIBVERSION);
802*fcf3ce44SJohn Forte 	    continue;
803*fcf3ce44SJohn Forte 	}
804*fcf3ce44SJohn Forte #endif
805*fcf3ce44SJohn Forte 	DEBUG(1, "%s libversion = %d", librarypath, libversion, 0);
806*fcf3ce44SJohn Forte 	LoadLibraryFunc = lib_infop->functionTable.LoadLibraryHandler;
807*fcf3ce44SJohn Forte 	if (LoadLibraryFunc == NULL) {
808*fcf3ce44SJohn Forte 	    /* this function is required */
809*fcf3ce44SJohn Forte 	    fprintf(stderr,
810*fcf3ce44SJohn Forte 		    "HBA_LoadLibrary: vendor specific LoadLibrary "
811*fcf3ce44SJohn Forte 		    "function not found.  lib: %s\n", librarypath);
812*fcf3ce44SJohn Forte 	    DEBUG(0, "HBA_LoadLibrary: vendor specific LoadLibrary "
813*fcf3ce44SJohn Forte 		    "function not found.  lib: %s\n", librarypath, 0, 0);
814*fcf3ce44SJohn Forte 	    continue;
815*fcf3ce44SJohn Forte 	}
816*fcf3ce44SJohn Forte 	/* Initialize this library */
817*fcf3ce44SJohn Forte 	if((status = ((LoadLibraryFunc)())) != HBA_STATUS_OK) {
818*fcf3ce44SJohn Forte 	    /* maybe this should be a printf so that we CANNOT miss it */
819*fcf3ce44SJohn Forte 	    fprintf(stderr,
820*fcf3ce44SJohn Forte 		    "HBA_LoadLibrary: Encounterd and error loading: %s",
821*fcf3ce44SJohn Forte 		    librarypath);
822*fcf3ce44SJohn Forte 	    DEBUG(0, "Encounterd and error loading: %s", librarypath, 0, 0);
823*fcf3ce44SJohn Forte 	    DEBUG(0, "  HBA_STATUS: %d", status, 0, 0);
824*fcf3ce44SJohn Forte 	    continue;
825*fcf3ce44SJohn Forte 	}
826*fcf3ce44SJohn Forte 	/* successfully loaded library */
827*fcf3ce44SJohn Forte 	lib_infop->status = HBA_LIBRARY_LOADED;
828*fcf3ce44SJohn Forte     }
829*fcf3ce44SJohn Forte 
830*fcf3ce44SJohn Forte     fclose(hbaconf);
831*fcf3ce44SJohn Forte #endif /* WIN32 or UNIX */
832*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
833*fcf3ce44SJohn Forte     ret = pthread_mutex_init(&_hbaapi_LL_mutex, NULL);
834*fcf3ce44SJohn Forte     if(ret == 0) {
835*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_AL_mutex, NULL);
836*fcf3ce44SJohn Forte     }
837*fcf3ce44SJohn Forte     if(ret == 0) {
838*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_AAE_mutex, NULL);
839*fcf3ce44SJohn Forte     }
840*fcf3ce44SJohn Forte     if(ret == 0) {
841*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_AE_mutex, NULL);
842*fcf3ce44SJohn Forte     }
843*fcf3ce44SJohn Forte     if(ret == 0) {
844*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_APE_mutex, NULL);
845*fcf3ce44SJohn Forte     }
846*fcf3ce44SJohn Forte     if(ret == 0) {
847*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_APSE_mutex, NULL);
848*fcf3ce44SJohn Forte     }
849*fcf3ce44SJohn Forte     if(ret == 0) {
850*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_TE_mutex, NULL);
851*fcf3ce44SJohn Forte     }
852*fcf3ce44SJohn Forte     if(ret == 0) {
853*fcf3ce44SJohn Forte 	ret = pthread_mutex_init(&_hbaapi_LE_mutex, NULL);
854*fcf3ce44SJohn Forte     }
855*fcf3ce44SJohn Forte     if(ret != 0) {
856*fcf3ce44SJohn Forte 	perror("pthread_mutec_init - HBA_LoadLibrary");
857*fcf3ce44SJohn Forte 	return(HBA_STATUS_ERROR);
858*fcf3ce44SJohn Forte     }
859*fcf3ce44SJohn Forte #elif defined(WIN32)
860*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_LL_mutex);
861*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_AL_mutex);
862*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_AAE_mutex);
863*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_AE_mutex);
864*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_APE_mutex);
865*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_APSE_mutex);
866*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_TE_mutex);
867*fcf3ce44SJohn Forte     InitializeCriticalSection(&_hbaapi_LE_mutex);
868*fcf3ce44SJohn Forte #endif
869*fcf3ce44SJohn Forte 
870*fcf3ce44SJohn Forte 
871*fcf3ce44SJohn Forte     return HBA_STATUS_OK;
872*fcf3ce44SJohn Forte }
873*fcf3ce44SJohn Forte 
874*fcf3ce44SJohn Forte HBA_STATUS
875*fcf3ce44SJohn Forte HBA_FreeLibrary(void) {
876*fcf3ce44SJohn Forte     HBAFreeLibraryFunc	FreeLibraryFunc;
877*fcf3ce44SJohn Forte     HBA_STATUS		status;
878*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
879*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_next;
880*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM
881*fcf3ce44SJohn Forte 			***listp;
882*fcf3ce44SJohn Forte     HBA_ADAPTER_INFO	*adapt_infop;
883*fcf3ce44SJohn Forte     HBA_ADAPTER_INFO	*adapt_next;
884*fcf3ce44SJohn Forte 
885*fcf3ce44SJohn Forte     ARE_WE_INITED();
886*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex);
887*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AL_mutex);
888*fcf3ce44SJohn Forte 
889*fcf3ce44SJohn Forte     DEBUG(1, "HBA_FreeLibrary()", 0, 0, 0);
890*fcf3ce44SJohn Forte     for(lib_infop = _hbaapi_librarylist; lib_infop != NULL; lib_infop = lib_next) {
891*fcf3ce44SJohn Forte 	lib_next = lib_infop->next;
892*fcf3ce44SJohn Forte 	if (lib_infop->status == HBA_LIBRARY_LOADED) {
893*fcf3ce44SJohn Forte 	    FreeLibraryFunc = lib_infop->functionTable.FreeLibraryHandler;
894*fcf3ce44SJohn Forte 	    if (FreeLibraryFunc != NULL) {
895*fcf3ce44SJohn Forte 		/* Free this library */
896*fcf3ce44SJohn Forte 		status = ((FreeLibraryFunc)());
897*fcf3ce44SJohn Forte 	    }
898*fcf3ce44SJohn Forte #ifdef WIN32
899*fcf3ce44SJohn Forte 	    FreeLibrary(lib_infop->hLibrary);	/* Unload DLL from memory */
900*fcf3ce44SJohn Forte #else
901*fcf3ce44SJohn Forte 	    dlclose(lib_infop->hLibrary);	/* Unload DLL from memory */
902*fcf3ce44SJohn Forte #endif
903*fcf3ce44SJohn Forte 	}
904*fcf3ce44SJohn Forte #ifndef WIN32
905*fcf3ce44SJohn Forte 	free(lib_infop->LibraryName);
906*fcf3ce44SJohn Forte #endif
907*fcf3ce44SJohn Forte 	free(lib_infop->LibraryPath);
908*fcf3ce44SJohn Forte 	free(lib_infop);
909*fcf3ce44SJohn Forte 
910*fcf3ce44SJohn Forte     }
911*fcf3ce44SJohn Forte     _hbaapi_librarylist = NULL;
912*fcf3ce44SJohn Forte     /* OK, now all functions are disabled except for LoadLibrary,
913*fcf3ce44SJohn Forte      * Hope no other thread calls it before we have returned */
914*fcf3ce44SJohn Forte     _hbaapi_total_library_count = 0;
915*fcf3ce44SJohn Forte 
916*fcf3ce44SJohn Forte     for(adapt_infop = _hbaapi_adapterlist;
917*fcf3ce44SJohn Forte 	adapt_infop != NULL;
918*fcf3ce44SJohn Forte 	adapt_infop = adapt_next) {
919*fcf3ce44SJohn Forte 	adapt_next = adapt_infop->next;
920*fcf3ce44SJohn Forte 	free(adapt_infop->name);
921*fcf3ce44SJohn Forte 	free(adapt_infop);
922*fcf3ce44SJohn Forte     }
923*fcf3ce44SJohn Forte     _hbaapi_adapterlist = NULL;
924*fcf3ce44SJohn Forte     _hbaapi_total_adapter_count = 0;
925*fcf3ce44SJohn Forte 
926*fcf3ce44SJohn Forte     /* Free up the callbacks, this is not the most efficient, but it works */
927*fcf3ce44SJohn Forte     while((volatile HBA_ADAPTERCALLBACK_ELEM *)
928*fcf3ce44SJohn Forte 	  _hbaapi_adapteraddevents_callback_list
929*fcf3ce44SJohn Forte 	  != NULL) {
930*fcf3ce44SJohn Forte 	local_remove_callback((HBA_CALLBACKHANDLE)
931*fcf3ce44SJohn Forte 			   _hbaapi_adapteraddevents_callback_list);
932*fcf3ce44SJohn Forte     }
933*fcf3ce44SJohn Forte     for(listp = cb_lists_array; *listp != NULL; listp++) {
934*fcf3ce44SJohn Forte 	while((volatile HBA_ADAPTERCALLBACK_ELEM ***)**listp != NULL) {
935*fcf3ce44SJohn Forte 	    local_remove_callback((HBA_CALLBACKHANDLE)**listp);
936*fcf3ce44SJohn Forte 	}
937*fcf3ce44SJohn Forte     }
938*fcf3ce44SJohn Forte 
939*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AL_mutex);
940*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_LL_mutex);
941*fcf3ce44SJohn Forte 
942*fcf3ce44SJohn Forte #ifdef USESYSLOG
943*fcf3ce44SJohn Forte     closelog();
944*fcf3ce44SJohn Forte #endif
945*fcf3ce44SJohn Forte #ifdef USELOGFILE
946*fcf3ce44SJohn Forte     if(_hbaapi_debug_fd != NULL) {
947*fcf3ce44SJohn Forte 	fclose(_hbaapi_debug_fd);
948*fcf3ce44SJohn Forte     }
949*fcf3ce44SJohn Forte     _hbaapi_debug_fd = NULL;
950*fcf3ce44SJohn Forte #endif
951*fcf3ce44SJohn Forte #ifdef POSIX_THREADS
952*fcf3ce44SJohn Forte     /* this will unlock them as well, but who cares */
953*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_LE_mutex);
954*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_TE_mutex);
955*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_APSE_mutex);
956*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_APE_mutex);
957*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_AE_mutex);
958*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_AAE_mutex);
959*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_AL_mutex);
960*fcf3ce44SJohn Forte     pthread_mutex_destroy(&_hbaapi_LL_mutex);
961*fcf3ce44SJohn Forte #elif defined(WIN32)
962*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_LL_mutex);
963*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_AL_mutex);
964*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_AAE_mutex);
965*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_AE_mutex);
966*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_APE_mutex);
967*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_APSE_mutex);
968*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_TE_mutex);
969*fcf3ce44SJohn Forte     DeleteCriticalSection(&_hbaapi_LE_mutex);
970*fcf3ce44SJohn Forte #endif
971*fcf3ce44SJohn Forte 
972*fcf3ce44SJohn Forte     return HBA_STATUS_OK;
973*fcf3ce44SJohn Forte }
974*fcf3ce44SJohn Forte 
975*fcf3ce44SJohn Forte /*
976*fcf3ce44SJohn Forte  * The API used to use fixed size tables as its primary data structure.
977*fcf3ce44SJohn Forte  * Indexing from 1 to N identified each adapters.  Now the adapters are
978*fcf3ce44SJohn Forte  * on a linked list.  There is a unique "index" foreach each adapter.
979*fcf3ce44SJohn Forte  * Adapters always keep their index, even if they are removed from the
980*fcf3ce44SJohn Forte  * hardware.  The only time the indexing is reset is on HBA_FreeLibrary
981*fcf3ce44SJohn Forte  */
982*fcf3ce44SJohn Forte HBA_UINT32
983*fcf3ce44SJohn Forte HBA_GetNumberOfAdapters(void) {
984*fcf3ce44SJohn Forte     int j=0;
985*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
986*fcf3ce44SJohn Forte     HBAGetNumberOfAdaptersFunc
987*fcf3ce44SJohn Forte 			GetNumberOfAdaptersFunc;
988*fcf3ce44SJohn Forte     HBAGetAdapterNameFunc
989*fcf3ce44SJohn Forte 			GetAdapterNameFunc;
990*fcf3ce44SJohn Forte     HBA_BOOLEAN		found_name;
991*fcf3ce44SJohn Forte     HBA_ADAPTER_INFO	*adapt_infop;
992*fcf3ce44SJohn Forte     HBA_STATUS		status;
993*fcf3ce44SJohn Forte 
994*fcf3ce44SJohn Forte     char adaptername[256];
995*fcf3ce44SJohn Forte     int num_adapters; /* local */
996*fcf3ce44SJohn Forte 
997*fcf3ce44SJohn Forte     if(_hbaapi_librarylist == NULL) {
998*fcf3ce44SJohn Forte 	return (0);
999*fcf3ce44SJohn Forte     }
1000*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex); /* pay attention to order */
1001*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AL_mutex);
1002*fcf3ce44SJohn Forte 
1003*fcf3ce44SJohn Forte     for (lib_infop = _hbaapi_librarylist;
1004*fcf3ce44SJohn Forte 	 lib_infop != NULL;
1005*fcf3ce44SJohn Forte 	 lib_infop = lib_infop->next) {
1006*fcf3ce44SJohn Forte 
1007*fcf3ce44SJohn Forte 	if (lib_infop->status != HBA_LIBRARY_LOADED) {
1008*fcf3ce44SJohn Forte 	    continue;
1009*fcf3ce44SJohn Forte 	}
1010*fcf3ce44SJohn Forte 
1011*fcf3ce44SJohn Forte 	GetNumberOfAdaptersFunc =
1012*fcf3ce44SJohn Forte 	    lib_infop->functionTable.GetNumberOfAdaptersHandler;
1013*fcf3ce44SJohn Forte 	if (GetNumberOfAdaptersFunc == NULL)  {
1014*fcf3ce44SJohn Forte 	    continue;
1015*fcf3ce44SJohn Forte 	}
1016*fcf3ce44SJohn Forte 	num_adapters = ((GetNumberOfAdaptersFunc)());
1017*fcf3ce44SJohn Forte #ifndef WIN32
1018*fcf3ce44SJohn Forte 	DEBUG(1, "HBAAPI: num_adapters for %s = %d\n",
1019*fcf3ce44SJohn Forte 	      lib_infop->LibraryName, num_adapters, 0);
1020*fcf3ce44SJohn Forte #else
1021*fcf3ce44SJohn Forte 	DEBUG(1, "HBAAPI: num_adapters for %s = %d\n",
1022*fcf3ce44SJohn Forte 	      lib_infop->LibraryPath, num_adapters, 0);
1023*fcf3ce44SJohn Forte #endif
1024*fcf3ce44SJohn Forte 
1025*fcf3ce44SJohn Forte 	/* Also get the names of all the adapters here and cache */
1026*fcf3ce44SJohn Forte 	GetAdapterNameFunc = lib_infop->functionTable.GetAdapterNameHandler;
1027*fcf3ce44SJohn Forte 	if(GetAdapterNameFunc == NULL) {
1028*fcf3ce44SJohn Forte 	    continue;
1029*fcf3ce44SJohn Forte 	}
1030*fcf3ce44SJohn Forte 
1031*fcf3ce44SJohn Forte 	for (j = 0; j < num_adapters; j++) {
1032*fcf3ce44SJohn Forte 	    found_name = 0;
1033*fcf3ce44SJohn Forte 	    status = (GetAdapterNameFunc)(j, (char *)&adaptername);
1034*fcf3ce44SJohn Forte 	    if(status == HBA_STATUS_OK) {
1035*fcf3ce44SJohn Forte 		for(adapt_infop = _hbaapi_adapterlist;
1036*fcf3ce44SJohn Forte 		    adapt_infop != NULL;
1037*fcf3ce44SJohn Forte 		    adapt_infop = adapt_infop->next) {
1038*fcf3ce44SJohn Forte 		    /*
1039*fcf3ce44SJohn Forte 		     * check for duplicates, really, this may just be a second
1040*fcf3ce44SJohn Forte 		     * call to this function
1041*fcf3ce44SJohn Forte 		     * ??? how do we know when a name becomes stale?
1042*fcf3ce44SJohn Forte 		     */
1043*fcf3ce44SJohn Forte 		    if(strcmp(adaptername, adapt_infop->name) == 0) {
1044*fcf3ce44SJohn Forte 			/* already got this one */
1045*fcf3ce44SJohn Forte 			found_name++;
1046*fcf3ce44SJohn Forte 			break;
1047*fcf3ce44SJohn Forte 		    }
1048*fcf3ce44SJohn Forte 		}
1049*fcf3ce44SJohn Forte 		if(found_name != 0) {
1050*fcf3ce44SJohn Forte 		    continue;
1051*fcf3ce44SJohn Forte 		}
1052*fcf3ce44SJohn Forte 	    }
1053*fcf3ce44SJohn Forte 
1054*fcf3ce44SJohn Forte 	    adapt_infop = (HBA_ADAPTER_INFO *)
1055*fcf3ce44SJohn Forte 		calloc(1, sizeof(HBA_ADAPTER_INFO));
1056*fcf3ce44SJohn Forte 	    if(adapt_infop == NULL) {
1057*fcf3ce44SJohn Forte #ifndef WIN32
1058*fcf3ce44SJohn Forte 		fprintf(stderr,
1059*fcf3ce44SJohn Forte 			"HBA_GetNumberOfAdapters: calloc failed on sizeof:%d\n",
1060*fcf3ce44SJohn Forte 			sizeof(HBA_ADAPTER_INFO));
1061*fcf3ce44SJohn Forte #endif
1062*fcf3ce44SJohn Forte 		RELEASE_MUTEX(&_hbaapi_AL_mutex);
1063*fcf3ce44SJohn Forte 		RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
1064*fcf3ce44SJohn Forte 				     _hbaapi_total_adapter_count);
1065*fcf3ce44SJohn Forte 	    }
1066*fcf3ce44SJohn Forte 	    if((adapt_infop->GNstatus = status) == HBA_STATUS_OK) {
1067*fcf3ce44SJohn Forte 		adapt_infop->name = strdup(adaptername);
1068*fcf3ce44SJohn Forte 	    } else {
1069*fcf3ce44SJohn Forte 		char dummyname[512];
1070*fcf3ce44SJohn Forte 		sprintf(dummyname, "NULLADAPTER-%s-%03d",
1071*fcf3ce44SJohn Forte 			lib_infop->LibraryPath, _hbaapi_total_adapter_count);
1072*fcf3ce44SJohn Forte 		dummyname[255] = '\0';
1073*fcf3ce44SJohn Forte 		adapt_infop->name = strdup(dummyname);
1074*fcf3ce44SJohn Forte 	    }
1075*fcf3ce44SJohn Forte 	    adapt_infop->library = lib_infop;
1076*fcf3ce44SJohn Forte 	    adapt_infop->next = _hbaapi_adapterlist;
1077*fcf3ce44SJohn Forte 	    adapt_infop->index = _hbaapi_total_adapter_count;
1078*fcf3ce44SJohn Forte 	    _hbaapi_adapterlist = adapt_infop;
1079*fcf3ce44SJohn Forte 	    _hbaapi_total_adapter_count++;
1080*fcf3ce44SJohn Forte 	}
1081*fcf3ce44SJohn Forte     }
1082*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AL_mutex);
1083*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, _hbaapi_total_adapter_count);
1084*fcf3ce44SJohn Forte }
1085*fcf3ce44SJohn Forte 
1086*fcf3ce44SJohn Forte HBA_STATUS
1087*fcf3ce44SJohn Forte HBA_GetAdapterName(
1088*fcf3ce44SJohn Forte     HBA_UINT32 adapterindex,
1089*fcf3ce44SJohn Forte     char *adaptername)
1090*fcf3ce44SJohn Forte {
1091*fcf3ce44SJohn Forte     HBA_ADAPTER_INFO	*adapt_infop;
1092*fcf3ce44SJohn Forte     HBA_STATUS		ret = HBA_STATUS_ERROR_ILLEGAL_INDEX;
1093*fcf3ce44SJohn Forte 
1094*fcf3ce44SJohn Forte     if (adaptername == NULL) {
1095*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1096*fcf3ce44SJohn Forte     }
1097*fcf3ce44SJohn Forte     /*
1098*fcf3ce44SJohn Forte      * The adapter index is from old code, but we have
1099*fcf3ce44SJohn Forte      * to support it.  Go down the list looking for
1100*fcf3ce44SJohn Forte      * the adapter
1101*fcf3ce44SJohn Forte      */
1102*fcf3ce44SJohn Forte     ARE_WE_INITED();
1103*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AL_mutex);
1104*fcf3ce44SJohn Forte     *adaptername = '\0';
1105*fcf3ce44SJohn Forte     for(adapt_infop = _hbaapi_adapterlist;
1106*fcf3ce44SJohn Forte 	adapt_infop != NULL;
1107*fcf3ce44SJohn Forte 	adapt_infop = adapt_infop->next) {
1108*fcf3ce44SJohn Forte 
1109*fcf3ce44SJohn Forte 	if(adapt_infop->index == adapterindex) {
1110*fcf3ce44SJohn Forte 	    if(adapt_infop->name != NULL &&
1111*fcf3ce44SJohn Forte 	       adapt_infop->GNstatus == HBA_STATUS_OK) {
1112*fcf3ce44SJohn Forte 		strcpy(adaptername, adapt_infop->name);
1113*fcf3ce44SJohn Forte 	    } else {
1114*fcf3ce44SJohn Forte 		*adaptername = '\0';
1115*fcf3ce44SJohn Forte 	    }
1116*fcf3ce44SJohn Forte 	    ret = adapt_infop->GNstatus;
1117*fcf3ce44SJohn Forte 	    break;
1118*fcf3ce44SJohn Forte 	}
1119*fcf3ce44SJohn Forte     }
1120*fcf3ce44SJohn Forte     DEBUG(2, "GetAdapterName for index:%d ->%s", adapterindex, adaptername, 0);
1121*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, ret);
1122*fcf3ce44SJohn Forte }
1123*fcf3ce44SJohn Forte 
1124*fcf3ce44SJohn Forte HBA_HANDLE
1125*fcf3ce44SJohn Forte HBA_OpenAdapter(char* adaptername) {
1126*fcf3ce44SJohn Forte     HBA_HANDLE		handle;
1127*fcf3ce44SJohn Forte     HBAOpenAdapterFunc	OpenAdapterFunc;
1128*fcf3ce44SJohn Forte     HBA_ADAPTER_INFO	*adapt_infop;
1129*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
1130*fcf3ce44SJohn Forte 
1131*fcf3ce44SJohn Forte     DEBUG(2, "OpenAdapter: %s", adaptername, 0, 0);
1132*fcf3ce44SJohn Forte 
1133*fcf3ce44SJohn Forte     if(_hbaapi_librarylist == NULL) {
1134*fcf3ce44SJohn Forte 	return(HBA_HANDLE_INVALID);
1135*fcf3ce44SJohn Forte     }
1136*fcf3ce44SJohn Forte     if (adaptername == NULL) {
1137*fcf3ce44SJohn Forte 	return(HBA_STATUS_ERROR_ARG);
1138*fcf3ce44SJohn Forte     }
1139*fcf3ce44SJohn Forte     handle = HBA_HANDLE_INVALID;
1140*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AL_mutex);
1141*fcf3ce44SJohn Forte     for(adapt_infop = _hbaapi_adapterlist;
1142*fcf3ce44SJohn Forte 	adapt_infop != NULL;
1143*fcf3ce44SJohn Forte 	adapt_infop = adapt_infop->next) {
1144*fcf3ce44SJohn Forte 	if (strcmp(adaptername, adapt_infop->name) != 0) {
1145*fcf3ce44SJohn Forte 	    continue;
1146*fcf3ce44SJohn Forte 	}
1147*fcf3ce44SJohn Forte 	lib_infop = adapt_infop->library;
1148*fcf3ce44SJohn Forte 	OpenAdapterFunc =
1149*fcf3ce44SJohn Forte 	    lib_infop->functionTable.OpenAdapterHandler;
1150*fcf3ce44SJohn Forte 	if (OpenAdapterFunc != NULL) {
1151*fcf3ce44SJohn Forte 	    /* retrieve the vendor handle */
1152*fcf3ce44SJohn Forte 	    handle = (OpenAdapterFunc)(adaptername);
1153*fcf3ce44SJohn Forte 	    if(handle != 0) {
1154*fcf3ce44SJohn Forte 		/* or this with the library index to get the common handle */
1155*fcf3ce44SJohn Forte 		handle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle);
1156*fcf3ce44SJohn Forte 	    }
1157*fcf3ce44SJohn Forte 	}
1158*fcf3ce44SJohn Forte 	break;
1159*fcf3ce44SJohn Forte     }
1160*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, handle);
1161*fcf3ce44SJohn Forte }
1162*fcf3ce44SJohn Forte /*
1163*fcf3ce44SJohn Forte  * This function ignores the list of known adapters and instead tries
1164*fcf3ce44SJohn Forte  * each vendors open function to see if one of them
1165*fcf3ce44SJohn Forte  * can open an adapter when referenced with a particular WWN
1166*fcf3ce44SJohn Forte  */
1167*fcf3ce44SJohn Forte HBA_STATUS
1168*fcf3ce44SJohn Forte HBA_OpenAdapterByWWN(HBA_HANDLE *phandle, HBA_WWN nodeWWN) {
1169*fcf3ce44SJohn Forte     HBA_HANDLE		handle;
1170*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
1171*fcf3ce44SJohn Forte     HBAGetNumberOfAdaptersFunc
1172*fcf3ce44SJohn Forte 			GetNumberOfAdaptersFunc;
1173*fcf3ce44SJohn Forte     HBAOpenAdapterByWWNFunc
1174*fcf3ce44SJohn Forte 			OpenAdapterFunc;
1175*fcf3ce44SJohn Forte     HBA_STATUS		status;
1176*fcf3ce44SJohn Forte 
1177*fcf3ce44SJohn Forte     DEBUG(2, "OpenAdapterByWWN: %s", WWN2STR1(&nodeWWN), 0, 0);
1178*fcf3ce44SJohn Forte 
1179*fcf3ce44SJohn Forte     if (phandle == NULL) {
1180*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1181*fcf3ce44SJohn Forte     }
1182*fcf3ce44SJohn Forte 
1183*fcf3ce44SJohn Forte     ARE_WE_INITED();
1184*fcf3ce44SJohn Forte 
1185*fcf3ce44SJohn Forte     *phandle = HBA_HANDLE_INVALID;
1186*fcf3ce44SJohn Forte 
1187*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex);
1188*fcf3ce44SJohn Forte     for (lib_infop = _hbaapi_librarylist;
1189*fcf3ce44SJohn Forte 	 lib_infop != NULL;
1190*fcf3ce44SJohn Forte 	 lib_infop = lib_infop->next) {
1191*fcf3ce44SJohn Forte 
1192*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_ILLEGAL_WWN;
1193*fcf3ce44SJohn Forte 
1194*fcf3ce44SJohn Forte 	if (lib_infop->status != HBA_LIBRARY_LOADED) {
1195*fcf3ce44SJohn Forte 	    continue;
1196*fcf3ce44SJohn Forte 	}
1197*fcf3ce44SJohn Forte 
1198*fcf3ce44SJohn Forte 	GetNumberOfAdaptersFunc =
1199*fcf3ce44SJohn Forte 	    lib_infop->functionTable.GetNumberOfAdaptersHandler;
1200*fcf3ce44SJohn Forte 	if (GetNumberOfAdaptersFunc == NULL)  {
1201*fcf3ce44SJohn Forte 	    continue;
1202*fcf3ce44SJohn Forte 	}
1203*fcf3ce44SJohn Forte 
1204*fcf3ce44SJohn Forte 	/* look for new hardware */
1205*fcf3ce44SJohn Forte 	(void) ((GetNumberOfAdaptersFunc)());
1206*fcf3ce44SJohn Forte 
1207*fcf3ce44SJohn Forte 	OpenAdapterFunc = lib_infop->functionTable.OpenAdapterByWWNHandler;
1208*fcf3ce44SJohn Forte 	if (OpenAdapterFunc == NULL) {
1209*fcf3ce44SJohn Forte 	    continue;
1210*fcf3ce44SJohn Forte 	}
1211*fcf3ce44SJohn Forte 	/*
1212*fcf3ce44SJohn Forte 	 * We do not know if the WWN is known by this vendor,
1213*fcf3ce44SJohn Forte 	 * just try it
1214*fcf3ce44SJohn Forte 	 */
1215*fcf3ce44SJohn Forte 	if((status = (OpenAdapterFunc)(&handle, nodeWWN)) != HBA_STATUS_OK) {
1216*fcf3ce44SJohn Forte 	    continue;
1217*fcf3ce44SJohn Forte 	}
1218*fcf3ce44SJohn Forte 	/* OK, make a vendor non-specific handle */
1219*fcf3ce44SJohn Forte 	*phandle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle);
1220*fcf3ce44SJohn Forte 	status = HBA_STATUS_OK;
1221*fcf3ce44SJohn Forte 	break;
1222*fcf3ce44SJohn Forte     }
1223*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1224*fcf3ce44SJohn Forte }
1225*fcf3ce44SJohn Forte 
1226*fcf3ce44SJohn Forte void
1227*fcf3ce44SJohn Forte HBA_RefreshAdapterConfiguration() {
1228*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RefreshAdapterConfiguration", 0, 0, 0);
1229*fcf3ce44SJohn Forte     (void)HBA_GetNumberOfAdapters();
1230*fcf3ce44SJohn Forte     return;
1231*fcf3ce44SJohn Forte }
1232*fcf3ce44SJohn Forte 
1233*fcf3ce44SJohn Forte HBA_UINT32
1234*fcf3ce44SJohn Forte HBA_GetVersion() {
1235*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetVersion", 0, 0, 0);
1236*fcf3ce44SJohn Forte     return HBA_LIBVERSION;
1237*fcf3ce44SJohn Forte }
1238*fcf3ce44SJohn Forte 
1239*fcf3ce44SJohn Forte /*
1240*fcf3ce44SJohn Forte  * This function is VERY OS dependent.  Wing it as best you can.
1241*fcf3ce44SJohn Forte  */
1242*fcf3ce44SJohn Forte HBA_UINT32
1243*fcf3ce44SJohn Forte HBA_GetWrapperLibraryAttributes (
1244*fcf3ce44SJohn Forte     HBA_LIBRARYATTRIBUTES *attributes)
1245*fcf3ce44SJohn Forte {
1246*fcf3ce44SJohn Forte 
1247*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetWrapperLibraryAttributes", 0, 0, 0);
1248*fcf3ce44SJohn Forte 
1249*fcf3ce44SJohn Forte     if (attributes == NULL) {
1250*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1251*fcf3ce44SJohn Forte     }
1252*fcf3ce44SJohn Forte 
1253*fcf3ce44SJohn Forte     memset(attributes, 0, sizeof(HBA_LIBRARYATTRIBUTES));
1254*fcf3ce44SJohn Forte 
1255*fcf3ce44SJohn Forte #if defined(SOLARIS)
1256*fcf3ce44SJohn Forte     if((handle = dlopen("libHBAAPI.so", RTLD_NOW)) != NULL) {
1257*fcf3ce44SJohn Forte 	if(dlinfo(handle, RTLD_DI_LINKMAP, &map) >= 0) {
1258*fcf3ce44SJohn Forte 	    for(mp = map; mp != NULL; mp = mp->l_next) {
1259*fcf3ce44SJohn Forte 		if(strlen(map->l_name) < 256) {
1260*fcf3ce44SJohn Forte 		    strcpy(attributes->LibPath, map->l_lname);
1261*fcf3ce44SJohn Forte 		}
1262*fcf3ce44SJohn Forte 	    }
1263*fcf3ce44SJohn Forte 	}
1264*fcf3ce44SJohn Forte     }
1265*fcf3ce44SJohn Forte #elif defined(WIN32)
1266*fcf3ce44SJohn Forte     {
1267*fcf3ce44SJohn Forte 	HMODULE module;
1268*fcf3ce44SJohn Forte 
1269*fcf3ce44SJohn Forte 	/* No need to do anything with the module handle */
1270*fcf3ce44SJohn Forte 	/* It wasn't alloocated so it doesn't need to be freed */
1271*fcf3ce44SJohn Forte 	module = GetModuleHandle("HBAAPI");
1272*fcf3ce44SJohn Forte 	if ( module != NULL ) {
1273*fcf3ce44SJohn Forte 	    if ( GetModuleFileName(module, attributes->LibPath,
1274*fcf3ce44SJohn Forte 				sizeof(attributes->LibPath)) == 0 ) {
1275*fcf3ce44SJohn Forte 	        attributes->LibPath[0] = '\0';
1276*fcf3ce44SJohn Forte 	    }
1277*fcf3ce44SJohn Forte 	}
1278*fcf3ce44SJohn Forte     }
1279*fcf3ce44SJohn Forte #endif
1280*fcf3ce44SJohn Forte #if defined(VENDOR)
1281*fcf3ce44SJohn Forte     strcpy(attributes->VName, VENDOR);
1282*fcf3ce44SJohn Forte #else
1283*fcf3ce44SJohn Forte     attributes->VName[0] = '\0';
1284*fcf3ce44SJohn Forte #endif
1285*fcf3ce44SJohn Forte #if defined(VERSION)
1286*fcf3ce44SJohn Forte     strcpy(attributes->VVersion, VERSION);
1287*fcf3ce44SJohn Forte #else
1288*fcf3ce44SJohn Forte     attributes->VVersion[0] = '\0';
1289*fcf3ce44SJohn Forte #endif
1290*fcf3ce44SJohn Forte #if defined(BUILD_DATE)
1291*fcf3ce44SJohn Forte #if defined(WIN32)
1292*fcf3ce44SJohn Forte     {
1293*fcf3ce44SJohn Forte 	int matchCount;
1294*fcf3ce44SJohn Forte 	matchCount = sscanf(BUILD_DATE, "%u/%u/%u %u:%u:%u",
1295*fcf3ce44SJohn Forte 		&attributes->build_date.tm_year,
1296*fcf3ce44SJohn Forte 		&attributes->build_date.tm_mon,
1297*fcf3ce44SJohn Forte 		&attributes->build_date.tm_mday,
1298*fcf3ce44SJohn Forte 		&attributes->build_date.tm_hour,
1299*fcf3ce44SJohn Forte 		&attributes->build_date.tm_min,
1300*fcf3ce44SJohn Forte 		&attributes->build_date.tm_sec
1301*fcf3ce44SJohn Forte 	);
1302*fcf3ce44SJohn Forte 
1303*fcf3ce44SJohn Forte 	if ( matchCount != 6 ) {
1304*fcf3ce44SJohn Forte 	    memset(&attributes->build_date, 0, sizeof(struct tm));
1305*fcf3ce44SJohn Forte 	} else {
1306*fcf3ce44SJohn Forte 	    attributes->build_date.tm_year -= 1900;
1307*fcf3ce44SJohn Forte 	    attributes->build_date.tm_isdst = -1;
1308*fcf3ce44SJohn Forte 	}
1309*fcf3ce44SJohn Forte 
1310*fcf3ce44SJohn Forte     }
1311*fcf3ce44SJohn Forte #else
1312*fcf3ce44SJohn Forte     if(strptime(BUILD_DATE, "%Y/%m/%d %T %Z", &(attributes->build_date)) == NULL) {
1313*fcf3ce44SJohn Forte 	memset(&attributes->build_date, 0, sizeof(struct tm));
1314*fcf3ce44SJohn Forte     }
1315*fcf3ce44SJohn Forte #endif
1316*fcf3ce44SJohn Forte #else
1317*fcf3ce44SJohn Forte     memset(&attributes->build_date, 0, sizeof(struct tm));
1318*fcf3ce44SJohn Forte #endif
1319*fcf3ce44SJohn Forte     return 2;
1320*fcf3ce44SJohn Forte }
1321*fcf3ce44SJohn Forte 
1322*fcf3ce44SJohn Forte /*
1323*fcf3ce44SJohn Forte  * Callback registation and handling
1324*fcf3ce44SJohn Forte  */
1325*fcf3ce44SJohn Forte HBA_STATUS
1326*fcf3ce44SJohn Forte HBA_RemoveCallback (HBA_CALLBACKHANDLE cbhandle) {
1327*fcf3ce44SJohn Forte     HBA_STATUS	status;
1328*fcf3ce44SJohn Forte 
1329*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RemoveCallback", 0, 0, 0);
1330*fcf3ce44SJohn Forte     ARE_WE_INITED();
1331*fcf3ce44SJohn Forte 
1332*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex);
1333*fcf3ce44SJohn Forte     status = local_remove_callback(cbhandle);
1334*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1335*fcf3ce44SJohn Forte }
1336*fcf3ce44SJohn Forte 
1337*fcf3ce44SJohn Forte /* Adapter Add Events *********************************************************/
1338*fcf3ce44SJohn Forte static void
1339*fcf3ce44SJohn Forte adapteraddevents_callback (void *data, HBA_WWN PortWWN, HBA_UINT32 eventType) {
1340*fcf3ce44SJohn Forte     HBA_ALLADAPTERSCALLBACK_ELEM	*cbp;
1341*fcf3ce44SJohn Forte 
1342*fcf3ce44SJohn Forte     DEBUG(3, "AddAdapterEvent, port:%s", WWN2STR1(&PortWWN), 0, 0);
1343*fcf3ce44SJohn Forte 
1344*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AAE_mutex);
1345*fcf3ce44SJohn Forte     for(cbp = _hbaapi_adapteraddevents_callback_list;
1346*fcf3ce44SJohn Forte 	cbp != NULL;
1347*fcf3ce44SJohn Forte 	cbp = cbp->next) {
1348*fcf3ce44SJohn Forte 	(*cbp->callback)(data, PortWWN, HBA_EVENT_ADAPTER_ADD);
1349*fcf3ce44SJohn Forte     }
1350*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1351*fcf3ce44SJohn Forte 
1352*fcf3ce44SJohn Forte }
1353*fcf3ce44SJohn Forte HBA_STATUS
1354*fcf3ce44SJohn Forte HBA_RegisterForAdapterAddEvents (
1355*fcf3ce44SJohn Forte     void		(*callback) (
1356*fcf3ce44SJohn Forte 	void		*data,
1357*fcf3ce44SJohn Forte 	HBA_WWN		PortWWN,
1358*fcf3ce44SJohn Forte 	HBA_UINT32	eventType
1359*fcf3ce44SJohn Forte 	),
1360*fcf3ce44SJohn Forte     void		*userData,
1361*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE *callbackHandle) {
1362*fcf3ce44SJohn Forte 
1363*fcf3ce44SJohn Forte     HBA_ALLADAPTERSCALLBACK_ELEM	*cbp;
1364*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM		*vcbp;
1365*fcf3ce44SJohn Forte     HBA_VENDORCALLBACK_ELEM		*vendorhandlelist;
1366*fcf3ce44SJohn Forte     HBARegisterForAdapterAddEventsFunc	registeredfunc;
1367*fcf3ce44SJohn Forte     HBA_STATUS				status = HBA_STATUS_OK;
1368*fcf3ce44SJohn Forte     HBA_STATUS				failure = HBA_STATUS_OK;
1369*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO			*lib_infop;
1370*fcf3ce44SJohn Forte     int					registered_cnt = 0;
1371*fcf3ce44SJohn Forte     int					vendor_cnt = 0;
1372*fcf3ce44SJohn Forte     int					not_supported_cnt = 0;
1373*fcf3ce44SJohn Forte     int					status_OK_bar_cnt = 0;
1374*fcf3ce44SJohn Forte     int					status_OK_cnt = 0;
1375*fcf3ce44SJohn Forte 
1376*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RegisterForAdapterAddEvents", 0, 0, 0);
1377*fcf3ce44SJohn Forte 
1378*fcf3ce44SJohn Forte     if (callbackHandle == NULL) {
1379*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1380*fcf3ce44SJohn Forte     }
1381*fcf3ce44SJohn Forte     ARE_WE_INITED();
1382*fcf3ce44SJohn Forte 
1383*fcf3ce44SJohn Forte     cbp = (HBA_ALLADAPTERSCALLBACK_ELEM *)
1384*fcf3ce44SJohn Forte 	calloc(1, sizeof(HBA_ALLADAPTERSCALLBACK_ELEM));
1385*fcf3ce44SJohn Forte     *callbackHandle = (HBA_CALLBACKHANDLE) cbp;
1386*fcf3ce44SJohn Forte     if(cbp == NULL) {
1387*fcf3ce44SJohn Forte #ifndef WIN32
1388*fcf3ce44SJohn Forte 	fprintf(stderr,
1389*fcf3ce44SJohn Forte 		"HBA_RegisterForAdapterAddEvents: calloc failed for %d bytes\n",
1390*fcf3ce44SJohn Forte 		sizeof(HBA_ALLADAPTERSCALLBACK_ELEM));
1391*fcf3ce44SJohn Forte #endif
1392*fcf3ce44SJohn Forte 	return HBA_STATUS_ERROR;
1393*fcf3ce44SJohn Forte     }
1394*fcf3ce44SJohn Forte 
1395*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex);
1396*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AAE_mutex);
1397*fcf3ce44SJohn Forte     cbp->callback = callback;
1398*fcf3ce44SJohn Forte     cbp->next = _hbaapi_adapteraddevents_callback_list;
1399*fcf3ce44SJohn Forte     _hbaapi_adapteraddevents_callback_list = cbp;
1400*fcf3ce44SJohn Forte     /* Need to release the mutex now incase the vendor function invokes the
1401*fcf3ce44SJohn Forte      * callback.  We will grap the mutex later to attach the vendor handle list
1402*fcf3ce44SJohn Forte      * to the callback structure */
1403*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1404*fcf3ce44SJohn Forte 
1405*fcf3ce44SJohn Forte 
1406*fcf3ce44SJohn Forte     /*
1407*fcf3ce44SJohn Forte      * now create a list of vendors (vendor libraryies, NOT ADAPTERS) that have
1408*fcf3ce44SJohn Forte      * successfully registerred
1409*fcf3ce44SJohn Forte      */
1410*fcf3ce44SJohn Forte     vendorhandlelist = NULL;
1411*fcf3ce44SJohn Forte     for(lib_infop = _hbaapi_librarylist;
1412*fcf3ce44SJohn Forte 	lib_infop != NULL;
1413*fcf3ce44SJohn Forte 	lib_infop = lib_infop->next) {
1414*fcf3ce44SJohn Forte 
1415*fcf3ce44SJohn Forte 	vendor_cnt++;
1416*fcf3ce44SJohn Forte 
1417*fcf3ce44SJohn Forte 	registeredfunc =
1418*fcf3ce44SJohn Forte 	    lib_infop->functionTable.RegisterForAdapterAddEventsHandler;
1419*fcf3ce44SJohn Forte 	if(registeredfunc == NULL) {
1420*fcf3ce44SJohn Forte 	    continue;
1421*fcf3ce44SJohn Forte 	}
1422*fcf3ce44SJohn Forte 
1423*fcf3ce44SJohn Forte 	vcbp = (HBA_VENDORCALLBACK_ELEM *)
1424*fcf3ce44SJohn Forte 	    calloc(1, sizeof(HBA_VENDORCALLBACK_ELEM));
1425*fcf3ce44SJohn Forte 	if(vcbp == NULL) {
1426*fcf3ce44SJohn Forte #ifndef WIN32
1427*fcf3ce44SJohn Forte 	    fprintf(stderr,
1428*fcf3ce44SJohn Forte 		    "HBA_RegisterForAdapterAddEvents: "
1429*fcf3ce44SJohn Forte 		    "calloc failed for %d bytes\n",
1430*fcf3ce44SJohn Forte 		    sizeof(HBA_VENDORCALLBACK_ELEM));
1431*fcf3ce44SJohn Forte #endif
1432*fcf3ce44SJohn Forte 	    freevendorhandlelist(vendorhandlelist);
1433*fcf3ce44SJohn Forte 	    status = HBA_STATUS_ERROR;
1434*fcf3ce44SJohn Forte 	    break;
1435*fcf3ce44SJohn Forte 	}
1436*fcf3ce44SJohn Forte 
1437*fcf3ce44SJohn Forte 	registered_cnt++;
1438*fcf3ce44SJohn Forte 	status = (registeredfunc)(adapteraddevents_callback,
1439*fcf3ce44SJohn Forte 				  userData, &vcbp->vendorcbhandle);
1440*fcf3ce44SJohn Forte 	if(status == HBA_STATUS_ERROR_NOT_SUPPORTED) {
1441*fcf3ce44SJohn Forte 	    not_supported_cnt++;
1442*fcf3ce44SJohn Forte 	    free(vcbp);
1443*fcf3ce44SJohn Forte 	    continue;
1444*fcf3ce44SJohn Forte 	} else if (status != HBA_STATUS_OK) {
1445*fcf3ce44SJohn Forte 	    status_OK_bar_cnt++;
1446*fcf3ce44SJohn Forte 	    DEBUG(0,
1447*fcf3ce44SJohn Forte 		  "HBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
1448*fcf3ce44SJohn Forte 		  lib_infop->LibraryPath, status, 0);
1449*fcf3ce44SJohn Forte #ifndef WIN32
1450*fcf3ce44SJohn Forte 	    fprintf(stderr,
1451*fcf3ce44SJohn Forte 		    "HBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
1452*fcf3ce44SJohn Forte 		    lib_infop->LibraryPath, status);
1453*fcf3ce44SJohn Forte #endif
1454*fcf3ce44SJohn Forte 	    failure = status;
1455*fcf3ce44SJohn Forte 	    free(vcbp);
1456*fcf3ce44SJohn Forte 	    continue;
1457*fcf3ce44SJohn Forte 	} else {
1458*fcf3ce44SJohn Forte 	    status_OK_cnt++;
1459*fcf3ce44SJohn Forte 	}
1460*fcf3ce44SJohn Forte 	vcbp->lib_info = lib_infop;
1461*fcf3ce44SJohn Forte 	vcbp->next = vendorhandlelist;
1462*fcf3ce44SJohn Forte 	vendorhandlelist = vcbp;
1463*fcf3ce44SJohn Forte     }
1464*fcf3ce44SJohn Forte     if(registered_cnt == 0) {
1465*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
1466*fcf3ce44SJohn Forte 	freevendorhandlelist(vendorhandlelist);
1467*fcf3ce44SJohn Forte 	local_remove_callback((HBA_CALLBACKHANDLE) cbp);
1468*fcf3ce44SJohn Forte     } else if (status_OK_cnt == 0 && not_supported_cnt != 0) {
1469*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
1470*fcf3ce44SJohn Forte     } else if (status_OK_cnt == 0) {
1471*fcf3ce44SJohn Forte 	/* At least one vendor library registered this function, but no
1472*fcf3ce44SJohn Forte 	 * vendor call succeeded */
1473*fcf3ce44SJohn Forte 	local_remove_callback((HBA_CALLBACKHANDLE) cbp);
1474*fcf3ce44SJohn Forte 	status = failure;
1475*fcf3ce44SJohn Forte     } else {
1476*fcf3ce44SJohn Forte 	/* we have had atleast some success, now finish up */
1477*fcf3ce44SJohn Forte 	GRAB_MUTEX(&_hbaapi_AAE_mutex);
1478*fcf3ce44SJohn Forte 	/* this seems silly, but what if another thread called
1479*fcf3ce44SJohn Forte 	 * the callback remove */
1480*fcf3ce44SJohn Forte 	for(cbp = _hbaapi_adapteraddevents_callback_list;
1481*fcf3ce44SJohn Forte 	    cbp != NULL; cbp = cbp->next) {
1482*fcf3ce44SJohn Forte 	    if((HBA_CALLBACKHANDLE)cbp == *callbackHandle) {
1483*fcf3ce44SJohn Forte 		/* yup, its still there, hooray */
1484*fcf3ce44SJohn Forte 		cbp->vendorhandlelist = vendorhandlelist;
1485*fcf3ce44SJohn Forte 		vendorhandlelist = NULL;
1486*fcf3ce44SJohn Forte 		break;
1487*fcf3ce44SJohn Forte 	    }
1488*fcf3ce44SJohn Forte 	}
1489*fcf3ce44SJohn Forte 	RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1490*fcf3ce44SJohn Forte 	if(vendorhandlelist != NULL) {
1491*fcf3ce44SJohn Forte 	    /* bummer, somebody removed the callback before we finished
1492*fcf3ce44SJohn Forte 	     * registration, probably will never happen */
1493*fcf3ce44SJohn Forte 	    freevendorhandlelist(vendorhandlelist);
1494*fcf3ce44SJohn Forte 	    DEBUG(0,
1495*fcf3ce44SJohn Forte 		  "HBA_RegisterForAdapterAddEvents: HBA_RemoveCallback was "
1496*fcf3ce44SJohn Forte 		  "called for a handle before registration was finished.",
1497*fcf3ce44SJohn Forte 		  0, 0, 0);
1498*fcf3ce44SJohn Forte 	    status = HBA_STATUS_ERROR;
1499*fcf3ce44SJohn Forte 	} else {
1500*fcf3ce44SJohn Forte 	    status = HBA_STATUS_OK;
1501*fcf3ce44SJohn Forte 	}
1502*fcf3ce44SJohn Forte     }
1503*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1504*fcf3ce44SJohn Forte }
1505*fcf3ce44SJohn Forte 
1506*fcf3ce44SJohn Forte /* Adapter Events (other than add) ********************************************/
1507*fcf3ce44SJohn Forte static void
1508*fcf3ce44SJohn Forte adapterevents_callback (void *data,
1509*fcf3ce44SJohn Forte 			HBA_WWN PortWWN,
1510*fcf3ce44SJohn Forte 			HBA_UINT32 eventType) {
1511*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1512*fcf3ce44SJohn Forte 
1513*fcf3ce44SJohn Forte     DEBUG(3, "AdapterEvent, port:%s, eventType:%d", WWN2STR1(&PortWWN),
1514*fcf3ce44SJohn Forte 	  eventType, 0);
1515*fcf3ce44SJohn Forte 
1516*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AE_mutex);
1517*fcf3ce44SJohn Forte     for(acbp = _hbaapi_adapterevents_callback_list;
1518*fcf3ce44SJohn Forte 	acbp != NULL;
1519*fcf3ce44SJohn Forte 	acbp = acbp->next) {
1520*fcf3ce44SJohn Forte 	if(data == (void *)acbp) {
1521*fcf3ce44SJohn Forte 	    (*acbp->callback)(acbp->userdata, PortWWN, eventType);
1522*fcf3ce44SJohn Forte 	    break;
1523*fcf3ce44SJohn Forte 	}
1524*fcf3ce44SJohn Forte     }
1525*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AE_mutex);
1526*fcf3ce44SJohn Forte }
1527*fcf3ce44SJohn Forte HBA_STATUS
1528*fcf3ce44SJohn Forte HBA_RegisterForAdapterEvents (
1529*fcf3ce44SJohn Forte     void		(*callback) (
1530*fcf3ce44SJohn Forte 	void		*data,
1531*fcf3ce44SJohn Forte 	HBA_WWN		PortWWN,
1532*fcf3ce44SJohn Forte 	HBA_UINT32	eventType
1533*fcf3ce44SJohn Forte 	),
1534*fcf3ce44SJohn Forte     void		*userData,
1535*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
1536*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE	*callbackHandle) {
1537*fcf3ce44SJohn Forte 
1538*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM		*acbp;
1539*fcf3ce44SJohn Forte     HBARegisterForAdapterEventsFunc	registeredfunc;
1540*fcf3ce44SJohn Forte     HBA_STATUS				status;
1541*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO			*lib_infop;
1542*fcf3ce44SJohn Forte     HBA_HANDLE				vendorHandle;
1543*fcf3ce44SJohn Forte 
1544*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RegisterForAdapterEvents", 0, 0, 0);
1545*fcf3ce44SJohn Forte 
1546*fcf3ce44SJohn Forte     if (callbackHandle == NULL) {
1547*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1548*fcf3ce44SJohn Forte     }
1549*fcf3ce44SJohn Forte 
1550*fcf3ce44SJohn Forte     CHECKLIBRARY();
1551*fcf3ce44SJohn Forte 
1552*fcf3ce44SJohn Forte     /* we now have the _hbaapi_LL_mutex */
1553*fcf3ce44SJohn Forte 
1554*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.RegisterForAdapterEventsHandler;
1555*fcf3ce44SJohn Forte     if(registeredfunc == NULL) {
1556*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1557*fcf3ce44SJohn Forte     }
1558*fcf3ce44SJohn Forte 
1559*fcf3ce44SJohn Forte     /*
1560*fcf3ce44SJohn Forte      * that allocated memory is used both as the handle for the
1561*fcf3ce44SJohn Forte      * caller, and as userdata to the vendor call so that on
1562*fcf3ce44SJohn Forte      * callback the specific registration may be recalled
1563*fcf3ce44SJohn Forte      */
1564*fcf3ce44SJohn Forte     acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1565*fcf3ce44SJohn Forte 	calloc(1, sizeof(HBA_ADAPTERCALLBACK_ELEM));
1566*fcf3ce44SJohn Forte     if(acbp == NULL) {
1567*fcf3ce44SJohn Forte #ifndef WIN32
1568*fcf3ce44SJohn Forte 	fprintf(stderr,
1569*fcf3ce44SJohn Forte 		"HBA_RegisterForAdapterEvents: calloc failed for %d bytes\n",
1570*fcf3ce44SJohn Forte 		sizeof(HBA_ADAPTERCALLBACK_ELEM));
1571*fcf3ce44SJohn Forte #endif
1572*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1573*fcf3ce44SJohn Forte     }
1574*fcf3ce44SJohn Forte     *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1575*fcf3ce44SJohn Forte     acbp->callback = callback;
1576*fcf3ce44SJohn Forte     acbp->userdata = userData;
1577*fcf3ce44SJohn Forte     acbp->lib_info = lib_infop;
1578*fcf3ce44SJohn Forte 
1579*fcf3ce44SJohn Forte     status = (registeredfunc)(adapterevents_callback,
1580*fcf3ce44SJohn Forte 			      (void *)acbp,
1581*fcf3ce44SJohn Forte 			      vendorHandle,
1582*fcf3ce44SJohn Forte 			      &acbp->vendorcbhandle);
1583*fcf3ce44SJohn Forte     if(status != HBA_STATUS_OK) {
1584*fcf3ce44SJohn Forte 	free(acbp);
1585*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1586*fcf3ce44SJohn Forte     }
1587*fcf3ce44SJohn Forte 
1588*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AE_mutex);
1589*fcf3ce44SJohn Forte     acbp->next = _hbaapi_adapterevents_callback_list;
1590*fcf3ce44SJohn Forte     _hbaapi_adapterevents_callback_list = acbp;
1591*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AE_mutex);
1592*fcf3ce44SJohn Forte 
1593*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1594*fcf3ce44SJohn Forte }
1595*fcf3ce44SJohn Forte 
1596*fcf3ce44SJohn Forte /* Adapter Port Events ********************************************************/
1597*fcf3ce44SJohn Forte static void
1598*fcf3ce44SJohn Forte adapterportevents_callback (void *data,
1599*fcf3ce44SJohn Forte 			    HBA_WWN PortWWN,
1600*fcf3ce44SJohn Forte 			    HBA_UINT32 eventType,
1601*fcf3ce44SJohn Forte 			    HBA_UINT32 fabricPortID) {
1602*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1603*fcf3ce44SJohn Forte 
1604*fcf3ce44SJohn Forte     DEBUG(3, "AdapterPortEvent, port:%s, eventType:%d fabricPortID:0X%06x",
1605*fcf3ce44SJohn Forte 	  WWN2STR1(&PortWWN), eventType, fabricPortID);
1606*fcf3ce44SJohn Forte 
1607*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_APE_mutex);
1608*fcf3ce44SJohn Forte 
1609*fcf3ce44SJohn Forte     for(acbp = _hbaapi_adapterportevents_callback_list;
1610*fcf3ce44SJohn Forte 	acbp != NULL;
1611*fcf3ce44SJohn Forte 	acbp = acbp->next) {
1612*fcf3ce44SJohn Forte 	if(data == (void *)acbp) {
1613*fcf3ce44SJohn Forte 	    (*acbp->callback)(acbp->userdata, PortWWN, eventType, fabricPortID);
1614*fcf3ce44SJohn Forte 	    break;
1615*fcf3ce44SJohn Forte 	}
1616*fcf3ce44SJohn Forte     }
1617*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_APE_mutex);
1618*fcf3ce44SJohn Forte }
1619*fcf3ce44SJohn Forte HBA_STATUS
1620*fcf3ce44SJohn Forte HBA_RegisterForAdapterPortEvents (
1621*fcf3ce44SJohn Forte     void		(*callback) (
1622*fcf3ce44SJohn Forte 	void		*data,
1623*fcf3ce44SJohn Forte 	HBA_WWN		PortWWN,
1624*fcf3ce44SJohn Forte 	HBA_UINT32	eventType,
1625*fcf3ce44SJohn Forte 	HBA_UINT32	fabricPortID
1626*fcf3ce44SJohn Forte 	),
1627*fcf3ce44SJohn Forte     void		*userData,
1628*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
1629*fcf3ce44SJohn Forte     HBA_WWN		PortWWN,
1630*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE	*callbackHandle) {
1631*fcf3ce44SJohn Forte 
1632*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM		*acbp;
1633*fcf3ce44SJohn Forte     HBARegisterForAdapterPortEventsFunc	registeredfunc;
1634*fcf3ce44SJohn Forte     HBA_STATUS				status;
1635*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO			*lib_infop;
1636*fcf3ce44SJohn Forte     HBA_HANDLE				vendorHandle;
1637*fcf3ce44SJohn Forte 
1638*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RegisterForAdapterPortEvents for port: %s",
1639*fcf3ce44SJohn Forte 	  WWN2STR1(&PortWWN), 0, 0);
1640*fcf3ce44SJohn Forte 
1641*fcf3ce44SJohn Forte     if (callbackHandle == NULL) {
1642*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1643*fcf3ce44SJohn Forte     }
1644*fcf3ce44SJohn Forte 
1645*fcf3ce44SJohn Forte     CHECKLIBRARY();
1646*fcf3ce44SJohn Forte     /* we now have the _hbaapi_LL_mutex */
1647*fcf3ce44SJohn Forte 
1648*fcf3ce44SJohn Forte     registeredfunc =
1649*fcf3ce44SJohn Forte 	lib_infop->functionTable.RegisterForAdapterPortEventsHandler;
1650*fcf3ce44SJohn Forte     if(registeredfunc == NULL) {
1651*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1652*fcf3ce44SJohn Forte     }
1653*fcf3ce44SJohn Forte 
1654*fcf3ce44SJohn Forte     /*
1655*fcf3ce44SJohn Forte      * that allocated memory is used both as the handle for the
1656*fcf3ce44SJohn Forte      * caller, and as userdata to the vendor call so that on
1657*fcf3ce44SJohn Forte      * callback the specific registration may be recalled
1658*fcf3ce44SJohn Forte      */
1659*fcf3ce44SJohn Forte     acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1660*fcf3ce44SJohn Forte 	calloc(1, sizeof(HBA_ADAPTERCALLBACK_ELEM));
1661*fcf3ce44SJohn Forte     if(acbp == NULL) {
1662*fcf3ce44SJohn Forte #ifndef WIN32
1663*fcf3ce44SJohn Forte 	fprintf(stderr,
1664*fcf3ce44SJohn Forte 		"HBA_RegisterForAdapterPortEvents: "
1665*fcf3ce44SJohn Forte 		"calloc failed for %d bytes\n",
1666*fcf3ce44SJohn Forte 		sizeof(HBA_ADAPTERCALLBACK_ELEM));
1667*fcf3ce44SJohn Forte #endif
1668*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1669*fcf3ce44SJohn Forte 
1670*fcf3ce44SJohn Forte     }
1671*fcf3ce44SJohn Forte     *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1672*fcf3ce44SJohn Forte     acbp->callback = callback;
1673*fcf3ce44SJohn Forte     acbp->userdata = userData;
1674*fcf3ce44SJohn Forte     acbp->lib_info = lib_infop;
1675*fcf3ce44SJohn Forte 
1676*fcf3ce44SJohn Forte     status = (registeredfunc)(adapterportevents_callback,
1677*fcf3ce44SJohn Forte 			      (void *)acbp,
1678*fcf3ce44SJohn Forte 			      vendorHandle,
1679*fcf3ce44SJohn Forte 			      PortWWN,
1680*fcf3ce44SJohn Forte 			      &acbp->vendorcbhandle);
1681*fcf3ce44SJohn Forte     if(status != HBA_STATUS_OK) {
1682*fcf3ce44SJohn Forte 	free(acbp);
1683*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1684*fcf3ce44SJohn Forte     }
1685*fcf3ce44SJohn Forte 
1686*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_APE_mutex);
1687*fcf3ce44SJohn Forte     acbp->next = _hbaapi_adapterportevents_callback_list;
1688*fcf3ce44SJohn Forte     _hbaapi_adapterportevents_callback_list = acbp;
1689*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_APE_mutex);
1690*fcf3ce44SJohn Forte 
1691*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1692*fcf3ce44SJohn Forte }
1693*fcf3ce44SJohn Forte 
1694*fcf3ce44SJohn Forte /* Adapter State Events *******************************************************/
1695*fcf3ce44SJohn Forte static void
1696*fcf3ce44SJohn Forte adapterportstatevents_callback (void *data,
1697*fcf3ce44SJohn Forte 				HBA_WWN PortWWN,
1698*fcf3ce44SJohn Forte 				HBA_UINT32 eventType) {
1699*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1700*fcf3ce44SJohn Forte 
1701*fcf3ce44SJohn Forte     DEBUG(3, "AdapterPortStateEvent, port:%s, eventType:%d", WWN2STR1(&PortWWN),
1702*fcf3ce44SJohn Forte 	  eventType, 0);
1703*fcf3ce44SJohn Forte 
1704*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_APSE_mutex);
1705*fcf3ce44SJohn Forte     for(acbp = _hbaapi_adapterportstatevents_callback_list;
1706*fcf3ce44SJohn Forte 	acbp != NULL;
1707*fcf3ce44SJohn Forte 	acbp = acbp->next) {
1708*fcf3ce44SJohn Forte 	if(data == (void *)acbp) {
1709*fcf3ce44SJohn Forte 	    (*acbp->callback)(acbp->userdata, PortWWN, eventType);
1710*fcf3ce44SJohn Forte 	    return;
1711*fcf3ce44SJohn Forte 	}
1712*fcf3ce44SJohn Forte     }
1713*fcf3ce44SJohn Forte }
1714*fcf3ce44SJohn Forte HBA_STATUS
1715*fcf3ce44SJohn Forte HBA_RegisterForAdapterPortStatEvents (
1716*fcf3ce44SJohn Forte     void		(*callback) (
1717*fcf3ce44SJohn Forte 	void		*data,
1718*fcf3ce44SJohn Forte 	HBA_WWN		PortWWN,
1719*fcf3ce44SJohn Forte 	HBA_UINT32	eventType
1720*fcf3ce44SJohn Forte 	),
1721*fcf3ce44SJohn Forte     void		*userData,
1722*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
1723*fcf3ce44SJohn Forte     HBA_WWN		PortWWN,
1724*fcf3ce44SJohn Forte     HBA_PORTSTATISTICS	stats,
1725*fcf3ce44SJohn Forte     HBA_UINT32		statType,
1726*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE	*callbackHandle) {
1727*fcf3ce44SJohn Forte 
1728*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1729*fcf3ce44SJohn Forte     HBARegisterForAdapterPortStatEventsFunc
1730*fcf3ce44SJohn Forte 				registeredfunc;
1731*fcf3ce44SJohn Forte     HBA_STATUS			status;
1732*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO		*lib_infop;
1733*fcf3ce44SJohn Forte     HBA_HANDLE			vendorHandle;
1734*fcf3ce44SJohn Forte 
1735*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RegisterForAdapterPortStatEvents for port: %s",
1736*fcf3ce44SJohn Forte 	  WWN2STR1(&PortWWN), 0, 0);
1737*fcf3ce44SJohn Forte 
1738*fcf3ce44SJohn Forte     if (callbackHandle == NULL) {
1739*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1740*fcf3ce44SJohn Forte     }
1741*fcf3ce44SJohn Forte 
1742*fcf3ce44SJohn Forte     CHECKLIBRARY();
1743*fcf3ce44SJohn Forte     /* we now have the _hbaapi_LL_mutex */
1744*fcf3ce44SJohn Forte 
1745*fcf3ce44SJohn Forte     registeredfunc =
1746*fcf3ce44SJohn Forte 	lib_infop->functionTable.RegisterForAdapterPortStatEventsHandler;
1747*fcf3ce44SJohn Forte     if(registeredfunc == NULL) {
1748*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1749*fcf3ce44SJohn Forte     }
1750*fcf3ce44SJohn Forte 
1751*fcf3ce44SJohn Forte     /*
1752*fcf3ce44SJohn Forte      * that allocated memory is used both as the handle for the
1753*fcf3ce44SJohn Forte      * caller, and as userdata to the vendor call so that on
1754*fcf3ce44SJohn Forte      * callback the specific registration may be recalled
1755*fcf3ce44SJohn Forte      */
1756*fcf3ce44SJohn Forte     acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1757*fcf3ce44SJohn Forte 	calloc(1, sizeof(HBA_ADAPTERCALLBACK_ELEM));
1758*fcf3ce44SJohn Forte     if(acbp == NULL) {
1759*fcf3ce44SJohn Forte #ifndef WIN32
1760*fcf3ce44SJohn Forte 	fprintf(stderr,
1761*fcf3ce44SJohn Forte 		"HBA_RegisterForAdapterPortStatEvents: "
1762*fcf3ce44SJohn Forte 		"calloc failed for %d bytes\n",
1763*fcf3ce44SJohn Forte 		sizeof(HBA_ADAPTERCALLBACK_ELEM));
1764*fcf3ce44SJohn Forte #endif
1765*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1766*fcf3ce44SJohn Forte     }
1767*fcf3ce44SJohn Forte     *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1768*fcf3ce44SJohn Forte     acbp->callback = callback;
1769*fcf3ce44SJohn Forte     acbp->userdata = userData;
1770*fcf3ce44SJohn Forte     acbp->lib_info = lib_infop;
1771*fcf3ce44SJohn Forte 
1772*fcf3ce44SJohn Forte     status = (registeredfunc)(adapterportstatevents_callback,
1773*fcf3ce44SJohn Forte 			      (void *)acbp,
1774*fcf3ce44SJohn Forte 			      vendorHandle,
1775*fcf3ce44SJohn Forte 			      PortWWN,
1776*fcf3ce44SJohn Forte 			      stats,
1777*fcf3ce44SJohn Forte 			      statType,
1778*fcf3ce44SJohn Forte 			      &acbp->vendorcbhandle);
1779*fcf3ce44SJohn Forte     if(status != HBA_STATUS_OK) {
1780*fcf3ce44SJohn Forte 	free(acbp);
1781*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1782*fcf3ce44SJohn Forte     }
1783*fcf3ce44SJohn Forte 
1784*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_APSE_mutex);
1785*fcf3ce44SJohn Forte     acbp->next = _hbaapi_adapterportstatevents_callback_list;
1786*fcf3ce44SJohn Forte     _hbaapi_adapterportstatevents_callback_list = acbp;
1787*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_APSE_mutex);
1788*fcf3ce44SJohn Forte 
1789*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1790*fcf3ce44SJohn Forte }
1791*fcf3ce44SJohn Forte 
1792*fcf3ce44SJohn Forte /* Target Events **************************************************************/
1793*fcf3ce44SJohn Forte static void
1794*fcf3ce44SJohn Forte targetevents_callback (void *data,
1795*fcf3ce44SJohn Forte 		       HBA_WWN hbaPortWWN,
1796*fcf3ce44SJohn Forte 		       HBA_WWN discoveredPortWWN,
1797*fcf3ce44SJohn Forte 		       HBA_UINT32 eventType) {
1798*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1799*fcf3ce44SJohn Forte 
1800*fcf3ce44SJohn Forte     DEBUG(3, "TargetEvent, hbaPort:%s, discoveredPort:%s eventType:%d",
1801*fcf3ce44SJohn Forte 	  WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), eventType);
1802*fcf3ce44SJohn Forte 
1803*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_TE_mutex);
1804*fcf3ce44SJohn Forte     for(acbp = _hbaapi_targetevents_callback_list;
1805*fcf3ce44SJohn Forte 	acbp != NULL;
1806*fcf3ce44SJohn Forte 	acbp = acbp->next) {
1807*fcf3ce44SJohn Forte 	if(data == (void *)acbp) {
1808*fcf3ce44SJohn Forte 	    (*acbp->callback)(acbp->userdata, hbaPortWWN,
1809*fcf3ce44SJohn Forte 			      discoveredPortWWN, eventType);
1810*fcf3ce44SJohn Forte 	    break;
1811*fcf3ce44SJohn Forte 	}
1812*fcf3ce44SJohn Forte     }
1813*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_TE_mutex);
1814*fcf3ce44SJohn Forte }
1815*fcf3ce44SJohn Forte HBA_STATUS
1816*fcf3ce44SJohn Forte HBA_RegisterForTargetEvents (
1817*fcf3ce44SJohn Forte     void		(*callback) (
1818*fcf3ce44SJohn Forte 	void		*data,
1819*fcf3ce44SJohn Forte 	HBA_WWN		hbaPortWWN,
1820*fcf3ce44SJohn Forte 	HBA_WWN		discoveredPortWWN,
1821*fcf3ce44SJohn Forte 	HBA_UINT32	eventType
1822*fcf3ce44SJohn Forte 	),
1823*fcf3ce44SJohn Forte     void		*userData,
1824*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
1825*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
1826*fcf3ce44SJohn Forte     HBA_WWN		discoveredPortWWN,
1827*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE	*callbackHandle,
1828*fcf3ce44SJohn Forte     HBA_UINT32		allTargets) {
1829*fcf3ce44SJohn Forte 
1830*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM
1831*fcf3ce44SJohn Forte 			*acbp;
1832*fcf3ce44SJohn Forte     HBARegisterForTargetEventsFunc
1833*fcf3ce44SJohn Forte 			registeredfunc;
1834*fcf3ce44SJohn Forte     HBA_STATUS		status;
1835*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
1836*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
1837*fcf3ce44SJohn Forte 
1838*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RegisterForTargetEvents, hbaPort: %s, discoveredPort: %s",
1839*fcf3ce44SJohn Forte 	  WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), 0);
1840*fcf3ce44SJohn Forte 
1841*fcf3ce44SJohn Forte     if (callbackHandle == NULL) {
1842*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1843*fcf3ce44SJohn Forte     }
1844*fcf3ce44SJohn Forte 
1845*fcf3ce44SJohn Forte     CHECKLIBRARY();
1846*fcf3ce44SJohn Forte     /* we now have the _hbaapi_LL_mutex */
1847*fcf3ce44SJohn Forte 
1848*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.RegisterForTargetEventsHandler;
1849*fcf3ce44SJohn Forte     if(registeredfunc == NULL) {
1850*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1851*fcf3ce44SJohn Forte     }
1852*fcf3ce44SJohn Forte 
1853*fcf3ce44SJohn Forte     /*
1854*fcf3ce44SJohn Forte      * that allocated memory is used both as the handle for the
1855*fcf3ce44SJohn Forte      * caller, and as userdata to the vendor call so that on
1856*fcf3ce44SJohn Forte      * callback the specific registration may be recalled
1857*fcf3ce44SJohn Forte      */
1858*fcf3ce44SJohn Forte     acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1859*fcf3ce44SJohn Forte 	calloc(1, sizeof(HBA_ADAPTERCALLBACK_ELEM));
1860*fcf3ce44SJohn Forte     if(acbp == NULL) {
1861*fcf3ce44SJohn Forte #ifndef WIN32
1862*fcf3ce44SJohn Forte 	fprintf(stderr,
1863*fcf3ce44SJohn Forte 		"HBA_RegisterForTargetEvents: calloc failed for %d bytes\n",
1864*fcf3ce44SJohn Forte 		sizeof(HBA_ADAPTERCALLBACK_ELEM));
1865*fcf3ce44SJohn Forte #endif
1866*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1867*fcf3ce44SJohn Forte     }
1868*fcf3ce44SJohn Forte     *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1869*fcf3ce44SJohn Forte     acbp->callback = callback;
1870*fcf3ce44SJohn Forte     acbp->userdata = userData;
1871*fcf3ce44SJohn Forte     acbp->lib_info = lib_infop;
1872*fcf3ce44SJohn Forte 
1873*fcf3ce44SJohn Forte     status = (registeredfunc)(targetevents_callback,
1874*fcf3ce44SJohn Forte 			      (void *)acbp,
1875*fcf3ce44SJohn Forte 			      vendorHandle,
1876*fcf3ce44SJohn Forte 			      hbaPortWWN,
1877*fcf3ce44SJohn Forte 			      discoveredPortWWN,
1878*fcf3ce44SJohn Forte 			      &acbp->vendorcbhandle,
1879*fcf3ce44SJohn Forte 			      allTargets);
1880*fcf3ce44SJohn Forte     if(status != HBA_STATUS_OK) {
1881*fcf3ce44SJohn Forte 	free(acbp);
1882*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1883*fcf3ce44SJohn Forte     }
1884*fcf3ce44SJohn Forte 
1885*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_TE_mutex);
1886*fcf3ce44SJohn Forte     acbp->next = _hbaapi_targetevents_callback_list;
1887*fcf3ce44SJohn Forte     _hbaapi_targetevents_callback_list = acbp;
1888*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_TE_mutex);
1889*fcf3ce44SJohn Forte 
1890*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1891*fcf3ce44SJohn Forte }
1892*fcf3ce44SJohn Forte 
1893*fcf3ce44SJohn Forte /* Link Events ****************************************************************/
1894*fcf3ce44SJohn Forte static void
1895*fcf3ce44SJohn Forte linkevents_callback (void *data,
1896*fcf3ce44SJohn Forte 		     HBA_WWN adapterWWN,
1897*fcf3ce44SJohn Forte 		     HBA_UINT32 eventType,
1898*fcf3ce44SJohn Forte 		     void *pRLIRBuffer,
1899*fcf3ce44SJohn Forte 		     HBA_UINT32 RLIRBufferSize) {
1900*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1901*fcf3ce44SJohn Forte 
1902*fcf3ce44SJohn Forte     DEBUG(3, "LinkEvent, hbaWWN:%s, eventType:%d",
1903*fcf3ce44SJohn Forte 	  WWN2STR1(&adapterWWN), eventType, 0);
1904*fcf3ce44SJohn Forte 
1905*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LE_mutex);
1906*fcf3ce44SJohn Forte     for(acbp = _hbaapi_linkevents_callback_list;
1907*fcf3ce44SJohn Forte 	acbp != NULL;
1908*fcf3ce44SJohn Forte 	acbp = acbp->next) {
1909*fcf3ce44SJohn Forte 	if(data == (void *)acbp) {
1910*fcf3ce44SJohn Forte 	    (*acbp->callback)(acbp->userdata, adapterWWN,
1911*fcf3ce44SJohn Forte 			      eventType, pRLIRBuffer, RLIRBufferSize);
1912*fcf3ce44SJohn Forte 	    break;
1913*fcf3ce44SJohn Forte 	}
1914*fcf3ce44SJohn Forte     }
1915*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_LE_mutex);
1916*fcf3ce44SJohn Forte }
1917*fcf3ce44SJohn Forte HBA_STATUS
1918*fcf3ce44SJohn Forte HBA_RegisterForLinkEvents (
1919*fcf3ce44SJohn Forte     void		(*callback) (
1920*fcf3ce44SJohn Forte 	void		*data,
1921*fcf3ce44SJohn Forte 	HBA_WWN		adapterWWN,
1922*fcf3ce44SJohn Forte 	HBA_UINT32	eventType,
1923*fcf3ce44SJohn Forte 	void		*pRLIRBuffer,
1924*fcf3ce44SJohn Forte 	HBA_UINT32	RLIRBufferSize),
1925*fcf3ce44SJohn Forte     void		*userData,
1926*fcf3ce44SJohn Forte     void		*pRLIRBuffer,
1927*fcf3ce44SJohn Forte     HBA_UINT32		RLIRBufferSize,
1928*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
1929*fcf3ce44SJohn Forte     HBA_CALLBACKHANDLE	*callbackHandle) {
1930*fcf3ce44SJohn Forte 
1931*fcf3ce44SJohn Forte     HBA_ADAPTERCALLBACK_ELEM	*acbp;
1932*fcf3ce44SJohn Forte     HBARegisterForLinkEventsFunc
1933*fcf3ce44SJohn Forte 				registeredfunc;
1934*fcf3ce44SJohn Forte     HBA_STATUS			status;
1935*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO		*lib_infop;
1936*fcf3ce44SJohn Forte     HBA_HANDLE			vendorHandle;
1937*fcf3ce44SJohn Forte 
1938*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RegisterForLinkEvents", 0, 0, 0);
1939*fcf3ce44SJohn Forte 
1940*fcf3ce44SJohn Forte     if (callbackHandle == NULL) {
1941*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
1942*fcf3ce44SJohn Forte     }
1943*fcf3ce44SJohn Forte 
1944*fcf3ce44SJohn Forte     CHECKLIBRARY();
1945*fcf3ce44SJohn Forte     /* we now have the _hbaapi_LL_mutex */
1946*fcf3ce44SJohn Forte 
1947*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.RegisterForLinkEventsHandler;
1948*fcf3ce44SJohn Forte     if(registeredfunc == NULL) {
1949*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1950*fcf3ce44SJohn Forte     }
1951*fcf3ce44SJohn Forte 
1952*fcf3ce44SJohn Forte     /*
1953*fcf3ce44SJohn Forte      * that allocated memory is used both as the handle for the
1954*fcf3ce44SJohn Forte      * caller, and as userdata to the vendor call so that on
1955*fcf3ce44SJohn Forte      * callback the specific registration may be recalled
1956*fcf3ce44SJohn Forte      */
1957*fcf3ce44SJohn Forte     acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1958*fcf3ce44SJohn Forte 	calloc(1, sizeof(HBA_ADAPTERCALLBACK_ELEM));
1959*fcf3ce44SJohn Forte     if(acbp == NULL) {
1960*fcf3ce44SJohn Forte #ifndef WIN32
1961*fcf3ce44SJohn Forte 	fprintf(stderr,
1962*fcf3ce44SJohn Forte 		"HBA_RegisterForLinkEvents: calloc failed for %d bytes\n",
1963*fcf3ce44SJohn Forte 		sizeof(HBA_ADAPTERCALLBACK_ELEM));
1964*fcf3ce44SJohn Forte #endif
1965*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1966*fcf3ce44SJohn Forte     }
1967*fcf3ce44SJohn Forte     *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1968*fcf3ce44SJohn Forte     acbp->callback = callback;
1969*fcf3ce44SJohn Forte     acbp->userdata = userData;
1970*fcf3ce44SJohn Forte     acbp->lib_info = lib_infop;
1971*fcf3ce44SJohn Forte 
1972*fcf3ce44SJohn Forte     status = (registeredfunc)(linkevents_callback,
1973*fcf3ce44SJohn Forte 			      (void *)acbp,
1974*fcf3ce44SJohn Forte 			      pRLIRBuffer,
1975*fcf3ce44SJohn Forte 			      RLIRBufferSize,
1976*fcf3ce44SJohn Forte 			      vendorHandle,
1977*fcf3ce44SJohn Forte 			      &acbp->vendorcbhandle);
1978*fcf3ce44SJohn Forte     if(status != HBA_STATUS_OK) {
1979*fcf3ce44SJohn Forte 	free(acbp);
1980*fcf3ce44SJohn Forte 	RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1981*fcf3ce44SJohn Forte     }
1982*fcf3ce44SJohn Forte 
1983*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LE_mutex);
1984*fcf3ce44SJohn Forte     acbp->next = _hbaapi_linkevents_callback_list;
1985*fcf3ce44SJohn Forte     _hbaapi_linkevents_callback_list = acbp;
1986*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_LE_mutex);
1987*fcf3ce44SJohn Forte 
1988*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1989*fcf3ce44SJohn Forte }
1990*fcf3ce44SJohn Forte 
1991*fcf3ce44SJohn Forte 
1992*fcf3ce44SJohn Forte /*
1993*fcf3ce44SJohn Forte  * All of the functions below are almost passthru functions to the
1994*fcf3ce44SJohn Forte  * vendor specific function
1995*fcf3ce44SJohn Forte  */
1996*fcf3ce44SJohn Forte 
1997*fcf3ce44SJohn Forte void
1998*fcf3ce44SJohn Forte HBA_CloseAdapter(HBA_HANDLE handle) {
1999*fcf3ce44SJohn Forte     HBA_STATUS		status;
2000*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2001*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2002*fcf3ce44SJohn Forte     HBACloseAdapterFunc CloseAdapterFunc;
2003*fcf3ce44SJohn Forte 
2004*fcf3ce44SJohn Forte     DEBUG(2, "HBA_CloseAdapter", 0, 0, 0);
2005*fcf3ce44SJohn Forte 
2006*fcf3ce44SJohn Forte     status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2007*fcf3ce44SJohn Forte     if (status == HBA_STATUS_OK) {
2008*fcf3ce44SJohn Forte 	CloseAdapterFunc = lib_infop->functionTable.CloseAdapterHandler;
2009*fcf3ce44SJohn Forte 	if (CloseAdapterFunc != NULL) {
2010*fcf3ce44SJohn Forte 	    ((CloseAdapterFunc)(vendorHandle));
2011*fcf3ce44SJohn Forte 	}
2012*fcf3ce44SJohn Forte 	RELEASE_MUTEX(&_hbaapi_LL_mutex);
2013*fcf3ce44SJohn Forte     }
2014*fcf3ce44SJohn Forte }
2015*fcf3ce44SJohn Forte 
2016*fcf3ce44SJohn Forte HBA_STATUS
2017*fcf3ce44SJohn Forte HBA_GetAdapterAttributes (
2018*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2019*fcf3ce44SJohn Forte     HBA_ADAPTERATTRIBUTES
2020*fcf3ce44SJohn Forte 			*hbaattributes)
2021*fcf3ce44SJohn Forte {
2022*fcf3ce44SJohn Forte     HBA_STATUS		status;
2023*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2024*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2025*fcf3ce44SJohn Forte     HBAGetAdapterAttributesFunc GetAdapterAttributesFunc;
2026*fcf3ce44SJohn Forte 
2027*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetAdapterAttributes", 0, 0, 0);
2028*fcf3ce44SJohn Forte 
2029*fcf3ce44SJohn Forte     CHECKLIBRARY();
2030*fcf3ce44SJohn Forte     GetAdapterAttributesFunc =
2031*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetAdapterAttributesHandler;
2032*fcf3ce44SJohn Forte     if (GetAdapterAttributesFunc != NULL) {
2033*fcf3ce44SJohn Forte 	status = ((GetAdapterAttributesFunc)(vendorHandle, hbaattributes));
2034*fcf3ce44SJohn Forte     } else {
2035*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2036*fcf3ce44SJohn Forte     }
2037*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2038*fcf3ce44SJohn Forte }
2039*fcf3ce44SJohn Forte 
2040*fcf3ce44SJohn Forte HBA_STATUS
2041*fcf3ce44SJohn Forte HBA_GetAdapterPortAttributes (
2042*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2043*fcf3ce44SJohn Forte     HBA_UINT32		portindex,
2044*fcf3ce44SJohn Forte     HBA_PORTATTRIBUTES	*portattributes)
2045*fcf3ce44SJohn Forte {
2046*fcf3ce44SJohn Forte     HBA_STATUS		status;
2047*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2048*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2049*fcf3ce44SJohn Forte     HBAGetAdapterPortAttributesFunc
2050*fcf3ce44SJohn Forte 			GetAdapterPortAttributesFunc;
2051*fcf3ce44SJohn Forte 
2052*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetAdapterPortAttributes", 0, 0, 0);
2053*fcf3ce44SJohn Forte 
2054*fcf3ce44SJohn Forte     CHECKLIBRARY();
2055*fcf3ce44SJohn Forte     GetAdapterPortAttributesFunc =
2056*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetAdapterPortAttributesHandler;
2057*fcf3ce44SJohn Forte     if (GetAdapterPortAttributesFunc != NULL) {
2058*fcf3ce44SJohn Forte 	status = ((GetAdapterPortAttributesFunc)
2059*fcf3ce44SJohn Forte 		  (vendorHandle, portindex, portattributes));
2060*fcf3ce44SJohn Forte     } else {
2061*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2062*fcf3ce44SJohn Forte     }
2063*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2064*fcf3ce44SJohn Forte }
2065*fcf3ce44SJohn Forte 
2066*fcf3ce44SJohn Forte HBA_STATUS
2067*fcf3ce44SJohn Forte HBA_GetPortStatistics (
2068*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2069*fcf3ce44SJohn Forte     HBA_UINT32		portindex,
2070*fcf3ce44SJohn Forte     HBA_PORTSTATISTICS	*portstatistics)
2071*fcf3ce44SJohn Forte {
2072*fcf3ce44SJohn Forte     HBA_STATUS		status;
2073*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2074*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2075*fcf3ce44SJohn Forte     HBAGetPortStatisticsFunc
2076*fcf3ce44SJohn Forte 			GetPortStatisticsFunc;
2077*fcf3ce44SJohn Forte 
2078*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetPortStatistics", 0, 0, 0);
2079*fcf3ce44SJohn Forte 
2080*fcf3ce44SJohn Forte     CHECKLIBRARY();
2081*fcf3ce44SJohn Forte     GetPortStatisticsFunc =
2082*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetPortStatisticsHandler;
2083*fcf3ce44SJohn Forte     if (GetPortStatisticsFunc != NULL) {
2084*fcf3ce44SJohn Forte 	status = ((GetPortStatisticsFunc)
2085*fcf3ce44SJohn Forte 		  (vendorHandle, portindex, portstatistics));
2086*fcf3ce44SJohn Forte     } else {
2087*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2088*fcf3ce44SJohn Forte     }
2089*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2090*fcf3ce44SJohn Forte }
2091*fcf3ce44SJohn Forte 
2092*fcf3ce44SJohn Forte HBA_STATUS
2093*fcf3ce44SJohn Forte HBA_GetDiscoveredPortAttributes (
2094*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2095*fcf3ce44SJohn Forte     HBA_UINT32		portindex,
2096*fcf3ce44SJohn Forte     HBA_UINT32		discoveredportindex,
2097*fcf3ce44SJohn Forte     HBA_PORTATTRIBUTES	*portattributes)
2098*fcf3ce44SJohn Forte {
2099*fcf3ce44SJohn Forte     HBA_STATUS		status;
2100*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2101*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2102*fcf3ce44SJohn Forte     HBAGetDiscoveredPortAttributesFunc
2103*fcf3ce44SJohn Forte 			GetDiscoveredPortAttributesFunc;
2104*fcf3ce44SJohn Forte 
2105*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetDiscoveredPortAttributes", 0, 0, 0);
2106*fcf3ce44SJohn Forte 
2107*fcf3ce44SJohn Forte     CHECKLIBRARY();
2108*fcf3ce44SJohn Forte     GetDiscoveredPortAttributesFunc =
2109*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetDiscoveredPortAttributesHandler;
2110*fcf3ce44SJohn Forte     if (GetDiscoveredPortAttributesFunc != NULL)  {
2111*fcf3ce44SJohn Forte 	status = ((GetDiscoveredPortAttributesFunc)
2112*fcf3ce44SJohn Forte 		  (vendorHandle, portindex, discoveredportindex,
2113*fcf3ce44SJohn Forte 		   portattributes));
2114*fcf3ce44SJohn Forte     } else {
2115*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2116*fcf3ce44SJohn Forte     }
2117*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2118*fcf3ce44SJohn Forte }
2119*fcf3ce44SJohn Forte 
2120*fcf3ce44SJohn Forte HBA_STATUS
2121*fcf3ce44SJohn Forte HBA_GetPortAttributesByWWN (
2122*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2123*fcf3ce44SJohn Forte     HBA_WWN		PortWWN,
2124*fcf3ce44SJohn Forte     HBA_PORTATTRIBUTES	*portattributes)
2125*fcf3ce44SJohn Forte {
2126*fcf3ce44SJohn Forte     HBA_STATUS		status;
2127*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2128*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2129*fcf3ce44SJohn Forte     HBAGetPortAttributesByWWNFunc
2130*fcf3ce44SJohn Forte 			GetPortAttributesByWWNFunc;
2131*fcf3ce44SJohn Forte 
2132*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetPortAttributesByWWN: %s", WWN2STR1(&PortWWN), 0, 0);
2133*fcf3ce44SJohn Forte 
2134*fcf3ce44SJohn Forte     CHECKLIBRARY();
2135*fcf3ce44SJohn Forte     GetPortAttributesByWWNFunc =
2136*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetPortAttributesByWWNHandler;
2137*fcf3ce44SJohn Forte     if (GetPortAttributesByWWNFunc != NULL) {
2138*fcf3ce44SJohn Forte 	status = ((GetPortAttributesByWWNFunc)
2139*fcf3ce44SJohn Forte 		  (vendorHandle, PortWWN, portattributes));
2140*fcf3ce44SJohn Forte     } else {
2141*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2142*fcf3ce44SJohn Forte     }
2143*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2144*fcf3ce44SJohn Forte }
2145*fcf3ce44SJohn Forte 
2146*fcf3ce44SJohn Forte HBA_STATUS
2147*fcf3ce44SJohn Forte HBA_SendCTPassThru (
2148*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2149*fcf3ce44SJohn Forte     void		*pReqBuffer,
2150*fcf3ce44SJohn Forte     HBA_UINT32		ReqBufferSize,
2151*fcf3ce44SJohn Forte     void		*pRspBuffer,
2152*fcf3ce44SJohn Forte     HBA_UINT32		RspBufferSize)
2153*fcf3ce44SJohn Forte {
2154*fcf3ce44SJohn Forte     HBA_STATUS		status;
2155*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2156*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2157*fcf3ce44SJohn Forte     HBASendCTPassThruFunc
2158*fcf3ce44SJohn Forte 			SendCTPassThruFunc;
2159*fcf3ce44SJohn Forte 
2160*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendCTPassThru", 0, 0, 0);
2161*fcf3ce44SJohn Forte 
2162*fcf3ce44SJohn Forte     CHECKLIBRARY();
2163*fcf3ce44SJohn Forte     SendCTPassThruFunc = lib_infop->functionTable.SendCTPassThruHandler;
2164*fcf3ce44SJohn Forte     if (SendCTPassThruFunc != NULL) {
2165*fcf3ce44SJohn Forte 	status = (SendCTPassThruFunc)
2166*fcf3ce44SJohn Forte 	    (vendorHandle,
2167*fcf3ce44SJohn Forte 	     pReqBuffer, ReqBufferSize,
2168*fcf3ce44SJohn Forte 	     pRspBuffer, RspBufferSize);
2169*fcf3ce44SJohn Forte     } else {
2170*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2171*fcf3ce44SJohn Forte     }
2172*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2173*fcf3ce44SJohn Forte }
2174*fcf3ce44SJohn Forte 
2175*fcf3ce44SJohn Forte HBA_STATUS
2176*fcf3ce44SJohn Forte HBA_SendCTPassThruV2 (
2177*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2178*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2179*fcf3ce44SJohn Forte     void		*pReqBuffer,
2180*fcf3ce44SJohn Forte     HBA_UINT32		ReqBufferSize,
2181*fcf3ce44SJohn Forte     void		*pRspBuffer,
2182*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2183*fcf3ce44SJohn Forte {
2184*fcf3ce44SJohn Forte     HBA_STATUS		status;
2185*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2186*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2187*fcf3ce44SJohn Forte     HBASendCTPassThruV2Func
2188*fcf3ce44SJohn Forte 			registeredfunc;
2189*fcf3ce44SJohn Forte 
2190*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendCTPassThruV2m hbaPortWWN: %s", WWN2STR1(&hbaPortWWN), 0, 0);
2191*fcf3ce44SJohn Forte 
2192*fcf3ce44SJohn Forte     CHECKLIBRARY();
2193*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendCTPassThruV2Handler;
2194*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2195*fcf3ce44SJohn Forte 	status = (registeredfunc)
2196*fcf3ce44SJohn Forte 	    (vendorHandle, hbaPortWWN,
2197*fcf3ce44SJohn Forte 	     pReqBuffer, ReqBufferSize,
2198*fcf3ce44SJohn Forte 	     pRspBuffer, pRspBufferSize);
2199*fcf3ce44SJohn Forte     } else {
2200*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2201*fcf3ce44SJohn Forte     }
2202*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2203*fcf3ce44SJohn Forte }
2204*fcf3ce44SJohn Forte 
2205*fcf3ce44SJohn Forte HBA_STATUS
2206*fcf3ce44SJohn Forte HBA_GetEventBuffer (
2207*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2208*fcf3ce44SJohn Forte     PHBA_EVENTINFO	EventBuffer,
2209*fcf3ce44SJohn Forte     HBA_UINT32		*EventBufferCount)
2210*fcf3ce44SJohn Forte {
2211*fcf3ce44SJohn Forte     HBA_STATUS		status;
2212*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2213*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2214*fcf3ce44SJohn Forte     HBAGetEventBufferFunc
2215*fcf3ce44SJohn Forte 			GetEventBufferFunc;
2216*fcf3ce44SJohn Forte 
2217*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetEventBuffer", 0, 0, 0);
2218*fcf3ce44SJohn Forte 
2219*fcf3ce44SJohn Forte     CHECKLIBRARY();
2220*fcf3ce44SJohn Forte     GetEventBufferFunc = lib_infop->functionTable.GetEventBufferHandler;
2221*fcf3ce44SJohn Forte     if (GetEventBufferFunc != NULL) {
2222*fcf3ce44SJohn Forte 	status = (GetEventBufferFunc)
2223*fcf3ce44SJohn Forte 	    (vendorHandle, EventBuffer, EventBufferCount);
2224*fcf3ce44SJohn Forte     } else {
2225*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2226*fcf3ce44SJohn Forte     }
2227*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2228*fcf3ce44SJohn Forte }
2229*fcf3ce44SJohn Forte 
2230*fcf3ce44SJohn Forte HBA_STATUS
2231*fcf3ce44SJohn Forte HBA_SetRNIDMgmtInfo (HBA_HANDLE handle, HBA_MGMTINFO Info) {
2232*fcf3ce44SJohn Forte     HBA_STATUS		status;
2233*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2234*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2235*fcf3ce44SJohn Forte     HBASetRNIDMgmtInfoFunc
2236*fcf3ce44SJohn Forte 			SetRNIDMgmtInfoFunc;
2237*fcf3ce44SJohn Forte 
2238*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SetRNIDMgmtInfo", 0, 0, 0);
2239*fcf3ce44SJohn Forte 
2240*fcf3ce44SJohn Forte     CHECKLIBRARY();
2241*fcf3ce44SJohn Forte     SetRNIDMgmtInfoFunc = lib_infop->functionTable.SetRNIDMgmtInfoHandler;
2242*fcf3ce44SJohn Forte     if (SetRNIDMgmtInfoFunc != NULL) {
2243*fcf3ce44SJohn Forte 	status = (SetRNIDMgmtInfoFunc)(vendorHandle, Info);
2244*fcf3ce44SJohn Forte     } else {
2245*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2246*fcf3ce44SJohn Forte     }
2247*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2248*fcf3ce44SJohn Forte }
2249*fcf3ce44SJohn Forte 
2250*fcf3ce44SJohn Forte HBA_STATUS
2251*fcf3ce44SJohn Forte HBA_GetRNIDMgmtInfo (HBA_HANDLE handle, HBA_MGMTINFO *pInfo) {
2252*fcf3ce44SJohn Forte     HBA_STATUS		status;
2253*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2254*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2255*fcf3ce44SJohn Forte     HBAGetRNIDMgmtInfoFunc
2256*fcf3ce44SJohn Forte 			 GetRNIDMgmtInfoFunc;
2257*fcf3ce44SJohn Forte 
2258*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetRNIDMgmtInfo", 0, 0, 0);
2259*fcf3ce44SJohn Forte 
2260*fcf3ce44SJohn Forte     CHECKLIBRARY();
2261*fcf3ce44SJohn Forte     GetRNIDMgmtInfoFunc = lib_infop->functionTable.GetRNIDMgmtInfoHandler;
2262*fcf3ce44SJohn Forte     if (GetRNIDMgmtInfoFunc != NULL) {
2263*fcf3ce44SJohn Forte 	status = (GetRNIDMgmtInfoFunc)(vendorHandle, pInfo);
2264*fcf3ce44SJohn Forte     } else {
2265*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2266*fcf3ce44SJohn Forte     }
2267*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2268*fcf3ce44SJohn Forte }
2269*fcf3ce44SJohn Forte 
2270*fcf3ce44SJohn Forte HBA_STATUS
2271*fcf3ce44SJohn Forte HBA_SendRNID (
2272*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2273*fcf3ce44SJohn Forte     HBA_WWN		wwn,
2274*fcf3ce44SJohn Forte     HBA_WWNTYPE		wwntype,
2275*fcf3ce44SJohn Forte     void		*pRspBuffer,
2276*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2277*fcf3ce44SJohn Forte {
2278*fcf3ce44SJohn Forte     HBA_STATUS		status;
2279*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2280*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2281*fcf3ce44SJohn Forte     HBASendRNIDFunc	SendRNIDFunc;
2282*fcf3ce44SJohn Forte 
2283*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendRNID for wwn: %s", WWN2STR1(&wwn), 0, 0);
2284*fcf3ce44SJohn Forte 
2285*fcf3ce44SJohn Forte     CHECKLIBRARY();
2286*fcf3ce44SJohn Forte     SendRNIDFunc = lib_infop->functionTable.SendRNIDHandler;
2287*fcf3ce44SJohn Forte     if (SendRNIDFunc != NULL) {
2288*fcf3ce44SJohn Forte 	status = ((SendRNIDFunc)(vendorHandle, wwn, wwntype,
2289*fcf3ce44SJohn Forte 				 pRspBuffer, pRspBufferSize));
2290*fcf3ce44SJohn Forte     } else {
2291*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2292*fcf3ce44SJohn Forte     }
2293*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2294*fcf3ce44SJohn Forte }
2295*fcf3ce44SJohn Forte 
2296*fcf3ce44SJohn Forte HBA_STATUS
2297*fcf3ce44SJohn Forte HBA_SendRNIDV2(
2298*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2299*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2300*fcf3ce44SJohn Forte     HBA_WWN		destWWN,
2301*fcf3ce44SJohn Forte     HBA_UINT32		destFCID,
2302*fcf3ce44SJohn Forte     HBA_UINT32		NodeIdDataFormat,
2303*fcf3ce44SJohn Forte     void		*pRspBuffer,
2304*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2305*fcf3ce44SJohn Forte {
2306*fcf3ce44SJohn Forte     HBA_STATUS		status;
2307*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2308*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2309*fcf3ce44SJohn Forte     HBASendRNIDV2Func	registeredfunc;
2310*fcf3ce44SJohn Forte 
2311*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendRNIDV2, hbaPortWWN: %s", WWN2STR1(&hbaPortWWN), 0, 0);
2312*fcf3ce44SJohn Forte 
2313*fcf3ce44SJohn Forte     CHECKLIBRARY();
2314*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendRNIDV2Handler;
2315*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2316*fcf3ce44SJohn Forte 	status = (registeredfunc)
2317*fcf3ce44SJohn Forte 	    (vendorHandle, hbaPortWWN, destWWN, destFCID, NodeIdDataFormat,
2318*fcf3ce44SJohn Forte 	     pRspBuffer, pRspBufferSize);
2319*fcf3ce44SJohn Forte     } else {
2320*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2321*fcf3ce44SJohn Forte     }
2322*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2323*fcf3ce44SJohn Forte }
2324*fcf3ce44SJohn Forte 
2325*fcf3ce44SJohn Forte void
2326*fcf3ce44SJohn Forte HBA_RefreshInformation (HBA_HANDLE handle) {
2327*fcf3ce44SJohn Forte     HBA_STATUS		status;
2328*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2329*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2330*fcf3ce44SJohn Forte     HBARefreshInformationFunc
2331*fcf3ce44SJohn Forte 			RefreshInformationFunc;
2332*fcf3ce44SJohn Forte 
2333*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RefreshInformation", 0, 0, 0);
2334*fcf3ce44SJohn Forte 
2335*fcf3ce44SJohn Forte     status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2336*fcf3ce44SJohn Forte     if(status == HBA_STATUS_OK) {
2337*fcf3ce44SJohn Forte 	RefreshInformationFunc =
2338*fcf3ce44SJohn Forte 	    lib_infop->functionTable.RefreshInformationHandler;
2339*fcf3ce44SJohn Forte 	if (RefreshInformationFunc != NULL) {
2340*fcf3ce44SJohn Forte 	    ((RefreshInformationFunc)(vendorHandle));
2341*fcf3ce44SJohn Forte 	}
2342*fcf3ce44SJohn Forte 	RELEASE_MUTEX(&_hbaapi_LL_mutex);
2343*fcf3ce44SJohn Forte     }
2344*fcf3ce44SJohn Forte }
2345*fcf3ce44SJohn Forte 
2346*fcf3ce44SJohn Forte void
2347*fcf3ce44SJohn Forte HBA_ResetStatistics (HBA_HANDLE handle, HBA_UINT32 portindex) {
2348*fcf3ce44SJohn Forte     HBA_STATUS		status;
2349*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2350*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2351*fcf3ce44SJohn Forte     HBAResetStatisticsFunc
2352*fcf3ce44SJohn Forte 			ResetStatisticsFunc;
2353*fcf3ce44SJohn Forte 
2354*fcf3ce44SJohn Forte     DEBUG(2, "HBA_ResetStatistics", 0, 0, 0);
2355*fcf3ce44SJohn Forte 
2356*fcf3ce44SJohn Forte     status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2357*fcf3ce44SJohn Forte     if(status == HBA_STATUS_OK) {
2358*fcf3ce44SJohn Forte 	ResetStatisticsFunc = lib_infop->functionTable.ResetStatisticsHandler;
2359*fcf3ce44SJohn Forte 	if (ResetStatisticsFunc != NULL) {
2360*fcf3ce44SJohn Forte 	    ((ResetStatisticsFunc)(vendorHandle, portindex));
2361*fcf3ce44SJohn Forte 	}
2362*fcf3ce44SJohn Forte 	RELEASE_MUTEX(&_hbaapi_LL_mutex);
2363*fcf3ce44SJohn Forte     }
2364*fcf3ce44SJohn Forte }
2365*fcf3ce44SJohn Forte 
2366*fcf3ce44SJohn Forte HBA_STATUS
2367*fcf3ce44SJohn Forte HBA_GetFcpTargetMapping (HBA_HANDLE handle, PHBA_FCPTARGETMAPPING mapping) {
2368*fcf3ce44SJohn Forte     HBA_STATUS		status;
2369*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2370*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2371*fcf3ce44SJohn Forte     HBAGetFcpTargetMappingFunc GetFcpTargetMappingFunc;
2372*fcf3ce44SJohn Forte 
2373*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetFcpTargetMapping", 0, 0, 0);
2374*fcf3ce44SJohn Forte 
2375*fcf3ce44SJohn Forte     CHECKLIBRARY();
2376*fcf3ce44SJohn Forte     GetFcpTargetMappingFunc =
2377*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetFcpTargetMappingHandler;
2378*fcf3ce44SJohn Forte     if (GetFcpTargetMappingFunc != NULL) {
2379*fcf3ce44SJohn Forte 	status = ((GetFcpTargetMappingFunc)(vendorHandle, mapping));
2380*fcf3ce44SJohn Forte     } else {
2381*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2382*fcf3ce44SJohn Forte     }
2383*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2384*fcf3ce44SJohn Forte }
2385*fcf3ce44SJohn Forte 
2386*fcf3ce44SJohn Forte HBA_STATUS
2387*fcf3ce44SJohn Forte HBA_GetFcpTargetMappingV2 (
2388*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2389*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2390*fcf3ce44SJohn Forte     HBA_FCPTARGETMAPPINGV2
2391*fcf3ce44SJohn Forte     			*pmapping)
2392*fcf3ce44SJohn Forte {
2393*fcf3ce44SJohn Forte     HBA_STATUS		status;
2394*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2395*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2396*fcf3ce44SJohn Forte     HBAGetFcpTargetMappingV2Func
2397*fcf3ce44SJohn Forte 			registeredfunc;
2398*fcf3ce44SJohn Forte 
2399*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetFcpTargetMapping", 0, 0, 0);
2400*fcf3ce44SJohn Forte 
2401*fcf3ce44SJohn Forte     CHECKLIBRARY();
2402*fcf3ce44SJohn Forte     registeredfunc =
2403*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetFcpTargetMappingV2Handler;
2404*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2405*fcf3ce44SJohn Forte 	status = ((registeredfunc)(vendorHandle, hbaPortWWN, pmapping));
2406*fcf3ce44SJohn Forte     } else {
2407*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2408*fcf3ce44SJohn Forte     }
2409*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2410*fcf3ce44SJohn Forte }
2411*fcf3ce44SJohn Forte 
2412*fcf3ce44SJohn Forte HBA_STATUS
2413*fcf3ce44SJohn Forte HBA_GetFcpPersistentBinding (HBA_HANDLE handle, PHBA_FCPBINDING binding) {
2414*fcf3ce44SJohn Forte     HBA_STATUS		status;
2415*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2416*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2417*fcf3ce44SJohn Forte     HBAGetFcpPersistentBindingFunc
2418*fcf3ce44SJohn Forte 			GetFcpPersistentBindingFunc;
2419*fcf3ce44SJohn Forte 
2420*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetFcpPersistentBinding", 0, 0, 0);
2421*fcf3ce44SJohn Forte 
2422*fcf3ce44SJohn Forte     CHECKLIBRARY();
2423*fcf3ce44SJohn Forte     GetFcpPersistentBindingFunc =
2424*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetFcpPersistentBindingHandler;
2425*fcf3ce44SJohn Forte     if (GetFcpPersistentBindingFunc != NULL) {
2426*fcf3ce44SJohn Forte 	status = ((GetFcpPersistentBindingFunc)(vendorHandle, binding));
2427*fcf3ce44SJohn Forte     } else {
2428*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2429*fcf3ce44SJohn Forte     }
2430*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2431*fcf3ce44SJohn Forte }
2432*fcf3ce44SJohn Forte 
2433*fcf3ce44SJohn Forte HBA_STATUS
2434*fcf3ce44SJohn Forte HBA_ScsiInquiryV2 (
2435*fcf3ce44SJohn Forte     HBA_HANDLE	handle,
2436*fcf3ce44SJohn Forte     HBA_WWN	hbaPortWWN,
2437*fcf3ce44SJohn Forte     HBA_WWN	discoveredPortWWN,
2438*fcf3ce44SJohn Forte     HBA_UINT64	fcLUN,
2439*fcf3ce44SJohn Forte     HBA_UINT8	CDB_Byte1,
2440*fcf3ce44SJohn Forte     HBA_UINT8	CDB_Byte2,
2441*fcf3ce44SJohn Forte     void	*pRspBuffer,
2442*fcf3ce44SJohn Forte     HBA_UINT32	*pRspBufferSize,
2443*fcf3ce44SJohn Forte     HBA_UINT8	*pScsiStatus,
2444*fcf3ce44SJohn Forte     void	*pSenseBuffer,
2445*fcf3ce44SJohn Forte     HBA_UINT32	*pSenseBufferSize)
2446*fcf3ce44SJohn Forte {
2447*fcf3ce44SJohn Forte     HBA_STATUS		status;
2448*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2449*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2450*fcf3ce44SJohn Forte     HBAScsiInquiryV2Func ScsiInquiryV2Func;
2451*fcf3ce44SJohn Forte 
2452*fcf3ce44SJohn Forte     DEBUG(2, "HBA_ScsiInquiryV2 to discoveredPortWWN: %s",
2453*fcf3ce44SJohn Forte 	  WWN2STR1(&discoveredPortWWN), 0, 0);
2454*fcf3ce44SJohn Forte 
2455*fcf3ce44SJohn Forte     CHECKLIBRARY();
2456*fcf3ce44SJohn Forte     ScsiInquiryV2Func =
2457*fcf3ce44SJohn Forte 	lib_infop->functionTable.ScsiInquiryV2Handler;
2458*fcf3ce44SJohn Forte     if (ScsiInquiryV2Func != NULL) {
2459*fcf3ce44SJohn Forte 	status =((ScsiInquiryV2Func)(
2460*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, discoveredPortWWN, fcLUN, CDB_Byte1,
2461*fcf3ce44SJohn Forte 	    CDB_Byte2, pRspBuffer, pRspBufferSize, pScsiStatus,
2462*fcf3ce44SJohn Forte 	    pSenseBuffer, pSenseBufferSize));
2463*fcf3ce44SJohn Forte     } else {
2464*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2465*fcf3ce44SJohn Forte     }
2466*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2467*fcf3ce44SJohn Forte }
2468*fcf3ce44SJohn Forte 
2469*fcf3ce44SJohn Forte HBA_STATUS
2470*fcf3ce44SJohn Forte HBA_SendScsiInquiry (
2471*fcf3ce44SJohn Forte     HBA_HANDLE	handle,
2472*fcf3ce44SJohn Forte     HBA_WWN	PortWWN,
2473*fcf3ce44SJohn Forte     HBA_UINT64	fcLUN,
2474*fcf3ce44SJohn Forte     HBA_UINT8	EVPD,
2475*fcf3ce44SJohn Forte     HBA_UINT32	PageCode,
2476*fcf3ce44SJohn Forte     void	*pRspBuffer,
2477*fcf3ce44SJohn Forte     HBA_UINT32	RspBufferSize,
2478*fcf3ce44SJohn Forte     void	*pSenseBuffer,
2479*fcf3ce44SJohn Forte     HBA_UINT32	SenseBufferSize)
2480*fcf3ce44SJohn Forte {
2481*fcf3ce44SJohn Forte     HBA_STATUS		status;
2482*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2483*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2484*fcf3ce44SJohn Forte     HBASendScsiInquiryFunc SendScsiInquiryFunc;
2485*fcf3ce44SJohn Forte 
2486*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendScsiInquiry to PortWWN: %s", WWN2STR1(&PortWWN), 0, 0);
2487*fcf3ce44SJohn Forte 
2488*fcf3ce44SJohn Forte     CHECKLIBRARY();
2489*fcf3ce44SJohn Forte     SendScsiInquiryFunc = lib_infop->functionTable.ScsiInquiryHandler;
2490*fcf3ce44SJohn Forte     if (SendScsiInquiryFunc != NULL) {
2491*fcf3ce44SJohn Forte 	status =((SendScsiInquiryFunc)(
2492*fcf3ce44SJohn Forte 	    vendorHandle, PortWWN, fcLUN, EVPD, PageCode, pRspBuffer,
2493*fcf3ce44SJohn Forte 	    RspBufferSize, pSenseBuffer, SenseBufferSize));
2494*fcf3ce44SJohn Forte     } else {
2495*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2496*fcf3ce44SJohn Forte     }
2497*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2498*fcf3ce44SJohn Forte }
2499*fcf3ce44SJohn Forte 
2500*fcf3ce44SJohn Forte HBA_STATUS
2501*fcf3ce44SJohn Forte HBA_ScsiReportLUNsV2 (
2502*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2503*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2504*fcf3ce44SJohn Forte     HBA_WWN		discoveredPortWWN,
2505*fcf3ce44SJohn Forte     void		*pRespBuffer,
2506*fcf3ce44SJohn Forte     HBA_UINT32		*pRespBufferSize,
2507*fcf3ce44SJohn Forte     HBA_UINT8		*pScsiStatus,
2508*fcf3ce44SJohn Forte     void		*pSenseBuffer,
2509*fcf3ce44SJohn Forte     HBA_UINT32		*pSenseBufferSize)
2510*fcf3ce44SJohn Forte {
2511*fcf3ce44SJohn Forte     HBA_STATUS		status;
2512*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2513*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2514*fcf3ce44SJohn Forte     HBAScsiReportLUNsV2Func ScsiReportLUNsV2Func;
2515*fcf3ce44SJohn Forte 
2516*fcf3ce44SJohn Forte     DEBUG(2, "HBA_ScsiReportLUNsV2 to discoveredPortWWN: %s",
2517*fcf3ce44SJohn Forte 	  WWN2STR1(&discoveredPortWWN), 0, 0);
2518*fcf3ce44SJohn Forte 
2519*fcf3ce44SJohn Forte     CHECKLIBRARY();
2520*fcf3ce44SJohn Forte     ScsiReportLUNsV2Func = lib_infop->functionTable.ScsiReportLUNsV2Handler;
2521*fcf3ce44SJohn Forte     if (ScsiReportLUNsV2Func != NULL) {
2522*fcf3ce44SJohn Forte 	status = ((ScsiReportLUNsV2Func)(
2523*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, discoveredPortWWN,
2524*fcf3ce44SJohn Forte 	    pRespBuffer, pRespBufferSize,
2525*fcf3ce44SJohn Forte 	    pScsiStatus,
2526*fcf3ce44SJohn Forte 	    pSenseBuffer, pSenseBufferSize));
2527*fcf3ce44SJohn Forte     } else {
2528*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2529*fcf3ce44SJohn Forte     }
2530*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2531*fcf3ce44SJohn Forte }
2532*fcf3ce44SJohn Forte 
2533*fcf3ce44SJohn Forte HBA_STATUS
2534*fcf3ce44SJohn Forte HBA_SendReportLUNs (
2535*fcf3ce44SJohn Forte     HBA_HANDLE handle,
2536*fcf3ce44SJohn Forte     HBA_WWN portWWN,
2537*fcf3ce44SJohn Forte     void *pRspBuffer,
2538*fcf3ce44SJohn Forte     HBA_UINT32 RspBufferSize,
2539*fcf3ce44SJohn Forte     void *pSenseBuffer,
2540*fcf3ce44SJohn Forte     HBA_UINT32 SenseBufferSize)
2541*fcf3ce44SJohn Forte {
2542*fcf3ce44SJohn Forte     HBA_STATUS		status;
2543*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2544*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2545*fcf3ce44SJohn Forte     HBASendReportLUNsFunc SendReportLUNsFunc;
2546*fcf3ce44SJohn Forte 
2547*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendReportLUNs to PortWWN: %s", WWN2STR1(&portWWN), 0, 0);
2548*fcf3ce44SJohn Forte 
2549*fcf3ce44SJohn Forte     CHECKLIBRARY();
2550*fcf3ce44SJohn Forte     SendReportLUNsFunc = lib_infop->functionTable.ReportLUNsHandler;
2551*fcf3ce44SJohn Forte     if (SendReportLUNsFunc != NULL) {
2552*fcf3ce44SJohn Forte 	status = ((SendReportLUNsFunc)(
2553*fcf3ce44SJohn Forte 	    vendorHandle, portWWN, pRspBuffer,
2554*fcf3ce44SJohn Forte 	    RspBufferSize, pSenseBuffer, SenseBufferSize));
2555*fcf3ce44SJohn Forte     } else {
2556*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2557*fcf3ce44SJohn Forte     }
2558*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2559*fcf3ce44SJohn Forte }
2560*fcf3ce44SJohn Forte 
2561*fcf3ce44SJohn Forte HBA_STATUS
2562*fcf3ce44SJohn Forte HBA_ScsiReadCapacityV2 (
2563*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2564*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2565*fcf3ce44SJohn Forte     HBA_WWN		discoveredPortWWN,
2566*fcf3ce44SJohn Forte     HBA_UINT64		fcLUN,
2567*fcf3ce44SJohn Forte     void		*pRspBuffer,
2568*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize,
2569*fcf3ce44SJohn Forte     HBA_UINT8		*pScsiStatus,
2570*fcf3ce44SJohn Forte     void		*pSenseBuffer,
2571*fcf3ce44SJohn Forte     HBA_UINT32		*SenseBufferSize)
2572*fcf3ce44SJohn Forte {
2573*fcf3ce44SJohn Forte     HBA_STATUS		status;
2574*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2575*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2576*fcf3ce44SJohn Forte     HBAScsiReadCapacityV2Func ScsiReadCapacityV2Func;
2577*fcf3ce44SJohn Forte 
2578*fcf3ce44SJohn Forte     DEBUG(2, "HBA_ScsiReadCapacityV2 to discoveredPortWWN: %s",
2579*fcf3ce44SJohn Forte 	  WWN2STR1(&discoveredPortWWN), 0, 0);
2580*fcf3ce44SJohn Forte 
2581*fcf3ce44SJohn Forte     CHECKLIBRARY();
2582*fcf3ce44SJohn Forte     ScsiReadCapacityV2Func =
2583*fcf3ce44SJohn Forte 	lib_infop->functionTable.ScsiReadCapacityV2Handler;
2584*fcf3ce44SJohn Forte     if (ScsiReadCapacityV2Func != NULL) {
2585*fcf3ce44SJohn Forte 	status =((ScsiReadCapacityV2Func)(
2586*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, discoveredPortWWN, fcLUN,
2587*fcf3ce44SJohn Forte 	    pRspBuffer, pRspBufferSize,
2588*fcf3ce44SJohn Forte 	    pScsiStatus,
2589*fcf3ce44SJohn Forte 	    pSenseBuffer, SenseBufferSize));
2590*fcf3ce44SJohn Forte     } else {
2591*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2592*fcf3ce44SJohn Forte     }
2593*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2594*fcf3ce44SJohn Forte }
2595*fcf3ce44SJohn Forte 
2596*fcf3ce44SJohn Forte HBA_STATUS
2597*fcf3ce44SJohn Forte HBA_SendReadCapacity (
2598*fcf3ce44SJohn Forte     HBA_HANDLE handle,
2599*fcf3ce44SJohn Forte     HBA_WWN portWWN,
2600*fcf3ce44SJohn Forte     HBA_UINT64 fcLUN,
2601*fcf3ce44SJohn Forte     void *pRspBuffer,
2602*fcf3ce44SJohn Forte     HBA_UINT32 RspBufferSize,
2603*fcf3ce44SJohn Forte     void *pSenseBuffer,
2604*fcf3ce44SJohn Forte     HBA_UINT32 SenseBufferSize)
2605*fcf3ce44SJohn Forte {
2606*fcf3ce44SJohn Forte     HBA_STATUS		status;
2607*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2608*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2609*fcf3ce44SJohn Forte     HBASendReadCapacityFunc SendReadCapacityFunc;
2610*fcf3ce44SJohn Forte 
2611*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendReadCapacity to portWWN: %s", WWN2STR1(&portWWN), 0, 0);
2612*fcf3ce44SJohn Forte 
2613*fcf3ce44SJohn Forte     CHECKLIBRARY();
2614*fcf3ce44SJohn Forte     SendReadCapacityFunc = lib_infop->functionTable.ReadCapacityHandler;
2615*fcf3ce44SJohn Forte     if (SendReadCapacityFunc != NULL) {
2616*fcf3ce44SJohn Forte 	status =((SendReadCapacityFunc)
2617*fcf3ce44SJohn Forte 		 (vendorHandle, portWWN, fcLUN, pRspBuffer,
2618*fcf3ce44SJohn Forte 		  RspBufferSize, pSenseBuffer, SenseBufferSize));
2619*fcf3ce44SJohn Forte     } else {
2620*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2621*fcf3ce44SJohn Forte     }
2622*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2623*fcf3ce44SJohn Forte }
2624*fcf3ce44SJohn Forte 
2625*fcf3ce44SJohn Forte HBA_STATUS
2626*fcf3ce44SJohn Forte HBA_SendRLS (
2627*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2628*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2629*fcf3ce44SJohn Forte     HBA_WWN		destWWN,
2630*fcf3ce44SJohn Forte     void		*pRspBuffer,
2631*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2632*fcf3ce44SJohn Forte {
2633*fcf3ce44SJohn Forte     HBA_STATUS		status;
2634*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2635*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2636*fcf3ce44SJohn Forte     HBASendRLSFunc registeredfunc;
2637*fcf3ce44SJohn Forte 
2638*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendRLS to agent_wwn: %s:%d",
2639*fcf3ce44SJohn Forte 	  WWN2STR1(&agent_wwn), agent_domain, 0);
2640*fcf3ce44SJohn Forte 
2641*fcf3ce44SJohn Forte     CHECKLIBRARY();
2642*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendRLSHandler;
2643*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2644*fcf3ce44SJohn Forte 	status =(registeredfunc)(
2645*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, destWWN, pRspBuffer, pRspBufferSize);
2646*fcf3ce44SJohn Forte     } else {
2647*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2648*fcf3ce44SJohn Forte     }
2649*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2650*fcf3ce44SJohn Forte }
2651*fcf3ce44SJohn Forte 
2652*fcf3ce44SJohn Forte HBA_STATUS
2653*fcf3ce44SJohn Forte HBA_SendRPL (
2654*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2655*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2656*fcf3ce44SJohn Forte     HBA_WWN		agent_wwn,
2657*fcf3ce44SJohn Forte     HBA_UINT32		agent_domain,
2658*fcf3ce44SJohn Forte     HBA_UINT32		portindex,
2659*fcf3ce44SJohn Forte     void		*pRspBuffer,
2660*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2661*fcf3ce44SJohn Forte {
2662*fcf3ce44SJohn Forte     HBA_STATUS		status;
2663*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2664*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2665*fcf3ce44SJohn Forte     HBASendRPLFunc registeredfunc;
2666*fcf3ce44SJohn Forte 
2667*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendRPL to agent_wwn: %s:%d",
2668*fcf3ce44SJohn Forte 	  WWN2STR1(&agent_wwn), agent_domain, 0);
2669*fcf3ce44SJohn Forte 
2670*fcf3ce44SJohn Forte     CHECKLIBRARY();
2671*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendRPLHandler;
2672*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2673*fcf3ce44SJohn Forte 	status =(registeredfunc)(
2674*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, agent_wwn, agent_domain, portindex,
2675*fcf3ce44SJohn Forte 	    pRspBuffer, pRspBufferSize);
2676*fcf3ce44SJohn Forte     } else {
2677*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2678*fcf3ce44SJohn Forte     }
2679*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2680*fcf3ce44SJohn Forte }
2681*fcf3ce44SJohn Forte 
2682*fcf3ce44SJohn Forte HBA_STATUS
2683*fcf3ce44SJohn Forte HBA_SendRPS (
2684*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2685*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2686*fcf3ce44SJohn Forte     HBA_WWN		agent_wwn,
2687*fcf3ce44SJohn Forte     HBA_UINT32		agent_domain,
2688*fcf3ce44SJohn Forte     HBA_WWN		object_wwn,
2689*fcf3ce44SJohn Forte     HBA_UINT32		object_port_number,
2690*fcf3ce44SJohn Forte     void		*pRspBuffer,
2691*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2692*fcf3ce44SJohn Forte {
2693*fcf3ce44SJohn Forte     HBA_STATUS		status;
2694*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2695*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2696*fcf3ce44SJohn Forte     HBASendRPSFunc registeredfunc;
2697*fcf3ce44SJohn Forte 
2698*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendRPS  to agent_wwn: %s:%d",
2699*fcf3ce44SJohn Forte 	  WWN2STR1(&agent_wwn), agent_domain, 0);
2700*fcf3ce44SJohn Forte 
2701*fcf3ce44SJohn Forte     CHECKLIBRARY();
2702*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendRPSHandler;
2703*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2704*fcf3ce44SJohn Forte 	status =(registeredfunc)(
2705*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, agent_wwn, agent_domain,
2706*fcf3ce44SJohn Forte 	    object_wwn, object_port_number,
2707*fcf3ce44SJohn Forte 	    pRspBuffer, pRspBufferSize);
2708*fcf3ce44SJohn Forte     } else {
2709*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2710*fcf3ce44SJohn Forte     }
2711*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2712*fcf3ce44SJohn Forte }
2713*fcf3ce44SJohn Forte 
2714*fcf3ce44SJohn Forte HBA_STATUS
2715*fcf3ce44SJohn Forte HBA_SendSRL (
2716*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2717*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2718*fcf3ce44SJohn Forte     HBA_WWN		wwn,
2719*fcf3ce44SJohn Forte     HBA_UINT32		domain,
2720*fcf3ce44SJohn Forte     void		*pRspBuffer,
2721*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2722*fcf3ce44SJohn Forte {
2723*fcf3ce44SJohn Forte     HBA_STATUS		status;
2724*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2725*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2726*fcf3ce44SJohn Forte     HBASendSRLFunc registeredfunc;
2727*fcf3ce44SJohn Forte 
2728*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendSRL to wwn:%s domain:%d", WWN2STR1(&wwn), domain, 0);
2729*fcf3ce44SJohn Forte 
2730*fcf3ce44SJohn Forte     CHECKLIBRARY();
2731*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendSRLHandler;
2732*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2733*fcf3ce44SJohn Forte 	status =(registeredfunc)(
2734*fcf3ce44SJohn Forte 	    vendorHandle, hbaPortWWN, wwn, domain,
2735*fcf3ce44SJohn Forte 	    pRspBuffer, pRspBufferSize);
2736*fcf3ce44SJohn Forte     } else {
2737*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2738*fcf3ce44SJohn Forte     }
2739*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2740*fcf3ce44SJohn Forte }
2741*fcf3ce44SJohn Forte 
2742*fcf3ce44SJohn Forte HBA_STATUS
2743*fcf3ce44SJohn Forte HBA_SendLIRR (
2744*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2745*fcf3ce44SJohn Forte     HBA_WWN		sourceWWN,
2746*fcf3ce44SJohn Forte     HBA_WWN		destWWN,
2747*fcf3ce44SJohn Forte     HBA_UINT8		function,
2748*fcf3ce44SJohn Forte     HBA_UINT8		type,
2749*fcf3ce44SJohn Forte     void		*pRspBuffer,
2750*fcf3ce44SJohn Forte     HBA_UINT32		*pRspBufferSize)
2751*fcf3ce44SJohn Forte {
2752*fcf3ce44SJohn Forte     HBA_STATUS		status;
2753*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2754*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2755*fcf3ce44SJohn Forte     HBASendLIRRFunc registeredfunc;
2756*fcf3ce44SJohn Forte 
2757*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SendLIRR destWWN:%s", WWN2STR1(&destWWN), 0, 0);
2758*fcf3ce44SJohn Forte 
2759*fcf3ce44SJohn Forte     CHECKLIBRARY();
2760*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SendLIRRHandler;
2761*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2762*fcf3ce44SJohn Forte 	status =(registeredfunc)(
2763*fcf3ce44SJohn Forte 	    vendorHandle, sourceWWN, destWWN, function, type,
2764*fcf3ce44SJohn Forte 	    pRspBuffer, pRspBufferSize);
2765*fcf3ce44SJohn Forte     } else {
2766*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2767*fcf3ce44SJohn Forte     }
2768*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2769*fcf3ce44SJohn Forte }
2770*fcf3ce44SJohn Forte 
2771*fcf3ce44SJohn Forte HBA_STATUS
2772*fcf3ce44SJohn Forte HBA_GetBindingCapability(
2773*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2774*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2775*fcf3ce44SJohn Forte     HBA_BIND_CAPABILITY *pcapability)
2776*fcf3ce44SJohn Forte {
2777*fcf3ce44SJohn Forte     HBA_STATUS		status;
2778*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2779*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2780*fcf3ce44SJohn Forte     HBAGetBindingCapabilityFunc
2781*fcf3ce44SJohn Forte 			registeredfunc;
2782*fcf3ce44SJohn Forte 
2783*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetBindingCapability", 0, 0, 0);
2784*fcf3ce44SJohn Forte 
2785*fcf3ce44SJohn Forte     CHECKLIBRARY();
2786*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.GetBindingCapabilityHandler;
2787*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2788*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN, pcapability);
2789*fcf3ce44SJohn Forte     } else {
2790*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2791*fcf3ce44SJohn Forte     }
2792*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2793*fcf3ce44SJohn Forte }
2794*fcf3ce44SJohn Forte 
2795*fcf3ce44SJohn Forte HBA_STATUS
2796*fcf3ce44SJohn Forte HBA_GetBindingSupport (
2797*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2798*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2799*fcf3ce44SJohn Forte     HBA_BIND_CAPABILITY *pcapability)
2800*fcf3ce44SJohn Forte {
2801*fcf3ce44SJohn Forte     HBA_STATUS		status;
2802*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2803*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2804*fcf3ce44SJohn Forte     HBAGetBindingSupportFunc
2805*fcf3ce44SJohn Forte 			registeredfunc;
2806*fcf3ce44SJohn Forte 
2807*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetBindingSupport", 0, 0, 0);
2808*fcf3ce44SJohn Forte 
2809*fcf3ce44SJohn Forte     CHECKLIBRARY();
2810*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.GetBindingSupportHandler;
2811*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2812*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN, pcapability);
2813*fcf3ce44SJohn Forte     } else {
2814*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2815*fcf3ce44SJohn Forte     }
2816*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2817*fcf3ce44SJohn Forte }
2818*fcf3ce44SJohn Forte 
2819*fcf3ce44SJohn Forte HBA_STATUS
2820*fcf3ce44SJohn Forte HBA_SetBindingSupport(
2821*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2822*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2823*fcf3ce44SJohn Forte     HBA_BIND_CAPABILITY capability)
2824*fcf3ce44SJohn Forte {
2825*fcf3ce44SJohn Forte     HBA_STATUS		status;
2826*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2827*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2828*fcf3ce44SJohn Forte     HBASetBindingSupportFunc
2829*fcf3ce44SJohn Forte 			registeredfunc;
2830*fcf3ce44SJohn Forte 
2831*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SetBindingSupport", 0, 0, 0);
2832*fcf3ce44SJohn Forte 
2833*fcf3ce44SJohn Forte     CHECKLIBRARY();
2834*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SetBindingSupportHandler;
2835*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2836*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN, capability);
2837*fcf3ce44SJohn Forte     } else {
2838*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2839*fcf3ce44SJohn Forte     }
2840*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2841*fcf3ce44SJohn Forte }
2842*fcf3ce44SJohn Forte 
2843*fcf3ce44SJohn Forte HBA_STATUS
2844*fcf3ce44SJohn Forte HBA_SetPersistentBindingV2 (
2845*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2846*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2847*fcf3ce44SJohn Forte     const HBA_FCPBINDING2
2848*fcf3ce44SJohn Forte     			*pbinding)
2849*fcf3ce44SJohn Forte {
2850*fcf3ce44SJohn Forte     HBA_STATUS		status;
2851*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2852*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2853*fcf3ce44SJohn Forte     HBASetPersistentBindingV2Func
2854*fcf3ce44SJohn Forte 			registeredfunc;
2855*fcf3ce44SJohn Forte 
2856*fcf3ce44SJohn Forte     DEBUG(2, "HBA_SetPersistentBindingV2 port: %s", WWN2STR1(&hbaPortWWN), 0, 0);
2857*fcf3ce44SJohn Forte 
2858*fcf3ce44SJohn Forte     CHECKLIBRARY();
2859*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.SetPersistentBindingV2Handler;
2860*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2861*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
2862*fcf3ce44SJohn Forte     } else {
2863*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2864*fcf3ce44SJohn Forte     }
2865*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2866*fcf3ce44SJohn Forte }
2867*fcf3ce44SJohn Forte 
2868*fcf3ce44SJohn Forte HBA_STATUS
2869*fcf3ce44SJohn Forte HBA_GetPersistentBindingV2 (
2870*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2871*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2872*fcf3ce44SJohn Forte     HBA_FCPBINDING2	*pbinding)
2873*fcf3ce44SJohn Forte {
2874*fcf3ce44SJohn Forte     HBA_STATUS		status;
2875*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2876*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2877*fcf3ce44SJohn Forte     HBAGetPersistentBindingV2Func
2878*fcf3ce44SJohn Forte 			registeredfunc;
2879*fcf3ce44SJohn Forte 
2880*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetPersistentBindingV2 port: %s", WWN2STR1(&hbaPortWWN), 0, 0);
2881*fcf3ce44SJohn Forte 
2882*fcf3ce44SJohn Forte     CHECKLIBRARY();
2883*fcf3ce44SJohn Forte     registeredfunc = lib_infop->functionTable.GetPersistentBindingV2Handler;
2884*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2885*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
2886*fcf3ce44SJohn Forte     } else {
2887*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2888*fcf3ce44SJohn Forte     }
2889*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2890*fcf3ce44SJohn Forte }
2891*fcf3ce44SJohn Forte 
2892*fcf3ce44SJohn Forte HBA_STATUS
2893*fcf3ce44SJohn Forte HBA_RemovePersistentBinding (
2894*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2895*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN,
2896*fcf3ce44SJohn Forte     const HBA_FCPBINDING2
2897*fcf3ce44SJohn Forte 			*pbinding)
2898*fcf3ce44SJohn Forte {
2899*fcf3ce44SJohn Forte     HBA_STATUS		status;
2900*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2901*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2902*fcf3ce44SJohn Forte     HBARemovePersistentBindingFunc
2903*fcf3ce44SJohn Forte 			registeredfunc;
2904*fcf3ce44SJohn Forte 
2905*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RemovePersistentBinding", 0, 0, 0);
2906*fcf3ce44SJohn Forte 
2907*fcf3ce44SJohn Forte     CHECKLIBRARY();
2908*fcf3ce44SJohn Forte     registeredfunc =
2909*fcf3ce44SJohn Forte 	lib_infop->functionTable.RemovePersistentBindingHandler;
2910*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2911*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
2912*fcf3ce44SJohn Forte     } else {
2913*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2914*fcf3ce44SJohn Forte     }
2915*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2916*fcf3ce44SJohn Forte }
2917*fcf3ce44SJohn Forte 
2918*fcf3ce44SJohn Forte HBA_STATUS
2919*fcf3ce44SJohn Forte HBA_RemoveAllPersistentBindings (
2920*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2921*fcf3ce44SJohn Forte     HBA_WWN		hbaPortWWN)
2922*fcf3ce44SJohn Forte {
2923*fcf3ce44SJohn Forte     HBA_STATUS		status;
2924*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2925*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2926*fcf3ce44SJohn Forte     HBARemoveAllPersistentBindingsFunc
2927*fcf3ce44SJohn Forte 			registeredfunc;
2928*fcf3ce44SJohn Forte 
2929*fcf3ce44SJohn Forte     DEBUG(2, "HBA_RemoveAllPersistentBindings", 0, 0, 0);
2930*fcf3ce44SJohn Forte 
2931*fcf3ce44SJohn Forte     CHECKLIBRARY();
2932*fcf3ce44SJohn Forte     registeredfunc =
2933*fcf3ce44SJohn Forte 	lib_infop->functionTable.RemoveAllPersistentBindingsHandler;
2934*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2935*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, hbaPortWWN);
2936*fcf3ce44SJohn Forte     } else {
2937*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2938*fcf3ce44SJohn Forte     }
2939*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2940*fcf3ce44SJohn Forte }
2941*fcf3ce44SJohn Forte 
2942*fcf3ce44SJohn Forte HBA_STATUS
2943*fcf3ce44SJohn Forte HBA_GetFC4Statistics (
2944*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2945*fcf3ce44SJohn Forte     HBA_WWN		portWWN,
2946*fcf3ce44SJohn Forte     HBA_UINT8		FC4type,
2947*fcf3ce44SJohn Forte     HBA_FC4STATISTICS	*pstatistics)
2948*fcf3ce44SJohn Forte {
2949*fcf3ce44SJohn Forte     HBA_STATUS		status;
2950*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2951*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2952*fcf3ce44SJohn Forte     HBAGetFC4StatisticsFunc
2953*fcf3ce44SJohn Forte 			registeredfunc;
2954*fcf3ce44SJohn Forte 
2955*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetFC4Statistics port: %s", WWN2STR1(&portWWN), 0, 0);
2956*fcf3ce44SJohn Forte 
2957*fcf3ce44SJohn Forte     CHECKLIBRARY();
2958*fcf3ce44SJohn Forte     registeredfunc =
2959*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetFC4StatisticsHandler;
2960*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2961*fcf3ce44SJohn Forte 	status =(registeredfunc)
2962*fcf3ce44SJohn Forte 	    (vendorHandle, portWWN, FC4type, pstatistics);
2963*fcf3ce44SJohn Forte     } else {
2964*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2965*fcf3ce44SJohn Forte     }
2966*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2967*fcf3ce44SJohn Forte }
2968*fcf3ce44SJohn Forte 
2969*fcf3ce44SJohn Forte HBA_STATUS
2970*fcf3ce44SJohn Forte HBA_GetFCPStatistics (
2971*fcf3ce44SJohn Forte     HBA_HANDLE		handle,
2972*fcf3ce44SJohn Forte     const HBA_SCSIID	*lunit,
2973*fcf3ce44SJohn Forte     HBA_FC4STATISTICS	*pstatistics)
2974*fcf3ce44SJohn Forte {
2975*fcf3ce44SJohn Forte     HBA_STATUS		status;
2976*fcf3ce44SJohn Forte     HBA_LIBRARY_INFO	*lib_infop;
2977*fcf3ce44SJohn Forte     HBA_HANDLE		vendorHandle;
2978*fcf3ce44SJohn Forte     HBAGetFCPStatisticsFunc
2979*fcf3ce44SJohn Forte 			registeredfunc;
2980*fcf3ce44SJohn Forte 
2981*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetFCPStatistics", 0, 0, 0);
2982*fcf3ce44SJohn Forte 
2983*fcf3ce44SJohn Forte     CHECKLIBRARY();
2984*fcf3ce44SJohn Forte     registeredfunc =
2985*fcf3ce44SJohn Forte 	lib_infop->functionTable.GetFCPStatisticsHandler;
2986*fcf3ce44SJohn Forte     if (registeredfunc != NULL) {
2987*fcf3ce44SJohn Forte 	status =(registeredfunc)(vendorHandle, lunit, pstatistics);
2988*fcf3ce44SJohn Forte     } else {
2989*fcf3ce44SJohn Forte 	status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2990*fcf3ce44SJohn Forte     }
2991*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2992*fcf3ce44SJohn Forte }
2993*fcf3ce44SJohn Forte 
2994*fcf3ce44SJohn Forte HBA_UINT32
2995*fcf3ce44SJohn Forte HBA_GetVendorLibraryAttributes (
2996*fcf3ce44SJohn Forte     HBA_UINT32 adapter_index,
2997*fcf3ce44SJohn Forte     HBA_LIBRARYATTRIBUTES *attributes)
2998*fcf3ce44SJohn Forte {
2999*fcf3ce44SJohn Forte     HBA_ADAPTER_INFO	*adapt_infop;
3000*fcf3ce44SJohn Forte     HBAGetVendorLibraryAttributesFunc
3001*fcf3ce44SJohn Forte 			registeredfunc;
3002*fcf3ce44SJohn Forte     HBA_UINT32		ret = 0;
3003*fcf3ce44SJohn Forte 
3004*fcf3ce44SJohn Forte     DEBUG(2, "HBA_GetVendorLibraryAttributes adapterindex:%d",
3005*fcf3ce44SJohn Forte 	  adapter_index, 0, 0);
3006*fcf3ce44SJohn Forte     if(_hbaapi_librarylist == NULL) {
3007*fcf3ce44SJohn Forte 	DEBUG(1, "HBAAPI not loaded yet.", 0, 0, 0);
3008*fcf3ce44SJohn Forte 	return(0);
3009*fcf3ce44SJohn Forte     }
3010*fcf3ce44SJohn Forte 
3011*fcf3ce44SJohn Forte     if (attributes == NULL) {
3012*fcf3ce44SJohn Forte 	    return(HBA_STATUS_ERROR_ARG);
3013*fcf3ce44SJohn Forte     }
3014*fcf3ce44SJohn Forte 
3015*fcf3ce44SJohn Forte     memset(attributes, 0, sizeof(HBA_LIBRARYATTRIBUTES));
3016*fcf3ce44SJohn Forte 
3017*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_LL_mutex);
3018*fcf3ce44SJohn Forte     GRAB_MUTEX(&_hbaapi_AL_mutex);
3019*fcf3ce44SJohn Forte     for(adapt_infop = _hbaapi_adapterlist;
3020*fcf3ce44SJohn Forte 	adapt_infop != NULL;
3021*fcf3ce44SJohn Forte 	adapt_infop = adapt_infop->next) {
3022*fcf3ce44SJohn Forte 
3023*fcf3ce44SJohn Forte 	if(adapt_infop->index == adapter_index) {
3024*fcf3ce44SJohn Forte 	    registeredfunc = adapt_infop->library->
3025*fcf3ce44SJohn Forte 		functionTable.GetVendorLibraryAttributesHandler;
3026*fcf3ce44SJohn Forte 	    if(registeredfunc != NULL) {
3027*fcf3ce44SJohn Forte 		ret = (registeredfunc)(attributes);
3028*fcf3ce44SJohn Forte 	    } else {
3029*fcf3ce44SJohn Forte 		/* Version 1 libary? */
3030*fcf3ce44SJohn Forte 		HBAGetVersionFunc	GetVersionFunc;
3031*fcf3ce44SJohn Forte 		GetVersionFunc = adapt_infop->library->
3032*fcf3ce44SJohn Forte 		    functionTable.GetVersionHandler;
3033*fcf3ce44SJohn Forte 		if(GetVersionFunc != NULL) {
3034*fcf3ce44SJohn Forte 		    ret = ((GetVersionFunc)());
3035*fcf3ce44SJohn Forte 		}
3036*fcf3ce44SJohn Forte #ifdef NOTDEF
3037*fcf3ce44SJohn Forte 		else {
3038*fcf3ce44SJohn Forte 		    /* This should not happen, dont think its going to */
3039*fcf3ce44SJohn Forte 		}
3040*fcf3ce44SJohn Forte #endif
3041*fcf3ce44SJohn Forte 	    }
3042*fcf3ce44SJohn Forte 	    if (attributes->LibPath[0] == '\0') {
3043*fcf3ce44SJohn Forte 		if(strlen(adapt_infop->library->LibraryPath) < 256) {
3044*fcf3ce44SJohn Forte 		    strcpy(attributes->LibPath,
3045*fcf3ce44SJohn Forte 			   adapt_infop->library->LibraryPath);
3046*fcf3ce44SJohn Forte 		}
3047*fcf3ce44SJohn Forte 	    }
3048*fcf3ce44SJohn Forte 	    break;
3049*fcf3ce44SJohn Forte 	}
3050*fcf3ce44SJohn Forte     }
3051*fcf3ce44SJohn Forte     RELEASE_MUTEX(&_hbaapi_AL_mutex);
3052*fcf3ce44SJohn Forte     RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, ret);
3053*fcf3ce44SJohn Forte }
3054