Print this page
NEX-14979 HBA_LoadLibrary needs to close config file when done.
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Jean McCormack <jean.mccormack@nexenta.com>
Reviewed by: Rob Gittins <rob.gittins@nexenta.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/smhba/common/SMHBAAPILIB.c
+++ new/usr/src/lib/smhba/common/SMHBAAPILIB.c
1 1 /*
2 2 * ************************************************************************
3 3 * Description
4 4 * HBAAPILIB.c - Implements a sample common (wrapper) HBA API library
5 5 *
6 6 * License:
7 7 * The contents of this file are subject to the SNIA Public License
8 8 * Version 1.0 (the "License"); you may not use this file except in
9 9 * compliance with the License. You may obtain a copy of the License at
10 10 *
11 11 * /http://www.snia.org/English/Resources/Code/OpenSource.html
12 12 *
13 13 * Software distributed under the License is distributed on an "AS IS"
14 14 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
15 15 * the License for the specific language governing rights and limitations
16 16 * under the License.
17 17 *
18 18 * The Original Code is SNIA HBA API Wrapper Library
19 19 *
20 20 * The Initial Developer of the Original Code is:
21 21 * Benjamin F. Kuo, Troika Networks, Inc. (benk@troikanetworks.com)
22 22 *
23 23 * Contributor(s):
24 24 * Tuan Lam, QLogic Corp. (t_lam@qlc.com)
25 25 * Dan Willie, Emulex Corp. (Dan.Willie@emulex.com)
26 26 * Dixon Hutchinson, Legato Systems, Inc. (dhutchin@legato.com)
27 27 * David Dillard, VERITAS Software Corp. (david.dillard@veritas.com)
28 28 *
29 29 * ************************************************************************
30 30 *
31 31 * Adding on SM-HBA support
32 32 *
33 33 * The implementation includes Three different categories functions to support
34 34 * both HBAAPI and SM-HBA through the same library.
35 35 *
36 36 * SM-HBA unique interface:
37 37 * 1. CHECKLIBRARYANDVERSION(SMHBA) : match SMHBA VSL
38 38 * Or checking specifically if version is SMHBA beforehand.
39 39 * 2. resolved to ftable.smhbafunctiontable.{interface}
40 40 * HBAAPIV2 unique functions
41 41 * 1. CHECKLIBRARYANDVERSION(HBAAPIV2) : validate and match HBAAPI V2 VSL.
42 42 * Or checking specifically if version is HBAAPIV2 beforehand.
43 43 * 2. resolved to ftable.functiontable.{interface}
44 44 * Common interface between SM-HBA and HBAAPIV2.
45 45 * 1. CHECKLIBRARY() : to validate the VSL.
46 46 * 2. FUNCCOMMON macro to map the appropriate entry point table
47 47 * (union ftable).
48 48 * 3. If the interface is not supported by HBAAPI(Version 1)
49 49 * the funtiion ptr will be set to NULL.
50 50 * Common interface between HBAAPI and HBAAPIV2.
51 51 * 1. Check if version is not SMHBA).
52 52 * 2. ftable.functiontalbe.(interface)
53 53 *
54 54 * ************************************************************************
55 55 */
56 56 /*
57 57 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
58 58 * Use is subject to license terms.
59 59 */
60 60
61 61 #ifdef WIN32
62 62 #include <windows.h>
63 63 #include <string.h>
64 64 /*
65 65 * Next define forces entry points in the dll to be exported
66 66 * See hbaapi.h to see what it does.
67 67 */
68 68 #define HBAAPI_EXPORTS
69 69 #else
70 70 #include <dlfcn.h>
71 71 #include <strings.h>
72 72 #endif
73 73 #include <stdio.h>
74 74 #include <time.h>
75 75 #include "smhbaapi.h"
76 76 #include "vendorsmhbaapi.h"
77 77 #include <stdlib.h>
78 78 #ifdef USESYSLOG
79 79 #include <syslog.h>
80 80 #endif
81 81 #ifdef SOLARIS
82 82 #include <link.h>
83 83 #include <limits.h>
84 84 static int *handle;
85 85 static Link_map *map, *mp;
86 86 #endif
87 87
88 88 /*
89 89 * LIBRARY_NUM is a shortcut to figure out which library we need to call.
90 90 * The top 16 bits of handle are the library index
91 91 */
92 92 #define LIBRARY_NUM(handle) ((handle)>>16)
93 93
94 94 /*
95 95 * VENDOR_HANDLE turns a global library handle into a vendor specific handle,
96 96 * with all upper 16 bits set to 0
97 97 */
98 98 #define VENDOR_HANDLE(handle) ((handle)&0xFFFF)
99 99
100 100 #define HBA_HANDLE_FROM_LOCAL(library, vendor) \
101 101 (((library)<<16) | ((vendor)&0x0000FFFF))
102 102
103 103 int _hbaapi_debuglevel = 0;
104 104 #define DEBUG(L, STR, A1, A2, A3)
105 105
106 106 #if defined(USESYSLOG) && defined(USELOGFILE)
107 107 FILE *_hbaapi_debug_fd = NULL;
108 108 int _hbaapi_sysloginit = 0;
109 109 #undef DEBUG
110 110 #ifdef WIN32
111 111 #define DEBUG(L, STR, A1, A2, A3)\
112 112 if ((L) <= _hbaapi_debuglevel) {\
113 113 if (_hbaapi_sysloginit == 0) {\
114 114 openlog("HBAAPI", LOG_PID|LOG_ODELAY, LOG_USER);\
115 115 _hbaapi_sysloginit = 1;\
116 116 }\
117 117 syslog(LOG_INFO, (STR), (A1), (A2), (A3));\
118 118 if (_hbaapi_debug_fd == NULL) {\
119 119 char _logFile[MAX_PATH]; \
120 120 GetTempPath(MAX_PATH, _logFile); \
121 121 strcat(_logFile, "HBAAPI.log"); \
122 122 _hbaapi_debug_fd = fopen(_logFile, "a");\
123 123 }\
124 124 if (_hbaapi_debug_fd != NULL) {\
125 125 fprintf(_hbaapi_debug_fd, #STR "\n", (A1), (A2), (A3));\
126 126 }\
127 127 }
128 128 #else /* WIN32 */
129 129 #define DEBUG(L, STR, A1, A2, A3)\
130 130 if ((L) <= _hbaapi_debuglevel) {\
131 131 if (_hbaapi_sysloginit == 0) {\
132 132 openlog("HBAAPI", LOG_PID|LOG_ODELAY, LOG_USER);\
133 133 _hbaapi_sysloginit = 1;\
134 134 }\
135 135 syslog(LOG_INFO, (STR), (A1), (A2), (A3));\
136 136 if (_hbaapi_debug_fd == NULL) {\
137 137 _hbaapi_debug_fd = fopen("/tmp/HBAAPI.log", "a");\
138 138 }\
139 139 if (_hbaapi_debug_fd != NULL) {\
140 140 fprintf(_hbaapi_debug_fd, #STR "\n", (A1), (A2), (A3));\
141 141 }\
142 142 }
143 143 #endif /* WIN32 */
144 144
145 145 #else /* Not both USESYSLOG and USELOGFILE */
146 146 #if defined(USESYSLOG)
147 147 int _hbaapi_sysloginit = 0;
148 148 #undef DEBUG
149 149 #define DEBUG(L, STR, A1, A2, A3) \
150 150 if ((L) <= _hbaapi_debuglevel) {\
151 151 if (_hbaapi_sysloginit == 0) {\
152 152 openlog("HBAAPI", LOG_PID|LOG_ODELAY, LOG_USER);\
153 153 _hbaapi_sysloginit = 1;\
154 154 }\
155 155 syslog(LOG_DEBUG, (STR), (A1), (A2), (A3));\
156 156 }
157 157 #endif /* USESYSLOG */
158 158 #if defined(USELOGFILE)
159 159 FILE *_hbaapi_debug_fd = NULL;
160 160 #undef DEBUG
161 161 #ifdef WIN32
162 162 #define DEBUG(L, STR, A1, A2, A3) \
163 163 if ((L) <= _hbaapi_debuglevel) {\
164 164 if (_hbaapi_debug_fd == NULL) {\
165 165 char _logFile[MAX_PATH]; \
166 166 GetTempPath(MAX_PATH, _logFile); \
167 167 strcat(_logFile, "HBAAPI.log"); \
168 168 _hbaapi_debug_fd = fopen(_logFile, "a");\
169 169 }\
170 170 }
171 171 #else /* WIN32 */
172 172 #define DEBUG(L, STR, A1, A2, A3) \
173 173 if ((L) <= _hbaapi_debuglevel) {\
174 174 if (_hbaapi_debug_fd == NULL) {\
175 175 _hbaapi_debug_fd = fopen("/tmp/HBAAPI.log", "a");\
176 176 }\
177 177 if (_hbaapi_debug_fd != NULL) { \
178 178 fprintf(_hbaapi_debug_fd, #STR "\n", (A1), (A2), (A3));\
179 179 }\
180 180 }
181 181 #endif /* WIN32 */
182 182 #endif /* USELOGFILE */
183 183 #endif /* Not both USELOGFILE and USESYSLOG */
184 184
185 185 #ifdef POSIX_THREADS
186 186 #include <pthread.h>
187 187 /*
188 188 * When multiple mutex's are grabed, they must be always be grabbed in
189 189 * the same order, or deadlock can result. There are three levels
190 190 * of mutex's involved in this API. If LL_mutex is grabbed, always grap
191 191 * it first. If AL_mutex is grabbed, it may not be grabbed before
192 192 * LL_mutex. If grabbed in a multi grab sequence, the mutex's protecting
193 193 * the callback lists must always be grabbed last and release before calling
194 194 * a vendor specific library function that might invoke a callback function
195 195 * on the same thread.
196 196 */
197 197 #define GRAB_MUTEX(M) grab_mutex(M)
198 198 #define RELEASE_MUTEX(M) release_mutex(M)
199 199 #define RELEASE_MUTEX_RETURN(M, RET) release_mutex(M); return (RET)
200 200 #elif defined(WIN32)
201 201 #define GRAB_MUTEX(m) EnterCriticalSection(m)
202 202 #define RELEASE_MUTEX(m) LeaveCriticalSection(m)
203 203 #define RELEASE_MUTEX_RETURN(m, RET) LeaveCriticalSection(m); return (RET)
204 204 #else
205 205 #define GRAB_MUTEX(M)
206 206 #define RELEASE_MUTEX(M)
207 207 #define RELEASE_MUTEX_RETURN(M, RET) return (RET)
208 208 #endif
209 209
210 210 /*
211 211 * Vendor library information
212 212 */
213 213 typedef enum {
214 214 HBA_LIBRARY_UNKNOWN,
215 215 HBA_LIBRARY_LOADED,
216 216 HBA_LIBRARY_NOT_LOADED
217 217 } HBA_LIBRARY_STATUS;
218 218
219 219 typedef enum {
220 220 UNKNOWN = 1,
221 221 SMHBA,
222 222 HBAAPIV2,
223 223 HBAAPI
224 224 } LIBRARY_VERSION;
225 225
226 226 typedef struct hba_library_info {
227 227 struct hba_library_info
228 228 *next;
229 229 #ifdef WIN32
230 230 HINSTANCE hLibrary; /* Handle to a loaded DLL */
231 231 #else
232 232 char *LibraryName;
233 233 void* hLibrary; /* Handle to a loaded DLL */
234 234 #endif
235 235 char *LibraryPath;
236 236 LIBRARY_VERSION version; /* resolve union */
237 237 HBA_UINT32 numOfAdapters;
238 238 union {
239 239 SMHBA_ENTRYPOINTS smhbafunctionTable; /* smhba function pointers */
240 240 HBA_ENTRYPOINTSV2 functionTable; /* hba api function pointers */
241 241 } ftable;
242 242 HBA_LIBRARY_STATUS status; /* info on this library */
243 243 HBA_UINT32 index;
244 244 } HBA_LIBRARY_INFO, *PHBA_LIBRARY_INFO;
245 245
246 246 #define ARE_WE_INITED() \
247 247 if (_hbaapi_librarylist == NULL) { \
248 248 return (HBA_STATUS_ERROR_NOT_LOADED); \
249 249 }
250 250 HBA_LIBRARY_INFO *_hbaapi_librarylist = NULL;
251 251 HBA_UINT32 _hbaapi_total_library_count = 0;
252 252 #ifdef POSIX_THREADS
253 253 pthread_mutex_t _hbaapi_LL_mutex = PTHREAD_MUTEX_INITIALIZER;
254 254 #elif defined(WIN32)
255 255 CRITICAL_SECTION _hbaapi_LL_mutex;
256 256 #endif
257 257
258 258 /*
259 259 * Macro to use the right function table between smhba and hbaapi.
260 260 */
261 261 #define FUNCTABLE(lib_infop) \
262 262 ((lib_infop->version == SMHBA) ? \
263 263 lib_infop->ftable.smhbafunctionTable : \
264 264 lib_infop->ftable.functionTable);
265 265
266 266 /*
267 267 * Macro to use the right function ptr between smhba and hbaapi function table.
268 268 * Should be used for an interface common to SM-HBA and HBAAPIV2.
269 269 */
270 270 #define FUNCCOMMON(lib_infop, func) \
271 271 ((lib_infop->version == SMHBA) ? \
272 272 lib_infop->ftable.smhbafunctionTable.func : \
273 273 lib_infop->ftable.functionTable.func)
274 274
275 275 /*
276 276 * Macro to use the hbaapi function ptr.
277 277 * Should be used for an interface applicable only HBAAPIV2.
278 278 */
279 279 #define FUNCHBAAPIV2(lib_infop, func) \
280 280 lib_infop->ftable.functionTable.func
281 281
282 282 /*
283 283 * Macro to use the hbaapi function ptr.
284 284 * Should be used for an interface applicable only HBAAPIV2.
285 285 */
286 286 #define FUNCSMHBA(lib_infop, func) \
287 287 lib_infop->ftable.smhbafunctionTable.func
288 288
289 289 /*
290 290 * Individual adapter (hba) information
291 291 */
292 292 typedef struct hba_adapter_info {
293 293 struct hba_adapter_info
294 294 *next;
295 295 HBA_STATUS GNstatus; /* status from GetAdapterNameFunc */
296 296 char *name;
297 297 HBA_WWN nodeWWN;
298 298 HBA_LIBRARY_INFO *library;
299 299 HBA_UINT32 index;
300 300 } HBA_ADAPTER_INFO;
301 301
302 302 HBA_ADAPTER_INFO *_hbaapi_adapterlist = NULL;
303 303 HBA_UINT32 _hbaapi_total_adapter_count = 0;
304 304 #ifdef POSIX_THREADS
305 305 pthread_mutex_t _hbaapi_AL_mutex = PTHREAD_MUTEX_INITIALIZER;
306 306 #elif defined(WIN32)
307 307 CRITICAL_SECTION _hbaapi_AL_mutex;
308 308 #endif
309 309
310 310 /*
311 311 * Call back registration
312 312 */
313 313 typedef struct hba_vendorcallback_elem {
314 314 struct hba_vendorcallback_elem
315 315 *next;
316 316 HBA_CALLBACKHANDLE vendorcbhandle;
317 317 HBA_LIBRARY_INFO *lib_info;
318 318 } HBA_VENDORCALLBACK_ELEM;
319 319
320 320 /*
321 321 * Each instance of HBA_ADAPTERCALLBACK_ELEM represents a call to one of
322 322 * "register" functions that apply to a particular adapter.
323 323 * HBA_ALLADAPTERSCALLBACK_ELEM is used just for HBA_RegisterForAdapterAddEvents
324 324 */
325 325 typedef struct hba_adaptercallback_elem {
326 326 struct hba_adaptercallback_elem
327 327 *next;
328 328 HBA_LIBRARY_INFO *lib_info;
329 329 void *userdata;
330 330 HBA_CALLBACKHANDLE vendorcbhandle;
331 331 void (*callback)();
332 332 } HBA_ADAPTERCALLBACK_ELEM;
333 333
334 334 typedef struct hba_alladapterscallback_elem {
335 335 struct hba_alladapterscallback_elem
336 336 *next;
337 337 void *userdata;
338 338 HBA_VENDORCALLBACK_ELEM *vendorhandlelist;
339 339 void (*callback)();
340 340 } HBA_ALLADAPTERSCALLBACK_ELEM;
341 341
342 342 HBA_ALLADAPTERSCALLBACK_ELEM *_hbaapi_adapteraddevents_callback_list = NULL;
343 343 HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterevents_callback_list = NULL;
344 344 HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterportevents_callback_list = NULL;
345 345 HBA_ADAPTERCALLBACK_ELEM *_hbaapi_adapterportstatevents_callback_list = NULL;
346 346 HBA_ADAPTERCALLBACK_ELEM *_hbaapi_targetevents_callback_list = NULL;
347 347 HBA_ADAPTERCALLBACK_ELEM *_hbaapi_linkevents_callback_list = NULL;
348 348
349 349 HBA_ALLADAPTERSCALLBACK_ELEM *_smhba_adapteraddevents_callback_list = NULL;
350 350 HBA_ADAPTERCALLBACK_ELEM *_smhba_adapterevents_callback_list = NULL;
351 351 HBA_ADAPTERCALLBACK_ELEM *_smhba_adapterportevents_callback_list = NULL;
352 352 HBA_ADAPTERCALLBACK_ELEM *_smhba_adapterportstatevents_callback_list = NULL;
353 353 HBA_ADAPTERCALLBACK_ELEM *_smhba_adapterphystatevents_callback_list = NULL;
354 354 HBA_ADAPTERCALLBACK_ELEM *_smhba_targetevents_callback_list = NULL;
355 355
356 356 #ifdef POSIX_THREADS
357 357 /* mutex's to protect each list */
358 358 pthread_mutex_t _hbaapi_AAE_mutex = PTHREAD_MUTEX_INITIALIZER;
359 359 pthread_mutex_t _hbaapi_AE_mutex = PTHREAD_MUTEX_INITIALIZER;
360 360 pthread_mutex_t _hbaapi_APE_mutex = PTHREAD_MUTEX_INITIALIZER;
361 361 pthread_mutex_t _hbaapi_APSE_mutex = PTHREAD_MUTEX_INITIALIZER;
362 362 pthread_mutex_t _hbaapi_TE_mutex = PTHREAD_MUTEX_INITIALIZER;
363 363 pthread_mutex_t _hbaapi_LE_mutex = PTHREAD_MUTEX_INITIALIZER;
364 364 pthread_mutex_t _smhba_AAE_mutex = PTHREAD_MUTEX_INITIALIZER;
365 365 pthread_mutex_t _smhba_AE_mutex = PTHREAD_MUTEX_INITIALIZER;
366 366 pthread_mutex_t _smhba_APE_mutex = PTHREAD_MUTEX_INITIALIZER;
367 367 pthread_mutex_t _smhba_APSE_mutex = PTHREAD_MUTEX_INITIALIZER;
368 368 pthread_mutex_t _smhba_APHYSE_mutex = PTHREAD_MUTEX_INITIALIZER;
369 369 pthread_mutex_t _smhba_TE_mutex = PTHREAD_MUTEX_INITIALIZER;
370 370 pthread_mutex_t _smhba_LE_mutex = PTHREAD_MUTEX_INITIALIZER;
371 371 #elif defined(WIN32)
372 372 CRITICAL_SECTION _hbaapi_AAE_mutex;
373 373 CRITICAL_SECTION _hbaapi_AE_mutex;
374 374 CRITICAL_SECTION _hbaapi_APE_mutex;
375 375 CRITICAL_SECTION _hbaapi_APSE_mutex;
376 376 CRITICAL_SECTION _hbaapi_TE_mutex;
377 377 CRITICAL_SECTION _smhba_AAE_mutex;
378 378 CRITICAL_SECTION _smhba_AE_mutex;
379 379 CRITICAL_SECTION _smhba_APE_mutex;
380 380 CRITICAL_SECTION _smhba_APSE_mutex;
381 381 CRITICAL_SECTION _smhba_APHYSE_mutex;
382 382 CRITICAL_SECTION _smhba_TE_mutex;
383 383 CRITICAL_SECTION _hbaapi_LE_mutex;
384 384 #endif
385 385
386 386 HBA_ADAPTERCALLBACK_ELEM **cb_lists_array[] = {
387 387 &_hbaapi_adapterevents_callback_list,
388 388 &_hbaapi_adapterportevents_callback_list,
389 389 &_hbaapi_adapterportstatevents_callback_list,
390 390 &_hbaapi_targetevents_callback_list,
391 391 &_hbaapi_linkevents_callback_list,
392 392 &_smhba_adapterevents_callback_list,
393 393 &_smhba_adapterportevents_callback_list,
394 394 &_smhba_adapterportstatevents_callback_list,
395 395 &_smhba_adapterphystatevents_callback_list,
396 396 &_smhba_targetevents_callback_list,
397 397 NULL};
398 398
399 399 /*
400 400 * Common library internal. Mutex handling
401 401 */
402 402 #ifdef POSIX_THREADS
403 403 static void
404 404 grab_mutex(pthread_mutex_t *mp) {
405 405 /* LINTED E_FUNC_SET_NOT_USED */
406 406 int ret;
407 407 if ((ret = pthread_mutex_lock(mp)) != 0) {
408 408 perror("pthread_mutex_lock - HBAAPI:");
409 409 DEBUG(1, "pthread_mutex_lock returned %d", ret, 0, 0);
410 410 }
411 411 }
412 412
413 413 static void
414 414 release_mutex(pthread_mutex_t *mp) {
415 415 /* LINTED E_FUNC_SET_NOT_USED */
416 416 int ret;
417 417 if ((ret = pthread_mutex_unlock(mp)) != 0) {
418 418 perror("pthread_mutex_unlock - HBAAPI:");
419 419 DEBUG(1, "pthread_mutex_unlock returned %d", ret, 0, 0);
420 420 }
421 421 }
422 422 #endif
423 423
424 424 /*
425 425 * Common library internal. Check library and return vendorhandle
426 426 */
427 427 static HBA_STATUS
428 428 HBA_CheckLibrary(HBA_HANDLE handle,
429 429 HBA_LIBRARY_INFO **lib_infopp,
430 430 HBA_HANDLE *vendorhandle) {
431 431
432 432 HBA_UINT32 libraryIndex;
433 433 HBA_LIBRARY_INFO *lib_infop;
434 434
435 435 if (_hbaapi_librarylist == NULL) {
436 436 return (HBA_STATUS_ERROR);
437 437 }
438 438 libraryIndex = LIBRARY_NUM(handle);
439 439
440 440 GRAB_MUTEX(&_hbaapi_LL_mutex);
441 441 for (lib_infop = _hbaapi_librarylist;
442 442 lib_infop != NULL;
443 443 lib_infop = lib_infop->next) {
444 444 if (lib_infop->index == libraryIndex) {
445 445 if (lib_infop->status != HBA_LIBRARY_LOADED) {
446 446 return (HBA_STATUS_ERROR);
447 447 }
448 448 *lib_infopp = lib_infop;
449 449 *vendorhandle = VENDOR_HANDLE(handle);
450 450 /* caller will release the mutex */
451 451 return (HBA_STATUS_OK);
452 452 }
453 453 }
454 454 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INVALID_HANDLE);
455 455 }
456 456 #define CHECKLIBRARY() \
457 457 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);\
458 458 if (status != HBA_STATUS_OK) { \
459 459 return (status); \
460 460 }
461 461
462 462 #define CHECKLIBRARYANDVERSION(ver) \
463 463 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle); \
464 464 if (status != HBA_STATUS_OK) { \
465 465 return (status); \
466 466 } else { \
467 467 if (ver != lib_infop->version) { \
468 468 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, \
469 469 HBA_STATUS_ERROR_INCOMPATIBLE); \
470 470 } \
471 471 }
472 472
473 473 /*
474 474 * freevendorhandlelist is called with _hbaapi_LL_mutex already held
475 475 */
476 476 static void
477 477 freevendorhandlelist(HBA_VENDORCALLBACK_ELEM *vhlist) {
478 478 HBA_VENDORCALLBACK_ELEM *vhlp;
479 479 HBA_VENDORCALLBACK_ELEM *vnext;
480 480 HBARemoveCallbackFunc registeredfunc;
481 481
482 482 for (vhlp = vhlist; vhlp != NULL; vhlp = vnext) {
483 483 vnext = vhlp->next;
484 484 registeredfunc =
485 485 FUNCCOMMON(vhlp->lib_info, RemoveCallbackHandler);
486 486 if (registeredfunc == NULL) {
487 487 continue;
488 488 }
489 489 (registeredfunc)(vhlp->vendorcbhandle);
490 490 free(vhlp);
491 491 }
492 492 }
493 493
494 494 static
495 495 HBA_STATUS
496 496 local_remove_callback(HBA_CALLBACKHANDLE cbhandle) {
497 497 HBA_ADAPTERCALLBACK_ELEM ***listp;
498 498 HBA_ADAPTERCALLBACK_ELEM **lastp;
499 499 HBA_ALLADAPTERSCALLBACK_ELEM **lap;
500 500 HBA_ALLADAPTERSCALLBACK_ELEM *allcbp;
501 501 HBA_ADAPTERCALLBACK_ELEM *cbp;
502 502 HBARemoveCallbackFunc registeredfunc;
503 503 HBA_VENDORCALLBACK_ELEM *vhlp;
504 504 HBA_VENDORCALLBACK_ELEM *vnext;
505 505 int found;
506 506 HBA_STATUS status = HBA_STATUS_ERROR_INVALID_HANDLE;
507 507
508 508
509 509 /* search through the simple lists first */
510 510 GRAB_MUTEX(&_hbaapi_AAE_mutex);
511 511 GRAB_MUTEX(&_hbaapi_AE_mutex);
512 512 GRAB_MUTEX(&_hbaapi_APE_mutex);
513 513 GRAB_MUTEX(&_hbaapi_APSE_mutex);
514 514 GRAB_MUTEX(&_hbaapi_TE_mutex);
515 515 GRAB_MUTEX(&_hbaapi_LE_mutex);
516 516 GRAB_MUTEX(&_smhba_AAE_mutex);
517 517 GRAB_MUTEX(&_smhba_AE_mutex);
518 518 GRAB_MUTEX(&_smhba_APE_mutex);
519 519 GRAB_MUTEX(&_smhba_APSE_mutex);
520 520 GRAB_MUTEX(&_smhba_TE_mutex);
521 521 for (listp = cb_lists_array, found = 0;
522 522 (found == 0 && *listp != NULL); listp++) {
523 523 lastp = *listp;
524 524 for (cbp = **listp; cbp != NULL; cbp = cbp->next) {
525 525 if (cbhandle != (HBA_CALLBACKHANDLE)cbp) {
526 526 lastp = &(cbp->next);
527 527 continue;
528 528 }
529 529 found = 1;
530 530 registeredfunc =
531 531 FUNCCOMMON(cbp->lib_info, RemoveCallbackHandler);
532 532 if (registeredfunc == NULL) {
533 533 break;
534 534 }
535 535 (registeredfunc)(cbp->vendorcbhandle);
536 536 *lastp = cbp->next;
537 537 free(cbp);
538 538 break;
539 539 }
540 540 }
541 541 RELEASE_MUTEX(&_hbaapi_LE_mutex);
542 542 RELEASE_MUTEX(&_hbaapi_TE_mutex);
543 543 RELEASE_MUTEX(&_hbaapi_APSE_mutex);
544 544 RELEASE_MUTEX(&_hbaapi_APE_mutex);
545 545 RELEASE_MUTEX(&_hbaapi_AE_mutex);
546 546 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
547 547 RELEASE_MUTEX(&_smhba_AAE_mutex);
548 548 RELEASE_MUTEX(&_smhba_AE_mutex);
549 549 RELEASE_MUTEX(&_smhba_APE_mutex);
550 550 RELEASE_MUTEX(&_smhba_APSE_mutex);
551 551 RELEASE_MUTEX(&_smhba_TE_mutex);
552 552
553 553 if (found != 0) {
554 554 if (registeredfunc == NULL) {
555 555 return (HBA_STATUS_ERROR_NOT_SUPPORTED);
556 556 }
557 557 return (HBA_STATUS_OK);
558 558 }
559 559
560 560 GRAB_MUTEX(&_hbaapi_AAE_mutex);
561 561 /*
562 562 * if it wasnt in the simple lists,
563 563 * look in the list for adapteraddevents
564 564 */
565 565 lap = &_hbaapi_adapteraddevents_callback_list;
566 566 for (allcbp = _hbaapi_adapteraddevents_callback_list;
567 567 allcbp != NULL;
568 568 allcbp = allcbp->next) {
569 569 if (cbhandle != (HBA_CALLBACKHANDLE)allcbp) {
570 570 lap = &allcbp->next;
571 571 continue;
572 572 }
573 573 for (vhlp = allcbp->vendorhandlelist; vhlp != NULL; vhlp = vnext) {
574 574 vnext = vhlp->next;
575 575 /* should be HBAAPIV2 VSL to get to here */
576 576 registeredfunc =
577 577 vhlp->lib_info->ftable.functionTable.RemoveCallbackHandler;
578 578 if (registeredfunc == NULL) {
579 579 continue;
580 580 }
581 581 (registeredfunc)(vhlp->vendorcbhandle);
582 582 free(vhlp);
583 583 }
584 584 *lap = allcbp->next;
585 585 free(allcbp);
586 586 status = HBA_STATUS_OK;
587 587 break;
588 588 }
589 589 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
590 590
591 591 /* now search smhba adapteradd events. */
592 592 GRAB_MUTEX(&_smhba_AAE_mutex);
593 593 lap = &_smhba_adapteraddevents_callback_list;
594 594 for (allcbp = _smhba_adapteraddevents_callback_list;
595 595 allcbp != NULL;
596 596 allcbp = allcbp->next) {
597 597 if (cbhandle != (HBA_CALLBACKHANDLE)allcbp) {
598 598 lap = &allcbp->next;
599 599 continue;
600 600 }
601 601 for (vhlp = allcbp->vendorhandlelist; vhlp != NULL; vhlp = vnext) {
602 602 vnext = vhlp->next;
603 603 /* should be SMHBA VSL to get to here */
604 604 registeredfunc =
605 605 vhlp->lib_info->
606 606 ftable.smhbafunctionTable.RemoveCallbackHandler;
607 607 if (registeredfunc == NULL) {
608 608 continue;
609 609 }
610 610 (registeredfunc)(vhlp->vendorcbhandle);
611 611 free(vhlp);
612 612 }
613 613 *lap = allcbp->next;
614 614 free(allcbp);
615 615 status = HBA_STATUS_OK;
616 616 break;
617 617 }
618 618 RELEASE_MUTEX(&_smhba_AAE_mutex);
619 619
620 620 return (status);
621 621 }
622 622
623 623 /* LINTED E_STATIC_UE_STATIC_UNUSED */
624 624 static char wwn_str1[17];
625 625 /* LINTED E_STATIC_UE_STATIC_UNUSED */
626 626 static char wwn_str2[17];
627 627 /* LINTED E_STATIC_UE_STATIC_UNUSED */
628 628 static char wwn_str3[17];
629 629 #define WWN2STR1(wwn) WWN2str(wwn_str1, (wwn))
630 630 #define WWN2STR2(wwn) WWN2str(wwn_str2, (wwn))
631 631 #define WWN2STR3(wwn) WWN2str(wwn_str3, (wwn))
632 632 static char *
633 633 /* LINTED E_STATIC_UE_STATIC_UNUSED */
634 634 WWN2str(char *buf, HBA_WWN *wwn) {
635 635 int j;
636 636 unsigned char *pc = (unsigned char *)&(wwn->wwn[0]);
637 637 buf[0] = '\0';
638 638 for (j = 0; j < 16; j += 2) {
639 639 (void) sprintf(&buf[j], "%02X", (int)*pc++);
640 640 }
641 641 return (buf);
642 642 }
643 643
644 644 #ifdef WIN32
645 645 BOOL APIENTRY
646 646 DllMain(HANDLE hModule,
647 647 DWORD ul_reason_for_call,
648 648 LPVOID lpReserved)
649 649 {
650 650 switch (ul_reason_for_call) {
651 651 case DLL_PROCESS_ATTACH:
652 652 break;
653 653 case DLL_PROCESS_DETACH:
654 654 break;
655 655 case DLL_THREAD_ATTACH:
656 656 case DLL_THREAD_DETACH:
657 657 break;
658 658 }
659 659 return (TRUE);
660 660 }
661 661 #endif
662 662
663 663 /*
664 664 * Read in the config file and load all the specified vendor specific
665 665 * libraries and perform the function registration exercise
666 666 */
667 667 HBA_STATUS
668 668 HBA_LoadLibrary()
669 669 {
670 670 HBARegisterLibraryFunc RegisterFunc;
671 671 HBARegisterLibraryV2Func RegisterV2Func;
672 672 SMHBARegisterLibraryFunc RegisterSMHBAFunc;
673 673 HBALoadLibraryFunc LoadLibraryFunc;
674 674 HBAGetVersionFunc GetVersionFunc;
675 675 #ifdef POSIX_THREADS
676 676 int ret;
677 677 #endif
678 678 HBA_STATUS status;
679 679 HBA_UINT32 libversion;
680 680
681 681 /* Open configuration file from known location */
682 682 #ifdef WIN32
683 683 LONG lStatus;
684 684 HKEY hkSniaHba, hkVendorLib;
685 685 FILETIME ftLastWriteTime;
686 686 TCHAR cSubKeyName[256];
687 687 DWORD i, dwSize, dwType;
688 688 BYTE byFileName[MAX_PATH];
689 689 HBA_LIBRARY_INFO *lib_infop;
690 690
691 691 if (_hbaapi_librarylist != NULL) {
692 692 /* this is an app programming error */
693 693 return (HBA_STATUS_ERROR);
694 694 }
695 695
696 696 lStatus = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\SNIA\\HBA",
697 697 0, KEY_READ, &hkSniaHba);
698 698 if (lStatus != ERROR_SUCCESS) {
699 699 /* ???Opportunity to send error msg, configuration error */
700 700 return (HBA_STATUS_ERROR);
701 701 }
702 702 /*
703 703 * Enumerate all the subkeys. These have the form:
704 704 * HKLM\Software\SNIA\HBA\<Vendor id> - note that we don't care
705 705 * what the vendor id is
706 706 */
707 707 for (i = 0; ; i++) {
708 708 dwSize = 255; /* how big the buffer is */
709 709 lStatus = RegEnumKeyEx(hkSniaHba, i,
710 710 (char *)&cSubKeyName, &dwSize, NULL,
711 711 NULL, NULL, &ftLastWriteTime);
712 712 if (lStatus == ERROR_NO_MORE_ITEMS) {
713 713 break; /* we're done */
714 714 } else if (lStatus == ERROR_MORE_DATA) { /* buffer not big enough */
715 715 /* do whatever */
716 716 ;
717 717 }
718 718 /* Now open the subkey that pertains to this vendor's library */
719 719 lStatus = RegOpenKeyEx(hkSniaHba, cSubKeyName, 0, KEY_READ,
720 720 &hkVendorLib);
721 721 if (lStatus != ERROR_SUCCESS) {
722 722 RegCloseKey(hkSniaHba);
723 723 /* ???Opportunity to send error msg, installation error */
724 724 return (HBA_STATUS_ERROR);
725 725 /*
726 726 * you may want to return something
727 727 * else or keep trying
728 728 */
729 729 }
730 730 /*
731 731 * The name of the library is contained in a REG_SZ Value
732 732 * keyed to "LibraryFile"
733 733 */
734 734 dwSize = MAX_PATH;
735 735 lStatus = RegQueryValueEx(hkVendorLib, "LibraryFile", NULL, &dwType,
736 736 byFileName, &dwSize);
737 737 if (lStatus != ERROR_SUCCESS) {
738 738 RegCloseKey(hkVendorLib);
739 739 /* ???Opportunity to send error msg, installation error */
740 740 continue;
741 741 }
742 742 lib_infop = (HBA_LIBRARY_INFO *)calloc(1, sizeof (HBA_LIBRARY_INFO));
743 743 if (lib_infop == NULL) {
744 744 /* what is the right thing to do in MS land??? */
745 745 RegCloseKey(hkVendorLib);
746 746 /* ???Opportunity to send error msg, installation error */
747 747 return (HBA_STATUS_ERROR);
748 748 }
749 749 lib_infop->status = HBA_LIBRARY_NOT_LOADED;
750 750 lib_infop->next = _hbaapi_librarylist;
751 751 lib_infop->index = _hbaapi_total_library_count;
752 752 _hbaapi_total_library_count++;
753 753 _hbaapi_librarylist = lib_infop;
754 754
755 755 /* Now I can try to load the library */
756 756 lib_infop->hLibrary = LoadLibrary(byFileName);
757 757 if (lib_infop->hLibrary == NULL) {
758 758 /* printf("unable to load library %s\n", librarypath); */
759 759 /* ???Opportunity to send error msg, installation error */
760 760 goto dud_library;
761 761 }
762 762 lib_infop->LibraryPath = strdup(byFileName);
763 763 DEBUG(1, "HBAAPI loading: %s\n", byFileName, 0, 0);
764 764
765 765 RegisterSMHBAFunc = (SMHBARegisterLibraryFunc)
766 766 GetProcAddress(lib_infop->hLibrary, "SMHBA_RegisterLibrary");
767 767 if (RegisterSMHBAFunc != NULL) {
768 768 status = ((RegisterSMHBAFunc)(SMHBA_ENTRYPOINTS *)
769 769 (&lib_infop->ftable.smhbafunctionTable));
770 770 if (status != HBA_STATUS_OK) {
771 771 /* library not loaded */
772 772 /* ???Opportunity to send error msg, library error? */
773 773 goto dud_library;
774 774 } else {
775 775 lib_infop->version = SMHBA;
776 776 }
777 777 } else {
778 778 /* Call the registration function to get the list of pointers */
779 779 RegisterV2Func = (HBARegisterLibraryV2Func)GetProcAddress(
780 780 lib_infop->hLibrary, "HBA_RegisterLibraryV2");
781 781 if (RegisterV2Func != NULL) {
782 782 /*
783 783 * Load the function pointers directly into
784 784 * the table of functions
785 785 */
786 786 status = ((RegisterV2Func)
787 787 (HBA_ENTRYPOINTSV2 *)(&lib_infop->ftable.functionTable));
788 788 if (status != HBA_STATUS_OK) {
789 789 /* library not loaded */
790 790 /* ???Opportunity to send error msg, library error? */
791 791 goto dud_library;
792 792 } else {
793 793 lib_infop->version = HBAAPIV2;
794 794 }
795 795 } else {
796 796 /* Maybe the vendor library is only Rev1 */
797 797 RegisterFunc = (HBARegisterLibraryFunc)
798 798 GetProcAddress(lib_infop->hLibrary, "HBA_RegisterLibrary");
799 799 if (RegisterFunc == NULL) {
800 800 /* ???Opportunity to send error msg, library error? */
801 801 goto dud_library;
802 802 }
803 803 /*
804 804 * Load the function points directly into
805 805 * the Rev 2 table of functions
806 806 */
807 807 status = ((RegisterFunc)(
808 808 (HBA_ENTRYPOINTS *)(&lib_infop->ftable.functionTable)));
809 809 if (status != HBA_STATUS_OK) {
810 810 /* library not loaded */
811 811 /* ???Opportunity to send error msg, library error? */
812 812 goto dud_library;
813 813 } else {
814 814 lib_infop->version = HBAAPI;
815 815 }
816 816 }
817 817 }
818 818
819 819 /* successfully loaded library */
820 820 /*
821 821 * SM-HBA and HBAAPI has a seperate handler for GetVersion but
822 822 * they have the same function signature so use the same variable here.
823 823 */
824 824 GetVersionFunc = FUNCCOMMON(lib_infop, GetVersionHandler);
825 825 if (GetVersionFunc != NULL) {
826 826 if (lib_infop->version == SMHBA) {
827 827 /* Check the version of this library before loading */
828 828 libversion = ((GetVersionFunc)());
829 829 #ifdef NOTDEF /* save for a later time... when it matters */
830 830 if (libversion < SMHBA_LIBVERSION) {
831 831 goto dud_library;
832 832 }
833 833 #endif
834 834 } else {
835 835 /* Check the version of this library before loading */
836 836 /* Actually... This wrapper is compatible with version 1 */
837 837 libversion = ((GetVersionFunc)());
838 838 #ifdef NOTDEF /* save for a later time... when it matters */
839 839 if (libversion < HBA_LIBVERSION) {
840 840 goto dud_library;
841 841 }
842 842 #endif
843 843 }
844 844 } else {
845 845 /* ???Opportunity to send error msg, library error? */
846 846 goto dud_library;
847 847 }
848 848
849 849 LoadLibraryFunc = FUNCCOMMON(lib_infop, LoadLibraryHandler);
850 850 if (LoadLibraryFunc == NULL) {
851 851 /* Hmmm, dont we need to flag this in a realy big way??? */
852 852 /* How about messages to the system event logger ??? */
853 853 /* ???Opportunity to send error msg, library error? */
854 854 goto dud_library;
855 855 }
856 856 /* Initialize this library */
857 857 status = ((LoadLibraryFunc)());
858 858 if (status != HBA_STATUS_OK) {
859 859 /* ???Opportunity to send error msg, library error? */
860 860 continue;
861 861 }
862 862 /* successfully loaded library */
863 863 lib_infop->status = HBA_LIBRARY_LOADED;
864 864
865 865 dud_library: /* its also just the end of the loop */
866 866 RegCloseKey(hkVendorLib);
867 867 }
868 868 RegCloseKey(hkSniaHba);
869 869
870 870 #else /* Unix as opposed to Win32 */
871 871 FILE *hbaconf;
872 872 char fullline[512]; /* line read from HBA.conf */
873 873 char *libraryname; /* Read in from file HBA.conf */
874 874 char *librarypath; /* Read in from file HBA.conf */
875 875 char hbaConfFilePath[256];
876 876 char *charPtr;
877 877 HBA_LIBRARY_INFO *lib_infop;
878 878
879 879 GRAB_MUTEX(&_hbaapi_LL_mutex);
880 880 if (_hbaapi_librarylist != NULL) {
881 881 (void) fprintf(stderr,
882 882 "HBA_LoadLibrary: previously unfreed "
883 883 "libraries exist, call HBA_FreeLibrary().\n");
884 884 RELEASE_MUTEX(&_hbaapi_LL_mutex);
885 885 return (HBA_STATUS_ERROR);
886 886 }
887 887
888 888 (void) strcpy(hbaConfFilePath, "/etc/smhba.conf");
889 889
890 890 if ((hbaconf = fopen(hbaConfFilePath, "r")) == NULL) {
891 891 (void) printf("Cannot open %s\n", hbaConfFilePath);
892 892 RELEASE_MUTEX(&_hbaapi_LL_mutex);
893 893 return (HBA_STATUS_ERROR);
894 894 }
895 895
896 896 /* Read in each line and load library */
897 897 while ((hbaconf != NULL) &&
898 898 (fgets(fullline, sizeof (fullline), hbaconf))) {
899 899 /* Skip the comments... */
900 900 if ((fullline[0] == '#') || (fullline[0] == '\n')) {
901 901 continue;
902 902 }
903 903
904 904 /* grab first 'thing' in line (if its there) */
905 905 if ((libraryname = strtok(fullline, " \t\n")) != NULL) {
906 906 if (strlen(libraryname) >= 64) {
907 907 (void) fprintf(stderr,
908 908 "Library name(%s) in %s is > 64 characters\n",
909 909 libraryname, hbaConfFilePath);
910 910 }
911 911 }
912 912 /* grab second 'thing' in line (if its there) */
913 913 if ((librarypath = strtok(NULL, " \t\n")) != NULL) {
914 914 if (strlen(librarypath) >= 256) {
915 915 (void) fprintf(stderr,
916 916 "Library path(%s) in %s is > 256 characters\n",
917 917 librarypath, hbaConfFilePath);
918 918 }
919 919 }
920 920
921 921 /* there should be no more 'things' in the line */
922 922 if ((charPtr = strtok(NULL, " \n\t")) != NULL) {
923 923 (void) fprintf(stderr, "Extraneous characters (\"%s\") in %s\n",
924 924 charPtr, hbaConfFilePath);
925 925 }
926 926
927 927 /* Continue to the next line if library name or path is invalid */
928 928 if (libraryname == NULL ||
929 929 strlen(libraryname) == 0 ||
930 930 librarypath == NULL ||
931 931 (strlen(librarypath) == 0)) {
932 932 continue;
933 933 }
934 934
935 935 /*
936 936 * Special case....
937 937 * Look for loglevel
938 938 */
939 939 if (strcmp(libraryname, "debuglevel") == 0) {
940 940 _hbaapi_debuglevel = strtol(librarypath, NULL, 10);
941 941 /* error handling does the right thing automagically */
942 942 continue;
943 943 }
944 944
945 945 lib_infop = (HBA_LIBRARY_INFO *)calloc(1, sizeof (HBA_LIBRARY_INFO));
946 946 if (lib_infop == NULL) {
947 947 (void) fprintf(stderr, "HBA_LoadLibrary: out of memeory\n");
948 948 RELEASE_MUTEX(&_hbaapi_LL_mutex);
949 949 return (HBA_STATUS_ERROR);
950 950 }
951 951 lib_infop->status = HBA_LIBRARY_NOT_LOADED;
952 952 lib_infop->LibraryName = strdup(libraryname);
953 953 lib_infop->LibraryPath = strdup(librarypath);
954 954 lib_infop->numOfAdapters = 0;
955 955 lib_infop->version = UNKNOWN;
956 956 lib_infop->index = _hbaapi_total_library_count;
957 957 _hbaapi_total_library_count++;
958 958 lib_infop->next = _hbaapi_librarylist;
959 959 _hbaapi_librarylist = lib_infop;
960 960
961 961 /* Load the DLL now */
962 962 if ((lib_infop->hLibrary = dlopen(librarypath, RTLD_LAZY)) == NULL) {
963 963 /* printf("unable to load library %s\n", librarypath); */
964 964 continue;
965 965 }
966 966 /* Call the registration function to get the list of pointers */
967 967 RegisterSMHBAFunc = (SMHBARegisterLibraryFunc)
968 968 dlsym(lib_infop->hLibrary, "SMHBA_RegisterLibrary");
969 969 if (RegisterSMHBAFunc != NULL) {
970 970 /*
971 971 * Load the function points directly into
972 972 * the table of functions
973 973 */
974 974 status = ((RegisterSMHBAFunc)
975 975 (&lib_infop->ftable.smhbafunctionTable));
976 976 if (status != HBA_STATUS_OK) {
977 977 /* library not loaded */
978 978 continue;
979 979 } else {
980 980 lib_infop->version = SMHBA;
981 981 }
982 982 } else {
983 983 RegisterV2Func = (HBARegisterLibraryV2Func)
984 984 dlsym(lib_infop->hLibrary, "HBA_RegisterLibraryV2");
985 985 if (RegisterV2Func != NULL) {
986 986 /*
987 987 * Load the function points directly into
988 988 * the table of functions
989 989 */
990 990 status = ((RegisterV2Func)((HBA_ENTRYPOINTSV2 *)
991 991 (&lib_infop->ftable.functionTable)));
992 992 if (status != HBA_STATUS_OK) {
993 993 /* library not loaded */
994 994 continue;
995 995 } else {
996 996 lib_infop->version = HBAAPIV2;
997 997 }
998 998 } else {
999 999 /* Maybe the vendor library is only Rev1 */
1000 1000 RegisterFunc = (HBARegisterLibraryFunc)
1001 1001 dlsym(lib_infop->hLibrary, "HBA_RegisterLibrary");
1002 1002 if (RegisterFunc == NULL) {
1003 1003 /* This function is required */
1004 1004 (void) fprintf(stderr,
1005 1005 "HBA_LoadLibrary: vendor specific RegisterLibrary "
1006 1006 "function not found. lib: %s\n", librarypath);
1007 1007 DEBUG(1, "HBA_LoadLibrary: vendor specific "
1008 1008 "RegisterLibrary function not found. lib: %s\n",
1009 1009 librarypath, 0, 0);
1010 1010 continue;
1011 1011 }
1012 1012 /*
1013 1013 * Load the function points directly into
1014 1014 * the table of functions
1015 1015 */
1016 1016 status = ((RegisterFunc)
1017 1017 ((HBA_ENTRYPOINTS *)(&lib_infop->ftable.functionTable)));
1018 1018 if (status != HBA_STATUS_OK) {
1019 1019 /* library not loaded */
1020 1020 (void) fprintf(stderr,
1021 1021 "HBA_LoadLibrary: vendor specific RegisterLibrary "
1022 1022 "function encountered an error. lib: %s\n",
1023 1023 librarypath);
1024 1024 DEBUG(1,
1025 1025 "HBA_LoadLibrary: vendor specific RegisterLibrary "
1026 1026 "function encountered an error. lib: %s\n",
1027 1027 librarypath, 0, 0);
1028 1028 continue;
1029 1029 } else {
1030 1030 lib_infop->version = HBAAPI;
1031 1031 }
1032 1032 }
1033 1033 }
1034 1034
1035 1035 /* successfully loaded library */
1036 1036 /*
1037 1037 * SM-HBA and HBAAPI has a seperate handler for GetVersion but
1038 1038 * they have the same function signature so use the same variable here.
1039 1039 */
1040 1040 if ((GetVersionFunc = FUNCCOMMON(lib_infop, GetVersionHandler))
1041 1041 == NULL) {
1042 1042 continue;
1043 1043 }
1044 1044 if (lib_infop->version == SMHBA) {
1045 1045 libversion = ((GetVersionFunc)());
1046 1046 if (libversion < SMHBA_LIBVERSION) {
1047 1047 (void) printf("Library version mismatch."
1048 1048 "Got %d expected %d.\n",
1049 1049 libversion, SMHBA_LIBVERSION);
1050 1050 continue;
1051 1051 }
1052 1052 } else {
1053 1053 libversion = ((GetVersionFunc)());
1054 1054 /* Check the version of this library before loading */
1055 1055 /* Actually... This wrapper is compatible with version 1 */
1056 1056 if (libversion < HBA_LIBVERSION) {
1057 1057 (void) printf("Library version mismatch."
1058 1058 "Got %d expected %d.\n",
1059 1059 libversion, HBA_LIBVERSION);
1060 1060 continue;
1061 1061 }
1062 1062 }
1063 1063
1064 1064 DEBUG(1, "%s libversion = %d", librarypath, libversion, 0);
1065 1065 LoadLibraryFunc = FUNCCOMMON(lib_infop, LoadLibraryHandler);
1066 1066 if (LoadLibraryFunc == NULL) {
1067 1067 /* this function is required */
1068 1068 (void) fprintf(stderr,
1069 1069 "HBA_LoadLibrary: vendor specific LoadLibrary "
1070 1070 "function not found. lib: %s\n", librarypath);
1071 1071 DEBUG(1, "HBA_LoadLibrary: vendor specific LoadLibrary "
1072 1072 "function not found. lib: %s\n", librarypath, 0, 0);
1073 1073 continue;
1074 1074 }
1075 1075 /* Initialize this library */
1076 1076 if ((status = ((LoadLibraryFunc)())) != HBA_STATUS_OK) {
1077 1077 /* maybe this should be a printf so that we CANNOT miss it */
|
↓ open down ↓ |
1077 lines elided |
↑ open up ↑ |
1078 1078 (void) fprintf(stderr,
1079 1079 "HBA_LoadLibrary: Encounterd and error loading: %s",
1080 1080 librarypath);
1081 1081 DEBUG(1, "Encounterd and error loading: %s", librarypath, 0, 0);
1082 1082 DEBUG(1, " HBA_STATUS: %d", status, 0, 0);
1083 1083 continue;
1084 1084 }
1085 1085 /* successfully loaded library */
1086 1086 lib_infop->status = HBA_LIBRARY_LOADED;
1087 1087 }
1088 + fclose(hbaconf);
1088 1089 #endif /* WIN32 or UNIX */
1089 1090 #ifdef POSIX_THREADS
1090 1091 /*
1091 1092 * The _hbaapi_LL_mutex is already grabbed to proctect the caller of
1092 1093 * HBA_FreeLibrary() during loading.
1093 1094 * The mutexes are already initialized
1094 1095 * with PTHREAD_MUTEX_INITIALIZER. Do we need to init again?
1095 1096 * Keeping the code from HBAAPI source...
1096 1097 */
1097 1098 ret = pthread_mutex_init(&_hbaapi_AL_mutex, NULL);
1098 1099 if (ret == 0) {
1099 1100 ret = pthread_mutex_init(&_hbaapi_AAE_mutex, NULL);
1100 1101 }
1101 1102 if (ret == 0) {
1102 1103 ret = pthread_mutex_init(&_hbaapi_AE_mutex, NULL);
1103 1104 }
1104 1105 if (ret == 0) {
1105 1106 ret = pthread_mutex_init(&_hbaapi_APE_mutex, NULL);
1106 1107 }
1107 1108 if (ret == 0) {
1108 1109 ret = pthread_mutex_init(&_hbaapi_APSE_mutex, NULL);
1109 1110 }
1110 1111 if (ret == 0) {
1111 1112 ret = pthread_mutex_init(&_hbaapi_TE_mutex, NULL);
1112 1113 }
1113 1114 if (ret == 0) {
1114 1115 ret = pthread_mutex_init(&_smhba_AAE_mutex, NULL);
1115 1116 }
1116 1117 if (ret == 0) {
1117 1118 ret = pthread_mutex_init(&_smhba_AE_mutex, NULL);
1118 1119 }
1119 1120 if (ret == 0) {
1120 1121 ret = pthread_mutex_init(&_smhba_APE_mutex, NULL);
1121 1122 }
1122 1123 if (ret == 0) {
1123 1124 ret = pthread_mutex_init(&_smhba_APSE_mutex, NULL);
1124 1125 }
1125 1126 if (ret == 0) {
1126 1127 ret = pthread_mutex_init(&_smhba_TE_mutex, NULL);
1127 1128 }
1128 1129 if (ret == 0) {
1129 1130 ret = pthread_mutex_init(&_hbaapi_LE_mutex, NULL);
1130 1131 }
1131 1132 if (ret != 0) {
1132 1133 perror("pthread_mutex_init - HBA_LoadLibrary");
1133 1134 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1134 1135 return (HBA_STATUS_ERROR);
1135 1136 }
1136 1137 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1137 1138 #elif defined(WIN32)
1138 1139 InitializeCriticalSection(&_hbaapi_LL_mutex);
1139 1140 InitializeCriticalSection(&_hbaapi_AL_mutex);
1140 1141 InitializeCriticalSection(&_hbaapi_AAE_mutex);
1141 1142 InitializeCriticalSection(&_hbaapi_AE_mutex);
1142 1143 InitializeCriticalSection(&_hbaapi_APE_mutex);
1143 1144 InitializeCriticalSection(&_hbaapi_APSE_mutex);
1144 1145 InitializeCriticalSection(&_hbaapi_TE_mutex);
1145 1146 InitializeCriticalSection(&_hbaapi_LE_mutex);
1146 1147 InitializeCriticalSection(&_smhba_AAE_mutex);
1147 1148 InitializeCriticalSection(&_smhba_AE_mutex);
1148 1149 InitializeCriticalSection(&_smhba_APE_mutex);
1149 1150 InitializeCriticalSection(&_smhba_APSE_mutex);
1150 1151 InitializeCriticalSection(&_smhba_TE_mutex);
1151 1152 #endif
1152 1153
1153 1154 return (HBA_STATUS_OK);
1154 1155 }
1155 1156
1156 1157 HBA_STATUS
1157 1158 HBA_FreeLibrary() {
1158 1159 HBAFreeLibraryFunc FreeLibraryFunc;
1159 1160 /* LINTED E_FUNC_SET_NOT_USED */
1160 1161 HBA_STATUS status __unused;
1161 1162 HBA_LIBRARY_INFO *lib_infop;
1162 1163 HBA_LIBRARY_INFO *lib_next;
1163 1164 HBA_ADAPTERCALLBACK_ELEM
1164 1165 ***listp;
1165 1166 HBA_ADAPTER_INFO *adapt_infop;
1166 1167 HBA_ADAPTER_INFO *adapt_next;
1167 1168
1168 1169 GRAB_MUTEX(&_hbaapi_LL_mutex);
1169 1170 if (_hbaapi_librarylist == NULL) {
1170 1171 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1171 1172 return (HBA_STATUS_ERROR_NOT_LOADED);
1172 1173 }
1173 1174
1174 1175 GRAB_MUTEX(&_hbaapi_AL_mutex);
1175 1176
1176 1177 DEBUG(1, "HBA_FreeLibrary()", 0, 0, 0);
1177 1178 for (lib_infop = _hbaapi_librarylist; lib_infop != NULL;
1178 1179 lib_infop = lib_next) {
1179 1180 lib_next = lib_infop->next;
1180 1181 if (lib_infop->status == HBA_LIBRARY_LOADED) {
1181 1182 FreeLibraryFunc = FUNCCOMMON(lib_infop, FreeLibraryHandler);
1182 1183 if (FreeLibraryFunc != NULL) {
1183 1184 /* Free this library */
1184 1185 status = ((FreeLibraryFunc)());
1185 1186 DEBUG(1, "HBA_FreeLibrary() Failed %d", status, 0, 0);
1186 1187 }
1187 1188 #ifdef WIN32
1188 1189 FreeLibrary(lib_infop->hLibrary); /* Unload DLL from memory */
1189 1190 #else
1190 1191 (void) dlclose(lib_infop->hLibrary); /* Unload DLL from memory */
1191 1192 #endif
1192 1193 }
1193 1194 #ifndef WIN32
1194 1195 free(lib_infop->LibraryName);
1195 1196 #endif
1196 1197 free(lib_infop->LibraryPath);
1197 1198 free(lib_infop);
1198 1199
1199 1200 }
1200 1201 _hbaapi_librarylist = NULL;
1201 1202 /*
1202 1203 * OK, now all functions are disabled except for LoadLibrary,
1203 1204 * Hope no other thread calls it before we have returned
1204 1205 */
1205 1206 _hbaapi_total_library_count = 0;
1206 1207
1207 1208 for (adapt_infop = _hbaapi_adapterlist;
1208 1209 adapt_infop != NULL;
1209 1210 adapt_infop = adapt_next) {
1210 1211 adapt_next = adapt_infop->next;
1211 1212 free(adapt_infop->name);
1212 1213 free(adapt_infop);
1213 1214 }
1214 1215 _hbaapi_adapterlist = NULL;
1215 1216 _hbaapi_total_adapter_count = 0;
1216 1217
1217 1218 /*
1218 1219 * Free up the callbacks, this is not the most efficient, but it works
1219 1220 */
1220 1221 while ((volatile HBA_ADAPTERCALLBACK_ELEM *)
1221 1222 _hbaapi_adapteraddevents_callback_list
1222 1223 != NULL) {
1223 1224 (void) local_remove_callback((HBA_CALLBACKHANDLE)
1224 1225 _hbaapi_adapteraddevents_callback_list);
1225 1226 }
1226 1227 while ((volatile HBA_ADAPTERCALLBACK_ELEM *)
1227 1228 _smhba_adapteraddevents_callback_list
1228 1229 != NULL) {
1229 1230 (void) local_remove_callback((HBA_CALLBACKHANDLE)
1230 1231 _smhba_adapteraddevents_callback_list);
1231 1232 }
1232 1233 for (listp = cb_lists_array; *listp != NULL; listp++) {
1233 1234 while ((volatile HBA_ADAPTERCALLBACK_ELEM ***)**listp != NULL) {
1234 1235 (void) local_remove_callback((HBA_CALLBACKHANDLE)**listp);
1235 1236 }
1236 1237 }
1237 1238
1238 1239 RELEASE_MUTEX(&_hbaapi_AL_mutex);
1239 1240 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1240 1241
1241 1242 #ifdef USESYSLOG
1242 1243 closelog();
1243 1244 #endif
1244 1245 #ifdef USELOGFILE
1245 1246 if (_hbaapi_debug_fd != NULL) {
1246 1247 fclose(_hbaapi_debug_fd);
1247 1248 }
1248 1249 _hbaapi_debug_fd = NULL;
1249 1250 #endif
1250 1251 #ifdef POSIX_THREADS
1251 1252 /* this will unlock them as well, but who cares */
1252 1253 (void) pthread_mutex_destroy(&_hbaapi_LE_mutex);
1253 1254 (void) pthread_mutex_destroy(&_hbaapi_TE_mutex);
1254 1255 (void) pthread_mutex_destroy(&_hbaapi_APSE_mutex);
1255 1256 (void) pthread_mutex_destroy(&_hbaapi_APE_mutex);
1256 1257 (void) pthread_mutex_destroy(&_hbaapi_AE_mutex);
1257 1258 (void) pthread_mutex_destroy(&_hbaapi_AAE_mutex);
1258 1259 (void) pthread_mutex_destroy(&_smhba_TE_mutex);
1259 1260 (void) pthread_mutex_destroy(&_smhba_APSE_mutex);
1260 1261 (void) pthread_mutex_destroy(&_smhba_APE_mutex);
1261 1262 (void) pthread_mutex_destroy(&_smhba_AE_mutex);
1262 1263 (void) pthread_mutex_destroy(&_smhba_AAE_mutex);
1263 1264 (void) pthread_mutex_destroy(&_hbaapi_AL_mutex);
1264 1265 (void) pthread_mutex_destroy(&_hbaapi_LL_mutex);
1265 1266 #elif defined(WIN32)
1266 1267 DeleteCriticalSection(&_hbaapi_LL_mutex);
1267 1268 DeleteCriticalSection(&_hbaapi_AL_mutex);
1268 1269 DeleteCriticalSection(&_hbaapi_AAE_mutex);
1269 1270 DeleteCriticalSection(&_hbaapi_AE_mutex);
1270 1271 DeleteCriticalSection(&_hbaapi_APE_mutex);
1271 1272 DeleteCriticalSection(&_hbaapi_APSE_mutex);
1272 1273 DeleteCriticalSection(&_hbaapi_TE_mutex);
1273 1274 DeleteCriticalSection(&_hbaapi_LE_mutex);
1274 1275 DeleteCriticalSection(&_smhba_TE_mutex);
1275 1276 DeleteCriticalSection(&_smhba_APSE_mutex);
1276 1277 DeleteCriticalSection(&_smhba_APE_mutex);
1277 1278 DeleteCriticalSection(&_smhba_AE_mutex);
1278 1279 DeleteCriticalSection(&_smhba_AAE_mutex);
1279 1280 #endif
1280 1281
1281 1282 return (HBA_STATUS_OK);
1282 1283 }
1283 1284
1284 1285 /*
1285 1286 * The API used to use fixed size tables as its primary data structure.
1286 1287 * Indexing from 1 to N identified each adapters. Now the adapters are
1287 1288 * on a linked list. There is a unique "index" foreach each adapter.
1288 1289 * Adapters always keep their index, even if they are removed from the
1289 1290 * hardware. The only time the indexing is reset is on HBA_FreeLibrary
1290 1291 */
1291 1292 HBA_UINT32
1292 1293 HBA_GetNumberOfAdapters()
1293 1294 {
1294 1295 int j = 0;
1295 1296 HBA_LIBRARY_INFO *lib_infop;
1296 1297 HBAGetNumberOfAdaptersFunc GetNumberOfAdaptersFunc;
1297 1298 HBAGetAdapterNameFunc GetAdapterNameFunc;
1298 1299 HBA_BOOLEAN found_name;
1299 1300 HBA_ADAPTER_INFO *adapt_infop;
1300 1301 HBA_STATUS status;
1301 1302
1302 1303 char adaptername[256];
1303 1304 int num_adapters; /* local */
1304 1305
1305 1306 if (_hbaapi_librarylist == NULL) {
1306 1307 return (0);
1307 1308 }
1308 1309 GRAB_MUTEX(&_hbaapi_LL_mutex); /* pay attention to order */
1309 1310 GRAB_MUTEX(&_hbaapi_AL_mutex);
1310 1311
1311 1312 for (lib_infop = _hbaapi_librarylist;
1312 1313 lib_infop != NULL;
1313 1314 lib_infop = lib_infop->next) {
1314 1315
1315 1316 if (lib_infop->status != HBA_LIBRARY_LOADED) {
1316 1317 continue;
1317 1318 }
1318 1319
1319 1320 GetNumberOfAdaptersFunc =
1320 1321 FUNCCOMMON(lib_infop, GetNumberOfAdaptersHandler);
1321 1322 if (GetNumberOfAdaptersFunc == NULL) {
1322 1323 continue;
1323 1324 }
1324 1325 num_adapters = ((GetNumberOfAdaptersFunc)());
1325 1326 #ifndef WIN32
1326 1327 DEBUG(1, "HBAAPI: num_adapters for %s = %d\n",
1327 1328 lib_infop->LibraryName, num_adapters, 0);
1328 1329 #else
1329 1330 DEBUG(1, "HBAAPI: num_adapters for %s = %d\n",
1330 1331 lib_infop->LibraryPath, num_adapters, 0);
1331 1332 #endif
1332 1333
1333 1334 /* Also get the names of all the adapters here and cache */
1334 1335 GetAdapterNameFunc = FUNCCOMMON(lib_infop, GetAdapterNameHandler);
1335 1336 if (GetAdapterNameFunc == NULL) {
1336 1337 continue;
1337 1338 }
1338 1339
1339 1340 for (j = 0; j < num_adapters; j++) {
1340 1341 found_name = 0;
1341 1342 status = (GetAdapterNameFunc)(j, (char *)&adaptername);
1342 1343 if (status == HBA_STATUS_OK) {
1343 1344 for (adapt_infop = _hbaapi_adapterlist;
1344 1345 adapt_infop != NULL;
1345 1346 adapt_infop = adapt_infop->next) {
1346 1347 /*
1347 1348 * check for duplicates, really,
1348 1349 * this may just be a second
1349 1350 * call to this function
1350 1351 * ??? how do we know when a name becomes stale?
1351 1352 */
1352 1353 if (strcmp(adaptername, adapt_infop->name) == 0) {
1353 1354 /* already got this one */
1354 1355 found_name++;
1355 1356 break;
1356 1357 }
1357 1358 }
1358 1359 if (found_name != 0) {
1359 1360 continue;
1360 1361 }
1361 1362 }
1362 1363
1363 1364 adapt_infop = (HBA_ADAPTER_INFO *)
1364 1365 calloc(1, sizeof (HBA_ADAPTER_INFO));
1365 1366 if (adapt_infop == NULL) {
1366 1367 #ifndef WIN32
1367 1368 (void) fprintf(stderr,
1368 1369 "HBA_GetNumberOfAdapters: calloc failed"
1369 1370 " on sizeof:%lu\n",
1370 1371 (unsigned long)(sizeof (HBA_ADAPTER_INFO)));
1371 1372 #endif
1372 1373 RELEASE_MUTEX(&_hbaapi_AL_mutex);
1373 1374 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
1374 1375 _hbaapi_total_adapter_count);
1375 1376 }
1376 1377 if ((adapt_infop->GNstatus = status) == HBA_STATUS_OK) {
1377 1378 adapt_infop->name = strdup(adaptername);
1378 1379 } else {
1379 1380 char dummyname[512];
1380 1381 (void) sprintf(dummyname, "NULLADAPTER-%255s-%03d",
1381 1382 lib_infop->LibraryPath, _hbaapi_total_adapter_count);
1382 1383 dummyname[511] = '\0';
1383 1384 adapt_infop->name = strdup(dummyname);
1384 1385 }
1385 1386 lib_infop->numOfAdapters++;
1386 1387 adapt_infop->library = lib_infop;
1387 1388 adapt_infop->next = _hbaapi_adapterlist;
1388 1389 adapt_infop->index = _hbaapi_total_adapter_count;
1389 1390 _hbaapi_adapterlist = adapt_infop;
1390 1391 _hbaapi_total_adapter_count++;
1391 1392 }
1392 1393 }
1393 1394 RELEASE_MUTEX(&_hbaapi_AL_mutex);
1394 1395 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, _hbaapi_total_adapter_count);
1395 1396 }
1396 1397
1397 1398 HBA_STATUS
1398 1399 HBA_GetAdapterName(
1399 1400 HBA_UINT32 adapterindex,
1400 1401 char *adaptername)
1401 1402 {
1402 1403 HBA_ADAPTER_INFO *adapt_infop;
1403 1404 HBA_STATUS ret = HBA_STATUS_ERROR_ILLEGAL_INDEX;
1404 1405
1405 1406 if (adaptername == NULL) {
1406 1407 DEBUG(1, "HBA_GetAdapterName: NULL pointer adaptername",
1407 1408 0, 0, 0);
1408 1409 return (HBA_STATUS_ERROR_ARG);
1409 1410 }
1410 1411
1411 1412 /*
1412 1413 * The adapter index is from old code, but we have
1413 1414 * to support it. Go down the list looking for
1414 1415 * the adapter
1415 1416 */
1416 1417 ARE_WE_INITED();
1417 1418 GRAB_MUTEX(&_hbaapi_AL_mutex);
1418 1419 *adaptername = '\0';
1419 1420 for (adapt_infop = _hbaapi_adapterlist;
1420 1421 adapt_infop != NULL;
1421 1422 adapt_infop = adapt_infop->next) {
1422 1423
1423 1424 if (adapt_infop->index == adapterindex) {
1424 1425 if (adapt_infop->name != NULL &&
1425 1426 adapt_infop->GNstatus == HBA_STATUS_OK) {
1426 1427 (void) strcpy(adaptername, adapt_infop->name);
1427 1428 } else {
1428 1429 *adaptername = '\0';
1429 1430 }
1430 1431 ret = adapt_infop->GNstatus;
1431 1432 break;
1432 1433 }
1433 1434 }
1434 1435 DEBUG(2, "GetAdapterName for index:%d ->%s",
1435 1436 adapterindex, adaptername, 0);
1436 1437 RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, ret);
1437 1438 }
1438 1439
1439 1440 HBA_HANDLE
1440 1441 HBA_OpenAdapter(char *adaptername)
1441 1442 {
1442 1443 HBA_HANDLE handle;
1443 1444 HBAOpenAdapterFunc OpenAdapterFunc;
1444 1445 HBA_ADAPTER_INFO *adapt_infop;
1445 1446 HBA_LIBRARY_INFO *lib_infop;
1446 1447
1447 1448 DEBUG(2, "OpenAdapter: %s", adaptername, 0, 0);
1448 1449
1449 1450 handle = HBA_HANDLE_INVALID;
1450 1451 if (_hbaapi_librarylist == NULL) {
1451 1452 return (handle);
1452 1453 }
1453 1454 if (adaptername == NULL) {
1454 1455 DEBUG(1, "HBA_OpenAdapter: NULL pointer adaptername",
1455 1456 0, 0, 0);
1456 1457 return (handle);
1457 1458 }
1458 1459 GRAB_MUTEX(&_hbaapi_AL_mutex);
1459 1460 for (adapt_infop = _hbaapi_adapterlist;
1460 1461 adapt_infop != NULL;
1461 1462 adapt_infop = adapt_infop->next) {
1462 1463 if (strcmp(adaptername, adapt_infop->name) != 0) {
1463 1464 continue;
1464 1465 }
1465 1466 lib_infop = adapt_infop->library;
1466 1467 OpenAdapterFunc = FUNCCOMMON(lib_infop, OpenAdapterHandler);
1467 1468
1468 1469 if (OpenAdapterFunc != NULL) {
1469 1470 /* retrieve the vendor handle */
1470 1471 handle = (OpenAdapterFunc)(adaptername);
1471 1472 if (handle != 0) {
1472 1473 /* or this with the library index to get the common handle */
1473 1474 handle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle);
1474 1475 }
1475 1476 }
1476 1477 break;
1477 1478 }
1478 1479 RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, handle);
1479 1480 }
1480 1481
1481 1482 /*
1482 1483 * Finding an adapter with matching WWN.
1483 1484 */
1484 1485 HBA_STATUS
1485 1486 HBA_OpenAdapterByWWN(HBA_HANDLE *phandle, HBA_WWN nodeWWN) {
1486 1487 HBA_HANDLE handle;
1487 1488 HBA_LIBRARY_INFO *lib_infop;
1488 1489 HBAGetNumberOfAdaptersFunc
1489 1490 GetNumberOfAdaptersFunc;
1490 1491 HBAOpenAdapterByWWNFunc
1491 1492 OpenAdapterFunc;
1492 1493 HBA_STATUS status;
1493 1494
1494 1495 DEBUG(2, "OpenAdapterByWWN: %s", WWN2STR1(&nodeWWN), 0, 0);
1495 1496 ARE_WE_INITED();
1496 1497
1497 1498 *phandle = HBA_HANDLE_INVALID;
1498 1499
1499 1500 GRAB_MUTEX(&_hbaapi_LL_mutex);
1500 1501 for (lib_infop = _hbaapi_librarylist;
1501 1502 lib_infop != NULL;
1502 1503 lib_infop = lib_infop->next) {
1503 1504
1504 1505 status = HBA_STATUS_ERROR_ILLEGAL_WWN;
1505 1506
1506 1507 if (lib_infop->status != HBA_LIBRARY_LOADED) {
1507 1508 continue;
1508 1509 }
1509 1510
1510 1511 /* only for HBAAPIV2 */
1511 1512 if (lib_infop->version != HBAAPIV2) {
1512 1513 continue;
1513 1514 }
1514 1515
1515 1516 GetNumberOfAdaptersFunc =
1516 1517 FUNCCOMMON(lib_infop, GetNumberOfAdaptersHandler);
1517 1518 if (GetNumberOfAdaptersFunc == NULL) {
1518 1519 continue;
1519 1520 }
1520 1521
1521 1522 /* look for new hardware */
1522 1523 (void) ((GetNumberOfAdaptersFunc)());
1523 1524
1524 1525 OpenAdapterFunc =
1525 1526 lib_infop->ftable.functionTable.OpenAdapterByWWNHandler;
1526 1527 if (OpenAdapterFunc == NULL) {
1527 1528 continue;
1528 1529 }
1529 1530 /*
1530 1531 * We do not know if the WWN is known by this vendor,
1531 1532 * just try it
1532 1533 */
1533 1534 if ((status = (OpenAdapterFunc)(&handle, nodeWWN)) != HBA_STATUS_OK) {
1534 1535 continue;
1535 1536 }
1536 1537 /* OK, make a vendor non-specific handle */
1537 1538 *phandle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle);
1538 1539 status = HBA_STATUS_OK;
1539 1540 break;
1540 1541 }
1541 1542 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1542 1543 }
1543 1544
1544 1545 void
1545 1546 HBA_RefreshAdapterConfiguration() {
1546 1547 DEBUG(2, "HBA_RefreshAdapterConfiguration", 0, 0, 0);
1547 1548 (void) HBA_GetNumberOfAdapters();
1548 1549 }
1549 1550
1550 1551 HBA_UINT32
1551 1552 HBA_GetVersion() {
1552 1553 DEBUG(2, "HBA_GetVersion", 0, 0, 0);
1553 1554 return (HBA_LIBVERSION);
1554 1555 }
1555 1556
1556 1557 /*
1557 1558 * This function is VERY OS dependent. Wing it as best you can.
1558 1559 */
1559 1560 HBA_UINT32
1560 1561 HBA_GetWrapperLibraryAttributes(
1561 1562 HBA_LIBRARYATTRIBUTES *attributes)
1562 1563 {
1563 1564
1564 1565 DEBUG(2, "HBA_GetWrapperLibraryAttributes", 0, 0, 0);
1565 1566
1566 1567 if (attributes == NULL) {
1567 1568 DEBUG(1, "HBA_GetWrapperLibraryAttributes:"
1568 1569 "NULL pointer attributes",
1569 1570 0, 0, 0);
1570 1571 return (HBA_STATUS_ERROR_ARG);
1571 1572 }
1572 1573
1573 1574 (void) memset(attributes, 0, sizeof (HBA_LIBRARYATTRIBUTES));
1574 1575
1575 1576 #if defined(SOLARIS)
1576 1577 if ((handle = dlopen("libHBAAPI.so", RTLD_NOW)) != NULL) {
1577 1578 if (dlinfo(handle, RTLD_DI_LINKMAP, &map) >= 0) {
1578 1579 for (mp = map; mp != NULL; mp = mp->l_next) {
1579 1580 if (strlen(map->l_name) < 256) {
1580 1581 (void) strcpy(attributes->LibPath, map->l_name);
1581 1582 }
1582 1583 }
1583 1584 }
1584 1585 }
1585 1586 #elif defined(WIN32)
1586 1587 HMODULE module;
1587 1588
1588 1589 /* No need to do anything with the module handle */
1589 1590 /* It wasn't alloocated so it doesn't need to be freed */
1590 1591 module = GetModuleHandle("HBAAPI");
1591 1592 if (module != NULL) {
1592 1593 if (GetModuleFileName(module, attributes->LibPath,
1593 1594 sizeof (attributes->LibPath)) == 0) {
1594 1595 attributes->LibPath[0] = '\0';
1595 1596 }
1596 1597 }
1597 1598 #endif
1598 1599 #if defined(VENDOR)
1599 1600 (void) strcpy(attributes->VName, VENDOR);
1600 1601 #else
1601 1602 attributes->VName[0] = '\0';
1602 1603 #endif
1603 1604 #if defined(VERSION)
1604 1605 (void) strcpy(attributes->VVersion, VERSION);
1605 1606 #else
1606 1607 attributes->VVersion[0] = '\0';
1607 1608 #endif
1608 1609 #if defined(BUILD_DATE)
1609 1610 #if defined(WIN32)
1610 1611 int matchCount;
1611 1612 matchCount = sscanf(BUILD_DATE, "%u/%u/%u %u:%u:%u",
1612 1613 &attributes->build_date.tm_year,
1613 1614 &attributes->build_date.tm_mon,
1614 1615 &attributes->build_date.tm_mday,
1615 1616 &attributes->build_date.tm_hour,
1616 1617 &attributes->build_date.tm_min,
1617 1618 &attributes->build_date.tm_sec);
1618 1619
1619 1620 if (matchCount != 6) {
1620 1621 memset(&attributes->build_date, 0, sizeof (struct tm));
1621 1622 } else {
1622 1623 attributes->build_date.tm_year -= 1900;
1623 1624 attributes->build_date.tm_isdst = -1;
1624 1625 }
1625 1626 #else
1626 1627 if (strptime(BUILD_DATE,
1627 1628 "%Y/%m/%d %T %Z", &(attributes->build_date)) == NULL) {
1628 1629 (void) memset(&attributes->build_date, 0, sizeof (struct tm));
1629 1630 }
1630 1631 #endif
1631 1632 #else
1632 1633 (void) memset(&attributes->build_date, 0, sizeof (struct tm));
1633 1634 #endif
1634 1635 return (2);
1635 1636 }
1636 1637
1637 1638 /*
1638 1639 * Callback registation and handling
1639 1640 */
1640 1641 HBA_STATUS
1641 1642 HBA_RemoveCallback(HBA_CALLBACKHANDLE cbhandle) {
1642 1643 HBA_STATUS status;
1643 1644
1644 1645 DEBUG(2, "HBA_RemoveCallback", 0, 0, 0);
1645 1646 ARE_WE_INITED();
1646 1647
1647 1648 GRAB_MUTEX(&_hbaapi_LL_mutex);
1648 1649 status = local_remove_callback(cbhandle);
1649 1650 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1650 1651 }
1651 1652
1652 1653 /* Adapter Add Events ************************************************* */
1653 1654 static void
1654 1655 /* LINTED E_FUNC_ARG_UNUSED */
1655 1656 adapteraddevents_callback(void *data, HBA_WWN PortWWN, HBA_UINT32 eventType) {
1656 1657 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
1657 1658
1658 1659 DEBUG(3, "AddAdapterEvent, port: %s", WWN2STR1(&PortWWN), 0, 0);
1659 1660
1660 1661 GRAB_MUTEX(&_hbaapi_AAE_mutex);
1661 1662 for (cbp = _hbaapi_adapteraddevents_callback_list;
1662 1663 cbp != NULL;
1663 1664 cbp = cbp->next) {
1664 1665 (*cbp->callback)(data, PortWWN, HBA_EVENT_ADAPTER_ADD);
1665 1666 }
1666 1667 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1667 1668
1668 1669 }
1669 1670
1670 1671 HBA_STATUS
1671 1672 HBA_RegisterForAdapterAddEvents(
1672 1673 void (*callback)(
1673 1674 void *data,
1674 1675 HBA_WWN PortWWN,
1675 1676 HBA_UINT32 eventType),
1676 1677 void *userData,
1677 1678 HBA_CALLBACKHANDLE *callbackHandle) {
1678 1679
1679 1680 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
1680 1681 HBA_VENDORCALLBACK_ELEM *vcbp;
1681 1682 HBA_VENDORCALLBACK_ELEM *vendorhandlelist;
1682 1683 HBARegisterForAdapterAddEventsFunc registeredfunc;
1683 1684 HBA_STATUS status = HBA_STATUS_OK;
1684 1685 HBA_STATUS failure = HBA_STATUS_OK;
1685 1686 HBA_LIBRARY_INFO *lib_infop;
1686 1687 int registered_cnt = 0;
1687 1688 int vendor_cnt = 0;
1688 1689 int not_supported_cnt = 0;
1689 1690 int status_OK_bar_cnt = 0;
1690 1691 int status_OK_cnt = 0;
1691 1692
1692 1693 DEBUG(2, "HBA_RegisterForAdapterAddEvents", 0, 0, 0);
1693 1694 ARE_WE_INITED();
1694 1695
1695 1696 cbp = (HBA_ALLADAPTERSCALLBACK_ELEM *)
1696 1697 calloc(1, sizeof (HBA_ALLADAPTERSCALLBACK_ELEM));
1697 1698 *callbackHandle = (HBA_CALLBACKHANDLE) cbp;
1698 1699 if (cbp == NULL) {
1699 1700 #ifndef WIN32
1700 1701 (void) fprintf(stderr,
1701 1702 "HBA_RegisterForAdapterAddEvents: calloc failed "
1702 1703 "for %lu bytes\n",
1703 1704 (unsigned long)(sizeof (HBA_ALLADAPTERSCALLBACK_ELEM)));
1704 1705 #endif
1705 1706 return (HBA_STATUS_ERROR);
1706 1707 }
1707 1708
1708 1709 GRAB_MUTEX(&_hbaapi_LL_mutex);
1709 1710 GRAB_MUTEX(&_hbaapi_AAE_mutex);
1710 1711 cbp->callback = callback;
1711 1712 cbp->next = _hbaapi_adapteraddevents_callback_list;
1712 1713 _hbaapi_adapteraddevents_callback_list = cbp;
1713 1714 /*
1714 1715 * Need to release the mutex now incase the vendor function invokes the
1715 1716 * callback. We will grap the mutex later to attach the vendor handle
1716 1717 * list to the callback structure
1717 1718 */
1718 1719 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1719 1720
1720 1721 /*
1721 1722 * now create a list of vendors (vendor libraryies, NOT ADAPTERS)
1722 1723 * that have successfully registerred
1723 1724 */
1724 1725 vendorhandlelist = NULL;
1725 1726 for (lib_infop = _hbaapi_librarylist;
1726 1727 lib_infop != NULL;
1727 1728 lib_infop = lib_infop->next) {
1728 1729
1729 1730 /* only for HBAAPI V2 */
1730 1731 if ((lib_infop->version != HBAAPIV2)) {
1731 1732 continue;
1732 1733 } else {
1733 1734 vendor_cnt++;
1734 1735 }
1735 1736
1736 1737 registeredfunc =
1737 1738 lib_infop->ftable.functionTable.RegisterForAdapterAddEventsHandler;
1738 1739 if (registeredfunc == NULL) {
1739 1740 continue;
1740 1741 }
1741 1742
1742 1743 vcbp = (HBA_VENDORCALLBACK_ELEM *)
1743 1744 calloc(1, sizeof (HBA_VENDORCALLBACK_ELEM));
1744 1745 if (vcbp == NULL) {
1745 1746 #ifndef WIN32
1746 1747 (void) fprintf(stderr,
1747 1748 "HBA_RegisterForAdapterAddEvents: "
1748 1749 "calloc failed for %lu bytes\n",
1749 1750 (unsigned long)(sizeof (HBA_VENDORCALLBACK_ELEM)));
1750 1751 #endif
1751 1752 freevendorhandlelist(vendorhandlelist);
1752 1753 status = HBA_STATUS_ERROR;
1753 1754 break;
1754 1755 }
1755 1756
1756 1757 registered_cnt++;
1757 1758 status = (registeredfunc)(adapteraddevents_callback,
1758 1759 userData, &vcbp->vendorcbhandle);
1759 1760 if (status == HBA_STATUS_ERROR_NOT_SUPPORTED) {
1760 1761 not_supported_cnt++;
1761 1762 free(vcbp);
1762 1763 continue;
1763 1764 } else if (status != HBA_STATUS_OK) {
1764 1765 status_OK_bar_cnt++;
1765 1766 DEBUG(1,
1766 1767 "HBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
1767 1768 lib_infop->LibraryPath, status, 0);
1768 1769 #ifndef WIN32
1769 1770 (void) fprintf(stderr,
1770 1771 "HBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
1771 1772 lib_infop->LibraryPath, status);
1772 1773 #endif
1773 1774 failure = status;
1774 1775 free(vcbp);
1775 1776 continue;
1776 1777 } else {
1777 1778 status_OK_cnt++;
1778 1779 }
1779 1780 vcbp->lib_info = lib_infop;
1780 1781 vcbp->next = vendorhandlelist;
1781 1782 vendorhandlelist = vcbp;
1782 1783 }
1783 1784 if (vendor_cnt == 0) {
1784 1785 /* no HBAAPIV2 is deteced. should be okay? */
1785 1786 status = HBA_STATUS_ERROR;
1786 1787 } else if (registered_cnt == 0) {
1787 1788 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
1788 1789 freevendorhandlelist(vendorhandlelist);
1789 1790 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
1790 1791 } else if (status_OK_cnt == 0 && not_supported_cnt != 0) {
1791 1792 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
1792 1793 } else if (status_OK_cnt == 0) {
1793 1794 /*
1794 1795 * At least one vendor library registered this function, but no
1795 1796 * vendor call succeeded
1796 1797 */
1797 1798 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
1798 1799 status = failure;
1799 1800 } else {
1800 1801 /* we have had atleast some success, now finish up */
1801 1802 GRAB_MUTEX(&_hbaapi_AAE_mutex);
1802 1803 /*
1803 1804 * this seems silly, but what if another thread called
1804 1805 * the callback remove
1805 1806 */
1806 1807 for (cbp = _hbaapi_adapteraddevents_callback_list;
1807 1808 cbp != NULL; cbp = cbp->next) {
1808 1809 if ((HBA_CALLBACKHANDLE)cbp == *callbackHandle) {
1809 1810 /* yup, its still there, hooray */
1810 1811 cbp->vendorhandlelist = vendorhandlelist;
1811 1812 vendorhandlelist = NULL;
1812 1813 break;
1813 1814 }
1814 1815 }
1815 1816 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1816 1817 if (vendorhandlelist != NULL) {
1817 1818 /*
1818 1819 * bummer, somebody removed the callback before we finished
1819 1820 * registration, probably will never happen
1820 1821 */
1821 1822 freevendorhandlelist(vendorhandlelist);
1822 1823 DEBUG(1,
1823 1824 "HBA_RegisterForAdapterAddEvents: HBA_RemoveCallback was "
1824 1825 "called for a handle before registration was finished.",
1825 1826 0, 0, 0);
1826 1827 status = HBA_STATUS_ERROR;
1827 1828 } else {
1828 1829 status = HBA_STATUS_OK;
1829 1830 }
1830 1831 }
1831 1832 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1832 1833 }
1833 1834
1834 1835 /* Adapter Events (other than add) ************************************** */
1835 1836 static void
1836 1837 adapterevents_callback(void *data,
1837 1838 HBA_WWN PortWWN,
1838 1839 HBA_UINT32 eventType) {
1839 1840 HBA_ADAPTERCALLBACK_ELEM *acbp;
1840 1841
1841 1842 DEBUG(3, "AdapterEvent, port:%s, eventType:%d", WWN2STR1(&PortWWN),
1842 1843 eventType, 0);
1843 1844
1844 1845 GRAB_MUTEX(&_hbaapi_AE_mutex);
1845 1846 for (acbp = _hbaapi_adapterevents_callback_list;
1846 1847 acbp != NULL;
1847 1848 acbp = acbp->next) {
1848 1849 if (data == (void *)acbp) {
1849 1850 (*acbp->callback)(acbp->userdata, PortWWN, eventType);
1850 1851 break;
1851 1852 }
1852 1853 }
1853 1854 RELEASE_MUTEX(&_hbaapi_AE_mutex);
1854 1855 }
1855 1856 HBA_STATUS
1856 1857 HBA_RegisterForAdapterEvents(
1857 1858 void (*callback) (
1858 1859 void *data,
1859 1860 HBA_WWN PortWWN,
1860 1861 HBA_UINT32 eventType),
1861 1862 void *userData,
1862 1863 HBA_HANDLE handle,
1863 1864 HBA_CALLBACKHANDLE *callbackHandle) {
1864 1865
1865 1866 HBA_ADAPTERCALLBACK_ELEM *acbp;
1866 1867 HBARegisterForAdapterEventsFunc registeredfunc;
1867 1868 HBA_STATUS status;
1868 1869 HBA_LIBRARY_INFO *lib_infop;
1869 1870 HBA_HANDLE vendorHandle;
1870 1871
1871 1872 DEBUG(2, "HBA_RegisterForAdapterEvents", 0, 0, 0);
1872 1873
1873 1874 CHECKLIBRARYANDVERSION(HBAAPIV2);
1874 1875
1875 1876 /* we now have the _hbaapi_LL_mutex */
1876 1877
1877 1878 registeredfunc =
1878 1879 lib_infop->ftable.functionTable.RegisterForAdapterEventsHandler;
1879 1880 if (registeredfunc == NULL) {
1880 1881 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1881 1882 }
1882 1883
1883 1884 /*
1884 1885 * that allocated memory is used both as the handle for the
1885 1886 * caller, and as userdata to the vendor call so that on
1886 1887 * callback the specific registration may be recalled
1887 1888 */
1888 1889 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1889 1890 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
1890 1891 if (acbp == NULL) {
1891 1892 #ifndef WIN32
1892 1893 (void) fprintf(stderr,
1893 1894 "HBA_RegisterForAdapterEvents: calloc failed for %lu bytes\n",
1894 1895 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
1895 1896 #endif
1896 1897 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1897 1898 }
1898 1899 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1899 1900 acbp->callback = callback;
1900 1901 acbp->userdata = userData;
1901 1902 acbp->lib_info = lib_infop;
1902 1903
1903 1904 status = (registeredfunc)(adapterevents_callback,
1904 1905 (void *)acbp,
1905 1906 vendorHandle,
1906 1907 &acbp->vendorcbhandle);
1907 1908 if (status != HBA_STATUS_OK) {
1908 1909 free(acbp);
1909 1910 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1910 1911 }
1911 1912
1912 1913 GRAB_MUTEX(&_hbaapi_AE_mutex);
1913 1914 acbp->next = _hbaapi_adapterevents_callback_list;
1914 1915 _hbaapi_adapterevents_callback_list = acbp;
1915 1916 RELEASE_MUTEX(&_hbaapi_AE_mutex);
1916 1917
1917 1918 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1918 1919 }
1919 1920
1920 1921 /* Adapter Port Events ************************************************** */
1921 1922 static void
1922 1923 adapterportevents_callback(void *data,
1923 1924 HBA_WWN PortWWN,
1924 1925 HBA_UINT32 eventType,
1925 1926 HBA_UINT32 fabricPortID) {
1926 1927 HBA_ADAPTERCALLBACK_ELEM *acbp;
1927 1928
1928 1929 DEBUG(3, "AdapterPortEvent, port:%s, eventType:%d fabricPortID:0X%06x",
1929 1930 WWN2STR1(&PortWWN), eventType, fabricPortID);
1930 1931
1931 1932 GRAB_MUTEX(&_hbaapi_APE_mutex);
1932 1933
1933 1934 for (acbp = _hbaapi_adapterportevents_callback_list;
1934 1935 acbp != NULL;
1935 1936 acbp = acbp->next) {
1936 1937 if (data == (void *)acbp) {
1937 1938 (*acbp->callback)(acbp->userdata, PortWWN, eventType, fabricPortID);
1938 1939 break;
1939 1940 }
1940 1941 }
1941 1942 RELEASE_MUTEX(&_hbaapi_APE_mutex);
1942 1943 }
1943 1944
1944 1945 HBA_STATUS
1945 1946 HBA_RegisterForAdapterPortEvents(
1946 1947 void (*callback) (
1947 1948 void *data,
1948 1949 HBA_WWN PortWWN,
1949 1950 HBA_UINT32 eventType,
1950 1951 HBA_UINT32 fabricPortID),
1951 1952 void *userData,
1952 1953 HBA_HANDLE handle,
1953 1954 HBA_WWN PortWWN,
1954 1955 HBA_CALLBACKHANDLE *callbackHandle) {
1955 1956
1956 1957 HBA_ADAPTERCALLBACK_ELEM *acbp;
1957 1958 HBARegisterForAdapterPortEventsFunc registeredfunc;
1958 1959 HBA_STATUS status;
1959 1960 HBA_LIBRARY_INFO *lib_infop;
1960 1961 HBA_HANDLE vendorHandle;
1961 1962
1962 1963 DEBUG(2, "HBA_RegisterForAdapterPortEvents for port: %s",
1963 1964 WWN2STR1(&PortWWN), 0, 0);
1964 1965
1965 1966 CHECKLIBRARYANDVERSION(HBAAPIV2);
1966 1967 /* we now have the _hbaapi_LL_mutex */
1967 1968
1968 1969 registeredfunc =
1969 1970 lib_infop->ftable.functionTable.RegisterForAdapterPortEventsHandler;
1970 1971 if (registeredfunc == NULL) {
1971 1972 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1972 1973 }
1973 1974
1974 1975 /*
1975 1976 * that allocated memory is used both as the handle for the
1976 1977 * caller, and as userdata to the vendor call so that on
1977 1978 * callback the specific registration may be recalled
1978 1979 */
1979 1980 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1980 1981 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
1981 1982 if (acbp == NULL) {
1982 1983 #ifndef WIN32
1983 1984 (void) fprintf(stderr,
1984 1985 "HBA_RegisterForAdapterPortEvents: "
1985 1986 "calloc failed for %lu bytes\n",
1986 1987 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
1987 1988 #endif
1988 1989 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1989 1990
1990 1991 }
1991 1992 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1992 1993 acbp->callback = callback;
1993 1994 acbp->userdata = userData;
1994 1995 acbp->lib_info = lib_infop;
1995 1996
1996 1997 status = (registeredfunc)(adapterportevents_callback,
1997 1998 (void *)acbp,
1998 1999 vendorHandle,
1999 2000 PortWWN,
2000 2001 &acbp->vendorcbhandle);
2001 2002 if (status != HBA_STATUS_OK) {
2002 2003 free(acbp);
2003 2004 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2004 2005 }
2005 2006
2006 2007 GRAB_MUTEX(&_hbaapi_APE_mutex);
2007 2008 acbp->next = _hbaapi_adapterportevents_callback_list;
2008 2009 _hbaapi_adapterportevents_callback_list = acbp;
2009 2010 RELEASE_MUTEX(&_hbaapi_APE_mutex);
2010 2011
2011 2012 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2012 2013 }
2013 2014
2014 2015 /* Adapter State Events ************************************************ */
2015 2016 static void
2016 2017 adapterportstatevents_callback(void *data,
2017 2018 HBA_WWN PortWWN,
2018 2019 HBA_UINT32 eventType) {
2019 2020 HBA_ADAPTERCALLBACK_ELEM *acbp;
2020 2021
2021 2022 DEBUG(3, "AdapterPortStatEvent, port:%s, eventType:%d",
2022 2023 WWN2STR1(&PortWWN),
2023 2024 eventType, 0);
2024 2025
2025 2026 GRAB_MUTEX(&_hbaapi_APSE_mutex);
2026 2027 for (acbp = _hbaapi_adapterportstatevents_callback_list;
2027 2028 acbp != NULL;
2028 2029 acbp = acbp->next) {
2029 2030 if (data == (void *)acbp) {
2030 2031 (*acbp->callback)(acbp->userdata, PortWWN, eventType);
2031 2032 return;
2032 2033 }
2033 2034 }
2034 2035 RELEASE_MUTEX(&_hbaapi_APSE_mutex);
2035 2036 }
2036 2037 HBA_STATUS
2037 2038 HBA_RegisterForAdapterPortStatEvents(
2038 2039 void (*callback) (
2039 2040 void *data,
2040 2041 HBA_WWN PortWWN,
2041 2042 HBA_UINT32 eventType),
2042 2043 void *userData,
2043 2044 HBA_HANDLE handle,
2044 2045 HBA_WWN PortWWN,
2045 2046 HBA_PORTSTATISTICS stats,
2046 2047 HBA_UINT32 statType,
2047 2048 HBA_CALLBACKHANDLE *callbackHandle) {
2048 2049
2049 2050 HBA_ADAPTERCALLBACK_ELEM *acbp;
2050 2051 HBARegisterForAdapterPortStatEventsFunc
2051 2052 registeredfunc;
2052 2053 HBA_STATUS status;
2053 2054 HBA_LIBRARY_INFO *lib_infop;
2054 2055 HBA_HANDLE vendorHandle;
2055 2056
2056 2057 DEBUG(2, "HBA_RegisterForAdapterPortStatEvents for port: %s",
2057 2058 WWN2STR1(&PortWWN), 0, 0);
2058 2059
2059 2060 CHECKLIBRARYANDVERSION(HBAAPIV2);
2060 2061 /* we now have the _hbaapi_LL_mutex */
2061 2062
2062 2063 registeredfunc =
2063 2064 lib_infop->ftable.functionTable.RegisterForAdapterPortStatEventsHandler;
2064 2065 if (registeredfunc == NULL) {
2065 2066 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
2066 2067 }
2067 2068
2068 2069 /*
2069 2070 * that allocated memory is used both as the handle for the
2070 2071 * caller, and as userdata to the vendor call so that on
2071 2072 * callback the specific registration may be recalled
2072 2073 */
2073 2074 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
2074 2075 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
2075 2076 if (acbp == NULL) {
2076 2077 #ifndef WIN32
2077 2078 (void) fprintf(stderr,
2078 2079 "HBA_RegisterForAdapterPortStatEvents: "
2079 2080 "calloc failed for %lu bytes\n",
2080 2081 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
2081 2082 #endif
2082 2083 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
2083 2084 }
2084 2085 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
2085 2086 acbp->callback = callback;
2086 2087 acbp->userdata = userData;
2087 2088 acbp->lib_info = lib_infop;
2088 2089
2089 2090 status = (registeredfunc)(adapterportstatevents_callback,
2090 2091 (void *)acbp,
2091 2092 vendorHandle,
2092 2093 PortWWN,
2093 2094 stats,
2094 2095 statType,
2095 2096 &acbp->vendorcbhandle);
2096 2097 if (status != HBA_STATUS_OK) {
2097 2098 free(acbp);
2098 2099 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2099 2100 }
2100 2101
2101 2102 GRAB_MUTEX(&_hbaapi_APSE_mutex);
2102 2103 acbp->next = _hbaapi_adapterportstatevents_callback_list;
2103 2104 _hbaapi_adapterportstatevents_callback_list = acbp;
2104 2105 RELEASE_MUTEX(&_hbaapi_APSE_mutex);
2105 2106
2106 2107 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2107 2108 }
2108 2109
2109 2110 /* Target Events ******************************************************* */
2110 2111 static void
2111 2112 targetevents_callback(void *data,
2112 2113 HBA_WWN hbaPortWWN,
2113 2114 HBA_WWN discoveredPortWWN,
2114 2115 HBA_UINT32 eventType) {
2115 2116
2116 2117 HBA_ADAPTERCALLBACK_ELEM *acbp;
2117 2118
2118 2119 DEBUG(3, "TargetEvent, hbaPort:%s, discoveredPort:%s eventType:%d",
2119 2120 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), eventType);
2120 2121
2121 2122 GRAB_MUTEX(&_hbaapi_TE_mutex);
2122 2123 for (acbp = _hbaapi_targetevents_callback_list;
2123 2124 acbp != NULL;
2124 2125 acbp = acbp->next) {
2125 2126 if (data == (void *)acbp) {
2126 2127 (*acbp->callback)(acbp->userdata, hbaPortWWN,
2127 2128 discoveredPortWWN, eventType);
2128 2129 break;
2129 2130 }
2130 2131 }
2131 2132 RELEASE_MUTEX(&_hbaapi_TE_mutex);
2132 2133 }
2133 2134
2134 2135 HBA_STATUS
2135 2136 HBA_RegisterForTargetEvents(
2136 2137 void (*callback) (
2137 2138 void *data,
2138 2139 HBA_WWN hbaPortWWN,
2139 2140 HBA_WWN discoveredPortWWN,
2140 2141 HBA_UINT32 eventType),
2141 2142 void *userData,
2142 2143 HBA_HANDLE handle,
2143 2144 HBA_WWN hbaPortWWN,
2144 2145 HBA_WWN discoveredPortWWN,
2145 2146 HBA_CALLBACKHANDLE *callbackHandle,
2146 2147 HBA_UINT32 allTargets) {
2147 2148
2148 2149 HBA_ADAPTERCALLBACK_ELEM
2149 2150 *acbp;
2150 2151 HBARegisterForTargetEventsFunc
2151 2152 registeredfunc;
2152 2153 HBA_STATUS status;
2153 2154 HBA_LIBRARY_INFO *lib_infop;
2154 2155 HBA_HANDLE vendorHandle;
2155 2156
2156 2157 DEBUG(2, "HBA_RegisterForTargetEvents, hbaPort: %s, discoveredPort: %s",
2157 2158 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), 0);
2158 2159
2159 2160 CHECKLIBRARYANDVERSION(HBAAPIV2);
2160 2161 /* we now have the _hbaapi_LL_mutex */
2161 2162
2162 2163 registeredfunc =
2163 2164 lib_infop->ftable.functionTable.RegisterForTargetEventsHandler;
2164 2165 if (registeredfunc == NULL) {
2165 2166 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
2166 2167 }
2167 2168
2168 2169 /*
2169 2170 * that allocated memory is used both as the handle for the
2170 2171 * caller, and as userdata to the vendor call so that on
2171 2172 * callback the specific registration may be recalled
2172 2173 */
2173 2174 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
2174 2175 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
2175 2176 if (acbp == NULL) {
2176 2177 #ifndef WIN32
2177 2178 (void) fprintf(stderr,
2178 2179 "HBA_RegisterForTargetEvents: calloc failed for %lu bytes\n",
2179 2180 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
2180 2181 #endif
2181 2182 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
2182 2183 }
2183 2184 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
2184 2185 acbp->callback = callback;
2185 2186 acbp->userdata = userData;
2186 2187 acbp->lib_info = lib_infop;
2187 2188
2188 2189 status = (registeredfunc)(targetevents_callback,
2189 2190 (void *)acbp,
2190 2191 vendorHandle,
2191 2192 hbaPortWWN,
2192 2193 discoveredPortWWN,
2193 2194 &acbp->vendorcbhandle,
2194 2195 allTargets);
2195 2196 if (status != HBA_STATUS_OK) {
2196 2197 free(acbp);
2197 2198 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2198 2199 }
2199 2200
2200 2201 GRAB_MUTEX(&_hbaapi_TE_mutex);
2201 2202 acbp->next = _hbaapi_targetevents_callback_list;
2202 2203 _hbaapi_targetevents_callback_list = acbp;
2203 2204 RELEASE_MUTEX(&_hbaapi_TE_mutex);
2204 2205
2205 2206 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2206 2207 }
2207 2208
2208 2209 /* Link Events ********************************************************* */
2209 2210 static void
2210 2211 linkevents_callback(void *data,
2211 2212 HBA_WWN adapterWWN,
2212 2213 HBA_UINT32 eventType,
2213 2214 void *pRLIRBuffer,
2214 2215 HBA_UINT32 RLIRBufferSize) {
2215 2216 HBA_ADAPTERCALLBACK_ELEM *acbp;
2216 2217
2217 2218 DEBUG(3, "LinkEvent, hbaWWN:%s, eventType:%d",
2218 2219 WWN2STR1(&adapterWWN), eventType, 0);
2219 2220
2220 2221 GRAB_MUTEX(&_hbaapi_LE_mutex);
2221 2222 for (acbp = _hbaapi_linkevents_callback_list;
2222 2223 acbp != NULL;
2223 2224 acbp = acbp->next) {
2224 2225 if (data == (void *)acbp) {
2225 2226 (*acbp->callback)(acbp->userdata, adapterWWN,
2226 2227 eventType, pRLIRBuffer, RLIRBufferSize);
2227 2228 break;
2228 2229 }
2229 2230 }
2230 2231 RELEASE_MUTEX(&_hbaapi_LE_mutex);
2231 2232 }
2232 2233 HBA_STATUS
2233 2234 HBA_RegisterForLinkEvents(
2234 2235 void (*callback) (
2235 2236 void *data,
2236 2237 HBA_WWN adapterWWN,
2237 2238 HBA_UINT32 eventType,
2238 2239 void *pRLIRBuffer,
2239 2240 HBA_UINT32 RLIRBufferSize),
2240 2241 void *userData,
2241 2242 void *pRLIRBuffer,
2242 2243 HBA_UINT32 RLIRBufferSize,
2243 2244 HBA_HANDLE handle,
2244 2245 HBA_CALLBACKHANDLE *callbackHandle) {
2245 2246
2246 2247 HBA_ADAPTERCALLBACK_ELEM *acbp;
2247 2248 HBARegisterForLinkEventsFunc
2248 2249 registeredfunc;
2249 2250 HBA_STATUS status;
2250 2251 HBA_LIBRARY_INFO *lib_infop;
2251 2252 HBA_HANDLE vendorHandle;
2252 2253
2253 2254 DEBUG(2, "HBA_RegisterForLinkEvents", 0, 0, 0);
2254 2255
2255 2256 CHECKLIBRARY();
2256 2257 /* we now have the _hbaapi_LL_mutex */
2257 2258
2258 2259 registeredfunc = FUNCCOMMON(lib_infop, RegisterForLinkEventsHandler);
2259 2260
2260 2261 if (registeredfunc == NULL) {
2261 2262 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
2262 2263 }
2263 2264
2264 2265 /*
2265 2266 * that allocated memory is used both as the handle for the
2266 2267 * caller, and as userdata to the vendor call so that on
2267 2268 * callback the specific registration may be recalled
2268 2269 */
2269 2270 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
2270 2271 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
2271 2272 if (acbp == NULL) {
2272 2273 #ifndef WIN32
2273 2274 (void) fprintf(stderr,
2274 2275 "HBA_RegisterForLinkEvents: calloc failed for %lu bytes\n",
2275 2276 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
2276 2277 #endif
2277 2278 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
2278 2279 }
2279 2280 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
2280 2281 acbp->callback = callback;
2281 2282 acbp->userdata = userData;
2282 2283 acbp->lib_info = lib_infop;
2283 2284
2284 2285 status = (registeredfunc)(linkevents_callback,
2285 2286 (void *)acbp,
2286 2287 pRLIRBuffer,
2287 2288 RLIRBufferSize,
2288 2289 vendorHandle,
2289 2290 &acbp->vendorcbhandle);
2290 2291 if (status != HBA_STATUS_OK) {
2291 2292 free(acbp);
2292 2293 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2293 2294 }
2294 2295
2295 2296 GRAB_MUTEX(&_hbaapi_LE_mutex);
2296 2297 acbp->next = _hbaapi_linkevents_callback_list;
2297 2298 _hbaapi_linkevents_callback_list = acbp;
2298 2299 RELEASE_MUTEX(&_hbaapi_LE_mutex);
2299 2300
2300 2301 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2301 2302 }
2302 2303
2303 2304 /*
2304 2305 * All of the functions below are almost passthru functions to the
2305 2306 * vendor specific function
2306 2307 */
2307 2308
2308 2309 void
2309 2310 HBA_CloseAdapter(HBA_HANDLE handle) {
2310 2311 HBA_STATUS status;
2311 2312 HBA_LIBRARY_INFO *lib_infop;
2312 2313 HBA_HANDLE vendorHandle;
2313 2314 HBACloseAdapterFunc CloseAdapterFunc;
2314 2315
2315 2316 DEBUG(2, "HBA_CloseAdapter", 0, 0, 0);
2316 2317
2317 2318 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2318 2319 if (status == HBA_STATUS_OK) {
2319 2320 CloseAdapterFunc = FUNCCOMMON(lib_infop, CloseAdapterHandler);
2320 2321 if (CloseAdapterFunc != NULL) {
2321 2322 ((CloseAdapterFunc)(vendorHandle));
2322 2323 }
2323 2324 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2324 2325 }
2325 2326 }
2326 2327
2327 2328 HBA_STATUS
2328 2329 HBA_GetAdapterAttributes(
2329 2330 HBA_HANDLE handle,
2330 2331 HBA_ADAPTERATTRIBUTES
2331 2332 *hbaattributes)
2332 2333 {
2333 2334 HBA_STATUS status;
2334 2335 HBA_LIBRARY_INFO *lib_infop;
2335 2336 HBA_HANDLE vendorHandle;
2336 2337 HBAGetAdapterAttributesFunc GetAdapterAttributesFunc;
2337 2338
2338 2339 DEBUG(2, "HBA_GetAdapterAttributes", 0, 0, 0);
2339 2340
2340 2341 CHECKLIBRARY();
2341 2342
2342 2343 if (lib_infop->version == SMHBA) {
2343 2344 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2344 2345 }
2345 2346
2346 2347 GetAdapterAttributesFunc =
2347 2348 lib_infop->ftable.functionTable.GetAdapterAttributesHandler;
2348 2349 if (GetAdapterAttributesFunc != NULL) {
2349 2350 status = ((GetAdapterAttributesFunc)(vendorHandle, hbaattributes));
2350 2351 } else {
2351 2352 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2352 2353 }
2353 2354 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2354 2355 }
2355 2356
2356 2357 HBA_STATUS
2357 2358 HBA_GetAdapterPortAttributes(
2358 2359 HBA_HANDLE handle,
2359 2360 HBA_UINT32 portindex,
2360 2361 HBA_PORTATTRIBUTES *portattributes)
2361 2362 {
2362 2363 HBA_STATUS status;
2363 2364 HBA_LIBRARY_INFO *lib_infop;
2364 2365 HBA_HANDLE vendorHandle;
2365 2366 HBAGetAdapterPortAttributesFunc
2366 2367 GetAdapterPortAttributesFunc;
2367 2368
2368 2369 DEBUG(2, "HBA_GetAdapterPortAttributes", 0, 0, 0);
2369 2370
2370 2371 CHECKLIBRARY();
2371 2372 if (lib_infop->version == SMHBA) {
2372 2373 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2373 2374 }
2374 2375
2375 2376 GetAdapterPortAttributesFunc =
2376 2377 lib_infop->ftable.functionTable.GetAdapterPortAttributesHandler;
2377 2378 if (GetAdapterPortAttributesFunc != NULL) {
2378 2379 status = ((GetAdapterPortAttributesFunc)
2379 2380 (vendorHandle, portindex, portattributes));
2380 2381 } else {
2381 2382 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2382 2383 }
2383 2384 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2384 2385 }
2385 2386
2386 2387 HBA_STATUS
2387 2388 HBA_GetPortStatistics(
2388 2389 HBA_HANDLE handle,
2389 2390 HBA_UINT32 portindex,
2390 2391 HBA_PORTSTATISTICS *portstatistics)
2391 2392 {
2392 2393 HBA_STATUS status;
2393 2394 HBA_LIBRARY_INFO *lib_infop;
2394 2395 HBA_HANDLE vendorHandle;
2395 2396 HBAGetPortStatisticsFunc
2396 2397 GetPortStatisticsFunc;
2397 2398
2398 2399 DEBUG(2, "HBA_GetPortStatistics", 0, 0, 0);
2399 2400
2400 2401 CHECKLIBRARY();
2401 2402 if (lib_infop->version == SMHBA) {
2402 2403 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2403 2404 }
2404 2405
2405 2406 GetPortStatisticsFunc =
2406 2407 lib_infop->ftable.functionTable.GetPortStatisticsHandler;
2407 2408 if (GetPortStatisticsFunc != NULL) {
2408 2409 status = ((GetPortStatisticsFunc)
2409 2410 (vendorHandle, portindex, portstatistics));
2410 2411 } else {
2411 2412 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2412 2413 }
2413 2414 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2414 2415 }
2415 2416
2416 2417 HBA_STATUS
2417 2418 HBA_GetDiscoveredPortAttributes(
2418 2419 HBA_HANDLE handle,
2419 2420 HBA_UINT32 portindex,
2420 2421 HBA_UINT32 discoveredportindex,
2421 2422 HBA_PORTATTRIBUTES *portattributes)
2422 2423 {
2423 2424 HBA_STATUS status;
2424 2425 HBA_LIBRARY_INFO *lib_infop;
2425 2426 HBA_HANDLE vendorHandle;
2426 2427 HBAGetDiscoveredPortAttributesFunc
2427 2428 GetDiscoveredPortAttributesFunc;
2428 2429
2429 2430 DEBUG(2, "HBA_GetDiscoveredPortAttributes", 0, 0, 0);
2430 2431
2431 2432 CHECKLIBRARY();
2432 2433 if (lib_infop->version == SMHBA) {
2433 2434 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2434 2435 }
2435 2436
2436 2437 GetDiscoveredPortAttributesFunc =
2437 2438 lib_infop->ftable.functionTable.GetDiscoveredPortAttributesHandler;
2438 2439 if (GetDiscoveredPortAttributesFunc != NULL) {
2439 2440 status = ((GetDiscoveredPortAttributesFunc)
2440 2441 (vendorHandle, portindex, discoveredportindex,
2441 2442 portattributes));
2442 2443 } else {
2443 2444 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2444 2445 }
2445 2446 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2446 2447 }
2447 2448
2448 2449 HBA_STATUS
2449 2450 HBA_GetPortAttributesByWWN(
2450 2451 HBA_HANDLE handle,
2451 2452 HBA_WWN PortWWN,
2452 2453 HBA_PORTATTRIBUTES *portattributes)
2453 2454 {
2454 2455 HBA_STATUS status;
2455 2456 HBA_LIBRARY_INFO *lib_infop;
2456 2457 HBA_HANDLE vendorHandle;
2457 2458 HBAGetPortAttributesByWWNFunc
2458 2459 GetPortAttributesByWWNFunc;
2459 2460
2460 2461 DEBUG(2, "HBA_GetPortAttributesByWWN: %s", WWN2STR1(&PortWWN), 0, 0);
2461 2462
2462 2463 CHECKLIBRARY();
2463 2464 if (lib_infop->version == SMHBA) {
2464 2465 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2465 2466 }
2466 2467
2467 2468 GetPortAttributesByWWNFunc =
2468 2469 lib_infop->ftable.functionTable.GetPortAttributesByWWNHandler;
2469 2470 if (GetPortAttributesByWWNFunc != NULL) {
2470 2471 status = ((GetPortAttributesByWWNFunc)
2471 2472 (vendorHandle, PortWWN, portattributes));
2472 2473 } else {
2473 2474 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2474 2475 }
2475 2476 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2476 2477 }
2477 2478
2478 2479 HBA_STATUS
2479 2480 HBA_SendCTPassThru(
2480 2481 HBA_HANDLE handle,
2481 2482 void *pReqBuffer,
2482 2483 HBA_UINT32 ReqBufferSize,
2483 2484 void *pRspBuffer,
2484 2485 HBA_UINT32 RspBufferSize)
2485 2486 {
2486 2487 HBA_STATUS status;
2487 2488 HBA_LIBRARY_INFO *lib_infop;
2488 2489 HBA_HANDLE vendorHandle;
2489 2490 HBASendCTPassThruFunc
2490 2491 SendCTPassThruFunc;
2491 2492
2492 2493 DEBUG(2, "HBA_SendCTPassThru", 0, 0, 0);
2493 2494
2494 2495 CHECKLIBRARY();
2495 2496 if (lib_infop->version == SMHBA) {
2496 2497 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2497 2498 }
2498 2499
2499 2500 SendCTPassThruFunc =
2500 2501 lib_infop->ftable.functionTable.SendCTPassThruHandler;
2501 2502 if (SendCTPassThruFunc != NULL) {
2502 2503 status = (SendCTPassThruFunc)
2503 2504 (vendorHandle,
2504 2505 pReqBuffer, ReqBufferSize,
2505 2506 pRspBuffer, RspBufferSize);
2506 2507 } else {
2507 2508 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2508 2509 }
2509 2510 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2510 2511 }
2511 2512
2512 2513 HBA_STATUS
2513 2514 HBA_SendCTPassThruV2(
2514 2515 HBA_HANDLE handle,
2515 2516 HBA_WWN hbaPortWWN,
2516 2517 void *pReqBuffer,
2517 2518 HBA_UINT32 ReqBufferSize,
2518 2519 void *pRspBuffer,
2519 2520 HBA_UINT32 *pRspBufferSize)
2520 2521 {
2521 2522 HBA_STATUS status;
2522 2523 HBA_LIBRARY_INFO *lib_infop;
2523 2524 HBA_HANDLE vendorHandle;
2524 2525 HBASendCTPassThruV2Func
2525 2526 registeredfunc;
2526 2527
2527 2528 DEBUG(2, "HBA_SendCTPassThruV2m hbaPortWWN: %s",
2528 2529 WWN2STR1(&hbaPortWWN), 0, 0);
2529 2530
2530 2531 CHECKLIBRARYANDVERSION(HBAAPIV2);
2531 2532 registeredfunc = FUNCCOMMON(lib_infop, SendCTPassThruV2Handler);
2532 2533 if (registeredfunc != NULL) {
2533 2534 status = (registeredfunc)
2534 2535 (vendorHandle, hbaPortWWN,
2535 2536 pReqBuffer, ReqBufferSize,
2536 2537 pRspBuffer, pRspBufferSize);
2537 2538 } else {
2538 2539 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2539 2540 }
2540 2541 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2541 2542 }
2542 2543
2543 2544 HBA_STATUS
2544 2545 HBA_GetEventBuffer(
2545 2546 HBA_HANDLE handle,
2546 2547 PHBA_EVENTINFO EventBuffer,
2547 2548 HBA_UINT32 *EventBufferCount)
2548 2549 {
2549 2550 HBA_STATUS status;
2550 2551 HBA_LIBRARY_INFO *lib_infop;
2551 2552 HBA_HANDLE vendorHandle;
2552 2553 HBAGetEventBufferFunc
2553 2554 GetEventBufferFunc;
2554 2555
2555 2556 DEBUG(2, "HBA_GetEventBuffer", 0, 0, 0);
2556 2557
2557 2558 CHECKLIBRARY();
2558 2559 if (lib_infop->version == SMHBA) {
2559 2560 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2560 2561 }
2561 2562
2562 2563 GetEventBufferFunc =
2563 2564 lib_infop->ftable.functionTable.GetEventBufferHandler;
2564 2565 if (GetEventBufferFunc != NULL) {
2565 2566 status = (GetEventBufferFunc)
2566 2567 (vendorHandle, EventBuffer, EventBufferCount);
2567 2568 } else {
2568 2569 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2569 2570 }
2570 2571 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2571 2572 }
2572 2573
2573 2574 HBA_STATUS
2574 2575 HBA_SetRNIDMgmtInfo(HBA_HANDLE handle, HBA_MGMTINFO Info) {
2575 2576 HBA_STATUS status;
2576 2577 HBA_LIBRARY_INFO *lib_infop;
2577 2578 HBA_HANDLE vendorHandle;
2578 2579 HBASetRNIDMgmtInfoFunc
2579 2580 SetRNIDMgmtInfoFunc;
2580 2581
2581 2582 DEBUG(2, "HBA_SetRNIDMgmtInfo", 0, 0, 0);
2582 2583
2583 2584 CHECKLIBRARY();
2584 2585 SetRNIDMgmtInfoFunc = FUNCCOMMON(lib_infop, SetRNIDMgmtInfoHandler);
2585 2586 if (SetRNIDMgmtInfoFunc != NULL) {
2586 2587 status = (SetRNIDMgmtInfoFunc)(vendorHandle, Info);
2587 2588 } else {
2588 2589 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2589 2590 }
2590 2591 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2591 2592 }
2592 2593
2593 2594 HBA_STATUS
2594 2595 HBA_GetRNIDMgmtInfo(HBA_HANDLE handle, HBA_MGMTINFO *pInfo) {
2595 2596 HBA_STATUS status;
2596 2597 HBA_LIBRARY_INFO *lib_infop;
2597 2598 HBA_HANDLE vendorHandle;
2598 2599 HBAGetRNIDMgmtInfoFunc
2599 2600 GetRNIDMgmtInfoFunc;
2600 2601
2601 2602 DEBUG(2, "HBA_GetRNIDMgmtInfo", 0, 0, 0);
2602 2603
2603 2604 CHECKLIBRARY();
2604 2605 GetRNIDMgmtInfoFunc = FUNCCOMMON(lib_infop, GetRNIDMgmtInfoHandler);
2605 2606 if (GetRNIDMgmtInfoFunc != NULL) {
2606 2607 status = (GetRNIDMgmtInfoFunc)(vendorHandle, pInfo);
2607 2608 } else {
2608 2609 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2609 2610 }
2610 2611 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2611 2612 }
2612 2613
2613 2614 HBA_STATUS
2614 2615 HBA_SendRNID(
2615 2616 HBA_HANDLE handle,
2616 2617 HBA_WWN wwn,
2617 2618 HBA_WWNTYPE wwntype,
2618 2619 void *pRspBuffer,
2619 2620 HBA_UINT32 *pRspBufferSize)
2620 2621 {
2621 2622 HBA_STATUS status;
2622 2623 HBA_LIBRARY_INFO *lib_infop;
2623 2624 HBA_HANDLE vendorHandle;
2624 2625 HBASendRNIDFunc SendRNIDFunc;
2625 2626
2626 2627 DEBUG(2, "HBA_SendRNID for wwn: %s", WWN2STR1(&wwn), 0, 0);
2627 2628
2628 2629 CHECKLIBRARY();
2629 2630 if (lib_infop->version == SMHBA) {
2630 2631 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2631 2632 }
2632 2633
2633 2634 SendRNIDFunc = lib_infop->ftable.functionTable.SendRNIDHandler;
2634 2635 if (SendRNIDFunc != NULL) {
2635 2636 status = ((SendRNIDFunc)(vendorHandle, wwn, wwntype,
2636 2637 pRspBuffer, pRspBufferSize));
2637 2638 } else {
2638 2639 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2639 2640 }
2640 2641 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2641 2642 }
2642 2643
2643 2644 HBA_STATUS
2644 2645 HBA_SendRNIDV2(
2645 2646 HBA_HANDLE handle,
2646 2647 HBA_WWN hbaPortWWN,
2647 2648 HBA_WWN destWWN,
2648 2649 HBA_UINT32 destFCID,
2649 2650 HBA_UINT32 NodeIdDataFormat,
2650 2651 void *pRspBuffer,
2651 2652 HBA_UINT32 *pRspBufferSize)
2652 2653 {
2653 2654 HBA_STATUS status;
2654 2655 HBA_LIBRARY_INFO *lib_infop;
2655 2656 HBA_HANDLE vendorHandle;
2656 2657 HBASendRNIDV2Func registeredfunc;
2657 2658
2658 2659 DEBUG(2, "HBA_SendRNIDV2, hbaPortWWN: %s", WWN2STR1(&hbaPortWWN), 0, 0);
2659 2660
2660 2661 CHECKLIBRARY();
2661 2662 registeredfunc = FUNCCOMMON(lib_infop, SendRNIDV2Handler);
2662 2663 if (registeredfunc != NULL) {
2663 2664 status = (registeredfunc)
2664 2665 (vendorHandle, hbaPortWWN, destWWN, destFCID, NodeIdDataFormat,
2665 2666 pRspBuffer, pRspBufferSize);
2666 2667 } else {
2667 2668 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2668 2669 }
2669 2670 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2670 2671 }
2671 2672
2672 2673 void
2673 2674 HBA_RefreshInformation(HBA_HANDLE handle) {
2674 2675 HBA_STATUS status;
2675 2676 HBA_LIBRARY_INFO *lib_infop;
2676 2677 HBA_HANDLE vendorHandle;
2677 2678 HBARefreshInformationFunc
2678 2679 RefreshInformationFunc;
2679 2680
2680 2681 DEBUG(2, "HBA_RefreshInformation", 0, 0, 0);
2681 2682
2682 2683 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2683 2684 if (status == HBA_STATUS_OK) {
2684 2685 RefreshInformationFunc =
2685 2686 FUNCCOMMON(lib_infop, RefreshInformationHandler);
2686 2687 if (RefreshInformationFunc != NULL) {
2687 2688 ((RefreshInformationFunc)(vendorHandle));
2688 2689 }
2689 2690 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2690 2691 }
2691 2692 }
2692 2693
2693 2694 void
2694 2695 HBA_ResetStatistics(HBA_HANDLE handle, HBA_UINT32 portindex) {
2695 2696 HBA_STATUS status;
2696 2697 HBA_LIBRARY_INFO *lib_infop;
2697 2698 HBA_HANDLE vendorHandle;
2698 2699 HBAResetStatisticsFunc
2699 2700 ResetStatisticsFunc;
2700 2701
2701 2702 DEBUG(2, "HBA_ResetStatistics", 0, 0, 0);
2702 2703
2703 2704 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2704 2705 if (status == HBA_STATUS_OK) {
2705 2706 if (lib_infop->version == SMHBA) {
2706 2707 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2707 2708 }
2708 2709
2709 2710 ResetStatisticsFunc =
2710 2711 lib_infop->ftable.functionTable.ResetStatisticsHandler;
2711 2712 if (ResetStatisticsFunc != NULL) {
2712 2713 ((ResetStatisticsFunc)(vendorHandle, portindex));
2713 2714 }
2714 2715 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2715 2716 }
2716 2717 }
2717 2718
2718 2719 HBA_STATUS
2719 2720 HBA_GetFcpTargetMapping(HBA_HANDLE handle, PHBA_FCPTARGETMAPPING mapping) {
2720 2721 HBA_STATUS status;
2721 2722 HBA_LIBRARY_INFO *lib_infop;
2722 2723 HBA_HANDLE vendorHandle;
2723 2724 HBAGetFcpTargetMappingFunc GetFcpTargetMappingFunc;
2724 2725
2725 2726 DEBUG(2, "HBA_GetFcpTargetMapping", 0, 0, 0);
2726 2727
2727 2728 CHECKLIBRARY();
2728 2729 if (lib_infop->version == SMHBA) {
2729 2730 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2730 2731 }
2731 2732
2732 2733 GetFcpTargetMappingFunc =
2733 2734 lib_infop->ftable.functionTable.GetFcpTargetMappingHandler;
2734 2735 if (GetFcpTargetMappingFunc != NULL) {
2735 2736 status = ((GetFcpTargetMappingFunc)(vendorHandle, mapping));
2736 2737 } else {
2737 2738 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2738 2739 }
2739 2740 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2740 2741 }
2741 2742
2742 2743 HBA_STATUS
2743 2744 HBA_GetFcpTargetMappingV2(
2744 2745 HBA_HANDLE handle,
2745 2746 HBA_WWN hbaPortWWN,
2746 2747 HBA_FCPTARGETMAPPINGV2 *pmapping)
2747 2748 {
2748 2749 HBA_STATUS status;
2749 2750 HBA_LIBRARY_INFO *lib_infop;
2750 2751 HBA_HANDLE vendorHandle;
2751 2752 HBAGetFcpTargetMappingV2Func
2752 2753 registeredfunc;
2753 2754
2754 2755 DEBUG(2, "HBA_GetFcpTargetMapping", 0, 0, 0);
2755 2756
2756 2757 CHECKLIBRARYANDVERSION(HBAAPIV2);
2757 2758
2758 2759 registeredfunc =
2759 2760 lib_infop->ftable.functionTable.GetFcpTargetMappingV2Handler;
2760 2761 if (registeredfunc != NULL) {
2761 2762 status = ((registeredfunc)(vendorHandle, hbaPortWWN, pmapping));
2762 2763 } else {
2763 2764 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2764 2765 }
2765 2766 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2766 2767 }
2767 2768
2768 2769 HBA_STATUS
2769 2770 HBA_GetFcpPersistentBinding(HBA_HANDLE handle, PHBA_FCPBINDING binding) {
2770 2771 HBA_STATUS status;
2771 2772 HBA_LIBRARY_INFO *lib_infop;
2772 2773 HBA_HANDLE vendorHandle;
2773 2774 HBAGetFcpPersistentBindingFunc
2774 2775 GetFcpPersistentBindingFunc;
2775 2776
2776 2777 DEBUG(2, "HBA_GetFcpPersistentBinding", 0, 0, 0);
2777 2778
2778 2779 CHECKLIBRARY();
2779 2780 if (lib_infop->version == SMHBA) {
2780 2781 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2781 2782 }
2782 2783
2783 2784 GetFcpPersistentBindingFunc =
2784 2785 lib_infop->ftable.functionTable.GetFcpPersistentBindingHandler;
2785 2786 if (GetFcpPersistentBindingFunc != NULL) {
2786 2787 status = ((GetFcpPersistentBindingFunc)(vendorHandle, binding));
2787 2788 } else {
2788 2789 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2789 2790 }
2790 2791 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2791 2792 }
2792 2793
2793 2794 HBA_STATUS
2794 2795 HBA_ScsiInquiryV2(
2795 2796 HBA_HANDLE handle,
2796 2797 HBA_WWN hbaPortWWN,
2797 2798 HBA_WWN discoveredPortWWN,
2798 2799 HBA_UINT64 fcLUN,
2799 2800 HBA_UINT8 CDB_Byte1,
2800 2801 HBA_UINT8 CDB_Byte2,
2801 2802 void *pRspBuffer,
2802 2803 HBA_UINT32 *pRspBufferSize,
2803 2804 HBA_UINT8 *pScsiStatus,
2804 2805 void *pSenseBuffer,
2805 2806 HBA_UINT32 *pSenseBufferSize)
2806 2807 {
2807 2808 HBA_STATUS status;
2808 2809 HBA_LIBRARY_INFO *lib_infop;
2809 2810 HBA_HANDLE vendorHandle;
2810 2811 HBAScsiInquiryV2Func ScsiInquiryV2Func;
2811 2812
2812 2813 DEBUG(2, "HBA_ScsiInquiryV2 to discoveredPortWWN: %s",
2813 2814 WWN2STR1(&discoveredPortWWN), 0, 0);
2814 2815
2815 2816 CHECKLIBRARYANDVERSION(HBAAPIV2);
2816 2817
2817 2818 ScsiInquiryV2Func =
2818 2819 lib_infop->ftable.functionTable.ScsiInquiryV2Handler;
2819 2820 if (ScsiInquiryV2Func != NULL) {
2820 2821 status = ((ScsiInquiryV2Func)(
2821 2822 vendorHandle, hbaPortWWN, discoveredPortWWN, fcLUN, CDB_Byte1,
2822 2823 CDB_Byte2, pRspBuffer, pRspBufferSize, pScsiStatus,
2823 2824 pSenseBuffer, pSenseBufferSize));
2824 2825 } else {
2825 2826 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2826 2827 }
2827 2828 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2828 2829 }
2829 2830
2830 2831 HBA_STATUS
2831 2832 HBA_SendScsiInquiry(
2832 2833 HBA_HANDLE handle,
2833 2834 HBA_WWN PortWWN,
2834 2835 HBA_UINT64 fcLUN,
2835 2836 HBA_UINT8 EVPD,
2836 2837 HBA_UINT32 PageCode,
2837 2838 void *pRspBuffer,
2838 2839 HBA_UINT32 RspBufferSize,
2839 2840 void *pSenseBuffer,
2840 2841 HBA_UINT32 SenseBufferSize)
2841 2842 {
2842 2843 HBA_STATUS status;
2843 2844 HBA_LIBRARY_INFO *lib_infop;
2844 2845 HBA_HANDLE vendorHandle;
2845 2846 HBASendScsiInquiryFunc SendScsiInquiryFunc;
2846 2847
2847 2848 DEBUG(2, "HBA_SendScsiInquiry to PortWWN: %s",
2848 2849 WWN2STR1(&PortWWN), 0, 0);
2849 2850
2850 2851 CHECKLIBRARY();
2851 2852 if (lib_infop->version == SMHBA) {
2852 2853 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2853 2854 }
2854 2855
2855 2856 SendScsiInquiryFunc =
2856 2857 lib_infop->ftable.functionTable.ScsiInquiryHandler;
2857 2858 if (SendScsiInquiryFunc != NULL) {
2858 2859 status = ((SendScsiInquiryFunc)(
2859 2860 vendorHandle, PortWWN, fcLUN, EVPD, PageCode, pRspBuffer,
2860 2861 RspBufferSize, pSenseBuffer, SenseBufferSize));
2861 2862 } else {
2862 2863 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2863 2864 }
2864 2865 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2865 2866 }
2866 2867
2867 2868 HBA_STATUS
2868 2869 HBA_ScsiReportLUNsV2(
2869 2870 HBA_HANDLE handle,
2870 2871 HBA_WWN hbaPortWWN,
2871 2872 HBA_WWN discoveredPortWWN,
2872 2873 void *pRespBuffer,
2873 2874 HBA_UINT32 *pRespBufferSize,
2874 2875 HBA_UINT8 *pScsiStatus,
2875 2876 void *pSenseBuffer,
2876 2877 HBA_UINT32 *pSenseBufferSize)
2877 2878 {
2878 2879 HBA_STATUS status;
2879 2880 HBA_LIBRARY_INFO *lib_infop;
2880 2881 HBA_HANDLE vendorHandle;
2881 2882 HBAScsiReportLUNsV2Func ScsiReportLUNsV2Func;
2882 2883
2883 2884 DEBUG(2, "HBA_ScsiReportLUNsV2 to discoveredPortWWN: %s",
2884 2885 WWN2STR1(&discoveredPortWWN), 0, 0);
2885 2886
2886 2887 CHECKLIBRARYANDVERSION(HBAAPIV2);
2887 2888
2888 2889 ScsiReportLUNsV2Func =
2889 2890 lib_infop->ftable.functionTable.ScsiReportLUNsV2Handler;
2890 2891 if (ScsiReportLUNsV2Func != NULL) {
2891 2892 status = ((ScsiReportLUNsV2Func)(
2892 2893 vendorHandle, hbaPortWWN, discoveredPortWWN,
2893 2894 pRespBuffer, pRespBufferSize,
2894 2895 pScsiStatus,
2895 2896 pSenseBuffer, pSenseBufferSize));
2896 2897 } else {
2897 2898 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2898 2899 }
2899 2900 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2900 2901 }
2901 2902
2902 2903 HBA_STATUS
2903 2904 HBA_SendReportLUNs(
2904 2905 HBA_HANDLE handle,
2905 2906 HBA_WWN portWWN,
2906 2907 void *pRspBuffer,
2907 2908 HBA_UINT32 RspBufferSize,
2908 2909 void *pSenseBuffer,
2909 2910 HBA_UINT32 SenseBufferSize)
2910 2911 {
2911 2912 HBA_STATUS status;
2912 2913 HBA_LIBRARY_INFO *lib_infop;
2913 2914 HBA_HANDLE vendorHandle;
2914 2915 HBASendReportLUNsFunc SendReportLUNsFunc;
2915 2916
2916 2917 DEBUG(2, "HBA_SendReportLUNs to PortWWN: %s", WWN2STR1(&portWWN), 0, 0);
2917 2918
2918 2919 CHECKLIBRARY();
2919 2920 if (lib_infop->version == SMHBA) {
2920 2921 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2921 2922 }
2922 2923
2923 2924 SendReportLUNsFunc = lib_infop->ftable.functionTable.ReportLUNsHandler;
2924 2925 if (SendReportLUNsFunc != NULL) {
2925 2926 status = ((SendReportLUNsFunc)(
2926 2927 vendorHandle, portWWN, pRspBuffer,
2927 2928 RspBufferSize, pSenseBuffer, SenseBufferSize));
2928 2929 } else {
2929 2930 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2930 2931 }
2931 2932 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2932 2933 }
2933 2934
2934 2935 HBA_STATUS
2935 2936 HBA_ScsiReadCapacityV2(
2936 2937 HBA_HANDLE handle,
2937 2938 HBA_WWN hbaPortWWN,
2938 2939 HBA_WWN discoveredPortWWN,
2939 2940 HBA_UINT64 fcLUN,
2940 2941 void *pRspBuffer,
2941 2942 HBA_UINT32 *pRspBufferSize,
2942 2943 HBA_UINT8 *pScsiStatus,
2943 2944 void *pSenseBuffer,
2944 2945 HBA_UINT32 *SenseBufferSize)
2945 2946 {
2946 2947 HBA_STATUS status;
2947 2948 HBA_LIBRARY_INFO *lib_infop;
2948 2949 HBA_HANDLE vendorHandle;
2949 2950 HBAScsiReadCapacityV2Func ScsiReadCapacityV2Func;
2950 2951
2951 2952 DEBUG(2, "HBA_ScsiReadCapacityV2 to discoveredPortWWN: %s",
2952 2953 WWN2STR1(&discoveredPortWWN), 0, 0);
2953 2954
2954 2955 CHECKLIBRARYANDVERSION(HBAAPIV2);
2955 2956
2956 2957 ScsiReadCapacityV2Func =
2957 2958 lib_infop->ftable.functionTable.ScsiReadCapacityV2Handler;
2958 2959 if (ScsiReadCapacityV2Func != NULL) {
2959 2960 status = ((ScsiReadCapacityV2Func)(
2960 2961 vendorHandle, hbaPortWWN, discoveredPortWWN, fcLUN,
2961 2962 pRspBuffer, pRspBufferSize,
2962 2963 pScsiStatus,
2963 2964 pSenseBuffer, SenseBufferSize));
2964 2965 } else {
2965 2966 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2966 2967 }
2967 2968 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2968 2969 }
2969 2970
2970 2971 HBA_STATUS
2971 2972 HBA_SendReadCapacity(
2972 2973 HBA_HANDLE handle,
2973 2974 HBA_WWN portWWN,
2974 2975 HBA_UINT64 fcLUN,
2975 2976 void *pRspBuffer,
2976 2977 HBA_UINT32 RspBufferSize,
2977 2978 void *pSenseBuffer,
2978 2979 HBA_UINT32 SenseBufferSize)
2979 2980 {
2980 2981 HBA_STATUS status;
2981 2982 HBA_LIBRARY_INFO *lib_infop;
2982 2983 HBA_HANDLE vendorHandle;
2983 2984 HBASendReadCapacityFunc SendReadCapacityFunc;
2984 2985
2985 2986 DEBUG(2, "HBA_SendReadCapacity to portWWN: %s",
2986 2987 WWN2STR1(&portWWN), 0, 0);
2987 2988
2988 2989 CHECKLIBRARY();
2989 2990 if (lib_infop->version == SMHBA) {
2990 2991 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2991 2992 }
2992 2993
2993 2994 SendReadCapacityFunc =
2994 2995 lib_infop->ftable.functionTable.ReadCapacityHandler;
2995 2996 if (SendReadCapacityFunc != NULL) {
2996 2997 status = ((SendReadCapacityFunc)
2997 2998 (vendorHandle, portWWN, fcLUN, pRspBuffer,
2998 2999 RspBufferSize, pSenseBuffer, SenseBufferSize));
2999 3000 } else {
3000 3001 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3001 3002 }
3002 3003 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3003 3004 }
3004 3005
3005 3006 HBA_STATUS
3006 3007 HBA_SendRPL(
3007 3008 HBA_HANDLE handle,
3008 3009 HBA_WWN hbaPortWWN,
3009 3010 HBA_WWN agent_wwn,
3010 3011 HBA_UINT32 agent_domain,
3011 3012 HBA_UINT32 portindex,
3012 3013 void *pRspBuffer,
3013 3014 HBA_UINT32 *pRspBufferSize)
3014 3015 {
3015 3016 HBA_STATUS status;
3016 3017 HBA_LIBRARY_INFO *lib_infop;
3017 3018 HBA_HANDLE vendorHandle;
3018 3019 HBASendRPLFunc registeredfunc;
3019 3020
3020 3021 DEBUG(2, "HBA_SendRPL to agent_wwn: %s:%d",
3021 3022 WWN2STR1(&agent_wwn), agent_domain, 0);
3022 3023
3023 3024 CHECKLIBRARY();
3024 3025 registeredfunc = FUNCCOMMON(lib_infop, SendRPLHandler);
3025 3026 if (registeredfunc != NULL) {
3026 3027 status = (registeredfunc)(
3027 3028 vendorHandle, hbaPortWWN, agent_wwn, agent_domain, portindex,
3028 3029 pRspBuffer, pRspBufferSize);
3029 3030 } else {
3030 3031 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3031 3032 }
3032 3033 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3033 3034 }
3034 3035
3035 3036 HBA_STATUS
3036 3037 HBA_SendRPS(
3037 3038 HBA_HANDLE handle,
3038 3039 HBA_WWN hbaPortWWN,
3039 3040 HBA_WWN agent_wwn,
3040 3041 HBA_UINT32 agent_domain,
3041 3042 HBA_WWN object_wwn,
3042 3043 HBA_UINT32 object_port_number,
3043 3044 void *pRspBuffer,
3044 3045 HBA_UINT32 *pRspBufferSize)
3045 3046 {
3046 3047 HBA_STATUS status;
3047 3048 HBA_LIBRARY_INFO *lib_infop;
3048 3049 HBA_HANDLE vendorHandle;
3049 3050 HBASendRPSFunc registeredfunc;
3050 3051
3051 3052 DEBUG(2, "HBA_SendRPS to agent_wwn: %s:%d",
3052 3053 WWN2STR1(&agent_wwn), agent_domain, 0);
3053 3054
3054 3055 CHECKLIBRARY();
3055 3056 registeredfunc = FUNCCOMMON(lib_infop, SendRPSHandler);
3056 3057 if (registeredfunc != NULL) {
3057 3058 status = (registeredfunc)(
3058 3059 vendorHandle, hbaPortWWN, agent_wwn, agent_domain,
3059 3060 object_wwn, object_port_number,
3060 3061 pRspBuffer, pRspBufferSize);
3061 3062 } else {
3062 3063 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3063 3064 }
3064 3065 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3065 3066 }
3066 3067
3067 3068 HBA_STATUS
3068 3069 HBA_SendSRL(
3069 3070 HBA_HANDLE handle,
3070 3071 HBA_WWN hbaPortWWN,
3071 3072 HBA_WWN wwn,
3072 3073 HBA_UINT32 domain,
3073 3074 void *pRspBuffer,
3074 3075 HBA_UINT32 *pRspBufferSize)
3075 3076 {
3076 3077 HBA_STATUS status;
3077 3078 HBA_LIBRARY_INFO *lib_infop;
3078 3079 HBA_HANDLE vendorHandle;
3079 3080 HBASendSRLFunc registeredfunc;
3080 3081
3081 3082 DEBUG(2, "HBA_SendSRL to wwn:%s domain:%d", WWN2STR1(&wwn), domain, 0);
3082 3083
3083 3084 CHECKLIBRARY();
3084 3085 registeredfunc = FUNCCOMMON(lib_infop, SendSRLHandler);
3085 3086 if (registeredfunc != NULL) {
3086 3087 status = (registeredfunc)(
3087 3088 vendorHandle, hbaPortWWN, wwn, domain,
3088 3089 pRspBuffer, pRspBufferSize);
3089 3090 } else {
3090 3091 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3091 3092 }
3092 3093 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3093 3094 }
3094 3095 HBA_STATUS
3095 3096 HBA_SendRLS(
3096 3097 HBA_HANDLE handle,
3097 3098 HBA_WWN hbaPortWWN,
3098 3099 HBA_WWN destWWN,
3099 3100 void *pRspBuffer,
3100 3101 HBA_UINT32 *pRspBufferSize)
3101 3102 {
3102 3103 HBA_STATUS status;
3103 3104 HBA_LIBRARY_INFO *lib_infop;
3104 3105 HBA_HANDLE vendorHandle;
3105 3106 HBASendRLSFunc registeredfunc;
3106 3107
3107 3108 DEBUG(2, "HBA_SendRLS dest_wwn: %s",
3108 3109 WWN2STR1(&destWWN), 0, 0);
3109 3110
3110 3111 CHECKLIBRARY();
3111 3112 registeredfunc = FUNCCOMMON(lib_infop, SendRLSHandler);
3112 3113 if (registeredfunc != NULL) {
3113 3114 status = (registeredfunc)(
3114 3115 vendorHandle, hbaPortWWN, destWWN,
3115 3116 pRspBuffer, pRspBufferSize);
3116 3117 } else {
3117 3118 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3118 3119 }
3119 3120 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3120 3121 }
3121 3122
3122 3123 HBA_STATUS
3123 3124 HBA_SendLIRR(
3124 3125 HBA_HANDLE handle,
3125 3126 HBA_WWN sourceWWN,
3126 3127 HBA_WWN destWWN,
3127 3128 HBA_UINT8 function,
3128 3129 HBA_UINT8 type,
3129 3130 void *pRspBuffer,
3130 3131 HBA_UINT32 *pRspBufferSize)
3131 3132 {
3132 3133 HBA_STATUS status;
3133 3134 HBA_LIBRARY_INFO *lib_infop;
3134 3135 HBA_HANDLE vendorHandle;
3135 3136 HBASendLIRRFunc registeredfunc;
3136 3137
3137 3138 DEBUG(2, "HBA_SendLIRR destWWN:%s", WWN2STR1(&destWWN), 0, 0);
3138 3139
3139 3140 CHECKLIBRARY();
3140 3141 registeredfunc = FUNCCOMMON(lib_infop, SendLIRRHandler);
3141 3142 if (registeredfunc != NULL) {
3142 3143 status = (registeredfunc)(
3143 3144 vendorHandle, sourceWWN, destWWN, function, type,
3144 3145 pRspBuffer, pRspBufferSize);
3145 3146 } else {
3146 3147 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3147 3148 }
3148 3149 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3149 3150 }
3150 3151
3151 3152 HBA_STATUS
3152 3153 HBA_GetBindingCapability(
3153 3154 HBA_HANDLE handle,
3154 3155 HBA_WWN hbaPortWWN,
3155 3156 HBA_BIND_CAPABILITY *pcapability)
3156 3157 {
3157 3158 HBA_STATUS status;
3158 3159 HBA_LIBRARY_INFO *lib_infop;
3159 3160 HBA_HANDLE vendorHandle;
3160 3161 HBAGetBindingCapabilityFunc
3161 3162 registeredfunc;
3162 3163
3163 3164 DEBUG(2, "HBA_GetBindingCapability", 0, 0, 0);
3164 3165
3165 3166 CHECKLIBRARYANDVERSION(HBAAPIV2);
3166 3167
3167 3168 registeredfunc =
3168 3169 lib_infop->ftable.functionTable.GetBindingCapabilityHandler;
3169 3170 if (registeredfunc != NULL) {
3170 3171 status = (registeredfunc)(vendorHandle, hbaPortWWN, pcapability);
3171 3172 } else {
3172 3173 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3173 3174 }
3174 3175 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3175 3176 }
3176 3177
3177 3178 HBA_STATUS
3178 3179 HBA_GetBindingSupport(
3179 3180 HBA_HANDLE handle,
3180 3181 HBA_WWN hbaPortWWN,
3181 3182 HBA_BIND_CAPABILITY *pcapability)
3182 3183 {
3183 3184 HBA_STATUS status;
3184 3185 HBA_LIBRARY_INFO *lib_infop;
3185 3186 HBA_HANDLE vendorHandle;
3186 3187 HBAGetBindingSupportFunc
3187 3188 registeredfunc;
3188 3189
3189 3190 DEBUG(2, "HBA_GetBindingSupport", 0, 0, 0);
3190 3191
3191 3192 CHECKLIBRARYANDVERSION(HBAAPIV2);
3192 3193
3193 3194 registeredfunc =
3194 3195 lib_infop->ftable.functionTable.GetBindingSupportHandler;
3195 3196 if (registeredfunc != NULL) {
3196 3197 status = (registeredfunc)(vendorHandle, hbaPortWWN, pcapability);
3197 3198 } else {
3198 3199 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3199 3200 }
3200 3201 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3201 3202 }
3202 3203
3203 3204 HBA_STATUS
3204 3205 HBA_SetBindingSupport(
3205 3206 HBA_HANDLE handle,
3206 3207 HBA_WWN hbaPortWWN,
3207 3208 HBA_BIND_CAPABILITY capability)
3208 3209 {
3209 3210 HBA_STATUS status;
3210 3211 HBA_LIBRARY_INFO *lib_infop;
3211 3212 HBA_HANDLE vendorHandle;
3212 3213 HBASetBindingSupportFunc
3213 3214 registeredfunc;
3214 3215
3215 3216 DEBUG(2, "HBA_SetBindingSupport", 0, 0, 0);
3216 3217
3217 3218 CHECKLIBRARYANDVERSION(HBAAPIV2);
3218 3219
3219 3220 registeredfunc =
3220 3221 lib_infop->ftable.functionTable.SetBindingSupportHandler;
3221 3222 if (registeredfunc != NULL) {
3222 3223 status = (registeredfunc)(vendorHandle, hbaPortWWN, capability);
3223 3224 } else {
3224 3225 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3225 3226 }
3226 3227 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3227 3228 }
3228 3229
3229 3230 HBA_STATUS
3230 3231 HBA_SetPersistentBindingV2(
3231 3232 HBA_HANDLE handle,
3232 3233 HBA_WWN hbaPortWWN,
3233 3234 const HBA_FCPBINDING2 *pbinding)
3234 3235 {
3235 3236 HBA_STATUS status;
3236 3237 HBA_LIBRARY_INFO *lib_infop;
3237 3238 HBA_HANDLE vendorHandle;
3238 3239 HBASetPersistentBindingV2Func
3239 3240 registeredfunc;
3240 3241
3241 3242 DEBUG(2, "HBA_SetPersistentBindingV2 port: %s",
3242 3243 WWN2STR1(&hbaPortWWN), 0, 0);
3243 3244
3244 3245 CHECKLIBRARYANDVERSION(HBAAPIV2);
3245 3246
3246 3247 registeredfunc =
3247 3248 lib_infop->ftable.functionTable.SetPersistentBindingV2Handler;
3248 3249 if (registeredfunc != NULL) {
3249 3250 status = (registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
3250 3251 } else {
3251 3252 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3252 3253 }
3253 3254 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3254 3255 }
3255 3256
3256 3257 HBA_STATUS
3257 3258 HBA_GetPersistentBindingV2(
3258 3259 HBA_HANDLE handle,
3259 3260 HBA_WWN hbaPortWWN,
3260 3261 HBA_FCPBINDING2 *pbinding)
3261 3262 {
3262 3263 HBA_STATUS status;
3263 3264 HBA_LIBRARY_INFO *lib_infop;
3264 3265 HBA_HANDLE vendorHandle;
3265 3266 HBAGetPersistentBindingV2Func
3266 3267 registeredfunc;
3267 3268
3268 3269 DEBUG(2, "HBA_GetPersistentBindingV2 port: %s",
3269 3270 WWN2STR1(&hbaPortWWN), 0, 0);
3270 3271
3271 3272 CHECKLIBRARYANDVERSION(HBAAPIV2);
3272 3273
3273 3274 registeredfunc =
3274 3275 lib_infop->ftable.functionTable.GetPersistentBindingV2Handler;
3275 3276 if (registeredfunc != NULL) {
3276 3277 status = (registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
3277 3278 } else {
3278 3279 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3279 3280 }
3280 3281 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3281 3282 }
3282 3283
3283 3284 HBA_STATUS
3284 3285 HBA_RemovePersistentBinding(
3285 3286 HBA_HANDLE handle,
3286 3287 HBA_WWN hbaPortWWN,
3287 3288 const HBA_FCPBINDING2
3288 3289 *pbinding)
3289 3290 {
3290 3291 HBA_STATUS status;
3291 3292 HBA_LIBRARY_INFO *lib_infop;
3292 3293 HBA_HANDLE vendorHandle;
3293 3294 HBARemovePersistentBindingFunc
3294 3295 registeredfunc;
3295 3296
3296 3297 DEBUG(2, "HBA_RemovePersistentBinding", 0, 0, 0);
3297 3298
3298 3299 CHECKLIBRARYANDVERSION(HBAAPIV2);
3299 3300
3300 3301 registeredfunc =
3301 3302 lib_infop->ftable.functionTable.RemovePersistentBindingHandler;
3302 3303 if (registeredfunc != NULL) {
3303 3304 status = (registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
3304 3305 } else {
3305 3306 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3306 3307 }
3307 3308 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3308 3309 }
3309 3310
3310 3311 HBA_STATUS
3311 3312 HBA_RemoveAllPersistentBindings(
3312 3313 HBA_HANDLE handle,
3313 3314 HBA_WWN hbaPortWWN)
3314 3315 {
3315 3316 HBA_STATUS status;
3316 3317 HBA_LIBRARY_INFO *lib_infop;
3317 3318 HBA_HANDLE vendorHandle;
3318 3319 HBARemoveAllPersistentBindingsFunc
3319 3320 registeredfunc;
3320 3321
3321 3322 DEBUG(2, "HBA_RemoveAllPersistentBindings", 0, 0, 0);
3322 3323
3323 3324 CHECKLIBRARYANDVERSION(HBAAPIV2);
3324 3325
3325 3326 registeredfunc =
3326 3327 lib_infop->ftable.functionTable.RemoveAllPersistentBindingsHandler;
3327 3328 if (registeredfunc != NULL) {
3328 3329 status = (registeredfunc)(vendorHandle, hbaPortWWN);
3329 3330 } else {
3330 3331 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3331 3332 }
3332 3333 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3333 3334 }
3334 3335
3335 3336 HBA_STATUS
3336 3337 HBA_GetFC4Statistics(
3337 3338 HBA_HANDLE handle,
3338 3339 HBA_WWN portWWN,
3339 3340 HBA_UINT8 FC4type,
3340 3341 HBA_FC4STATISTICS *pstatistics)
3341 3342 {
3342 3343 HBA_STATUS status;
3343 3344 HBA_LIBRARY_INFO *lib_infop;
3344 3345 HBA_HANDLE vendorHandle;
3345 3346 HBAGetFC4StatisticsFunc
3346 3347 registeredfunc;
3347 3348
3348 3349 DEBUG(2, "HBA_GetFC4Statistics port: %s", WWN2STR1(&portWWN), 0, 0);
3349 3350
3350 3351 CHECKLIBRARYANDVERSION(HBAAPIV2);
3351 3352
3352 3353 registeredfunc =
3353 3354 lib_infop->ftable.functionTable.GetFC4StatisticsHandler;
3354 3355 if (registeredfunc != NULL) {
3355 3356 status = (registeredfunc)
3356 3357 (vendorHandle, portWWN, FC4type, pstatistics);
3357 3358 } else {
3358 3359 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3359 3360 }
3360 3361 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3361 3362 }
3362 3363
3363 3364 HBA_STATUS
3364 3365 HBA_GetFCPStatistics(
3365 3366 HBA_HANDLE handle,
3366 3367 const HBA_SCSIID *lunit,
3367 3368 HBA_FC4STATISTICS *pstatistics)
3368 3369 {
3369 3370 HBA_STATUS status;
3370 3371 HBA_LIBRARY_INFO *lib_infop;
3371 3372 HBA_HANDLE vendorHandle;
3372 3373 HBAGetFCPStatisticsFunc
3373 3374 registeredfunc;
3374 3375
3375 3376 DEBUG(2, "HBA_GetFCPStatistics", 0, 0, 0);
3376 3377
3377 3378 CHECKLIBRARYANDVERSION(HBAAPIV2);
3378 3379
3379 3380 registeredfunc =
3380 3381 lib_infop->ftable.functionTable.GetFCPStatisticsHandler;
3381 3382 if (registeredfunc != NULL) {
3382 3383 status = (registeredfunc)(vendorHandle, lunit, pstatistics);
3383 3384 } else {
3384 3385 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3385 3386 }
3386 3387 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3387 3388 }
3388 3389
3389 3390 HBA_UINT32
3390 3391 HBA_GetVendorLibraryAttributes(
3391 3392 HBA_UINT32 adapter_index,
3392 3393 HBA_LIBRARYATTRIBUTES *attributes)
3393 3394 {
3394 3395 HBA_ADAPTER_INFO *adapt_infop;
3395 3396 HBAGetVendorLibraryAttributesFunc
3396 3397 registeredfunc;
3397 3398 HBA_UINT32 ret = 0;
3398 3399
3399 3400 DEBUG(2, "HBA_GetVendorLibraryAttributes adapterindex:%d",
3400 3401 adapter_index, 0, 0);
3401 3402 if (_hbaapi_librarylist == NULL) {
3402 3403 DEBUG(1, "HBAAPI not loaded yet.", 0, 0, 0);
3403 3404 return (0);
3404 3405 }
3405 3406
3406 3407 if (attributes == NULL) {
3407 3408 DEBUG(1,
3408 3409 "HBA_GetVendorLibraryAttributes: NULL pointer attributes",
3409 3410 0, 0, 0);
3410 3411 return (HBA_STATUS_ERROR_ARG);
3411 3412 }
3412 3413
3413 3414 (void) memset(attributes, 0, sizeof (HBA_LIBRARYATTRIBUTES));
3414 3415
3415 3416 GRAB_MUTEX(&_hbaapi_LL_mutex);
3416 3417 GRAB_MUTEX(&_hbaapi_AL_mutex);
3417 3418 for (adapt_infop = _hbaapi_adapterlist;
3418 3419 adapt_infop != NULL;
3419 3420 adapt_infop = adapt_infop->next) {
3420 3421
3421 3422 if (adapt_infop->index == adapter_index) {
3422 3423
3423 3424 if (adapt_infop->library->version == SMHBA) {
3424 3425 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3425 3426 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
3426 3427 HBA_STATUS_ERROR_INCOMPATIBLE);
3427 3428 }
3428 3429
3429 3430 registeredfunc = adapt_infop->library->
3430 3431 ftable.functionTable.GetVendorLibraryAttributesHandler;
3431 3432 if (registeredfunc != NULL) {
3432 3433 ret = (registeredfunc)(attributes);
3433 3434 } else {
3434 3435 /* Version 1 libary? */
3435 3436 HBAGetVersionFunc GetVersionFunc;
3436 3437 GetVersionFunc = adapt_infop->library->
3437 3438 ftable.functionTable.GetVersionHandler;
3438 3439 if (GetVersionFunc != NULL) {
3439 3440 ret = ((GetVersionFunc)());
3440 3441 }
3441 3442 #ifdef NOTDEF
3442 3443 else {
3443 3444 /* This should not happen, dont think its going to */
3444 3445 }
3445 3446 #endif
3446 3447 }
3447 3448 if (attributes->LibPath[0] == '\0') {
3448 3449 if (strlen(adapt_infop->library->LibraryPath) < 256) {
3449 3450 (void) strcpy(attributes->LibPath,
3450 3451 adapt_infop->library->LibraryPath);
3451 3452 }
3452 3453 }
3453 3454 break;
3454 3455 }
3455 3456 }
3456 3457 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3457 3458 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, ret);
3458 3459 }
3459 3460
3460 3461
3461 3462 /*
3462 3463 * This function returns SM-HBA version that the warpper library implemented.
3463 3464 */
3464 3465 HBA_UINT32
3465 3466 SMHBA_GetVersion() {
3466 3467 DEBUG(2, "SMHBA_GetVersion", 0, 0, 0);
3467 3468 return (SMHBA_LIBVERSION);
3468 3469 }
3469 3470
3470 3471 /*
3471 3472 * This function returns the attributes for the warpper library.
3472 3473 */
3473 3474 HBA_UINT32
3474 3475 SMHBA_GetWrapperLibraryAttributes(
3475 3476 SMHBA_LIBRARYATTRIBUTES *attributes)
3476 3477 {
3477 3478
3478 3479 struct timeval tv;
3479 3480 struct tm tp;
3480 3481
3481 3482 DEBUG(2, "SMHBA_GetWrapperLibraryAttributes", 0, 0, 0);
3482 3483
3483 3484 if (attributes == NULL) {
3484 3485 DEBUG(1, "SMHBA_GetWrapperLibraryAttributes: "
3485 3486 "NULL pointer attributes",
3486 3487 0, 0, 0);
3487 3488 return (HBA_STATUS_ERROR_ARG);
3488 3489 }
3489 3490
3490 3491 (void) memset(attributes, 0, sizeof (SMHBA_LIBRARYATTRIBUTES));
3491 3492
3492 3493 #if defined(SOLARIS)
3493 3494 if ((handle = dlopen("libSMHBAAPI.so", RTLD_NOW)) != NULL) {
3494 3495 if (dlinfo(handle, RTLD_DI_LINKMAP, &map) >= 0) {
3495 3496 for (mp = map; mp != NULL; mp = mp->l_next) {
3496 3497 if (strlen(map->l_name) < 256) {
3497 3498 (void) strcpy(attributes->LibPath, map->l_name);
3498 3499 }
3499 3500 }
3500 3501 }
3501 3502 }
3502 3503
3503 3504 #endif
3504 3505
3505 3506 #if defined(VENDOR)
3506 3507 (void) strcpy(attributes->VName, VENDOR);
3507 3508 #else
3508 3509 attributes->VName[0] = '\0';
3509 3510 #endif
3510 3511 #if defined(VERSION)
3511 3512 (void) strcpy(attributes->VVersion, VERSION);
3512 3513 #else
3513 3514 attributes->VVersion[0] = '\0';
3514 3515 #endif
3515 3516
3516 3517 if (gettimeofday(&tv, (void *)0) == 0) {
3517 3518 if (localtime_r(&tv.tv_sec, &tp) != NULL) {
3518 3519 attributes->build_date.tm_mday = tp.tm_mday;
3519 3520 attributes->build_date.tm_mon = tp.tm_mon;
3520 3521 attributes->build_date.tm_year = tp.tm_year;
3521 3522 } else {
3522 3523 (void) memset(&attributes->build_date, 0,
3523 3524 sizeof (attributes->build_date));
3524 3525 }
3525 3526 (void) memset(&attributes->build_date, 0,
3526 3527 sizeof (attributes->build_date));
3527 3528 }
3528 3529
3529 3530 return (1);
3530 3531 }
3531 3532
3532 3533 /*
3533 3534 * This function returns the attributes for the warpper library.
3534 3535 */
3535 3536 HBA_UINT32
3536 3537 SMHBA_GetVendorLibraryAttributes(
3537 3538 HBA_UINT32 adapter_index,
3538 3539 SMHBA_LIBRARYATTRIBUTES *attributes)
3539 3540 {
3540 3541 HBA_ADAPTER_INFO *adapt_infop;
3541 3542 SMHBAGetVendorLibraryAttributesFunc
3542 3543 registeredfunc;
3543 3544 HBA_UINT32 ret = 0;
3544 3545
3545 3546 DEBUG(2, "SMHBA_GetVendorLibraryAttributes adapterindex:%d",
3546 3547 adapter_index, 0, 0);
3547 3548 if (_hbaapi_librarylist == NULL) {
3548 3549 DEBUG(1, "SMHBAAPI not loaded yet.", 0, 0, 0);
3549 3550 return (0);
3550 3551 }
3551 3552
3552 3553 if (attributes == NULL) {
3553 3554 DEBUG(1, "SMHBA_GetVendorLibraryAttributes: "
3554 3555 "NULL pointer attributes",
3555 3556 0, 0, 0);
3556 3557 return (HBA_STATUS_ERROR_ARG);
3557 3558 }
3558 3559
3559 3560 (void) memset(attributes, 0, sizeof (SMHBA_LIBRARYATTRIBUTES));
3560 3561
3561 3562 GRAB_MUTEX(&_hbaapi_LL_mutex);
3562 3563 GRAB_MUTEX(&_hbaapi_AL_mutex);
3563 3564 for (adapt_infop = _hbaapi_adapterlist;
3564 3565 adapt_infop != NULL;
3565 3566 adapt_infop = adapt_infop->next) {
3566 3567
3567 3568 if (adapt_infop->index == adapter_index) {
3568 3569
3569 3570 if (adapt_infop->library->version != SMHBA) {
3570 3571 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3571 3572 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
3572 3573 HBA_STATUS_ERROR_INCOMPATIBLE);
3573 3574 }
3574 3575
3575 3576 registeredfunc = adapt_infop->library->
3576 3577 ftable.smhbafunctionTable.GetVendorLibraryAttributesHandler;
3577 3578 if (registeredfunc != NULL) {
3578 3579 ret = (registeredfunc)(attributes);
3579 3580 #ifdef NOTDEF
3580 3581 } else {
3581 3582 /* This should not happen since the VSL is already loaded. */
3582 3583 #endif
3583 3584 }
3584 3585 if (attributes->LibPath[0] == '\0') {
3585 3586 if (strlen(adapt_infop->library->LibraryPath) < 256) {
3586 3587 (void) strcpy(attributes->LibPath,
3587 3588 adapt_infop->library->LibraryPath);
3588 3589 }
3589 3590 }
3590 3591 break;
3591 3592 }
3592 3593 }
3593 3594 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3594 3595 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, ret);
3595 3596 }
3596 3597
3597 3598 HBA_STATUS
3598 3599 SMHBA_GetAdapterAttributes(
3599 3600 HBA_HANDLE handle,
3600 3601 SMHBA_ADAPTERATTRIBUTES *hbaattributes)
3601 3602 {
3602 3603 HBA_STATUS status;
3603 3604 HBA_LIBRARY_INFO *lib_infop;
3604 3605 HBA_HANDLE vendorHandle;
3605 3606 SMHBAGetAdapterAttributesFunc GetAdapterAttributesFunc;
3606 3607
3607 3608 DEBUG(2, "SMHBA_GetAdapterAttributes", 0, 0, 0);
3608 3609
3609 3610 CHECKLIBRARYANDVERSION(SMHBA);
3610 3611
3611 3612 GetAdapterAttributesFunc =
3612 3613 lib_infop->ftable.smhbafunctionTable.GetAdapterAttributesHandler;
3613 3614 if (GetAdapterAttributesFunc != NULL) {
3614 3615 status = ((GetAdapterAttributesFunc)(vendorHandle, hbaattributes));
3615 3616 } else {
3616 3617 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3617 3618 }
3618 3619 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3619 3620 }
3620 3621
3621 3622 HBA_STATUS
3622 3623 SMHBA_GetNumberOfPorts(
3623 3624 HBA_HANDLE handle,
3624 3625 HBA_UINT32 *numberofports)
3625 3626 {
3626 3627 HBA_STATUS status;
3627 3628 HBA_LIBRARY_INFO *lib_infop;
3628 3629 HBA_HANDLE vendorHandle;
3629 3630 SMHBAGetNumberOfPortsFunc GetNumberOfPortsFunc;
3630 3631
3631 3632 DEBUG(2, "SMHBA_GetAdapterAttributes", 0, 0, 0);
3632 3633
3633 3634 CHECKLIBRARYANDVERSION(SMHBA);
3634 3635
3635 3636 GetNumberOfPortsFunc =
3636 3637 lib_infop->ftable.smhbafunctionTable.GetNumberOfPortsHandler;
3637 3638 if (GetNumberOfPortsFunc != NULL) {
3638 3639 status = ((GetNumberOfPortsFunc)(vendorHandle, numberofports));
3639 3640 } else {
3640 3641 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3641 3642 }
3642 3643 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3643 3644 }
3644 3645
3645 3646 HBA_STATUS
3646 3647 SMHBA_GetPortType(
3647 3648 HBA_HANDLE handle,
3648 3649 HBA_UINT32 portindex,
3649 3650 HBA_PORTTYPE *porttype)
3650 3651 {
3651 3652 HBA_STATUS status;
3652 3653 HBA_LIBRARY_INFO *lib_infop;
3653 3654 HBA_HANDLE vendorHandle;
3654 3655 SMHBAGetPortTypeFunc GetPortTypeFunc;
3655 3656
3656 3657 DEBUG(2, "SMHBA_GetAdapterAttributes", 0, 0, 0);
3657 3658
3658 3659 CHECKLIBRARYANDVERSION(SMHBA);
3659 3660
3660 3661 GetPortTypeFunc =
3661 3662 lib_infop->ftable.smhbafunctionTable.GetPortTypeHandler;
3662 3663 if (GetPortTypeFunc != NULL) {
3663 3664 status = ((GetPortTypeFunc)(vendorHandle, portindex, porttype));
3664 3665 } else {
3665 3666 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3666 3667 }
3667 3668 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3668 3669 }
3669 3670
3670 3671 HBA_STATUS
3671 3672 SMHBA_GetAdapterPortAttributes(
3672 3673 HBA_HANDLE handle,
3673 3674 HBA_UINT32 portindex,
3674 3675 SMHBA_PORTATTRIBUTES *portattributes)
3675 3676 {
3676 3677 HBA_STATUS status;
3677 3678 HBA_LIBRARY_INFO *lib_infop;
3678 3679 HBA_HANDLE vendorHandle;
3679 3680 SMHBAGetAdapterPortAttributesFunc
3680 3681 GetAdapterPortAttributesFunc;
3681 3682
3682 3683 DEBUG(2, "SMHBA_GetAdapterPortAttributes", 0, 0, 0);
3683 3684
3684 3685 CHECKLIBRARYANDVERSION(SMHBA);
3685 3686
3686 3687 GetAdapterPortAttributesFunc =
3687 3688 lib_infop->ftable.smhbafunctionTable.\
3688 3689 GetAdapterPortAttributesHandler;
3689 3690 if (GetAdapterPortAttributesFunc != NULL) {
3690 3691 status = ((GetAdapterPortAttributesFunc)
3691 3692 (vendorHandle, portindex, portattributes));
3692 3693 } else {
3693 3694 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3694 3695 }
3695 3696 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3696 3697 }
3697 3698
3698 3699 HBA_STATUS
3699 3700 SMHBA_GetDiscoveredPortAttributes(
3700 3701 HBA_HANDLE handle,
3701 3702 HBA_UINT32 portindex,
3702 3703 HBA_UINT32 discoveredportindex,
3703 3704 SMHBA_PORTATTRIBUTES *portattributes)
3704 3705 {
3705 3706 HBA_STATUS status;
3706 3707 HBA_LIBRARY_INFO *lib_infop;
3707 3708 HBA_HANDLE vendorHandle;
3708 3709 SMHBAGetDiscoveredPortAttributesFunc
3709 3710 GetDiscoveredPortAttributesFunc;
3710 3711
3711 3712 DEBUG(2, "SMHBA_GetDiscoveredPortAttributes", 0, 0, 0);
3712 3713
3713 3714 CHECKLIBRARYANDVERSION(SMHBA);
3714 3715
3715 3716 GetDiscoveredPortAttributesFunc =
3716 3717 lib_infop->ftable.smhbafunctionTable.\
3717 3718 GetDiscoveredPortAttributesHandler;
3718 3719 if (GetDiscoveredPortAttributesFunc != NULL) {
3719 3720 status = ((GetDiscoveredPortAttributesFunc)
3720 3721 (vendorHandle, portindex, discoveredportindex,
3721 3722 portattributes));
3722 3723 } else {
3723 3724 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3724 3725 }
3725 3726 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3726 3727 }
3727 3728
3728 3729 HBA_STATUS
3729 3730 SMHBA_GetPortAttributesByWWN(
3730 3731 HBA_HANDLE handle,
3731 3732 HBA_WWN portWWN,
3732 3733 HBA_WWN domainPortWWN,
3733 3734 SMHBA_PORTATTRIBUTES *portattributes)
3734 3735 {
3735 3736 HBA_STATUS status;
3736 3737 HBA_LIBRARY_INFO *lib_infop;
3737 3738 HBA_HANDLE vendorHandle;
3738 3739 SMHBAGetPortAttributesByWWNFunc
3739 3740 GetPortAttributesByWWNFunc;
3740 3741
3741 3742 DEBUG(2, "SMHBA_GetPortAttributesByWWN: %s", WWN2STR1(&portWWN), 0, 0);
3742 3743
3743 3744 CHECKLIBRARYANDVERSION(SMHBA);
3744 3745
3745 3746 GetPortAttributesByWWNFunc =
3746 3747 lib_infop->ftable.smhbafunctionTable.GetPortAttributesByWWNHandler;
3747 3748 if (GetPortAttributesByWWNFunc != NULL) {
3748 3749 status = ((GetPortAttributesByWWNFunc)
3749 3750 (vendorHandle, portWWN, domainPortWWN, portattributes));
3750 3751 } else {
3751 3752 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3752 3753 }
3753 3754 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3754 3755 }
3755 3756
3756 3757 HBA_STATUS
3757 3758 SMHBA_GetFCPhyAttributes(
3758 3759 HBA_HANDLE handle,
3759 3760 HBA_UINT32 portindex,
3760 3761 HBA_UINT32 phyindex,
3761 3762 SMHBA_FC_PHY *phytype)
3762 3763 {
3763 3764 HBA_STATUS status;
3764 3765 HBA_LIBRARY_INFO *lib_infop;
3765 3766 HBA_HANDLE vendorHandle;
3766 3767 SMHBAGetFCPhyAttributesFunc GetFCPhyAttributesFunc;
3767 3768
3768 3769 DEBUG(2, "SMHBA_GetFCPhyAttributesByWWN", 0, 0, 0);
3769 3770
3770 3771 CHECKLIBRARYANDVERSION(SMHBA);
3771 3772
3772 3773 GetFCPhyAttributesFunc =
3773 3774 lib_infop->ftable.smhbafunctionTable.GetFCPhyAttributesHandler;
3774 3775 if (GetFCPhyAttributesFunc != NULL) {
3775 3776 status = ((GetFCPhyAttributesFunc)
3776 3777 (vendorHandle, portindex, phyindex, phytype));
3777 3778 } else {
3778 3779 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3779 3780 }
3780 3781 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3781 3782 }
3782 3783
3783 3784 HBA_STATUS
3784 3785 SMHBA_GetSASPhyAttributes(
3785 3786 HBA_HANDLE handle,
3786 3787 HBA_UINT32 portindex,
3787 3788 HBA_UINT32 phyindex,
3788 3789 SMHBA_SAS_PHY *phytype)
3789 3790 {
3790 3791 HBA_STATUS status;
3791 3792 HBA_LIBRARY_INFO *lib_infop;
3792 3793 HBA_HANDLE vendorHandle;
3793 3794 SMHBAGetSASPhyAttributesFunc GetSASPhyAttributesFunc;
3794 3795
3795 3796 DEBUG(2, "SMHBA_GetFCPhyAttributesByWWN", 0, 0, 0);
3796 3797
3797 3798 CHECKLIBRARYANDVERSION(SMHBA);
3798 3799
3799 3800 GetSASPhyAttributesFunc =
3800 3801 lib_infop->ftable.smhbafunctionTable.GetSASPhyAttributesHandler;
3801 3802 if (GetSASPhyAttributesFunc != NULL) {
3802 3803 status = ((GetSASPhyAttributesFunc)
3803 3804 (vendorHandle, portindex, phyindex, phytype));
3804 3805 } else {
3805 3806 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3806 3807 }
3807 3808 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3808 3809 }
3809 3810
3810 3811 HBA_STATUS
3811 3812 SMHBA_GetProtocolStatistics(
3812 3813 HBA_HANDLE handle,
3813 3814 HBA_UINT32 portindex,
3814 3815 HBA_UINT32 protocoltype,
3815 3816 SMHBA_PROTOCOLSTATISTICS *pProtocolStatistics)
3816 3817 {
3817 3818 HBA_STATUS status;
3818 3819 HBA_LIBRARY_INFO *lib_infop;
3819 3820 HBA_HANDLE vendorHandle;
3820 3821 SMHBAGetProtocolStatisticsFunc
3821 3822 GetProtocolStatisticsFunc;
3822 3823
3823 3824 DEBUG(2, "SMHBA_GetProtocolStatistics port index: %d protocol type: %d",
3824 3825 portindex, protocoltype, 0);
3825 3826
3826 3827 CHECKLIBRARYANDVERSION(SMHBA);
3827 3828
3828 3829 GetProtocolStatisticsFunc =
3829 3830 lib_infop->ftable.smhbafunctionTable.GetProtocolStatisticsHandler;
3830 3831 if (GetProtocolStatisticsFunc != NULL) {
3831 3832 status = (GetProtocolStatisticsFunc)
3832 3833 (vendorHandle, portindex, protocoltype, pProtocolStatistics);
3833 3834 } else {
3834 3835 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3835 3836 }
3836 3837 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3837 3838 }
3838 3839
3839 3840 HBA_STATUS
3840 3841 SMHBA_GetPhyStatistics(
3841 3842 HBA_HANDLE handle,
3842 3843 HBA_UINT32 portindex,
3843 3844 HBA_UINT32 phyindex,
3844 3845 SMHBA_PHYSTATISTICS *pPhyStatistics)
3845 3846 {
3846 3847 HBA_STATUS status;
3847 3848 HBA_LIBRARY_INFO *lib_infop;
3848 3849 HBA_HANDLE vendorHandle;
3849 3850 SMHBAGetPhyStatisticsFunc
3850 3851 GetPhyStatisticsFunc;
3851 3852
3852 3853 DEBUG(2, "SMHBA_GetPhyStatistics port index: %d phy idex: %d",
3853 3854 portindex, phyindex, 0);
3854 3855
3855 3856 CHECKLIBRARYANDVERSION(SMHBA);
3856 3857
3857 3858 GetPhyStatisticsFunc =
3858 3859 lib_infop->ftable.smhbafunctionTable.GetPhyStatisticsHandler;
3859 3860 if (GetPhyStatisticsFunc != NULL) {
3860 3861 status = (GetPhyStatisticsFunc)
3861 3862 (vendorHandle, portindex, phyindex, pPhyStatistics);
3862 3863 } else {
3863 3864 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3864 3865 }
3865 3866 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3866 3867 }
3867 3868
3868 3869 HBA_STATUS
3869 3870 SMHBA_GetBindingCapability(
3870 3871 HBA_HANDLE handle,
3871 3872 HBA_WWN hbaPortWWN,
3872 3873 HBA_WWN domainPortWWN,
3873 3874 SMHBA_BIND_CAPABILITY *pFlags)
3874 3875 {
3875 3876 HBA_STATUS status;
3876 3877 HBA_LIBRARY_INFO *lib_infop;
3877 3878 HBA_HANDLE vendorHandle;
3878 3879 SMHBAGetBindingCapabilityFunc GetBindingCapabilityFunc;
3879 3880
3880 3881 DEBUG(2, "HBA_GetBindingCapability", 0, 0, 0);
3881 3882
3882 3883 CHECKLIBRARYANDVERSION(SMHBA);
3883 3884
3884 3885 GetBindingCapabilityFunc =
3885 3886 lib_infop->ftable.smhbafunctionTable.GetBindingCapabilityHandler;
3886 3887 if (GetBindingCapabilityFunc != NULL) {
3887 3888 status = (GetBindingCapabilityFunc)(vendorHandle, hbaPortWWN,
3888 3889 domainPortWWN, pFlags);
3889 3890 } else {
3890 3891 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3891 3892 }
3892 3893 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3893 3894 }
3894 3895
3895 3896 HBA_STATUS
3896 3897 SMHBA_GetBindingSupport(
3897 3898 HBA_HANDLE handle,
3898 3899 HBA_WWN hbaPortWWN,
3899 3900 HBA_WWN domainPortWWN,
3900 3901 SMHBA_BIND_CAPABILITY *pFlags)
3901 3902 {
3902 3903 HBA_STATUS status;
3903 3904 HBA_LIBRARY_INFO *lib_infop;
3904 3905 HBA_HANDLE vendorHandle;
3905 3906 SMHBAGetBindingSupportFunc
3906 3907 GetBindingSupporFunc;
3907 3908
3908 3909 DEBUG(2, "SMHBA_GetBindingSupport port: %s",
3909 3910 WWN2STR1(&hbaPortWWN), 0, 0);
3910 3911
3911 3912 CHECKLIBRARYANDVERSION(SMHBA);
3912 3913
3913 3914 GetBindingSupporFunc =
3914 3915 lib_infop->ftable.smhbafunctionTable.GetBindingSupportHandler;
3915 3916 if (GetBindingSupporFunc != NULL) {
3916 3917 status = (GetBindingSupporFunc)(vendorHandle,
3917 3918 hbaPortWWN, domainPortWWN, pFlags);
3918 3919 } else {
3919 3920 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3920 3921 }
3921 3922 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3922 3923 }
3923 3924
3924 3925 HBA_STATUS
3925 3926 SMHBA_SetBindingSupport(
3926 3927 HBA_HANDLE handle,
3927 3928 HBA_WWN hbaPortWWN,
3928 3929 HBA_WWN domainPortWWN,
3929 3930 SMHBA_BIND_CAPABILITY flags)
3930 3931 {
3931 3932 HBA_STATUS status;
3932 3933 HBA_LIBRARY_INFO *lib_infop;
3933 3934 HBA_HANDLE vendorHandle;
3934 3935 SMHBASetBindingSupportFunc
3935 3936 SetBindingSupporFunc;
3936 3937
3937 3938 DEBUG(2, "SMHBA_GetBindingSupport port: %s",
3938 3939 WWN2STR1(&hbaPortWWN), 0, 0);
3939 3940
3940 3941 CHECKLIBRARYANDVERSION(HBAAPIV2);
3941 3942
3942 3943 SetBindingSupporFunc =
3943 3944 lib_infop->ftable.smhbafunctionTable.SetBindingSupportHandler;
3944 3945 if (SetBindingSupporFunc != NULL) {
3945 3946 status = (SetBindingSupporFunc)
3946 3947 (vendorHandle, hbaPortWWN, domainPortWWN, flags);
3947 3948 } else {
3948 3949 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3949 3950 }
3950 3951 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3951 3952 }
3952 3953
3953 3954 HBA_STATUS
3954 3955 SMHBA_GetTargetMapping(
3955 3956 HBA_HANDLE handle,
3956 3957 HBA_WWN hbaPortWWN,
3957 3958 HBA_WWN domainPortWWN,
3958 3959 SMHBA_TARGETMAPPING *pMapping)
3959 3960 {
3960 3961 HBA_STATUS status;
3961 3962 HBA_LIBRARY_INFO *lib_infop;
3962 3963 HBA_HANDLE vendorHandle;
3963 3964 SMHBAGetTargetMappingFunc GetTargetMappingFunc;
3964 3965
3965 3966 DEBUG(2, "SMHBA_GetTargetMapping port WWN: %s",
3966 3967 WWN2STR1(&hbaPortWWN), 0, 0);
3967 3968
3968 3969 CHECKLIBRARYANDVERSION(SMHBA);
3969 3970
3970 3971 GetTargetMappingFunc =
3971 3972 lib_infop->ftable.smhbafunctionTable.GetTargetMappingHandler;
3972 3973 if (GetTargetMappingFunc != NULL) {
3973 3974 status = ((GetTargetMappingFunc)(vendorHandle,
3974 3975 hbaPortWWN, domainPortWWN, pMapping));
3975 3976 } else {
3976 3977 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3977 3978 }
3978 3979 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3979 3980 }
3980 3981
3981 3982 HBA_STATUS
3982 3983 SMHBA_GetPersistentBinding(
3983 3984 HBA_HANDLE handle,
3984 3985 HBA_WWN hbaPortWWN,
3985 3986 HBA_WWN domainPortWWN,
3986 3987 SMHBA_BINDING *binding)
3987 3988 {
3988 3989 HBA_STATUS status;
3989 3990 HBA_LIBRARY_INFO *lib_infop;
3990 3991 HBA_HANDLE vendorHandle;
3991 3992 SMHBAGetPersistentBindingFunc
3992 3993 GetPersistentBindingFunc;
3993 3994
3994 3995 DEBUG(2, "SMHBA_GetPersistentBinding port WWN: %s",
3995 3996 WWN2STR1(&hbaPortWWN), 0, 0);
3996 3997
3997 3998 CHECKLIBRARYANDVERSION(SMHBA);
3998 3999
3999 4000 GetPersistentBindingFunc =
4000 4001 lib_infop->ftable.smhbafunctionTable.GetPersistentBindingHandler;
4001 4002 if (GetPersistentBindingFunc != NULL) {
4002 4003 status = ((GetPersistentBindingFunc)(vendorHandle,
4003 4004 hbaPortWWN, domainPortWWN, binding));
4004 4005 } else {
4005 4006 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4006 4007 }
4007 4008 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4008 4009 }
4009 4010
4010 4011 HBA_STATUS
4011 4012 SMHBA_SetPersistentBinding(
4012 4013 HBA_HANDLE handle,
4013 4014 HBA_WWN hbaPortWWN,
4014 4015 HBA_WWN domainPortWWN,
4015 4016 const SMHBA_BINDING *binding)
4016 4017 {
4017 4018 HBA_STATUS status;
4018 4019 HBA_LIBRARY_INFO *lib_infop;
4019 4020 HBA_HANDLE vendorHandle;
4020 4021 SMHBASetPersistentBindingFunc
4021 4022 SetPersistentBindingFunc;
4022 4023
4023 4024 DEBUG(2, "SMHBA_SetPersistentBinding port WWN: %s",
4024 4025 WWN2STR1(&hbaPortWWN), 0, 0);
4025 4026
4026 4027 CHECKLIBRARYANDVERSION(SMHBA);
4027 4028
4028 4029 SetPersistentBindingFunc =
4029 4030 lib_infop->ftable.smhbafunctionTable.SetPersistentBindingHandler;
4030 4031 if (SetPersistentBindingFunc != NULL) {
4031 4032 status = ((SetPersistentBindingFunc)(vendorHandle,
4032 4033 hbaPortWWN, domainPortWWN, binding));
4033 4034 } else {
4034 4035 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4035 4036 }
4036 4037 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4037 4038 }
4038 4039
4039 4040 HBA_STATUS
4040 4041 SMHBA_RemovePersistentBinding(
4041 4042 HBA_HANDLE handle,
4042 4043 HBA_WWN hbaPortWWN,
4043 4044 HBA_WWN domainPortWWN,
4044 4045 const SMHBA_BINDING *binding)
4045 4046 {
4046 4047 HBA_STATUS status;
4047 4048 HBA_LIBRARY_INFO *lib_infop;
4048 4049 HBA_HANDLE vendorHandle;
4049 4050 SMHBARemovePersistentBindingFunc
4050 4051 RemovePersistentBindingFunc;
4051 4052
4052 4053 DEBUG(2, "SMHBA_RemovePersistentBinding port WWN: %s",
4053 4054 WWN2STR1(&hbaPortWWN), 0, 0);
4054 4055
4055 4056 CHECKLIBRARYANDVERSION(SMHBA);
4056 4057
4057 4058 RemovePersistentBindingFunc =
4058 4059 lib_infop->ftable.smhbafunctionTable.RemovePersistentBindingHandler;
4059 4060 if (RemovePersistentBindingFunc != NULL) {
4060 4061 status = ((RemovePersistentBindingFunc)(vendorHandle,
4061 4062 hbaPortWWN, domainPortWWN, binding));
4062 4063 } else {
4063 4064 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4064 4065 }
4065 4066 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4066 4067 }
4067 4068
4068 4069 HBA_STATUS
4069 4070 SMHBA_RemoveAllPersistentBindings(
4070 4071 HBA_HANDLE handle,
4071 4072 HBA_WWN hbaPortWWN,
4072 4073 HBA_WWN domainPortWWN)
4073 4074 {
4074 4075 HBA_STATUS status;
4075 4076 HBA_LIBRARY_INFO *lib_infop;
4076 4077 HBA_HANDLE vendorHandle;
4077 4078 SMHBARemoveAllPersistentBindingsFunc
4078 4079 RemoveAllPersistentBindingsFunc;
4079 4080
4080 4081 DEBUG(2, "SMHBA_RemoveAllPersistentBinding port WWN: %s",
4081 4082 WWN2STR1(&hbaPortWWN), 0, 0);
4082 4083
4083 4084 CHECKLIBRARYANDVERSION(SMHBA);
4084 4085
4085 4086 RemoveAllPersistentBindingsFunc =
4086 4087 lib_infop->ftable.smhbafunctionTable.\
4087 4088 RemoveAllPersistentBindingsHandler;
4088 4089 if (RemoveAllPersistentBindingsFunc != NULL) {
4089 4090 status = ((RemoveAllPersistentBindingsFunc)(vendorHandle,
4090 4091 hbaPortWWN, domainPortWWN));
4091 4092 } else {
4092 4093 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4093 4094 }
4094 4095 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4095 4096 }
4096 4097
4097 4098 HBA_STATUS
4098 4099 SMHBA_GetLUNStatistics(
4099 4100 HBA_HANDLE handle,
4100 4101 const HBA_SCSIID *lunit,
4101 4102 SMHBA_PROTOCOLSTATISTICS *statistics)
4102 4103 {
4103 4104 HBA_STATUS status;
4104 4105 HBA_LIBRARY_INFO *lib_infop;
4105 4106 HBA_HANDLE vendorHandle;
4106 4107 SMHBAGetLUNStatisticsFunc GetLUNStatisticsFunc;
4107 4108
4108 4109 DEBUG(2, "SMHBA_GetLUNStatistics", 0, 0, 0);
4109 4110
4110 4111 CHECKLIBRARYANDVERSION(SMHBA);
4111 4112
4112 4113 GetLUNStatisticsFunc =
4113 4114 lib_infop->ftable.smhbafunctionTable.GetLUNStatisticsHandler;
4114 4115 if (GetLUNStatisticsFunc != NULL) {
4115 4116 status = ((GetLUNStatisticsFunc)(vendorHandle, lunit, statistics));
4116 4117 } else {
4117 4118 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4118 4119 }
4119 4120 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4120 4121 }
4121 4122
4122 4123 HBA_STATUS
4123 4124 SMHBA_ScsiInquiry(
4124 4125 HBA_HANDLE handle,
4125 4126 HBA_WWN hbaPortWWN,
4126 4127 HBA_WWN discoveredPortWWN,
4127 4128 HBA_WWN domainPortWWN,
4128 4129 SMHBA_SCSILUN smhbaLUN,
4129 4130 HBA_UINT8 CDB_Byte1,
4130 4131 HBA_UINT8 CDB_Byte2,
4131 4132 void *pRspBuffer,
4132 4133 HBA_UINT32 *pRspBufferSize,
4133 4134 HBA_UINT8 *pScsiStatus,
4134 4135 void *pSenseBuffer,
4135 4136 HBA_UINT32 *pSenseBufferSize)
4136 4137 {
4137 4138 HBA_STATUS status;
4138 4139 HBA_LIBRARY_INFO *lib_infop;
4139 4140 HBA_HANDLE vendorHandle;
4140 4141 SMHBAScsiInquiryFunc ScsiInquiryFunc;
4141 4142
4142 4143 DEBUG(2, "SMHBA_ScsiInquiry to hba port: %s discoveredPortWWN: %s",
4143 4144 WWN2STR1(&hbaPortWWN), WWN2STR1(&discoveredPortWWN), 0);
4144 4145
4145 4146 CHECKLIBRARYANDVERSION(SMHBA);
4146 4147
4147 4148 ScsiInquiryFunc =
4148 4149 lib_infop->ftable.smhbafunctionTable.ScsiInquiryHandler;
4149 4150 if (ScsiInquiryFunc != NULL) {
4150 4151 status = ((ScsiInquiryFunc)(
4151 4152 vendorHandle, hbaPortWWN, discoveredPortWWN, domainPortWWN,
4152 4153 smhbaLUN, CDB_Byte1, CDB_Byte2, pRspBuffer, pRspBufferSize,
4153 4154 pScsiStatus, pSenseBuffer, pSenseBufferSize));
4154 4155 } else {
4155 4156 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4156 4157 }
4157 4158 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4158 4159 }
4159 4160
4160 4161 HBA_STATUS
4161 4162 SMHBA_ScsiReportLUNs(
4162 4163 HBA_HANDLE handle,
4163 4164 HBA_WWN hbaPortWWN,
4164 4165 HBA_WWN discoveredPortWWN,
4165 4166 HBA_WWN domainPortWWN,
4166 4167 void *pRspBuffer,
4167 4168 HBA_UINT32 *pRspBufferSize,
4168 4169 HBA_UINT8 *pScsiStatus,
4169 4170 void *pSenseBuffer,
4170 4171 HBA_UINT32 *pSenseBufferSize)
4171 4172 {
4172 4173 HBA_STATUS status;
4173 4174 HBA_LIBRARY_INFO *lib_infop;
4174 4175 HBA_HANDLE vendorHandle;
4175 4176 SMHBAScsiReportLUNsFunc ScsiReportLUNsFunc;
4176 4177
4177 4178 DEBUG(2, "SMHBA_ScsiReportLuns to hba port: %s discoveredPortWWN: %s",
4178 4179 WWN2STR1(&hbaPortWWN), WWN2STR1(&discoveredPortWWN), 0);
4179 4180
4180 4181 CHECKLIBRARYANDVERSION(SMHBA);
4181 4182
4182 4183 ScsiReportLUNsFunc =
4183 4184 lib_infop->ftable.smhbafunctionTable.ScsiReportLUNsHandler;
4184 4185 if (ScsiReportLUNsFunc != NULL) {
4185 4186 status = ((ScsiReportLUNsFunc)(
4186 4187 vendorHandle, hbaPortWWN, discoveredPortWWN, domainPortWWN,
4187 4188 pRspBuffer, pRspBufferSize, pScsiStatus, pSenseBuffer,
4188 4189 pSenseBufferSize));
4189 4190 } else {
4190 4191 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4191 4192 }
4192 4193 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4193 4194 }
4194 4195
4195 4196 HBA_STATUS
4196 4197 SMHBA_ScsiReadCapacity(
4197 4198 HBA_HANDLE handle,
4198 4199 HBA_WWN hbaPortWWN,
4199 4200 HBA_WWN discoveredPortWWN,
4200 4201 HBA_WWN domainPortWWN,
4201 4202 SMHBA_SCSILUN smhbaLUN,
4202 4203 void *pRspBuffer,
4203 4204 HBA_UINT32 *pRspBufferSize,
4204 4205 HBA_UINT8 *pScsiStatus,
4205 4206 void *pSenseBuffer,
4206 4207 HBA_UINT32 *pSenseBufferSize)
4207 4208 {
4208 4209 HBA_STATUS status;
4209 4210 HBA_LIBRARY_INFO *lib_infop;
4210 4211 HBA_HANDLE vendorHandle;
4211 4212 SMHBAScsiReadCapacityFunc ScsiReadCapacityFunc;
4212 4213
4213 4214 DEBUG(2, "SMHBA_ScsiReadCapacity to hba port: %s discoveredPortWWN: %s",
4214 4215 WWN2STR1(&hbaPortWWN), WWN2STR1(&discoveredPortWWN), 0);
4215 4216
4216 4217 CHECKLIBRARYANDVERSION(SMHBA);
4217 4218
4218 4219 ScsiReadCapacityFunc =
4219 4220 lib_infop->ftable.smhbafunctionTable.ScsiReadCapacityHandler;
4220 4221 if (ScsiReadCapacityFunc != NULL) {
4221 4222 status = ((ScsiReadCapacityFunc)(
4222 4223 vendorHandle, hbaPortWWN, discoveredPortWWN, domainPortWWN,
4223 4224 smhbaLUN, pRspBuffer, pRspBufferSize, pScsiStatus, pSenseBuffer,
4224 4225 pSenseBufferSize));
4225 4226 } else {
4226 4227 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4227 4228 }
4228 4229 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4229 4230 }
4230 4231
4231 4232 HBA_STATUS
4232 4233 SMHBA_SendTEST(
4233 4234 HBA_HANDLE handle,
4234 4235 HBA_WWN hbaPortWWN,
4235 4236 HBA_WWN destWWN,
4236 4237 HBA_UINT32 destFCID,
4237 4238 void *pRspBuffer,
4238 4239 HBA_UINT32 pRspBufferSize)
4239 4240 {
4240 4241 HBA_STATUS status;
4241 4242 HBA_LIBRARY_INFO *lib_infop;
4242 4243 HBA_HANDLE vendorHandle;
4243 4244 SMHBASendTESTFunc SendTESTFunc;
4244 4245
4245 4246 DEBUG(2, "SMHBA_SendTEST, hbaPortWWN: %s destWWN",
4246 4247 WWN2STR1(&hbaPortWWN),
4247 4248 WWN2STR1(&destWWN), 0);
4248 4249
4249 4250 CHECKLIBRARYANDVERSION(SMHBA);
4250 4251
4251 4252 SendTESTFunc = lib_infop->ftable.smhbafunctionTable.SendTESTHandler;
4252 4253 if (SendTESTFunc != NULL) {
4253 4254 status = (SendTESTFunc)
4254 4255 (vendorHandle, hbaPortWWN, destWWN, destFCID,
4255 4256 pRspBuffer, pRspBufferSize);
4256 4257 } else {
4257 4258 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4258 4259 }
4259 4260 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4260 4261 }
4261 4262
4262 4263 HBA_STATUS
4263 4264 SMHBA_SendECHO(
4264 4265 HBA_HANDLE handle,
4265 4266 HBA_WWN hbaPortWWN,
4266 4267 HBA_WWN destWWN,
4267 4268 HBA_UINT32 destFCID,
4268 4269 void *pReqBuffer,
4269 4270 HBA_UINT32 ReqBufferSize,
4270 4271 void *pRspBuffer,
4271 4272 HBA_UINT32 *pRspBufferSize)
4272 4273 {
4273 4274 HBA_STATUS status;
4274 4275 HBA_LIBRARY_INFO *lib_infop;
4275 4276 HBA_HANDLE vendorHandle;
4276 4277 SMHBASendECHOFunc SendECHOFunc;
4277 4278
4278 4279 DEBUG(2, "SMHBA_SendECHO, hbaPortWWN: %s destWWN",
4279 4280 WWN2STR1(&hbaPortWWN), WWN2STR1(&destWWN), 0);
4280 4281
4281 4282 CHECKLIBRARYANDVERSION(SMHBA);
4282 4283
4283 4284 SendECHOFunc = lib_infop->ftable.smhbafunctionTable.SendECHOHandler;
4284 4285 if (SendECHOFunc != NULL) {
4285 4286 status = (SendECHOFunc)
4286 4287 (vendorHandle, hbaPortWWN, destWWN, destFCID,
4287 4288 pReqBuffer, ReqBufferSize, pRspBuffer, pRspBufferSize);
4288 4289 } else {
4289 4290 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4290 4291 }
4291 4292 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4292 4293 }
4293 4294
4294 4295 HBA_STATUS
4295 4296 SMHBA_SendSMPPassThru(
4296 4297 HBA_HANDLE handle,
4297 4298 HBA_WWN hbaPortWWN,
4298 4299 HBA_WWN destWWN,
4299 4300 HBA_WWN domainPortWWN,
4300 4301 void *pReqBuffer,
4301 4302 HBA_UINT32 ReqBufferSize,
4302 4303 void *pRspBuffer,
4303 4304 HBA_UINT32 *pRspBufferSize)
4304 4305 {
4305 4306 HBA_STATUS status;
4306 4307 HBA_LIBRARY_INFO *lib_infop;
4307 4308 HBA_HANDLE vendorHandle;
4308 4309 SMHBASendSMPPassThruFunc SendSMPPassThruFunc;
4309 4310
4310 4311 DEBUG(2, "SMHBA_SendSMPPassThru, hbaPortWWN: %s destWWN: %s",
4311 4312 WWN2STR1(&hbaPortWWN), WWN2STR1(&destWWN), 0);
4312 4313
4313 4314 CHECKLIBRARYANDVERSION(SMHBA);
4314 4315
4315 4316 SendSMPPassThruFunc = lib_infop->ftable.\
4316 4317 smhbafunctionTable.SendSMPPassThruHandler;
4317 4318
4318 4319 if (SendSMPPassThruFunc != NULL) {
4319 4320 status = (SendSMPPassThruFunc)
4320 4321 (vendorHandle, hbaPortWWN, destWWN, domainPortWWN,
4321 4322 pReqBuffer, ReqBufferSize, pRspBuffer, pRspBufferSize);
4322 4323 } else {
4323 4324 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4324 4325 }
4325 4326 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4326 4327 }
4327 4328
4328 4329 /*
4329 4330 * Following the similar logic of HBAAPI addaspterevents_callback.
4330 4331 *
4331 4332 * Unlike other events Adapter Add Event is not limited to a specific
4332 4333 * adapter(i.e. no adapter handle is passed for registration) so
4333 4334 * the event should be passed to all registrants. The routine below
4334 4335 * is passed to the VSLs as a callback and when Adapter Add event is detected
4335 4336 * by VSL it will call smhba_adapteraddevents_callback() which in turn check
4336 4337 * if the passed userdata ptr matches with the one stored in the callback list
4337 4338 * and calls the stored callback.
4338 4339 *
4339 4340 * For the situation that multiple clients are registered for Adapter Add event
4340 4341 * each registration is passed to VSLs so VSL may call
4341 4342 * smhba_adapteraddevents_callback() multiple times or it may call only once
4342 4343 * since the callback function is same. For this implemneation, the userdata
4343 4344 * is stored in HBA_ALLADAPTERSCALLBACK_ELEM so it is expected that VSL call
4344 4345 * smhba_adapteraddevents_callback() only once and
4345 4346 * smhba_adapteraddevents_callback() will call the client callback with proper
4346 4347 * userdata.
4347 4348 */
4348 4349 static void
4349 4350 smhba_adapteraddevents_callback(
4350 4351 /* LINTED E_FUNC_ARG_UNUSED */
4351 4352 void *data,
4352 4353 HBA_WWN PortWWN,
4353 4354 /* LINTED E_FUNC_ARG_UNUSED */
4354 4355 HBA_UINT32 eventType)
4355 4356 {
4356 4357 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
4357 4358
4358 4359 DEBUG(3, "AddAdapterEvent, port:%s", WWN2STR1(&PortWWN), 0, 0);
4359 4360
4360 4361 GRAB_MUTEX(&_smhba_AAE_mutex);
4361 4362 for (cbp = _smhba_adapteraddevents_callback_list;
4362 4363 cbp != NULL;
4363 4364 cbp = cbp->next) {
4364 4365 (*cbp->callback)(cbp->userdata, PortWWN, HBA_EVENT_ADAPTER_ADD);
4365 4366 }
4366 4367 RELEASE_MUTEX(&_smhba_AAE_mutex);
4367 4368
4368 4369 }
4369 4370
4370 4371 HBA_STATUS
4371 4372 SMHBA_RegisterForAdapterAddEvents(
4372 4373 void (*pCallback) (
4373 4374 void *data,
4374 4375 HBA_WWN PortWWN,
4375 4376 HBA_UINT32 eventType),
4376 4377 void *pUserData,
4377 4378 HBA_CALLBACKHANDLE *pCallbackHandle) {
4378 4379
4379 4380 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
4380 4381 HBA_VENDORCALLBACK_ELEM *vcbp;
4381 4382 HBA_VENDORCALLBACK_ELEM *vendorhandlelist;
4382 4383 SMHBARegisterForAdapterAddEventsFunc registeredfunc;
4383 4384 HBA_STATUS status = HBA_STATUS_OK;
4384 4385 HBA_STATUS failure = HBA_STATUS_OK;
4385 4386 HBA_LIBRARY_INFO *lib_infop;
4386 4387 int registered_cnt = 0;
4387 4388 int vendor_cnt = 0;
4388 4389 int not_supported_cnt = 0;
4389 4390 int status_OK_bar_cnt = 0;
4390 4391 int status_OK_cnt = 0;
4391 4392
4392 4393 DEBUG(2, "SMHBA_RegisterForAdapterAddEvents", 0, 0, 0);
4393 4394 ARE_WE_INITED();
4394 4395
4395 4396 cbp = (HBA_ALLADAPTERSCALLBACK_ELEM *)
4396 4397 calloc(1, sizeof (HBA_ALLADAPTERSCALLBACK_ELEM));
4397 4398 *pCallbackHandle = (HBA_CALLBACKHANDLE) cbp;
4398 4399 if (cbp == NULL) {
4399 4400 return (HBA_STATUS_ERROR);
4400 4401 }
4401 4402
4402 4403 GRAB_MUTEX(&_hbaapi_LL_mutex);
4403 4404 GRAB_MUTEX(&_smhba_AAE_mutex);
4404 4405 cbp->callback = pCallback;
4405 4406 cbp->userdata = pUserData;
4406 4407 cbp->next = _smhba_adapteraddevents_callback_list;
4407 4408 _smhba_adapteraddevents_callback_list = cbp;
4408 4409
4409 4410 /*
4410 4411 * Need to release the mutex now incase the vendor function invokes the
4411 4412 * callback. We will grap the mutex later to attach the vendor handle
4412 4413 * list to the callback structure
4413 4414 */
4414 4415 RELEASE_MUTEX(&_smhba_AAE_mutex);
4415 4416
4416 4417
4417 4418 /*
4418 4419 * now create a list of vendors (vendor libraryies, NOT ADAPTERS)
4419 4420 * that have successfully registerred
4420 4421 */
4421 4422 vendorhandlelist = NULL;
4422 4423 for (lib_infop = _hbaapi_librarylist;
4423 4424 lib_infop != NULL;
4424 4425 lib_infop = lib_infop->next) {
4425 4426
4426 4427 /* only for HBAAPI V2 */
4427 4428 if (lib_infop->version != SMHBA) {
4428 4429 continue;
4429 4430 } else {
4430 4431 vendor_cnt++;
4431 4432 }
4432 4433
4433 4434 registeredfunc =
4434 4435 lib_infop->ftable.smhbafunctionTable.\
4435 4436 RegisterForAdapterAddEventsHandler;
4436 4437 if (registeredfunc == NULL) {
4437 4438 continue;
4438 4439 }
4439 4440
4440 4441 vcbp = (HBA_VENDORCALLBACK_ELEM *)
4441 4442 calloc(1, sizeof (HBA_VENDORCALLBACK_ELEM));
4442 4443 if (vcbp == NULL) {
4443 4444 freevendorhandlelist(vendorhandlelist);
4444 4445 status = HBA_STATUS_ERROR;
4445 4446 break;
4446 4447 }
4447 4448
4448 4449 registered_cnt++;
4449 4450 status = (registeredfunc)(smhba_adapteraddevents_callback,
4450 4451 pUserData, &vcbp->vendorcbhandle);
4451 4452 if (status == HBA_STATUS_ERROR_NOT_SUPPORTED) {
4452 4453 not_supported_cnt++;
4453 4454 free(vcbp);
4454 4455 continue;
4455 4456 } else if (status != HBA_STATUS_OK) {
4456 4457 status_OK_bar_cnt++;
4457 4458 DEBUG(1,
4458 4459 "SMHBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
4459 4460 lib_infop->LibraryPath, status, 0);
4460 4461 failure = status;
4461 4462 free(vcbp);
4462 4463 continue;
4463 4464 } else {
4464 4465 status_OK_cnt++;
4465 4466 }
4466 4467 vcbp->lib_info = lib_infop;
4467 4468 vcbp->next = vendorhandlelist;
4468 4469 vendorhandlelist = vcbp;
4469 4470 }
4470 4471
4471 4472 if (vendor_cnt == 0) {
4472 4473 /* no SMHBA VSL found. Should be okay?? */
4473 4474 status = HBA_STATUS_ERROR;
4474 4475 } else if (registered_cnt == 0) {
4475 4476 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4476 4477 freevendorhandlelist(vendorhandlelist);
4477 4478 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
4478 4479 } else if (status_OK_cnt == 0 && not_supported_cnt != 0) {
4479 4480 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4480 4481 } else if (status_OK_cnt == 0) {
4481 4482 /*
4482 4483 * At least one vendor library registered this function, but no
4483 4484 * vendor call succeeded
4484 4485 */
4485 4486 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
4486 4487 status = failure;
4487 4488 } else {
4488 4489 /* we have had atleast some success, now finish up */
4489 4490 GRAB_MUTEX(&_smhba_AAE_mutex);
4490 4491 /*
4491 4492 * this seems silly, but what if another thread called
4492 4493 * the callback remove
4493 4494 */
4494 4495 for (cbp = _smhba_adapteraddevents_callback_list;
4495 4496 cbp != NULL; cbp = cbp->next) {
4496 4497 if ((HBA_CALLBACKHANDLE)cbp == *pCallbackHandle) {
4497 4498 /* yup, its still there, hooray */
4498 4499 cbp->vendorhandlelist = vendorhandlelist;
4499 4500 vendorhandlelist = NULL;
4500 4501 break;
4501 4502 }
4502 4503 }
4503 4504 RELEASE_MUTEX(&_smhba_AAE_mutex);
4504 4505 if (vendorhandlelist != NULL) {
4505 4506 /*
4506 4507 * bummer, somebody removed the callback before we finished
4507 4508 * registration, probably will never happen
4508 4509 */
4509 4510 freevendorhandlelist(vendorhandlelist);
4510 4511 DEBUG(1,
4511 4512 "HBA_RegisterForAdapterAddEvents: HBA_RemoveCallback was "
4512 4513 "called for a handle before registration was finished.",
4513 4514 0, 0, 0);
4514 4515 status = HBA_STATUS_ERROR;
4515 4516 } else {
4516 4517 status = HBA_STATUS_OK;
4517 4518 }
4518 4519 }
4519 4520 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4520 4521 }
4521 4522
4522 4523 /* SMHBA Adapter Events (other than add) ******************************** */
4523 4524 static void
4524 4525 smhba_adapterevents_callback(void *data,
4525 4526 HBA_WWN PortWWN,
4526 4527 HBA_UINT32 eventType)
4527 4528 {
4528 4529 HBA_ADAPTERCALLBACK_ELEM *acbp;
4529 4530
4530 4531 DEBUG(3, "AdapterEvent, port:%s, eventType:%d", WWN2STR1(&PortWWN),
4531 4532 eventType, 0);
4532 4533
4533 4534 GRAB_MUTEX(&_hbaapi_AE_mutex);
4534 4535 for (acbp = _smhba_adapterevents_callback_list;
4535 4536 acbp != NULL;
4536 4537 acbp = acbp->next) {
4537 4538 if (data == (void *)acbp) {
4538 4539 (*acbp->callback)(acbp->userdata, PortWWN, eventType);
4539 4540 break;
4540 4541 }
4541 4542 }
4542 4543 RELEASE_MUTEX(&_hbaapi_AE_mutex);
4543 4544 }
4544 4545
4545 4546 HBA_STATUS
4546 4547 SMHBA_RegisterForAdapterEvents(
4547 4548 void (*pCallback) (
4548 4549 void *data,
4549 4550 HBA_WWN PortWWN,
4550 4551 HBA_UINT32 eventType),
4551 4552 void *pUserData,
4552 4553 HBA_HANDLE handle,
4553 4554 HBA_CALLBACKHANDLE *pCallbackHandle) {
4554 4555
4555 4556 HBA_ADAPTERCALLBACK_ELEM *acbp;
4556 4557 SMHBARegisterForAdapterEventsFunc registeredfunc;
4557 4558 HBA_STATUS status;
4558 4559 HBA_LIBRARY_INFO *lib_infop;
4559 4560 HBA_HANDLE vendorHandle;
4560 4561
4561 4562 DEBUG(2, "SMHBA_RegisterForAdapterEvents", 0, 0, 0);
4562 4563
4563 4564 CHECKLIBRARYANDVERSION(SMHBA);
4564 4565
4565 4566 /* we now have the _hbaapi_LL_mutex */
4566 4567
4567 4568 registeredfunc = lib_infop->ftable.smhbafunctionTable.\
4568 4569 RegisterForAdapterEventsHandler;
4569 4570 if (registeredfunc == NULL) {
4570 4571 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4571 4572 }
4572 4573
4573 4574 /*
4574 4575 * that allocated memory is used both as the handle for the
4575 4576 * caller, and as userdata to the vendor call so that on
4576 4577 * callback the specific registration may be recalled
4577 4578 */
4578 4579 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4579 4580 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4580 4581 if (acbp == NULL) {
4581 4582 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4582 4583 }
4583 4584 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4584 4585 acbp->callback = pCallback;
4585 4586 acbp->userdata = pUserData;
4586 4587 acbp->lib_info = lib_infop;
4587 4588
4588 4589 status = (registeredfunc)(smhba_adapterevents_callback,
4589 4590 (void *)acbp,
4590 4591 vendorHandle,
4591 4592 &acbp->vendorcbhandle);
4592 4593 if (status != HBA_STATUS_OK) {
4593 4594 free(acbp);
4594 4595 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4595 4596 }
4596 4597
4597 4598 GRAB_MUTEX(&_smhba_AE_mutex);
4598 4599 acbp->next = _smhba_adapterevents_callback_list;
4599 4600 _hbaapi_adapterevents_callback_list = acbp;
4600 4601
4601 4602 RELEASE_MUTEX(&_smhba_AE_mutex);
4602 4603 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4603 4604 }
4604 4605
4605 4606 /* Adapter Port Events *********************************************** */
4606 4607 static void
4607 4608 smhba_adapterportevents_callback(void *data,
4608 4609 HBA_WWN PortWWN,
4609 4610 HBA_UINT32 eventType,
4610 4611 HBA_UINT32 fabricPortID)
4611 4612 {
4612 4613 HBA_ADAPTERCALLBACK_ELEM *acbp;
4613 4614
4614 4615 DEBUG(3,
4615 4616 "SMHBA_AdapterPortEvent, port:%s, eventType:%d fabricPortID:0X%06x",
4616 4617 WWN2STR1(&PortWWN), eventType, fabricPortID);
4617 4618
4618 4619 GRAB_MUTEX(&_smhba_APE_mutex);
4619 4620
4620 4621 for (acbp = _smhba_adapterportevents_callback_list;
4621 4622 acbp != NULL;
4622 4623 acbp = acbp->next) {
4623 4624 if (data == (void *)acbp) {
4624 4625 (*acbp->callback)(acbp->userdata, PortWWN,
4625 4626 eventType, fabricPortID);
4626 4627 break;
4627 4628 }
4628 4629 }
4629 4630 RELEASE_MUTEX(&_smhba_APE_mutex);
4630 4631 }
4631 4632
4632 4633 HBA_STATUS
4633 4634 SMHBA_RegisterForAdapterPortEvents(
4634 4635 void (*pCallback) (
4635 4636 void *pData,
4636 4637 HBA_WWN PortWWN,
4637 4638 HBA_UINT32 eventType,
4638 4639 HBA_UINT32 fabricPortID),
4639 4640 void *pUserData,
4640 4641 HBA_HANDLE handle,
4641 4642 HBA_WWN portWWN,
4642 4643 HBA_UINT32 specificEventType,
4643 4644 HBA_CALLBACKHANDLE *pCallbackHandle) {
4644 4645
4645 4646 HBA_ADAPTERCALLBACK_ELEM *acbp;
4646 4647 SMHBARegisterForAdapterPortEventsFunc registeredfunc;
4647 4648 HBA_STATUS status;
4648 4649 HBA_LIBRARY_INFO *lib_infop;
4649 4650 HBA_HANDLE vendorHandle;
4650 4651
4651 4652 DEBUG(2, "SMHBA_RegisterForAdapterPortEvents for port: %s",
4652 4653 WWN2STR1(&portWWN), 0, 0);
4653 4654
4654 4655 CHECKLIBRARYANDVERSION(SMHBA);
4655 4656 /* we now have the _hbaapi_LL_mutex */
4656 4657
4657 4658 registeredfunc =
4658 4659 lib_infop->ftable.smhbafunctionTable.\
4659 4660 RegisterForAdapterPortEventsHandler;
4660 4661 if (registeredfunc == NULL) {
4661 4662 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4662 4663 }
4663 4664
4664 4665 /*
4665 4666 * that allocated memory is used both as the handle for the
4666 4667 * caller, and as userdata to the vendor call so that on
4667 4668 * callback the specific registration may be recalled
4668 4669 */
4669 4670 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4670 4671 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4671 4672 if (acbp == NULL) {
4672 4673 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4673 4674 }
4674 4675 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4675 4676 acbp->callback = pCallback;
4676 4677 acbp->userdata = pUserData;
4677 4678 acbp->lib_info = lib_infop;
4678 4679
4679 4680 status = (registeredfunc)(smhba_adapterportevents_callback,
4680 4681 (void *)acbp,
4681 4682 vendorHandle,
4682 4683 portWWN,
4683 4684 specificEventType,
4684 4685 &acbp->vendorcbhandle);
4685 4686 if (status != HBA_STATUS_OK) {
4686 4687 free(acbp);
4687 4688 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4688 4689 }
4689 4690
4690 4691 GRAB_MUTEX(&_smhba_APE_mutex);
4691 4692 acbp->next = _smhba_adapterportevents_callback_list;
4692 4693 _smhba_adapterportevents_callback_list = acbp;
4693 4694
4694 4695 RELEASE_MUTEX(&_smhba_APE_mutex);
4695 4696 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4696 4697 }
4697 4698
4698 4699 /* SMHBA Adapter Port Stat Events ******************************** */
4699 4700 static void
4700 4701 smhba_adapterportstatevents_callback(void *data,
4701 4702 HBA_WWN portWWN,
4702 4703 HBA_UINT32 protocolType,
4703 4704 HBA_UINT32 eventType)
4704 4705 {
4705 4706 HBA_ADAPTERCALLBACK_ELEM *acbp;
4706 4707
4707 4708 DEBUG(3,
4708 4709 "SMBA_AdapterPortStateEvent, port:%s, eventType:%d",
4709 4710 WWN2STR1(&portWWN), eventType, 0);
4710 4711
4711 4712 GRAB_MUTEX(&_smhba_APSE_mutex);
4712 4713 for (acbp = _smhba_adapterportstatevents_callback_list;
4713 4714 acbp != NULL;
4714 4715 acbp = acbp->next) {
4715 4716 if (data == (void *)acbp) {
4716 4717 (*acbp->callback)(acbp->userdata, portWWN,
4717 4718 protocolType, eventType);
4718 4719 return;
4719 4720 }
4720 4721 }
4721 4722 RELEASE_MUTEX(&_smhba_APSE_mutex);
4722 4723 }
4723 4724
4724 4725 HBA_STATUS
4725 4726 SMHBA_RegisterForAdapterPortStatEvents(
4726 4727 void (*pCallback) (
4727 4728 void *pData,
4728 4729 HBA_WWN portWWN,
4729 4730 HBA_UINT32 protocolType,
4730 4731 HBA_UINT32 eventType),
4731 4732 void *pUserData,
4732 4733 HBA_HANDLE handle,
4733 4734 HBA_WWN portWWN,
4734 4735 HBA_UINT32 protocolType,
4735 4736 SMHBA_PROTOCOLSTATISTICS stats,
4736 4737 HBA_UINT32 statType,
4737 4738 HBA_CALLBACKHANDLE *pCallbackHandle) {
4738 4739
4739 4740 HBA_ADAPTERCALLBACK_ELEM *acbp;
4740 4741 SMHBARegisterForAdapterPortStatEventsFunc
4741 4742 registeredfunc;
4742 4743 HBA_STATUS status;
4743 4744 HBA_LIBRARY_INFO *lib_infop;
4744 4745 HBA_HANDLE vendorHandle;
4745 4746
4746 4747 DEBUG(2, "SMHBA_RegisterForAdapterPortStatEvents for port: %s",
4747 4748 WWN2STR1(&portWWN), 0, 0);
4748 4749
4749 4750 CHECKLIBRARYANDVERSION(SMHBA);
4750 4751 /* we now have the _hbaapi_LL_mutex */
4751 4752
4752 4753 registeredfunc =
4753 4754 lib_infop->ftable.smhbafunctionTable.\
4754 4755 RegisterForAdapterPortStatEventsHandler;
4755 4756 if (registeredfunc == NULL) {
4756 4757 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4757 4758 }
4758 4759
4759 4760 /*
4760 4761 * that allocated memory is used both as the handle for the
4761 4762 * caller, and as userdata to the vendor call so that on
4762 4763 * callback the specific registration may be recalled
4763 4764 */
4764 4765 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4765 4766 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4766 4767 if (acbp == NULL) {
4767 4768 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4768 4769 }
4769 4770 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4770 4771 acbp->callback = pCallback;
4771 4772 acbp->userdata = pUserData;
4772 4773 acbp->lib_info = lib_infop;
4773 4774
4774 4775 status = (registeredfunc)(smhba_adapterportstatevents_callback,
4775 4776 (void *)acbp,
4776 4777 vendorHandle,
4777 4778 portWWN,
4778 4779 protocolType,
4779 4780 stats,
4780 4781 statType,
4781 4782 &acbp->vendorcbhandle);
4782 4783 if (status != HBA_STATUS_OK) {
4783 4784 free(acbp);
4784 4785 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4785 4786 }
4786 4787
4787 4788 GRAB_MUTEX(&_smhba_APSE_mutex);
4788 4789 acbp->next = _smhba_adapterportstatevents_callback_list;
4789 4790 _smhba_adapterportstatevents_callback_list = acbp;
4790 4791
4791 4792 RELEASE_MUTEX(&_smhba_APSE_mutex);
4792 4793 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4793 4794 }
4794 4795
4795 4796 /* SMHBA Adapter Port Phy Stat Events ************************************ */
4796 4797 static void
4797 4798 smhba_adapterphystatevents_callback(void *data,
4798 4799 HBA_WWN portWWN,
4799 4800 HBA_UINT32 phyIndex,
4800 4801 HBA_UINT32 eventType)
4801 4802 {
4802 4803 HBA_ADAPTERCALLBACK_ELEM *acbp;
4803 4804
4804 4805 DEBUG(3,
4805 4806 "SMBA_AdapterPortStateEvent, port:%s, eventType:%d",
4806 4807 WWN2STR1(&portWWN), eventType, 0);
4807 4808
4808 4809 GRAB_MUTEX(&_smhba_APHYSE_mutex);
4809 4810 for (acbp = _smhba_adapterphystatevents_callback_list;
4810 4811 acbp != NULL;
4811 4812 acbp = acbp->next) {
4812 4813 if (data == (void *)acbp) {
4813 4814 (*acbp->callback)(acbp->userdata, portWWN, phyIndex, eventType);
4814 4815 return;
4815 4816 }
4816 4817 }
4817 4818 RELEASE_MUTEX(&_smhba_APHYSE_mutex);
4818 4819 }
4819 4820
4820 4821 HBA_STATUS
4821 4822 SMHBA_RegisterForAdapterPhyStatEvents(
4822 4823 void (*pCallback) (
4823 4824 void *pData,
4824 4825 HBA_WWN portWWN,
4825 4826 HBA_UINT32 phyIndex,
4826 4827 HBA_UINT32 eventType),
4827 4828 void *pUserData,
4828 4829 HBA_HANDLE handle,
4829 4830 HBA_WWN portWWN,
4830 4831 HBA_UINT32 phyIndex,
4831 4832 SMHBA_PHYSTATISTICS stats,
4832 4833 HBA_UINT32 statType,
4833 4834 HBA_CALLBACKHANDLE *pCallbackHandle) {
4834 4835
4835 4836 HBA_ADAPTERCALLBACK_ELEM *acbp;
4836 4837 SMHBARegisterForAdapterPhyStatEventsFunc
4837 4838 registeredfunc;
4838 4839 HBA_STATUS status;
4839 4840 HBA_LIBRARY_INFO *lib_infop;
4840 4841 HBA_HANDLE vendorHandle;
4841 4842
4842 4843 DEBUG(2, "SMHBA_RegisterForAdapterPhyStatEvents for port: %s",
4843 4844 WWN2STR1(&portWWN), 0, 0);
4844 4845
4845 4846 CHECKLIBRARYANDVERSION(SMHBA);
4846 4847 /* we now have the _hbaapi_LL_mutex */
4847 4848
4848 4849 registeredfunc =
4849 4850 lib_infop->ftable.smhbafunctionTable.\
4850 4851 RegisterForAdapterPhyStatEventsHandler;
4851 4852 if (registeredfunc == NULL) {
4852 4853 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4853 4854 }
4854 4855
4855 4856 /*
4856 4857 * that allocated memory is used both as the handle for the
4857 4858 * caller, and as userdata to the vendor call so that on
4858 4859 * callback the specific registration may be recalled
4859 4860 */
4860 4861 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4861 4862 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4862 4863 if (acbp == NULL) {
4863 4864 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4864 4865 }
4865 4866 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4866 4867 acbp->callback = pCallback;
4867 4868 acbp->userdata = pUserData;
4868 4869 acbp->lib_info = lib_infop;
4869 4870
4870 4871 status = (registeredfunc)(smhba_adapterphystatevents_callback,
4871 4872 (void *)acbp,
4872 4873 vendorHandle,
4873 4874 portWWN,
4874 4875 phyIndex,
4875 4876 stats,
4876 4877 statType,
4877 4878 &acbp->vendorcbhandle);
4878 4879 if (status != HBA_STATUS_OK) {
4879 4880 free(acbp);
4880 4881 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4881 4882 }
4882 4883
4883 4884 GRAB_MUTEX(&_smhba_APHYSE_mutex);
4884 4885 acbp->next = _smhba_adapterphystatevents_callback_list;
4885 4886 _smhba_adapterphystatevents_callback_list = acbp;
4886 4887
4887 4888 RELEASE_MUTEX(&_smhba_APHYSE_mutex);
4888 4889 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4889 4890 }
4890 4891
4891 4892 /* SMHBA Target Events ********************************************* */
4892 4893 static void
4893 4894 smhba_targetevents_callback(void *data,
4894 4895 HBA_WWN hbaPortWWN,
4895 4896 HBA_WWN discoveredPortWWN,
4896 4897 HBA_WWN domainPortWWN,
4897 4898 HBA_UINT32 eventType)
4898 4899 {
4899 4900 HBA_ADAPTERCALLBACK_ELEM *acbp;
4900 4901
4901 4902 DEBUG(3, "TargetEvent, hbaPort:%s, discoveredPort:%s eventType:%d",
4902 4903 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), eventType);
4903 4904
4904 4905 GRAB_MUTEX(&_smhba_TE_mutex);
4905 4906 for (acbp = _smhba_targetevents_callback_list;
4906 4907 acbp != NULL;
4907 4908 acbp = acbp->next) {
4908 4909 if (data == (void *)acbp) {
4909 4910 (*acbp->callback)(acbp->userdata, hbaPortWWN,
4910 4911 discoveredPortWWN, domainPortWWN, eventType);
4911 4912 break;
4912 4913 }
4913 4914 }
4914 4915 RELEASE_MUTEX(&_smhba_TE_mutex);
4915 4916 }
4916 4917
4917 4918 HBA_STATUS
4918 4919 SMHBA_RegisterForTargetEvents(
4919 4920 void (*pCallback) (
4920 4921 void *pData,
4921 4922 HBA_WWN hbaPortWWN,
4922 4923 HBA_WWN discoveredPortWWN,
4923 4924 HBA_WWN domainPortWWN,
4924 4925 HBA_UINT32 eventType),
4925 4926 void *pUserData,
4926 4927 HBA_HANDLE handle,
4927 4928 HBA_WWN hbaPortWWN,
4928 4929 HBA_WWN discoveredPortWWN,
4929 4930 HBA_WWN domainPortWWN,
4930 4931 HBA_CALLBACKHANDLE *pCallbackHandle,
4931 4932 HBA_UINT32 allTargets) {
4932 4933
4933 4934 HBA_ADAPTERCALLBACK_ELEM *acbp;
4934 4935 SMHBARegisterForTargetEventsFunc
4935 4936 registeredfunc;
4936 4937 HBA_STATUS status;
4937 4938 HBA_LIBRARY_INFO *lib_infop;
4938 4939 HBA_HANDLE vendorHandle;
4939 4940
4940 4941 DEBUG(2, "SMHBA_RegisterForTargetEvents, hbaPort:"
4941 4942 "%s, discoveredPort: %s",
4942 4943 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), 0);
4943 4944
4944 4945 CHECKLIBRARYANDVERSION(SMHBA);
4945 4946 /* we now have the _hbaapi_LL_mutex */
4946 4947
4947 4948 registeredfunc = lib_infop->ftable.smhbafunctionTable.\
4948 4949 RegisterForTargetEventsHandler;
4949 4950
4950 4951 if (registeredfunc == NULL) {
4951 4952 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4952 4953 }
4953 4954
4954 4955 /*
4955 4956 * that allocated memory is used both as the handle for the
4956 4957 * caller, and as userdata to the vendor call so that on
4957 4958 * callback the specific registration may be recalled
4958 4959 */
4959 4960 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4960 4961 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4961 4962 if (acbp == NULL) {
4962 4963 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4963 4964 }
4964 4965 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4965 4966 acbp->callback = pCallback;
4966 4967 acbp->userdata = pUserData;
4967 4968 acbp->lib_info = lib_infop;
4968 4969
4969 4970 status = (registeredfunc)(smhba_targetevents_callback,
4970 4971 (void *)acbp,
4971 4972 vendorHandle,
4972 4973 hbaPortWWN,
4973 4974 discoveredPortWWN,
4974 4975 domainPortWWN,
4975 4976 &acbp->vendorcbhandle,
4976 4977 allTargets);
4977 4978 if (status != HBA_STATUS_OK) {
4978 4979 free(acbp);
4979 4980 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4980 4981 }
4981 4982
4982 4983 GRAB_MUTEX(&_smhba_TE_mutex);
4983 4984 acbp->next = _smhba_targetevents_callback_list;
4984 4985 _smhba_targetevents_callback_list = acbp;
4985 4986
4986 4987 RELEASE_MUTEX(&_smhba_TE_mutex);
4987 4988 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4988 4989 }
|
↓ open down ↓ |
3891 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX