Print this page
3217 cfgadm should spell "adaptors" correctly
Reviewed by: Alexander Eremin <alexander.r.eremin@gmail.com>
Reviewed by: David Hoeppner <0xffea@gmail.com>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Eric Schrock <Eric.Schrock@delphix.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 */
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 1088 #endif /* WIN32 or UNIX */
1089 1089 #ifdef POSIX_THREADS
1090 1090 /*
1091 1091 * The _hbaapi_LL_mutex is already grabbed to proctect the caller of
1092 1092 * HBA_FreeLibrary() during loading.
1093 1093 * The mutexes are already initialized
1094 1094 * with PTHREAD_MUTEX_INITIALIZER. Do we need to init again?
1095 1095 * Keeping the code from HBAAPI source...
1096 1096 */
1097 1097 ret = pthread_mutex_init(&_hbaapi_AL_mutex, NULL);
1098 1098 if (ret == 0) {
1099 1099 ret = pthread_mutex_init(&_hbaapi_AAE_mutex, NULL);
1100 1100 }
1101 1101 if (ret == 0) {
1102 1102 ret = pthread_mutex_init(&_hbaapi_AE_mutex, NULL);
1103 1103 }
1104 1104 if (ret == 0) {
1105 1105 ret = pthread_mutex_init(&_hbaapi_APE_mutex, NULL);
1106 1106 }
1107 1107 if (ret == 0) {
1108 1108 ret = pthread_mutex_init(&_hbaapi_APSE_mutex, NULL);
1109 1109 }
1110 1110 if (ret == 0) {
1111 1111 ret = pthread_mutex_init(&_hbaapi_TE_mutex, NULL);
1112 1112 }
1113 1113 if (ret == 0) {
1114 1114 ret = pthread_mutex_init(&_smhba_AAE_mutex, NULL);
1115 1115 }
1116 1116 if (ret == 0) {
1117 1117 ret = pthread_mutex_init(&_smhba_AE_mutex, NULL);
1118 1118 }
1119 1119 if (ret == 0) {
1120 1120 ret = pthread_mutex_init(&_smhba_APE_mutex, NULL);
1121 1121 }
1122 1122 if (ret == 0) {
1123 1123 ret = pthread_mutex_init(&_smhba_APSE_mutex, NULL);
1124 1124 }
1125 1125 if (ret == 0) {
1126 1126 ret = pthread_mutex_init(&_smhba_TE_mutex, NULL);
1127 1127 }
1128 1128 if (ret == 0) {
1129 1129 ret = pthread_mutex_init(&_hbaapi_LE_mutex, NULL);
1130 1130 }
1131 1131 if (ret != 0) {
1132 1132 perror("pthread_mutex_init - HBA_LoadLibrary");
1133 1133 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1134 1134 return (HBA_STATUS_ERROR);
1135 1135 }
1136 1136 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1137 1137 #elif defined(WIN32)
1138 1138 InitializeCriticalSection(&_hbaapi_LL_mutex);
1139 1139 InitializeCriticalSection(&_hbaapi_AL_mutex);
1140 1140 InitializeCriticalSection(&_hbaapi_AAE_mutex);
1141 1141 InitializeCriticalSection(&_hbaapi_AE_mutex);
1142 1142 InitializeCriticalSection(&_hbaapi_APE_mutex);
1143 1143 InitializeCriticalSection(&_hbaapi_APSE_mutex);
1144 1144 InitializeCriticalSection(&_hbaapi_TE_mutex);
1145 1145 InitializeCriticalSection(&_hbaapi_LE_mutex);
1146 1146 InitializeCriticalSection(&_smhba_AAE_mutex);
1147 1147 InitializeCriticalSection(&_smhba_AE_mutex);
1148 1148 InitializeCriticalSection(&_smhba_APE_mutex);
1149 1149 InitializeCriticalSection(&_smhba_APSE_mutex);
1150 1150 InitializeCriticalSection(&_smhba_TE_mutex);
1151 1151 #endif
1152 1152
1153 1153 return (HBA_STATUS_OK);
1154 1154 }
1155 1155
1156 1156 HBA_STATUS
1157 1157 HBA_FreeLibrary() {
1158 1158 HBAFreeLibraryFunc FreeLibraryFunc;
1159 1159 /* LINTED E_FUNC_SET_NOT_USED */
1160 1160 HBA_STATUS status;
1161 1161 HBA_LIBRARY_INFO *lib_infop;
1162 1162 HBA_LIBRARY_INFO *lib_next;
1163 1163 HBA_ADAPTERCALLBACK_ELEM
1164 1164 ***listp;
1165 1165 HBA_ADAPTER_INFO *adapt_infop;
1166 1166 HBA_ADAPTER_INFO *adapt_next;
1167 1167
1168 1168 GRAB_MUTEX(&_hbaapi_LL_mutex);
1169 1169 if (_hbaapi_librarylist == NULL) {
1170 1170 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1171 1171 return (HBA_STATUS_ERROR_NOT_LOADED);
1172 1172 }
1173 1173
1174 1174 GRAB_MUTEX(&_hbaapi_AL_mutex);
1175 1175
1176 1176 DEBUG(1, "HBA_FreeLibrary()", 0, 0, 0);
1177 1177 for (lib_infop = _hbaapi_librarylist; lib_infop != NULL;
1178 1178 lib_infop = lib_next) {
1179 1179 lib_next = lib_infop->next;
1180 1180 if (lib_infop->status == HBA_LIBRARY_LOADED) {
1181 1181 FreeLibraryFunc = FUNCCOMMON(lib_infop, FreeLibraryHandler);
1182 1182 if (FreeLibraryFunc != NULL) {
1183 1183 /* Free this library */
1184 1184 status = ((FreeLibraryFunc)());
1185 1185 DEBUG(1, "HBA_FreeLibrary() Failed %d", status, 0, 0);
1186 1186 }
1187 1187 #ifdef WIN32
1188 1188 FreeLibrary(lib_infop->hLibrary); /* Unload DLL from memory */
1189 1189 #else
1190 1190 (void) dlclose(lib_infop->hLibrary); /* Unload DLL from memory */
1191 1191 #endif
1192 1192 }
1193 1193 #ifndef WIN32
1194 1194 free(lib_infop->LibraryName);
1195 1195 #endif
1196 1196 free(lib_infop->LibraryPath);
1197 1197 free(lib_infop);
1198 1198
1199 1199 }
1200 1200 _hbaapi_librarylist = NULL;
1201 1201 /*
1202 1202 * OK, now all functions are disabled except for LoadLibrary,
1203 1203 * Hope no other thread calls it before we have returned
1204 1204 */
1205 1205 _hbaapi_total_library_count = 0;
1206 1206
1207 1207 for (adapt_infop = _hbaapi_adapterlist;
1208 1208 adapt_infop != NULL;
1209 1209 adapt_infop = adapt_next) {
1210 1210 adapt_next = adapt_infop->next;
1211 1211 free(adapt_infop->name);
1212 1212 free(adapt_infop);
1213 1213 }
1214 1214 _hbaapi_adapterlist = NULL;
1215 1215 _hbaapi_total_adapter_count = 0;
1216 1216
1217 1217 /*
1218 1218 * Free up the callbacks, this is not the most efficient, but it works
1219 1219 */
1220 1220 while ((volatile HBA_ADAPTERCALLBACK_ELEM *)
1221 1221 _hbaapi_adapteraddevents_callback_list
1222 1222 != NULL) {
1223 1223 (void) local_remove_callback((HBA_CALLBACKHANDLE)
1224 1224 _hbaapi_adapteraddevents_callback_list);
1225 1225 }
1226 1226 while ((volatile HBA_ADAPTERCALLBACK_ELEM *)
1227 1227 _smhba_adapteraddevents_callback_list
1228 1228 != NULL) {
1229 1229 (void) local_remove_callback((HBA_CALLBACKHANDLE)
1230 1230 _smhba_adapteraddevents_callback_list);
1231 1231 }
1232 1232 for (listp = cb_lists_array; *listp != NULL; listp++) {
1233 1233 while ((volatile HBA_ADAPTERCALLBACK_ELEM ***)**listp != NULL) {
1234 1234 (void) local_remove_callback((HBA_CALLBACKHANDLE)**listp);
1235 1235 }
1236 1236 }
1237 1237
1238 1238 RELEASE_MUTEX(&_hbaapi_AL_mutex);
1239 1239 RELEASE_MUTEX(&_hbaapi_LL_mutex);
1240 1240
1241 1241 #ifdef USESYSLOG
1242 1242 closelog();
1243 1243 #endif
1244 1244 #ifdef USELOGFILE
1245 1245 if (_hbaapi_debug_fd != NULL) {
1246 1246 fclose(_hbaapi_debug_fd);
1247 1247 }
1248 1248 _hbaapi_debug_fd = NULL;
1249 1249 #endif
1250 1250 #ifdef POSIX_THREADS
1251 1251 /* this will unlock them as well, but who cares */
1252 1252 (void) pthread_mutex_destroy(&_hbaapi_LE_mutex);
1253 1253 (void) pthread_mutex_destroy(&_hbaapi_TE_mutex);
1254 1254 (void) pthread_mutex_destroy(&_hbaapi_APSE_mutex);
1255 1255 (void) pthread_mutex_destroy(&_hbaapi_APE_mutex);
1256 1256 (void) pthread_mutex_destroy(&_hbaapi_AE_mutex);
1257 1257 (void) pthread_mutex_destroy(&_hbaapi_AAE_mutex);
1258 1258 (void) pthread_mutex_destroy(&_smhba_TE_mutex);
1259 1259 (void) pthread_mutex_destroy(&_smhba_APSE_mutex);
1260 1260 (void) pthread_mutex_destroy(&_smhba_APE_mutex);
1261 1261 (void) pthread_mutex_destroy(&_smhba_AE_mutex);
1262 1262 (void) pthread_mutex_destroy(&_smhba_AAE_mutex);
1263 1263 (void) pthread_mutex_destroy(&_hbaapi_AL_mutex);
1264 1264 (void) pthread_mutex_destroy(&_hbaapi_LL_mutex);
1265 1265 #elif defined(WIN32)
1266 1266 DeleteCriticalSection(&_hbaapi_LL_mutex);
1267 1267 DeleteCriticalSection(&_hbaapi_AL_mutex);
1268 1268 DeleteCriticalSection(&_hbaapi_AAE_mutex);
1269 1269 DeleteCriticalSection(&_hbaapi_AE_mutex);
1270 1270 DeleteCriticalSection(&_hbaapi_APE_mutex);
1271 1271 DeleteCriticalSection(&_hbaapi_APSE_mutex);
1272 1272 DeleteCriticalSection(&_hbaapi_TE_mutex);
1273 1273 DeleteCriticalSection(&_hbaapi_LE_mutex);
1274 1274 DeleteCriticalSection(&_smhba_TE_mutex);
1275 1275 DeleteCriticalSection(&_smhba_APSE_mutex);
1276 1276 DeleteCriticalSection(&_smhba_APE_mutex);
1277 1277 DeleteCriticalSection(&_smhba_AE_mutex);
1278 1278 DeleteCriticalSection(&_smhba_AAE_mutex);
1279 1279 #endif
1280 1280
1281 1281 return (HBA_STATUS_OK);
1282 1282 }
1283 1283
1284 1284 /*
1285 1285 * The API used to use fixed size tables as its primary data structure.
1286 1286 * Indexing from 1 to N identified each adapters. Now the adapters are
1287 1287 * on a linked list. There is a unique "index" foreach each adapter.
1288 1288 * Adapters always keep their index, even if they are removed from the
1289 1289 * hardware. The only time the indexing is reset is on HBA_FreeLibrary
1290 1290 */
1291 1291 HBA_UINT32
1292 1292 HBA_GetNumberOfAdapters()
1293 1293 {
1294 1294 int j = 0;
1295 1295 HBA_LIBRARY_INFO *lib_infop;
1296 1296 HBAGetNumberOfAdaptersFunc GetNumberOfAdaptersFunc;
1297 1297 HBAGetAdapterNameFunc GetAdapterNameFunc;
1298 1298 HBA_BOOLEAN found_name;
1299 1299 HBA_ADAPTER_INFO *adapt_infop;
1300 1300 HBA_STATUS status;
1301 1301
1302 1302 char adaptername[256];
1303 1303 int num_adapters; /* local */
1304 1304
1305 1305 if (_hbaapi_librarylist == NULL) {
1306 1306 return (0);
1307 1307 }
1308 1308 GRAB_MUTEX(&_hbaapi_LL_mutex); /* pay attention to order */
1309 1309 GRAB_MUTEX(&_hbaapi_AL_mutex);
1310 1310
1311 1311 for (lib_infop = _hbaapi_librarylist;
1312 1312 lib_infop != NULL;
1313 1313 lib_infop = lib_infop->next) {
1314 1314
1315 1315 if (lib_infop->status != HBA_LIBRARY_LOADED) {
1316 1316 continue;
1317 1317 }
1318 1318
1319 1319 GetNumberOfAdaptersFunc =
1320 1320 FUNCCOMMON(lib_infop, GetNumberOfAdaptersHandler);
1321 1321 if (GetNumberOfAdaptersFunc == NULL) {
1322 1322 continue;
1323 1323 }
1324 1324 num_adapters = ((GetNumberOfAdaptersFunc)());
1325 1325 #ifndef WIN32
1326 1326 DEBUG(1, "HBAAPI: num_adapters for %s = %d\n",
1327 1327 lib_infop->LibraryName, num_adapters, 0);
1328 1328 #else
1329 1329 DEBUG(1, "HBAAPI: num_adapters for %s = %d\n",
1330 1330 lib_infop->LibraryPath, num_adapters, 0);
1331 1331 #endif
1332 1332
1333 1333 /* Also get the names of all the adapters here and cache */
1334 1334 GetAdapterNameFunc = FUNCCOMMON(lib_infop, GetAdapterNameHandler);
1335 1335 if (GetAdapterNameFunc == NULL) {
1336 1336 continue;
1337 1337 }
1338 1338
1339 1339 for (j = 0; j < num_adapters; j++) {
1340 1340 found_name = 0;
1341 1341 status = (GetAdapterNameFunc)(j, (char *)&adaptername);
1342 1342 if (status == HBA_STATUS_OK) {
1343 1343 for (adapt_infop = _hbaapi_adapterlist;
1344 1344 adapt_infop != NULL;
1345 1345 adapt_infop = adapt_infop->next) {
1346 1346 /*
1347 1347 * check for duplicates, really,
1348 1348 * this may just be a second
1349 1349 * call to this function
1350 1350 * ??? how do we know when a name becomes stale?
1351 1351 */
1352 1352 if (strcmp(adaptername, adapt_infop->name) == 0) {
1353 1353 /* already got this one */
1354 1354 found_name++;
1355 1355 break;
1356 1356 }
1357 1357 }
1358 1358 if (found_name != 0) {
1359 1359 continue;
1360 1360 }
1361 1361 }
1362 1362
1363 1363 adapt_infop = (HBA_ADAPTER_INFO *)
1364 1364 calloc(1, sizeof (HBA_ADAPTER_INFO));
1365 1365 if (adapt_infop == NULL) {
1366 1366 #ifndef WIN32
1367 1367 (void) fprintf(stderr,
1368 1368 "HBA_GetNumberOfAdapters: calloc failed"
1369 1369 " on sizeof:%lu\n",
1370 1370 (unsigned long)(sizeof (HBA_ADAPTER_INFO)));
1371 1371 #endif
1372 1372 RELEASE_MUTEX(&_hbaapi_AL_mutex);
1373 1373 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
1374 1374 _hbaapi_total_adapter_count);
1375 1375 }
1376 1376 if ((adapt_infop->GNstatus = status) == HBA_STATUS_OK) {
1377 1377 adapt_infop->name = strdup(adaptername);
1378 1378 } else {
1379 1379 char dummyname[512];
1380 1380 (void) sprintf(dummyname, "NULLADAPTER-%255s-%03d",
1381 1381 lib_infop->LibraryPath, _hbaapi_total_adapter_count);
1382 1382 dummyname[511] = '\0';
1383 1383 adapt_infop->name = strdup(dummyname);
1384 1384 }
1385 1385 lib_infop->numOfAdapters++;
1386 1386 adapt_infop->library = lib_infop;
1387 1387 adapt_infop->next = _hbaapi_adapterlist;
1388 1388 adapt_infop->index = _hbaapi_total_adapter_count;
1389 1389 _hbaapi_adapterlist = adapt_infop;
1390 1390 _hbaapi_total_adapter_count++;
1391 1391 }
1392 1392 }
1393 1393 RELEASE_MUTEX(&_hbaapi_AL_mutex);
1394 1394 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, _hbaapi_total_adapter_count);
1395 1395 }
↓ open down ↓ |
1395 lines elided |
↑ open up ↑ |
1396 1396
1397 1397 HBA_STATUS
1398 1398 HBA_GetAdapterName(
1399 1399 HBA_UINT32 adapterindex,
1400 1400 char *adaptername)
1401 1401 {
1402 1402 HBA_ADAPTER_INFO *adapt_infop;
1403 1403 HBA_STATUS ret = HBA_STATUS_ERROR_ILLEGAL_INDEX;
1404 1404
1405 1405 if (adaptername == NULL) {
1406 - DEBUG(1, "HBA_GetAdapterName: NULL pointer adatpername",
1406 + DEBUG(1, "HBA_GetAdapterName: NULL pointer adaptername",
1407 1407 0, 0, 0);
1408 1408 return (HBA_STATUS_ERROR_ARG);
1409 1409 }
1410 1410
1411 1411 /*
1412 1412 * The adapter index is from old code, but we have
1413 1413 * to support it. Go down the list looking for
1414 1414 * the adapter
1415 1415 */
1416 1416 ARE_WE_INITED();
1417 1417 GRAB_MUTEX(&_hbaapi_AL_mutex);
1418 1418 *adaptername = '\0';
1419 1419 for (adapt_infop = _hbaapi_adapterlist;
1420 1420 adapt_infop != NULL;
1421 1421 adapt_infop = adapt_infop->next) {
1422 1422
1423 1423 if (adapt_infop->index == adapterindex) {
1424 1424 if (adapt_infop->name != NULL &&
1425 1425 adapt_infop->GNstatus == HBA_STATUS_OK) {
1426 1426 (void) strcpy(adaptername, adapt_infop->name);
1427 1427 } else {
1428 1428 *adaptername = '\0';
1429 1429 }
1430 1430 ret = adapt_infop->GNstatus;
1431 1431 break;
1432 1432 }
1433 1433 }
1434 1434 DEBUG(2, "GetAdapterName for index:%d ->%s",
1435 1435 adapterindex, adaptername, 0);
1436 1436 RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, ret);
1437 1437 }
1438 1438
1439 1439 HBA_HANDLE
1440 1440 HBA_OpenAdapter(char *adaptername)
1441 1441 {
1442 1442 HBA_HANDLE handle;
1443 1443 HBAOpenAdapterFunc OpenAdapterFunc;
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
1444 1444 HBA_ADAPTER_INFO *adapt_infop;
1445 1445 HBA_LIBRARY_INFO *lib_infop;
1446 1446
1447 1447 DEBUG(2, "OpenAdapter: %s", adaptername, 0, 0);
1448 1448
1449 1449 handle = HBA_HANDLE_INVALID;
1450 1450 if (_hbaapi_librarylist == NULL) {
1451 1451 return (handle);
1452 1452 }
1453 1453 if (adaptername == NULL) {
1454 - DEBUG(1, "HBA_OpenAdapter: NULL pointer adatpername",
1454 + DEBUG(1, "HBA_OpenAdapter: NULL pointer adaptername",
1455 1455 0, 0, 0);
1456 1456 return (handle);
1457 1457 }
1458 1458 GRAB_MUTEX(&_hbaapi_AL_mutex);
1459 1459 for (adapt_infop = _hbaapi_adapterlist;
1460 1460 adapt_infop != NULL;
1461 1461 adapt_infop = adapt_infop->next) {
1462 1462 if (strcmp(adaptername, adapt_infop->name) != 0) {
1463 1463 continue;
1464 1464 }
1465 1465 lib_infop = adapt_infop->library;
1466 1466 OpenAdapterFunc = FUNCCOMMON(lib_infop, OpenAdapterHandler);
1467 1467
1468 1468 if (OpenAdapterFunc != NULL) {
1469 1469 /* retrieve the vendor handle */
1470 1470 handle = (OpenAdapterFunc)(adaptername);
1471 1471 if (handle != 0) {
1472 1472 /* or this with the library index to get the common handle */
1473 1473 handle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle);
1474 1474 }
1475 1475 }
1476 1476 break;
1477 1477 }
1478 1478 RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, handle);
1479 1479 }
1480 1480
1481 1481 /*
1482 1482 * Finding an adapter with matching WWN.
1483 1483 */
1484 1484 HBA_STATUS
1485 1485 HBA_OpenAdapterByWWN(HBA_HANDLE *phandle, HBA_WWN nodeWWN) {
1486 1486 HBA_HANDLE handle;
1487 1487 HBA_LIBRARY_INFO *lib_infop;
1488 1488 HBAGetNumberOfAdaptersFunc
1489 1489 GetNumberOfAdaptersFunc;
1490 1490 HBAOpenAdapterByWWNFunc
1491 1491 OpenAdapterFunc;
1492 1492 HBA_STATUS status;
1493 1493
1494 1494 DEBUG(2, "OpenAdapterByWWN: %s", WWN2STR1(&nodeWWN), 0, 0);
1495 1495 ARE_WE_INITED();
1496 1496
1497 1497 *phandle = HBA_HANDLE_INVALID;
1498 1498
1499 1499 GRAB_MUTEX(&_hbaapi_LL_mutex);
1500 1500 for (lib_infop = _hbaapi_librarylist;
1501 1501 lib_infop != NULL;
1502 1502 lib_infop = lib_infop->next) {
1503 1503
1504 1504 status = HBA_STATUS_ERROR_ILLEGAL_WWN;
1505 1505
1506 1506 if (lib_infop->status != HBA_LIBRARY_LOADED) {
1507 1507 continue;
1508 1508 }
1509 1509
1510 1510 /* only for HBAAPIV2 */
1511 1511 if (lib_infop->version != HBAAPIV2) {
1512 1512 continue;
1513 1513 }
1514 1514
1515 1515 GetNumberOfAdaptersFunc =
1516 1516 FUNCCOMMON(lib_infop, GetNumberOfAdaptersHandler);
1517 1517 if (GetNumberOfAdaptersFunc == NULL) {
1518 1518 continue;
1519 1519 }
1520 1520
1521 1521 /* look for new hardware */
1522 1522 (void) ((GetNumberOfAdaptersFunc)());
1523 1523
1524 1524 OpenAdapterFunc =
1525 1525 lib_infop->ftable.functionTable.OpenAdapterByWWNHandler;
1526 1526 if (OpenAdapterFunc == NULL) {
1527 1527 continue;
1528 1528 }
1529 1529 /*
1530 1530 * We do not know if the WWN is known by this vendor,
1531 1531 * just try it
1532 1532 */
1533 1533 if ((status = (OpenAdapterFunc)(&handle, nodeWWN)) != HBA_STATUS_OK) {
1534 1534 continue;
1535 1535 }
1536 1536 /* OK, make a vendor non-specific handle */
1537 1537 *phandle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle);
1538 1538 status = HBA_STATUS_OK;
1539 1539 break;
1540 1540 }
1541 1541 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1542 1542 }
1543 1543
1544 1544 void
1545 1545 HBA_RefreshAdapterConfiguration() {
1546 1546 DEBUG(2, "HBA_RefreshAdapterConfiguration", 0, 0, 0);
1547 1547 (void) HBA_GetNumberOfAdapters();
1548 1548 }
1549 1549
1550 1550 HBA_UINT32
1551 1551 HBA_GetVersion() {
1552 1552 DEBUG(2, "HBA_GetVersion", 0, 0, 0);
1553 1553 return (HBA_LIBVERSION);
1554 1554 }
1555 1555
1556 1556 /*
1557 1557 * This function is VERY OS dependent. Wing it as best you can.
1558 1558 */
1559 1559 HBA_UINT32
1560 1560 HBA_GetWrapperLibraryAttributes(
1561 1561 HBA_LIBRARYATTRIBUTES *attributes)
1562 1562 {
1563 1563
1564 1564 DEBUG(2, "HBA_GetWrapperLibraryAttributes", 0, 0, 0);
1565 1565
1566 1566 if (attributes == NULL) {
1567 1567 DEBUG(1, "HBA_GetWrapperLibraryAttributes:"
1568 1568 "NULL pointer attributes",
1569 1569 0, 0, 0);
1570 1570 return (HBA_STATUS_ERROR_ARG);
1571 1571 }
1572 1572
1573 1573 (void) memset(attributes, 0, sizeof (HBA_LIBRARYATTRIBUTES));
1574 1574
1575 1575 #if defined(SOLARIS)
1576 1576 if ((handle = dlopen("libHBAAPI.so", RTLD_NOW)) != NULL) {
1577 1577 if (dlinfo(handle, RTLD_DI_LINKMAP, &map) >= 0) {
1578 1578 for (mp = map; mp != NULL; mp = mp->l_next) {
1579 1579 if (strlen(map->l_name) < 256) {
1580 1580 (void) strcpy(attributes->LibPath, map->l_name);
1581 1581 }
1582 1582 }
1583 1583 }
1584 1584 }
1585 1585 #elif defined(WIN32)
1586 1586 HMODULE module;
1587 1587
1588 1588 /* No need to do anything with the module handle */
1589 1589 /* It wasn't alloocated so it doesn't need to be freed */
1590 1590 module = GetModuleHandle("HBAAPI");
1591 1591 if (module != NULL) {
1592 1592 if (GetModuleFileName(module, attributes->LibPath,
1593 1593 sizeof (attributes->LibPath)) == 0) {
1594 1594 attributes->LibPath[0] = '\0';
1595 1595 }
1596 1596 }
1597 1597 #endif
1598 1598 #if defined(VENDOR)
1599 1599 (void) strcpy(attributes->VName, VENDOR);
1600 1600 #else
1601 1601 attributes->VName[0] = '\0';
1602 1602 #endif
1603 1603 #if defined(VERSION)
1604 1604 (void) strcpy(attributes->VVersion, VERSION);
1605 1605 #else
1606 1606 attributes->VVersion[0] = '\0';
1607 1607 #endif
1608 1608 #if defined(BUILD_DATE)
1609 1609 #if defined(WIN32)
1610 1610 int matchCount;
1611 1611 matchCount = sscanf(BUILD_DATE, "%u/%u/%u %u:%u:%u",
1612 1612 &attributes->build_date.tm_year,
1613 1613 &attributes->build_date.tm_mon,
1614 1614 &attributes->build_date.tm_mday,
1615 1615 &attributes->build_date.tm_hour,
1616 1616 &attributes->build_date.tm_min,
1617 1617 &attributes->build_date.tm_sec);
1618 1618
1619 1619 if (matchCount != 6) {
1620 1620 memset(&attributes->build_date, 0, sizeof (struct tm));
1621 1621 } else {
1622 1622 attributes->build_date.tm_year -= 1900;
1623 1623 attributes->build_date.tm_isdst = -1;
1624 1624 }
1625 1625 #else
1626 1626 if (strptime(BUILD_DATE,
1627 1627 "%Y/%m/%d %T %Z", &(attributes->build_date)) == NULL) {
1628 1628 (void) memset(&attributes->build_date, 0, sizeof (struct tm));
1629 1629 }
1630 1630 #endif
1631 1631 #else
1632 1632 (void) memset(&attributes->build_date, 0, sizeof (struct tm));
1633 1633 #endif
1634 1634 return (2);
1635 1635 }
1636 1636
1637 1637 /*
1638 1638 * Callback registation and handling
1639 1639 */
1640 1640 HBA_STATUS
1641 1641 HBA_RemoveCallback(HBA_CALLBACKHANDLE cbhandle) {
1642 1642 HBA_STATUS status;
1643 1643
1644 1644 DEBUG(2, "HBA_RemoveCallback", 0, 0, 0);
1645 1645 ARE_WE_INITED();
1646 1646
1647 1647 GRAB_MUTEX(&_hbaapi_LL_mutex);
1648 1648 status = local_remove_callback(cbhandle);
1649 1649 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1650 1650 }
1651 1651
1652 1652 /* Adapter Add Events ************************************************* */
1653 1653 static void
1654 1654 /* LINTED E_FUNC_ARG_UNUSED */
1655 1655 adapteraddevents_callback(void *data, HBA_WWN PortWWN, HBA_UINT32 eventType) {
1656 1656 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
1657 1657
1658 1658 DEBUG(3, "AddAdapterEvent, port: %s", WWN2STR1(&PortWWN), 0, 0);
1659 1659
1660 1660 GRAB_MUTEX(&_hbaapi_AAE_mutex);
1661 1661 for (cbp = _hbaapi_adapteraddevents_callback_list;
1662 1662 cbp != NULL;
1663 1663 cbp = cbp->next) {
1664 1664 (*cbp->callback)(data, PortWWN, HBA_EVENT_ADAPTER_ADD);
1665 1665 }
1666 1666 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1667 1667
1668 1668 }
1669 1669
1670 1670 HBA_STATUS
1671 1671 HBA_RegisterForAdapterAddEvents(
1672 1672 void (*callback)(
1673 1673 void *data,
1674 1674 HBA_WWN PortWWN,
1675 1675 HBA_UINT32 eventType),
1676 1676 void *userData,
1677 1677 HBA_CALLBACKHANDLE *callbackHandle) {
1678 1678
1679 1679 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
1680 1680 HBA_VENDORCALLBACK_ELEM *vcbp;
1681 1681 HBA_VENDORCALLBACK_ELEM *vendorhandlelist;
1682 1682 HBARegisterForAdapterAddEventsFunc registeredfunc;
1683 1683 HBA_STATUS status = HBA_STATUS_OK;
1684 1684 HBA_STATUS failure = HBA_STATUS_OK;
1685 1685 HBA_LIBRARY_INFO *lib_infop;
1686 1686 int registered_cnt = 0;
1687 1687 int vendor_cnt = 0;
1688 1688 int not_supported_cnt = 0;
1689 1689 int status_OK_bar_cnt = 0;
1690 1690 int status_OK_cnt = 0;
1691 1691
1692 1692 DEBUG(2, "HBA_RegisterForAdapterAddEvents", 0, 0, 0);
1693 1693 ARE_WE_INITED();
1694 1694
1695 1695 cbp = (HBA_ALLADAPTERSCALLBACK_ELEM *)
1696 1696 calloc(1, sizeof (HBA_ALLADAPTERSCALLBACK_ELEM));
1697 1697 *callbackHandle = (HBA_CALLBACKHANDLE) cbp;
1698 1698 if (cbp == NULL) {
1699 1699 #ifndef WIN32
1700 1700 (void) fprintf(stderr,
1701 1701 "HBA_RegisterForAdapterAddEvents: calloc failed "
1702 1702 "for %lu bytes\n",
1703 1703 (unsigned long)(sizeof (HBA_ALLADAPTERSCALLBACK_ELEM)));
1704 1704 #endif
1705 1705 return (HBA_STATUS_ERROR);
1706 1706 }
1707 1707
1708 1708 GRAB_MUTEX(&_hbaapi_LL_mutex);
1709 1709 GRAB_MUTEX(&_hbaapi_AAE_mutex);
1710 1710 cbp->callback = callback;
1711 1711 cbp->next = _hbaapi_adapteraddevents_callback_list;
1712 1712 _hbaapi_adapteraddevents_callback_list = cbp;
1713 1713 /*
1714 1714 * Need to release the mutex now incase the vendor function invokes the
1715 1715 * callback. We will grap the mutex later to attach the vendor handle
1716 1716 * list to the callback structure
1717 1717 */
1718 1718 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1719 1719
1720 1720 /*
1721 1721 * now create a list of vendors (vendor libraryies, NOT ADAPTERS)
1722 1722 * that have successfully registerred
1723 1723 */
1724 1724 vendorhandlelist = NULL;
1725 1725 for (lib_infop = _hbaapi_librarylist;
1726 1726 lib_infop != NULL;
1727 1727 lib_infop = lib_infop->next) {
1728 1728
1729 1729 /* only for HBAAPI V2 */
1730 1730 if ((lib_infop->version != HBAAPIV2)) {
1731 1731 continue;
1732 1732 } else {
1733 1733 vendor_cnt++;
1734 1734 }
1735 1735
1736 1736 registeredfunc =
1737 1737 lib_infop->ftable.functionTable.RegisterForAdapterAddEventsHandler;
1738 1738 if (registeredfunc == NULL) {
1739 1739 continue;
1740 1740 }
1741 1741
1742 1742 vcbp = (HBA_VENDORCALLBACK_ELEM *)
1743 1743 calloc(1, sizeof (HBA_VENDORCALLBACK_ELEM));
1744 1744 if (vcbp == NULL) {
1745 1745 #ifndef WIN32
1746 1746 (void) fprintf(stderr,
1747 1747 "HBA_RegisterForAdapterAddEvents: "
1748 1748 "calloc failed for %lu bytes\n",
1749 1749 (unsigned long)(sizeof (HBA_VENDORCALLBACK_ELEM)));
1750 1750 #endif
1751 1751 freevendorhandlelist(vendorhandlelist);
1752 1752 status = HBA_STATUS_ERROR;
1753 1753 break;
1754 1754 }
1755 1755
1756 1756 registered_cnt++;
1757 1757 status = (registeredfunc)(adapteraddevents_callback,
1758 1758 userData, &vcbp->vendorcbhandle);
1759 1759 if (status == HBA_STATUS_ERROR_NOT_SUPPORTED) {
1760 1760 not_supported_cnt++;
1761 1761 free(vcbp);
1762 1762 continue;
1763 1763 } else if (status != HBA_STATUS_OK) {
1764 1764 status_OK_bar_cnt++;
1765 1765 DEBUG(1,
1766 1766 "HBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
1767 1767 lib_infop->LibraryPath, status, 0);
1768 1768 #ifndef WIN32
1769 1769 (void) fprintf(stderr,
1770 1770 "HBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
1771 1771 lib_infop->LibraryPath, status);
1772 1772 #endif
1773 1773 failure = status;
1774 1774 free(vcbp);
1775 1775 continue;
1776 1776 } else {
1777 1777 status_OK_cnt++;
1778 1778 }
1779 1779 vcbp->lib_info = lib_infop;
1780 1780 vcbp->next = vendorhandlelist;
1781 1781 vendorhandlelist = vcbp;
1782 1782 }
1783 1783 if (vendor_cnt == 0) {
1784 1784 /* no HBAAPIV2 is deteced. should be okay? */
1785 1785 status = HBA_STATUS_ERROR;
1786 1786 } else if (registered_cnt == 0) {
1787 1787 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
1788 1788 freevendorhandlelist(vendorhandlelist);
1789 1789 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
1790 1790 } else if (status_OK_cnt == 0 && not_supported_cnt != 0) {
1791 1791 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
1792 1792 } else if (status_OK_cnt == 0) {
1793 1793 /*
1794 1794 * At least one vendor library registered this function, but no
1795 1795 * vendor call succeeded
1796 1796 */
1797 1797 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
1798 1798 status = failure;
1799 1799 } else {
1800 1800 /* we have had atleast some success, now finish up */
1801 1801 GRAB_MUTEX(&_hbaapi_AAE_mutex);
1802 1802 /*
1803 1803 * this seems silly, but what if another thread called
1804 1804 * the callback remove
1805 1805 */
1806 1806 for (cbp = _hbaapi_adapteraddevents_callback_list;
1807 1807 cbp != NULL; cbp = cbp->next) {
1808 1808 if ((HBA_CALLBACKHANDLE)cbp == *callbackHandle) {
1809 1809 /* yup, its still there, hooray */
1810 1810 cbp->vendorhandlelist = vendorhandlelist;
1811 1811 vendorhandlelist = NULL;
1812 1812 break;
1813 1813 }
1814 1814 }
1815 1815 RELEASE_MUTEX(&_hbaapi_AAE_mutex);
1816 1816 if (vendorhandlelist != NULL) {
1817 1817 /*
1818 1818 * bummer, somebody removed the callback before we finished
1819 1819 * registration, probably will never happen
1820 1820 */
1821 1821 freevendorhandlelist(vendorhandlelist);
1822 1822 DEBUG(1,
1823 1823 "HBA_RegisterForAdapterAddEvents: HBA_RemoveCallback was "
1824 1824 "called for a handle before registration was finished.",
1825 1825 0, 0, 0);
1826 1826 status = HBA_STATUS_ERROR;
1827 1827 } else {
1828 1828 status = HBA_STATUS_OK;
1829 1829 }
1830 1830 }
1831 1831 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1832 1832 }
1833 1833
1834 1834 /* Adapter Events (other than add) ************************************** */
1835 1835 static void
1836 1836 adapterevents_callback(void *data,
1837 1837 HBA_WWN PortWWN,
1838 1838 HBA_UINT32 eventType) {
1839 1839 HBA_ADAPTERCALLBACK_ELEM *acbp;
1840 1840
1841 1841 DEBUG(3, "AdapterEvent, port:%s, eventType:%d", WWN2STR1(&PortWWN),
1842 1842 eventType, 0);
1843 1843
1844 1844 GRAB_MUTEX(&_hbaapi_AE_mutex);
1845 1845 for (acbp = _hbaapi_adapterevents_callback_list;
1846 1846 acbp != NULL;
1847 1847 acbp = acbp->next) {
1848 1848 if (data == (void *)acbp) {
1849 1849 (*acbp->callback)(acbp->userdata, PortWWN, eventType);
1850 1850 break;
1851 1851 }
1852 1852 }
1853 1853 RELEASE_MUTEX(&_hbaapi_AE_mutex);
1854 1854 }
1855 1855 HBA_STATUS
1856 1856 HBA_RegisterForAdapterEvents(
1857 1857 void (*callback) (
1858 1858 void *data,
1859 1859 HBA_WWN PortWWN,
1860 1860 HBA_UINT32 eventType),
1861 1861 void *userData,
1862 1862 HBA_HANDLE handle,
1863 1863 HBA_CALLBACKHANDLE *callbackHandle) {
1864 1864
1865 1865 HBA_ADAPTERCALLBACK_ELEM *acbp;
1866 1866 HBARegisterForAdapterEventsFunc registeredfunc;
1867 1867 HBA_STATUS status;
1868 1868 HBA_LIBRARY_INFO *lib_infop;
1869 1869 HBA_HANDLE vendorHandle;
1870 1870
1871 1871 DEBUG(2, "HBA_RegisterForAdapterEvents", 0, 0, 0);
1872 1872
1873 1873 CHECKLIBRARYANDVERSION(HBAAPIV2);
1874 1874
1875 1875 /* we now have the _hbaapi_LL_mutex */
1876 1876
1877 1877 registeredfunc =
1878 1878 lib_infop->ftable.functionTable.RegisterForAdapterEventsHandler;
1879 1879 if (registeredfunc == NULL) {
1880 1880 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1881 1881 }
1882 1882
1883 1883 /*
1884 1884 * that allocated memory is used both as the handle for the
1885 1885 * caller, and as userdata to the vendor call so that on
1886 1886 * callback the specific registration may be recalled
1887 1887 */
1888 1888 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1889 1889 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
1890 1890 if (acbp == NULL) {
1891 1891 #ifndef WIN32
1892 1892 (void) fprintf(stderr,
1893 1893 "HBA_RegisterForAdapterEvents: calloc failed for %lu bytes\n",
1894 1894 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
1895 1895 #endif
1896 1896 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1897 1897 }
1898 1898 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1899 1899 acbp->callback = callback;
1900 1900 acbp->userdata = userData;
1901 1901 acbp->lib_info = lib_infop;
1902 1902
1903 1903 status = (registeredfunc)(adapterevents_callback,
1904 1904 (void *)acbp,
1905 1905 vendorHandle,
1906 1906 &acbp->vendorcbhandle);
1907 1907 if (status != HBA_STATUS_OK) {
1908 1908 free(acbp);
1909 1909 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
1910 1910 }
1911 1911
1912 1912 GRAB_MUTEX(&_hbaapi_AE_mutex);
1913 1913 acbp->next = _hbaapi_adapterevents_callback_list;
1914 1914 _hbaapi_adapterevents_callback_list = acbp;
1915 1915 RELEASE_MUTEX(&_hbaapi_AE_mutex);
1916 1916
1917 1917 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
1918 1918 }
1919 1919
1920 1920 /* Adapter Port Events ************************************************** */
1921 1921 static void
1922 1922 adapterportevents_callback(void *data,
1923 1923 HBA_WWN PortWWN,
1924 1924 HBA_UINT32 eventType,
1925 1925 HBA_UINT32 fabricPortID) {
1926 1926 HBA_ADAPTERCALLBACK_ELEM *acbp;
1927 1927
1928 1928 DEBUG(3, "AdapterPortEvent, port:%s, eventType:%d fabricPortID:0X%06x",
1929 1929 WWN2STR1(&PortWWN), eventType, fabricPortID);
1930 1930
1931 1931 GRAB_MUTEX(&_hbaapi_APE_mutex);
1932 1932
1933 1933 for (acbp = _hbaapi_adapterportevents_callback_list;
1934 1934 acbp != NULL;
1935 1935 acbp = acbp->next) {
1936 1936 if (data == (void *)acbp) {
1937 1937 (*acbp->callback)(acbp->userdata, PortWWN, eventType, fabricPortID);
1938 1938 break;
1939 1939 }
1940 1940 }
1941 1941 RELEASE_MUTEX(&_hbaapi_APE_mutex);
1942 1942 }
1943 1943
1944 1944 HBA_STATUS
1945 1945 HBA_RegisterForAdapterPortEvents(
1946 1946 void (*callback) (
1947 1947 void *data,
1948 1948 HBA_WWN PortWWN,
1949 1949 HBA_UINT32 eventType,
1950 1950 HBA_UINT32 fabricPortID),
1951 1951 void *userData,
1952 1952 HBA_HANDLE handle,
1953 1953 HBA_WWN PortWWN,
1954 1954 HBA_CALLBACKHANDLE *callbackHandle) {
1955 1955
1956 1956 HBA_ADAPTERCALLBACK_ELEM *acbp;
1957 1957 HBARegisterForAdapterPortEventsFunc registeredfunc;
1958 1958 HBA_STATUS status;
1959 1959 HBA_LIBRARY_INFO *lib_infop;
1960 1960 HBA_HANDLE vendorHandle;
1961 1961
1962 1962 DEBUG(2, "HBA_RegisterForAdapterPortEvents for port: %s",
1963 1963 WWN2STR1(&PortWWN), 0, 0);
1964 1964
1965 1965 CHECKLIBRARYANDVERSION(HBAAPIV2);
1966 1966 /* we now have the _hbaapi_LL_mutex */
1967 1967
1968 1968 registeredfunc =
1969 1969 lib_infop->ftable.functionTable.RegisterForAdapterPortEventsHandler;
1970 1970 if (registeredfunc == NULL) {
1971 1971 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
1972 1972 }
1973 1973
1974 1974 /*
1975 1975 * that allocated memory is used both as the handle for the
1976 1976 * caller, and as userdata to the vendor call so that on
1977 1977 * callback the specific registration may be recalled
1978 1978 */
1979 1979 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
1980 1980 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
1981 1981 if (acbp == NULL) {
1982 1982 #ifndef WIN32
1983 1983 (void) fprintf(stderr,
1984 1984 "HBA_RegisterForAdapterPortEvents: "
1985 1985 "calloc failed for %lu bytes\n",
1986 1986 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
1987 1987 #endif
1988 1988 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
1989 1989
1990 1990 }
1991 1991 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
1992 1992 acbp->callback = callback;
1993 1993 acbp->userdata = userData;
1994 1994 acbp->lib_info = lib_infop;
1995 1995
1996 1996 status = (registeredfunc)(adapterportevents_callback,
1997 1997 (void *)acbp,
1998 1998 vendorHandle,
1999 1999 PortWWN,
2000 2000 &acbp->vendorcbhandle);
2001 2001 if (status != HBA_STATUS_OK) {
2002 2002 free(acbp);
2003 2003 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2004 2004 }
2005 2005
2006 2006 GRAB_MUTEX(&_hbaapi_APE_mutex);
2007 2007 acbp->next = _hbaapi_adapterportevents_callback_list;
2008 2008 _hbaapi_adapterportevents_callback_list = acbp;
2009 2009 RELEASE_MUTEX(&_hbaapi_APE_mutex);
2010 2010
2011 2011 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2012 2012 }
2013 2013
2014 2014 /* Adapter State Events ************************************************ */
2015 2015 static void
2016 2016 adapterportstatevents_callback(void *data,
2017 2017 HBA_WWN PortWWN,
2018 2018 HBA_UINT32 eventType) {
2019 2019 HBA_ADAPTERCALLBACK_ELEM *acbp;
2020 2020
2021 2021 DEBUG(3, "AdapterPortStatEvent, port:%s, eventType:%d",
2022 2022 WWN2STR1(&PortWWN),
2023 2023 eventType, 0);
2024 2024
2025 2025 GRAB_MUTEX(&_hbaapi_APSE_mutex);
2026 2026 for (acbp = _hbaapi_adapterportstatevents_callback_list;
2027 2027 acbp != NULL;
2028 2028 acbp = acbp->next) {
2029 2029 if (data == (void *)acbp) {
2030 2030 (*acbp->callback)(acbp->userdata, PortWWN, eventType);
2031 2031 return;
2032 2032 }
2033 2033 }
2034 2034 RELEASE_MUTEX(&_hbaapi_APSE_mutex);
2035 2035 }
2036 2036 HBA_STATUS
2037 2037 HBA_RegisterForAdapterPortStatEvents(
2038 2038 void (*callback) (
2039 2039 void *data,
2040 2040 HBA_WWN PortWWN,
2041 2041 HBA_UINT32 eventType),
2042 2042 void *userData,
2043 2043 HBA_HANDLE handle,
2044 2044 HBA_WWN PortWWN,
2045 2045 HBA_PORTSTATISTICS stats,
2046 2046 HBA_UINT32 statType,
2047 2047 HBA_CALLBACKHANDLE *callbackHandle) {
2048 2048
2049 2049 HBA_ADAPTERCALLBACK_ELEM *acbp;
2050 2050 HBARegisterForAdapterPortStatEventsFunc
2051 2051 registeredfunc;
2052 2052 HBA_STATUS status;
2053 2053 HBA_LIBRARY_INFO *lib_infop;
2054 2054 HBA_HANDLE vendorHandle;
2055 2055
2056 2056 DEBUG(2, "HBA_RegisterForAdapterPortStatEvents for port: %s",
2057 2057 WWN2STR1(&PortWWN), 0, 0);
2058 2058
2059 2059 CHECKLIBRARYANDVERSION(HBAAPIV2);
2060 2060 /* we now have the _hbaapi_LL_mutex */
2061 2061
2062 2062 registeredfunc =
2063 2063 lib_infop->ftable.functionTable.RegisterForAdapterPortStatEventsHandler;
2064 2064 if (registeredfunc == NULL) {
2065 2065 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
2066 2066 }
2067 2067
2068 2068 /*
2069 2069 * that allocated memory is used both as the handle for the
2070 2070 * caller, and as userdata to the vendor call so that on
2071 2071 * callback the specific registration may be recalled
2072 2072 */
2073 2073 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
2074 2074 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
2075 2075 if (acbp == NULL) {
2076 2076 #ifndef WIN32
2077 2077 (void) fprintf(stderr,
2078 2078 "HBA_RegisterForAdapterPortStatEvents: "
2079 2079 "calloc failed for %lu bytes\n",
2080 2080 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
2081 2081 #endif
2082 2082 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
2083 2083 }
2084 2084 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
2085 2085 acbp->callback = callback;
2086 2086 acbp->userdata = userData;
2087 2087 acbp->lib_info = lib_infop;
2088 2088
2089 2089 status = (registeredfunc)(adapterportstatevents_callback,
2090 2090 (void *)acbp,
2091 2091 vendorHandle,
2092 2092 PortWWN,
2093 2093 stats,
2094 2094 statType,
2095 2095 &acbp->vendorcbhandle);
2096 2096 if (status != HBA_STATUS_OK) {
2097 2097 free(acbp);
2098 2098 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2099 2099 }
2100 2100
2101 2101 GRAB_MUTEX(&_hbaapi_APSE_mutex);
2102 2102 acbp->next = _hbaapi_adapterportstatevents_callback_list;
2103 2103 _hbaapi_adapterportstatevents_callback_list = acbp;
2104 2104 RELEASE_MUTEX(&_hbaapi_APSE_mutex);
2105 2105
2106 2106 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2107 2107 }
2108 2108
2109 2109 /* Target Events ******************************************************* */
2110 2110 static void
2111 2111 targetevents_callback(void *data,
2112 2112 HBA_WWN hbaPortWWN,
2113 2113 HBA_WWN discoveredPortWWN,
2114 2114 HBA_UINT32 eventType) {
2115 2115
2116 2116 HBA_ADAPTERCALLBACK_ELEM *acbp;
2117 2117
2118 2118 DEBUG(3, "TargetEvent, hbaPort:%s, discoveredPort:%s eventType:%d",
2119 2119 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), eventType);
2120 2120
2121 2121 GRAB_MUTEX(&_hbaapi_TE_mutex);
2122 2122 for (acbp = _hbaapi_targetevents_callback_list;
2123 2123 acbp != NULL;
2124 2124 acbp = acbp->next) {
2125 2125 if (data == (void *)acbp) {
2126 2126 (*acbp->callback)(acbp->userdata, hbaPortWWN,
2127 2127 discoveredPortWWN, eventType);
2128 2128 break;
2129 2129 }
2130 2130 }
2131 2131 RELEASE_MUTEX(&_hbaapi_TE_mutex);
2132 2132 }
2133 2133
2134 2134 HBA_STATUS
2135 2135 HBA_RegisterForTargetEvents(
2136 2136 void (*callback) (
2137 2137 void *data,
2138 2138 HBA_WWN hbaPortWWN,
2139 2139 HBA_WWN discoveredPortWWN,
2140 2140 HBA_UINT32 eventType),
2141 2141 void *userData,
2142 2142 HBA_HANDLE handle,
2143 2143 HBA_WWN hbaPortWWN,
2144 2144 HBA_WWN discoveredPortWWN,
2145 2145 HBA_CALLBACKHANDLE *callbackHandle,
2146 2146 HBA_UINT32 allTargets) {
2147 2147
2148 2148 HBA_ADAPTERCALLBACK_ELEM
2149 2149 *acbp;
2150 2150 HBARegisterForTargetEventsFunc
2151 2151 registeredfunc;
2152 2152 HBA_STATUS status;
2153 2153 HBA_LIBRARY_INFO *lib_infop;
2154 2154 HBA_HANDLE vendorHandle;
2155 2155
2156 2156 DEBUG(2, "HBA_RegisterForTargetEvents, hbaPort: %s, discoveredPort: %s",
2157 2157 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), 0);
2158 2158
2159 2159 CHECKLIBRARYANDVERSION(HBAAPIV2);
2160 2160 /* we now have the _hbaapi_LL_mutex */
2161 2161
2162 2162 registeredfunc =
2163 2163 lib_infop->ftable.functionTable.RegisterForTargetEventsHandler;
2164 2164 if (registeredfunc == NULL) {
2165 2165 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
2166 2166 }
2167 2167
2168 2168 /*
2169 2169 * that allocated memory is used both as the handle for the
2170 2170 * caller, and as userdata to the vendor call so that on
2171 2171 * callback the specific registration may be recalled
2172 2172 */
2173 2173 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
2174 2174 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
2175 2175 if (acbp == NULL) {
2176 2176 #ifndef WIN32
2177 2177 (void) fprintf(stderr,
2178 2178 "HBA_RegisterForTargetEvents: calloc failed for %lu bytes\n",
2179 2179 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
2180 2180 #endif
2181 2181 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
2182 2182 }
2183 2183 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
2184 2184 acbp->callback = callback;
2185 2185 acbp->userdata = userData;
2186 2186 acbp->lib_info = lib_infop;
2187 2187
2188 2188 status = (registeredfunc)(targetevents_callback,
2189 2189 (void *)acbp,
2190 2190 vendorHandle,
2191 2191 hbaPortWWN,
2192 2192 discoveredPortWWN,
2193 2193 &acbp->vendorcbhandle,
2194 2194 allTargets);
2195 2195 if (status != HBA_STATUS_OK) {
2196 2196 free(acbp);
2197 2197 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2198 2198 }
2199 2199
2200 2200 GRAB_MUTEX(&_hbaapi_TE_mutex);
2201 2201 acbp->next = _hbaapi_targetevents_callback_list;
2202 2202 _hbaapi_targetevents_callback_list = acbp;
2203 2203 RELEASE_MUTEX(&_hbaapi_TE_mutex);
2204 2204
2205 2205 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2206 2206 }
2207 2207
2208 2208 /* Link Events ********************************************************* */
2209 2209 static void
2210 2210 linkevents_callback(void *data,
2211 2211 HBA_WWN adapterWWN,
2212 2212 HBA_UINT32 eventType,
2213 2213 void *pRLIRBuffer,
2214 2214 HBA_UINT32 RLIRBufferSize) {
2215 2215 HBA_ADAPTERCALLBACK_ELEM *acbp;
2216 2216
2217 2217 DEBUG(3, "LinkEvent, hbaWWN:%s, eventType:%d",
2218 2218 WWN2STR1(&adapterWWN), eventType, 0);
2219 2219
2220 2220 GRAB_MUTEX(&_hbaapi_LE_mutex);
2221 2221 for (acbp = _hbaapi_linkevents_callback_list;
2222 2222 acbp != NULL;
2223 2223 acbp = acbp->next) {
2224 2224 if (data == (void *)acbp) {
2225 2225 (*acbp->callback)(acbp->userdata, adapterWWN,
2226 2226 eventType, pRLIRBuffer, RLIRBufferSize);
2227 2227 break;
2228 2228 }
2229 2229 }
2230 2230 RELEASE_MUTEX(&_hbaapi_LE_mutex);
2231 2231 }
2232 2232 HBA_STATUS
2233 2233 HBA_RegisterForLinkEvents(
2234 2234 void (*callback) (
2235 2235 void *data,
2236 2236 HBA_WWN adapterWWN,
2237 2237 HBA_UINT32 eventType,
2238 2238 void *pRLIRBuffer,
2239 2239 HBA_UINT32 RLIRBufferSize),
2240 2240 void *userData,
2241 2241 void *pRLIRBuffer,
2242 2242 HBA_UINT32 RLIRBufferSize,
2243 2243 HBA_HANDLE handle,
2244 2244 HBA_CALLBACKHANDLE *callbackHandle) {
2245 2245
2246 2246 HBA_ADAPTERCALLBACK_ELEM *acbp;
2247 2247 HBARegisterForLinkEventsFunc
2248 2248 registeredfunc;
2249 2249 HBA_STATUS status;
2250 2250 HBA_LIBRARY_INFO *lib_infop;
2251 2251 HBA_HANDLE vendorHandle;
2252 2252
2253 2253 DEBUG(2, "HBA_RegisterForLinkEvents", 0, 0, 0);
2254 2254
2255 2255 CHECKLIBRARY();
2256 2256 /* we now have the _hbaapi_LL_mutex */
2257 2257
2258 2258 registeredfunc = FUNCCOMMON(lib_infop, RegisterForLinkEventsHandler);
2259 2259
2260 2260 if (registeredfunc == NULL) {
2261 2261 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
2262 2262 }
2263 2263
2264 2264 /*
2265 2265 * that allocated memory is used both as the handle for the
2266 2266 * caller, and as userdata to the vendor call so that on
2267 2267 * callback the specific registration may be recalled
2268 2268 */
2269 2269 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
2270 2270 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
2271 2271 if (acbp == NULL) {
2272 2272 #ifndef WIN32
2273 2273 (void) fprintf(stderr,
2274 2274 "HBA_RegisterForLinkEvents: calloc failed for %lu bytes\n",
2275 2275 (unsigned long)(sizeof (HBA_ADAPTERCALLBACK_ELEM)));
2276 2276 #endif
2277 2277 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
2278 2278 }
2279 2279 *callbackHandle = (HBA_CALLBACKHANDLE) acbp;
2280 2280 acbp->callback = callback;
2281 2281 acbp->userdata = userData;
2282 2282 acbp->lib_info = lib_infop;
2283 2283
2284 2284 status = (registeredfunc)(linkevents_callback,
2285 2285 (void *)acbp,
2286 2286 pRLIRBuffer,
2287 2287 RLIRBufferSize,
2288 2288 vendorHandle,
2289 2289 &acbp->vendorcbhandle);
2290 2290 if (status != HBA_STATUS_OK) {
2291 2291 free(acbp);
2292 2292 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2293 2293 }
2294 2294
2295 2295 GRAB_MUTEX(&_hbaapi_LE_mutex);
2296 2296 acbp->next = _hbaapi_linkevents_callback_list;
2297 2297 _hbaapi_linkevents_callback_list = acbp;
2298 2298 RELEASE_MUTEX(&_hbaapi_LE_mutex);
2299 2299
2300 2300 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
2301 2301 }
2302 2302
2303 2303 /*
2304 2304 * All of the functions below are almost passthru functions to the
2305 2305 * vendor specific function
2306 2306 */
2307 2307
2308 2308 void
2309 2309 HBA_CloseAdapter(HBA_HANDLE handle) {
2310 2310 HBA_STATUS status;
2311 2311 HBA_LIBRARY_INFO *lib_infop;
2312 2312 HBA_HANDLE vendorHandle;
2313 2313 HBACloseAdapterFunc CloseAdapterFunc;
2314 2314
2315 2315 DEBUG(2, "HBA_CloseAdapter", 0, 0, 0);
2316 2316
2317 2317 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2318 2318 if (status == HBA_STATUS_OK) {
2319 2319 CloseAdapterFunc = FUNCCOMMON(lib_infop, CloseAdapterHandler);
2320 2320 if (CloseAdapterFunc != NULL) {
2321 2321 ((CloseAdapterFunc)(vendorHandle));
2322 2322 }
2323 2323 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2324 2324 }
2325 2325 }
2326 2326
2327 2327 HBA_STATUS
2328 2328 HBA_GetAdapterAttributes(
2329 2329 HBA_HANDLE handle,
2330 2330 HBA_ADAPTERATTRIBUTES
2331 2331 *hbaattributes)
2332 2332 {
2333 2333 HBA_STATUS status;
2334 2334 HBA_LIBRARY_INFO *lib_infop;
2335 2335 HBA_HANDLE vendorHandle;
2336 2336 HBAGetAdapterAttributesFunc GetAdapterAttributesFunc;
2337 2337
2338 2338 DEBUG(2, "HBA_GetAdapterAttributes", 0, 0, 0);
2339 2339
2340 2340 CHECKLIBRARY();
2341 2341
2342 2342 if (lib_infop->version == SMHBA) {
2343 2343 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2344 2344 }
2345 2345
2346 2346 GetAdapterAttributesFunc =
2347 2347 lib_infop->ftable.functionTable.GetAdapterAttributesHandler;
2348 2348 if (GetAdapterAttributesFunc != NULL) {
2349 2349 status = ((GetAdapterAttributesFunc)(vendorHandle, hbaattributes));
2350 2350 } else {
2351 2351 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2352 2352 }
2353 2353 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2354 2354 }
2355 2355
2356 2356 HBA_STATUS
2357 2357 HBA_GetAdapterPortAttributes(
2358 2358 HBA_HANDLE handle,
2359 2359 HBA_UINT32 portindex,
2360 2360 HBA_PORTATTRIBUTES *portattributes)
2361 2361 {
2362 2362 HBA_STATUS status;
2363 2363 HBA_LIBRARY_INFO *lib_infop;
2364 2364 HBA_HANDLE vendorHandle;
2365 2365 HBAGetAdapterPortAttributesFunc
2366 2366 GetAdapterPortAttributesFunc;
2367 2367
2368 2368 DEBUG(2, "HBA_GetAdapterPortAttributes", 0, 0, 0);
2369 2369
2370 2370 CHECKLIBRARY();
2371 2371 if (lib_infop->version == SMHBA) {
2372 2372 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2373 2373 }
2374 2374
2375 2375 GetAdapterPortAttributesFunc =
2376 2376 lib_infop->ftable.functionTable.GetAdapterPortAttributesHandler;
2377 2377 if (GetAdapterPortAttributesFunc != NULL) {
2378 2378 status = ((GetAdapterPortAttributesFunc)
2379 2379 (vendorHandle, portindex, portattributes));
2380 2380 } else {
2381 2381 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2382 2382 }
2383 2383 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2384 2384 }
2385 2385
2386 2386 HBA_STATUS
2387 2387 HBA_GetPortStatistics(
2388 2388 HBA_HANDLE handle,
2389 2389 HBA_UINT32 portindex,
2390 2390 HBA_PORTSTATISTICS *portstatistics)
2391 2391 {
2392 2392 HBA_STATUS status;
2393 2393 HBA_LIBRARY_INFO *lib_infop;
2394 2394 HBA_HANDLE vendorHandle;
2395 2395 HBAGetPortStatisticsFunc
2396 2396 GetPortStatisticsFunc;
2397 2397
2398 2398 DEBUG(2, "HBA_GetPortStatistics", 0, 0, 0);
2399 2399
2400 2400 CHECKLIBRARY();
2401 2401 if (lib_infop->version == SMHBA) {
2402 2402 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2403 2403 }
2404 2404
2405 2405 GetPortStatisticsFunc =
2406 2406 lib_infop->ftable.functionTable.GetPortStatisticsHandler;
2407 2407 if (GetPortStatisticsFunc != NULL) {
2408 2408 status = ((GetPortStatisticsFunc)
2409 2409 (vendorHandle, portindex, portstatistics));
2410 2410 } else {
2411 2411 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2412 2412 }
2413 2413 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2414 2414 }
2415 2415
2416 2416 HBA_STATUS
2417 2417 HBA_GetDiscoveredPortAttributes(
2418 2418 HBA_HANDLE handle,
2419 2419 HBA_UINT32 portindex,
2420 2420 HBA_UINT32 discoveredportindex,
2421 2421 HBA_PORTATTRIBUTES *portattributes)
2422 2422 {
2423 2423 HBA_STATUS status;
2424 2424 HBA_LIBRARY_INFO *lib_infop;
2425 2425 HBA_HANDLE vendorHandle;
2426 2426 HBAGetDiscoveredPortAttributesFunc
2427 2427 GetDiscoveredPortAttributesFunc;
2428 2428
2429 2429 DEBUG(2, "HBA_GetDiscoveredPortAttributes", 0, 0, 0);
2430 2430
2431 2431 CHECKLIBRARY();
2432 2432 if (lib_infop->version == SMHBA) {
2433 2433 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2434 2434 }
2435 2435
2436 2436 GetDiscoveredPortAttributesFunc =
2437 2437 lib_infop->ftable.functionTable.GetDiscoveredPortAttributesHandler;
2438 2438 if (GetDiscoveredPortAttributesFunc != NULL) {
2439 2439 status = ((GetDiscoveredPortAttributesFunc)
2440 2440 (vendorHandle, portindex, discoveredportindex,
2441 2441 portattributes));
2442 2442 } else {
2443 2443 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2444 2444 }
2445 2445 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2446 2446 }
2447 2447
2448 2448 HBA_STATUS
2449 2449 HBA_GetPortAttributesByWWN(
2450 2450 HBA_HANDLE handle,
2451 2451 HBA_WWN PortWWN,
2452 2452 HBA_PORTATTRIBUTES *portattributes)
2453 2453 {
2454 2454 HBA_STATUS status;
2455 2455 HBA_LIBRARY_INFO *lib_infop;
2456 2456 HBA_HANDLE vendorHandle;
2457 2457 HBAGetPortAttributesByWWNFunc
2458 2458 GetPortAttributesByWWNFunc;
2459 2459
2460 2460 DEBUG(2, "HBA_GetPortAttributesByWWN: %s", WWN2STR1(&PortWWN), 0, 0);
2461 2461
2462 2462 CHECKLIBRARY();
2463 2463 if (lib_infop->version == SMHBA) {
2464 2464 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2465 2465 }
2466 2466
2467 2467 GetPortAttributesByWWNFunc =
2468 2468 lib_infop->ftable.functionTable.GetPortAttributesByWWNHandler;
2469 2469 if (GetPortAttributesByWWNFunc != NULL) {
2470 2470 status = ((GetPortAttributesByWWNFunc)
2471 2471 (vendorHandle, PortWWN, portattributes));
2472 2472 } else {
2473 2473 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2474 2474 }
2475 2475 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2476 2476 }
2477 2477
2478 2478 HBA_STATUS
2479 2479 HBA_SendCTPassThru(
2480 2480 HBA_HANDLE handle,
2481 2481 void *pReqBuffer,
2482 2482 HBA_UINT32 ReqBufferSize,
2483 2483 void *pRspBuffer,
2484 2484 HBA_UINT32 RspBufferSize)
2485 2485 {
2486 2486 HBA_STATUS status;
2487 2487 HBA_LIBRARY_INFO *lib_infop;
2488 2488 HBA_HANDLE vendorHandle;
2489 2489 HBASendCTPassThruFunc
2490 2490 SendCTPassThruFunc;
2491 2491
2492 2492 DEBUG(2, "HBA_SendCTPassThru", 0, 0, 0);
2493 2493
2494 2494 CHECKLIBRARY();
2495 2495 if (lib_infop->version == SMHBA) {
2496 2496 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2497 2497 }
2498 2498
2499 2499 SendCTPassThruFunc =
2500 2500 lib_infop->ftable.functionTable.SendCTPassThruHandler;
2501 2501 if (SendCTPassThruFunc != NULL) {
2502 2502 status = (SendCTPassThruFunc)
2503 2503 (vendorHandle,
2504 2504 pReqBuffer, ReqBufferSize,
2505 2505 pRspBuffer, RspBufferSize);
2506 2506 } else {
2507 2507 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2508 2508 }
2509 2509 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2510 2510 }
2511 2511
2512 2512 HBA_STATUS
2513 2513 HBA_SendCTPassThruV2(
2514 2514 HBA_HANDLE handle,
2515 2515 HBA_WWN hbaPortWWN,
2516 2516 void *pReqBuffer,
2517 2517 HBA_UINT32 ReqBufferSize,
2518 2518 void *pRspBuffer,
2519 2519 HBA_UINT32 *pRspBufferSize)
2520 2520 {
2521 2521 HBA_STATUS status;
2522 2522 HBA_LIBRARY_INFO *lib_infop;
2523 2523 HBA_HANDLE vendorHandle;
2524 2524 HBASendCTPassThruV2Func
2525 2525 registeredfunc;
2526 2526
2527 2527 DEBUG(2, "HBA_SendCTPassThruV2m hbaPortWWN: %s",
2528 2528 WWN2STR1(&hbaPortWWN), 0, 0);
2529 2529
2530 2530 CHECKLIBRARYANDVERSION(HBAAPIV2);
2531 2531 registeredfunc = FUNCCOMMON(lib_infop, SendCTPassThruV2Handler);
2532 2532 if (registeredfunc != NULL) {
2533 2533 status = (registeredfunc)
2534 2534 (vendorHandle, hbaPortWWN,
2535 2535 pReqBuffer, ReqBufferSize,
2536 2536 pRspBuffer, pRspBufferSize);
2537 2537 } else {
2538 2538 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2539 2539 }
2540 2540 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2541 2541 }
2542 2542
2543 2543 HBA_STATUS
2544 2544 HBA_GetEventBuffer(
2545 2545 HBA_HANDLE handle,
2546 2546 PHBA_EVENTINFO EventBuffer,
2547 2547 HBA_UINT32 *EventBufferCount)
2548 2548 {
2549 2549 HBA_STATUS status;
2550 2550 HBA_LIBRARY_INFO *lib_infop;
2551 2551 HBA_HANDLE vendorHandle;
2552 2552 HBAGetEventBufferFunc
2553 2553 GetEventBufferFunc;
2554 2554
2555 2555 DEBUG(2, "HBA_GetEventBuffer", 0, 0, 0);
2556 2556
2557 2557 CHECKLIBRARY();
2558 2558 if (lib_infop->version == SMHBA) {
2559 2559 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2560 2560 }
2561 2561
2562 2562 GetEventBufferFunc =
2563 2563 lib_infop->ftable.functionTable.GetEventBufferHandler;
2564 2564 if (GetEventBufferFunc != NULL) {
2565 2565 status = (GetEventBufferFunc)
2566 2566 (vendorHandle, EventBuffer, EventBufferCount);
2567 2567 } else {
2568 2568 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2569 2569 }
2570 2570 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2571 2571 }
2572 2572
2573 2573 HBA_STATUS
2574 2574 HBA_SetRNIDMgmtInfo(HBA_HANDLE handle, HBA_MGMTINFO Info) {
2575 2575 HBA_STATUS status;
2576 2576 HBA_LIBRARY_INFO *lib_infop;
2577 2577 HBA_HANDLE vendorHandle;
2578 2578 HBASetRNIDMgmtInfoFunc
2579 2579 SetRNIDMgmtInfoFunc;
2580 2580
2581 2581 DEBUG(2, "HBA_SetRNIDMgmtInfo", 0, 0, 0);
2582 2582
2583 2583 CHECKLIBRARY();
2584 2584 SetRNIDMgmtInfoFunc = FUNCCOMMON(lib_infop, SetRNIDMgmtInfoHandler);
2585 2585 if (SetRNIDMgmtInfoFunc != NULL) {
2586 2586 status = (SetRNIDMgmtInfoFunc)(vendorHandle, Info);
2587 2587 } else {
2588 2588 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2589 2589 }
2590 2590 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2591 2591 }
2592 2592
2593 2593 HBA_STATUS
2594 2594 HBA_GetRNIDMgmtInfo(HBA_HANDLE handle, HBA_MGMTINFO *pInfo) {
2595 2595 HBA_STATUS status;
2596 2596 HBA_LIBRARY_INFO *lib_infop;
2597 2597 HBA_HANDLE vendorHandle;
2598 2598 HBAGetRNIDMgmtInfoFunc
2599 2599 GetRNIDMgmtInfoFunc;
2600 2600
2601 2601 DEBUG(2, "HBA_GetRNIDMgmtInfo", 0, 0, 0);
2602 2602
2603 2603 CHECKLIBRARY();
2604 2604 GetRNIDMgmtInfoFunc = FUNCCOMMON(lib_infop, GetRNIDMgmtInfoHandler);
2605 2605 if (GetRNIDMgmtInfoFunc != NULL) {
2606 2606 status = (GetRNIDMgmtInfoFunc)(vendorHandle, pInfo);
2607 2607 } else {
2608 2608 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2609 2609 }
2610 2610 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2611 2611 }
2612 2612
2613 2613 HBA_STATUS
2614 2614 HBA_SendRNID(
2615 2615 HBA_HANDLE handle,
2616 2616 HBA_WWN wwn,
2617 2617 HBA_WWNTYPE wwntype,
2618 2618 void *pRspBuffer,
2619 2619 HBA_UINT32 *pRspBufferSize)
2620 2620 {
2621 2621 HBA_STATUS status;
2622 2622 HBA_LIBRARY_INFO *lib_infop;
2623 2623 HBA_HANDLE vendorHandle;
2624 2624 HBASendRNIDFunc SendRNIDFunc;
2625 2625
2626 2626 DEBUG(2, "HBA_SendRNID for wwn: %s", WWN2STR1(&wwn), 0, 0);
2627 2627
2628 2628 CHECKLIBRARY();
2629 2629 if (lib_infop->version == SMHBA) {
2630 2630 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2631 2631 }
2632 2632
2633 2633 SendRNIDFunc = lib_infop->ftable.functionTable.SendRNIDHandler;
2634 2634 if (SendRNIDFunc != NULL) {
2635 2635 status = ((SendRNIDFunc)(vendorHandle, wwn, wwntype,
2636 2636 pRspBuffer, pRspBufferSize));
2637 2637 } else {
2638 2638 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2639 2639 }
2640 2640 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2641 2641 }
2642 2642
2643 2643 HBA_STATUS
2644 2644 HBA_SendRNIDV2(
2645 2645 HBA_HANDLE handle,
2646 2646 HBA_WWN hbaPortWWN,
2647 2647 HBA_WWN destWWN,
2648 2648 HBA_UINT32 destFCID,
2649 2649 HBA_UINT32 NodeIdDataFormat,
2650 2650 void *pRspBuffer,
2651 2651 HBA_UINT32 *pRspBufferSize)
2652 2652 {
2653 2653 HBA_STATUS status;
2654 2654 HBA_LIBRARY_INFO *lib_infop;
2655 2655 HBA_HANDLE vendorHandle;
2656 2656 HBASendRNIDV2Func registeredfunc;
2657 2657
2658 2658 DEBUG(2, "HBA_SendRNIDV2, hbaPortWWN: %s", WWN2STR1(&hbaPortWWN), 0, 0);
2659 2659
2660 2660 CHECKLIBRARY();
2661 2661 registeredfunc = FUNCCOMMON(lib_infop, SendRNIDV2Handler);
2662 2662 if (registeredfunc != NULL) {
2663 2663 status = (registeredfunc)
2664 2664 (vendorHandle, hbaPortWWN, destWWN, destFCID, NodeIdDataFormat,
2665 2665 pRspBuffer, pRspBufferSize);
2666 2666 } else {
2667 2667 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2668 2668 }
2669 2669 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2670 2670 }
2671 2671
2672 2672 void
2673 2673 HBA_RefreshInformation(HBA_HANDLE handle) {
2674 2674 HBA_STATUS status;
2675 2675 HBA_LIBRARY_INFO *lib_infop;
2676 2676 HBA_HANDLE vendorHandle;
2677 2677 HBARefreshInformationFunc
2678 2678 RefreshInformationFunc;
2679 2679
2680 2680 DEBUG(2, "HBA_RefreshInformation", 0, 0, 0);
2681 2681
2682 2682 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2683 2683 if (status == HBA_STATUS_OK) {
2684 2684 RefreshInformationFunc =
2685 2685 FUNCCOMMON(lib_infop, RefreshInformationHandler);
2686 2686 if (RefreshInformationFunc != NULL) {
2687 2687 ((RefreshInformationFunc)(vendorHandle));
2688 2688 }
2689 2689 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2690 2690 }
2691 2691 }
2692 2692
2693 2693 void
2694 2694 HBA_ResetStatistics(HBA_HANDLE handle, HBA_UINT32 portindex) {
2695 2695 HBA_STATUS status;
2696 2696 HBA_LIBRARY_INFO *lib_infop;
2697 2697 HBA_HANDLE vendorHandle;
2698 2698 HBAResetStatisticsFunc
2699 2699 ResetStatisticsFunc;
2700 2700
2701 2701 DEBUG(2, "HBA_ResetStatistics", 0, 0, 0);
2702 2702
2703 2703 status = HBA_CheckLibrary(handle, &lib_infop, &vendorHandle);
2704 2704 if (status == HBA_STATUS_OK) {
2705 2705 if (lib_infop->version == SMHBA) {
2706 2706 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2707 2707 }
2708 2708
2709 2709 ResetStatisticsFunc =
2710 2710 lib_infop->ftable.functionTable.ResetStatisticsHandler;
2711 2711 if (ResetStatisticsFunc != NULL) {
2712 2712 ((ResetStatisticsFunc)(vendorHandle, portindex));
2713 2713 }
2714 2714 RELEASE_MUTEX(&_hbaapi_LL_mutex);
2715 2715 }
2716 2716 }
2717 2717
2718 2718 HBA_STATUS
2719 2719 HBA_GetFcpTargetMapping(HBA_HANDLE handle, PHBA_FCPTARGETMAPPING mapping) {
2720 2720 HBA_STATUS status;
2721 2721 HBA_LIBRARY_INFO *lib_infop;
2722 2722 HBA_HANDLE vendorHandle;
2723 2723 HBAGetFcpTargetMappingFunc GetFcpTargetMappingFunc;
2724 2724
2725 2725 DEBUG(2, "HBA_GetFcpTargetMapping", 0, 0, 0);
2726 2726
2727 2727 CHECKLIBRARY();
2728 2728 if (lib_infop->version == SMHBA) {
2729 2729 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2730 2730 }
2731 2731
2732 2732 GetFcpTargetMappingFunc =
2733 2733 lib_infop->ftable.functionTable.GetFcpTargetMappingHandler;
2734 2734 if (GetFcpTargetMappingFunc != NULL) {
2735 2735 status = ((GetFcpTargetMappingFunc)(vendorHandle, mapping));
2736 2736 } else {
2737 2737 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2738 2738 }
2739 2739 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2740 2740 }
2741 2741
2742 2742 HBA_STATUS
2743 2743 HBA_GetFcpTargetMappingV2(
2744 2744 HBA_HANDLE handle,
2745 2745 HBA_WWN hbaPortWWN,
2746 2746 HBA_FCPTARGETMAPPINGV2 *pmapping)
2747 2747 {
2748 2748 HBA_STATUS status;
2749 2749 HBA_LIBRARY_INFO *lib_infop;
2750 2750 HBA_HANDLE vendorHandle;
2751 2751 HBAGetFcpTargetMappingV2Func
2752 2752 registeredfunc;
2753 2753
2754 2754 DEBUG(2, "HBA_GetFcpTargetMapping", 0, 0, 0);
2755 2755
2756 2756 CHECKLIBRARYANDVERSION(HBAAPIV2);
2757 2757
2758 2758 registeredfunc =
2759 2759 lib_infop->ftable.functionTable.GetFcpTargetMappingV2Handler;
2760 2760 if (registeredfunc != NULL) {
2761 2761 status = ((registeredfunc)(vendorHandle, hbaPortWWN, pmapping));
2762 2762 } else {
2763 2763 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2764 2764 }
2765 2765 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2766 2766 }
2767 2767
2768 2768 HBA_STATUS
2769 2769 HBA_GetFcpPersistentBinding(HBA_HANDLE handle, PHBA_FCPBINDING binding) {
2770 2770 HBA_STATUS status;
2771 2771 HBA_LIBRARY_INFO *lib_infop;
2772 2772 HBA_HANDLE vendorHandle;
2773 2773 HBAGetFcpPersistentBindingFunc
2774 2774 GetFcpPersistentBindingFunc;
2775 2775
2776 2776 DEBUG(2, "HBA_GetFcpPersistentBinding", 0, 0, 0);
2777 2777
2778 2778 CHECKLIBRARY();
2779 2779 if (lib_infop->version == SMHBA) {
2780 2780 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2781 2781 }
2782 2782
2783 2783 GetFcpPersistentBindingFunc =
2784 2784 lib_infop->ftable.functionTable.GetFcpPersistentBindingHandler;
2785 2785 if (GetFcpPersistentBindingFunc != NULL) {
2786 2786 status = ((GetFcpPersistentBindingFunc)(vendorHandle, binding));
2787 2787 } else {
2788 2788 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2789 2789 }
2790 2790 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2791 2791 }
2792 2792
2793 2793 HBA_STATUS
2794 2794 HBA_ScsiInquiryV2(
2795 2795 HBA_HANDLE handle,
2796 2796 HBA_WWN hbaPortWWN,
2797 2797 HBA_WWN discoveredPortWWN,
2798 2798 HBA_UINT64 fcLUN,
2799 2799 HBA_UINT8 CDB_Byte1,
2800 2800 HBA_UINT8 CDB_Byte2,
2801 2801 void *pRspBuffer,
2802 2802 HBA_UINT32 *pRspBufferSize,
2803 2803 HBA_UINT8 *pScsiStatus,
2804 2804 void *pSenseBuffer,
2805 2805 HBA_UINT32 *pSenseBufferSize)
2806 2806 {
2807 2807 HBA_STATUS status;
2808 2808 HBA_LIBRARY_INFO *lib_infop;
2809 2809 HBA_HANDLE vendorHandle;
2810 2810 HBAScsiInquiryV2Func ScsiInquiryV2Func;
2811 2811
2812 2812 DEBUG(2, "HBA_ScsiInquiryV2 to discoveredPortWWN: %s",
2813 2813 WWN2STR1(&discoveredPortWWN), 0, 0);
2814 2814
2815 2815 CHECKLIBRARYANDVERSION(HBAAPIV2);
2816 2816
2817 2817 ScsiInquiryV2Func =
2818 2818 lib_infop->ftable.functionTable.ScsiInquiryV2Handler;
2819 2819 if (ScsiInquiryV2Func != NULL) {
2820 2820 status = ((ScsiInquiryV2Func)(
2821 2821 vendorHandle, hbaPortWWN, discoveredPortWWN, fcLUN, CDB_Byte1,
2822 2822 CDB_Byte2, pRspBuffer, pRspBufferSize, pScsiStatus,
2823 2823 pSenseBuffer, pSenseBufferSize));
2824 2824 } else {
2825 2825 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2826 2826 }
2827 2827 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2828 2828 }
2829 2829
2830 2830 HBA_STATUS
2831 2831 HBA_SendScsiInquiry(
2832 2832 HBA_HANDLE handle,
2833 2833 HBA_WWN PortWWN,
2834 2834 HBA_UINT64 fcLUN,
2835 2835 HBA_UINT8 EVPD,
2836 2836 HBA_UINT32 PageCode,
2837 2837 void *pRspBuffer,
2838 2838 HBA_UINT32 RspBufferSize,
2839 2839 void *pSenseBuffer,
2840 2840 HBA_UINT32 SenseBufferSize)
2841 2841 {
2842 2842 HBA_STATUS status;
2843 2843 HBA_LIBRARY_INFO *lib_infop;
2844 2844 HBA_HANDLE vendorHandle;
2845 2845 HBASendScsiInquiryFunc SendScsiInquiryFunc;
2846 2846
2847 2847 DEBUG(2, "HBA_SendScsiInquiry to PortWWN: %s",
2848 2848 WWN2STR1(&PortWWN), 0, 0);
2849 2849
2850 2850 CHECKLIBRARY();
2851 2851 if (lib_infop->version == SMHBA) {
2852 2852 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2853 2853 }
2854 2854
2855 2855 SendScsiInquiryFunc =
2856 2856 lib_infop->ftable.functionTable.ScsiInquiryHandler;
2857 2857 if (SendScsiInquiryFunc != NULL) {
2858 2858 status = ((SendScsiInquiryFunc)(
2859 2859 vendorHandle, PortWWN, fcLUN, EVPD, PageCode, pRspBuffer,
2860 2860 RspBufferSize, pSenseBuffer, SenseBufferSize));
2861 2861 } else {
2862 2862 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2863 2863 }
2864 2864 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2865 2865 }
2866 2866
2867 2867 HBA_STATUS
2868 2868 HBA_ScsiReportLUNsV2(
2869 2869 HBA_HANDLE handle,
2870 2870 HBA_WWN hbaPortWWN,
2871 2871 HBA_WWN discoveredPortWWN,
2872 2872 void *pRespBuffer,
2873 2873 HBA_UINT32 *pRespBufferSize,
2874 2874 HBA_UINT8 *pScsiStatus,
2875 2875 void *pSenseBuffer,
2876 2876 HBA_UINT32 *pSenseBufferSize)
2877 2877 {
2878 2878 HBA_STATUS status;
2879 2879 HBA_LIBRARY_INFO *lib_infop;
2880 2880 HBA_HANDLE vendorHandle;
2881 2881 HBAScsiReportLUNsV2Func ScsiReportLUNsV2Func;
2882 2882
2883 2883 DEBUG(2, "HBA_ScsiReportLUNsV2 to discoveredPortWWN: %s",
2884 2884 WWN2STR1(&discoveredPortWWN), 0, 0);
2885 2885
2886 2886 CHECKLIBRARYANDVERSION(HBAAPIV2);
2887 2887
2888 2888 ScsiReportLUNsV2Func =
2889 2889 lib_infop->ftable.functionTable.ScsiReportLUNsV2Handler;
2890 2890 if (ScsiReportLUNsV2Func != NULL) {
2891 2891 status = ((ScsiReportLUNsV2Func)(
2892 2892 vendorHandle, hbaPortWWN, discoveredPortWWN,
2893 2893 pRespBuffer, pRespBufferSize,
2894 2894 pScsiStatus,
2895 2895 pSenseBuffer, pSenseBufferSize));
2896 2896 } else {
2897 2897 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2898 2898 }
2899 2899 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2900 2900 }
2901 2901
2902 2902 HBA_STATUS
2903 2903 HBA_SendReportLUNs(
2904 2904 HBA_HANDLE handle,
2905 2905 HBA_WWN portWWN,
2906 2906 void *pRspBuffer,
2907 2907 HBA_UINT32 RspBufferSize,
2908 2908 void *pSenseBuffer,
2909 2909 HBA_UINT32 SenseBufferSize)
2910 2910 {
2911 2911 HBA_STATUS status;
2912 2912 HBA_LIBRARY_INFO *lib_infop;
2913 2913 HBA_HANDLE vendorHandle;
2914 2914 HBASendReportLUNsFunc SendReportLUNsFunc;
2915 2915
2916 2916 DEBUG(2, "HBA_SendReportLUNs to PortWWN: %s", WWN2STR1(&portWWN), 0, 0);
2917 2917
2918 2918 CHECKLIBRARY();
2919 2919 if (lib_infop->version == SMHBA) {
2920 2920 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2921 2921 }
2922 2922
2923 2923 SendReportLUNsFunc = lib_infop->ftable.functionTable.ReportLUNsHandler;
2924 2924 if (SendReportLUNsFunc != NULL) {
2925 2925 status = ((SendReportLUNsFunc)(
2926 2926 vendorHandle, portWWN, pRspBuffer,
2927 2927 RspBufferSize, pSenseBuffer, SenseBufferSize));
2928 2928 } else {
2929 2929 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2930 2930 }
2931 2931 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2932 2932 }
2933 2933
2934 2934 HBA_STATUS
2935 2935 HBA_ScsiReadCapacityV2(
2936 2936 HBA_HANDLE handle,
2937 2937 HBA_WWN hbaPortWWN,
2938 2938 HBA_WWN discoveredPortWWN,
2939 2939 HBA_UINT64 fcLUN,
2940 2940 void *pRspBuffer,
2941 2941 HBA_UINT32 *pRspBufferSize,
2942 2942 HBA_UINT8 *pScsiStatus,
2943 2943 void *pSenseBuffer,
2944 2944 HBA_UINT32 *SenseBufferSize)
2945 2945 {
2946 2946 HBA_STATUS status;
2947 2947 HBA_LIBRARY_INFO *lib_infop;
2948 2948 HBA_HANDLE vendorHandle;
2949 2949 HBAScsiReadCapacityV2Func ScsiReadCapacityV2Func;
2950 2950
2951 2951 DEBUG(2, "HBA_ScsiReadCapacityV2 to discoveredPortWWN: %s",
2952 2952 WWN2STR1(&discoveredPortWWN), 0, 0);
2953 2953
2954 2954 CHECKLIBRARYANDVERSION(HBAAPIV2);
2955 2955
2956 2956 ScsiReadCapacityV2Func =
2957 2957 lib_infop->ftable.functionTable.ScsiReadCapacityV2Handler;
2958 2958 if (ScsiReadCapacityV2Func != NULL) {
2959 2959 status = ((ScsiReadCapacityV2Func)(
2960 2960 vendorHandle, hbaPortWWN, discoveredPortWWN, fcLUN,
2961 2961 pRspBuffer, pRspBufferSize,
2962 2962 pScsiStatus,
2963 2963 pSenseBuffer, SenseBufferSize));
2964 2964 } else {
2965 2965 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
2966 2966 }
2967 2967 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
2968 2968 }
2969 2969
2970 2970 HBA_STATUS
2971 2971 HBA_SendReadCapacity(
2972 2972 HBA_HANDLE handle,
2973 2973 HBA_WWN portWWN,
2974 2974 HBA_UINT64 fcLUN,
2975 2975 void *pRspBuffer,
2976 2976 HBA_UINT32 RspBufferSize,
2977 2977 void *pSenseBuffer,
2978 2978 HBA_UINT32 SenseBufferSize)
2979 2979 {
2980 2980 HBA_STATUS status;
2981 2981 HBA_LIBRARY_INFO *lib_infop;
2982 2982 HBA_HANDLE vendorHandle;
2983 2983 HBASendReadCapacityFunc SendReadCapacityFunc;
2984 2984
2985 2985 DEBUG(2, "HBA_SendReadCapacity to portWWN: %s",
2986 2986 WWN2STR1(&portWWN), 0, 0);
2987 2987
2988 2988 CHECKLIBRARY();
2989 2989 if (lib_infop->version == SMHBA) {
2990 2990 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INCOMPATIBLE);
2991 2991 }
2992 2992
2993 2993 SendReadCapacityFunc =
2994 2994 lib_infop->ftable.functionTable.ReadCapacityHandler;
2995 2995 if (SendReadCapacityFunc != NULL) {
2996 2996 status = ((SendReadCapacityFunc)
2997 2997 (vendorHandle, portWWN, fcLUN, pRspBuffer,
2998 2998 RspBufferSize, pSenseBuffer, SenseBufferSize));
2999 2999 } else {
3000 3000 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3001 3001 }
3002 3002 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3003 3003 }
3004 3004
3005 3005 HBA_STATUS
3006 3006 HBA_SendRPL(
3007 3007 HBA_HANDLE handle,
3008 3008 HBA_WWN hbaPortWWN,
3009 3009 HBA_WWN agent_wwn,
3010 3010 HBA_UINT32 agent_domain,
3011 3011 HBA_UINT32 portindex,
3012 3012 void *pRspBuffer,
3013 3013 HBA_UINT32 *pRspBufferSize)
3014 3014 {
3015 3015 HBA_STATUS status;
3016 3016 HBA_LIBRARY_INFO *lib_infop;
3017 3017 HBA_HANDLE vendorHandle;
3018 3018 HBASendRPLFunc registeredfunc;
3019 3019
3020 3020 DEBUG(2, "HBA_SendRPL to agent_wwn: %s:%d",
3021 3021 WWN2STR1(&agent_wwn), agent_domain, 0);
3022 3022
3023 3023 CHECKLIBRARY();
3024 3024 registeredfunc = FUNCCOMMON(lib_infop, SendRPLHandler);
3025 3025 if (registeredfunc != NULL) {
3026 3026 status = (registeredfunc)(
3027 3027 vendorHandle, hbaPortWWN, agent_wwn, agent_domain, portindex,
3028 3028 pRspBuffer, pRspBufferSize);
3029 3029 } else {
3030 3030 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3031 3031 }
3032 3032 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3033 3033 }
3034 3034
3035 3035 HBA_STATUS
3036 3036 HBA_SendRPS(
3037 3037 HBA_HANDLE handle,
3038 3038 HBA_WWN hbaPortWWN,
3039 3039 HBA_WWN agent_wwn,
3040 3040 HBA_UINT32 agent_domain,
3041 3041 HBA_WWN object_wwn,
3042 3042 HBA_UINT32 object_port_number,
3043 3043 void *pRspBuffer,
3044 3044 HBA_UINT32 *pRspBufferSize)
3045 3045 {
3046 3046 HBA_STATUS status;
3047 3047 HBA_LIBRARY_INFO *lib_infop;
3048 3048 HBA_HANDLE vendorHandle;
3049 3049 HBASendRPSFunc registeredfunc;
3050 3050
3051 3051 DEBUG(2, "HBA_SendRPS to agent_wwn: %s:%d",
3052 3052 WWN2STR1(&agent_wwn), agent_domain, 0);
3053 3053
3054 3054 CHECKLIBRARY();
3055 3055 registeredfunc = FUNCCOMMON(lib_infop, SendRPSHandler);
3056 3056 if (registeredfunc != NULL) {
3057 3057 status = (registeredfunc)(
3058 3058 vendorHandle, hbaPortWWN, agent_wwn, agent_domain,
3059 3059 object_wwn, object_port_number,
3060 3060 pRspBuffer, pRspBufferSize);
3061 3061 } else {
3062 3062 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3063 3063 }
3064 3064 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3065 3065 }
3066 3066
3067 3067 HBA_STATUS
3068 3068 HBA_SendSRL(
3069 3069 HBA_HANDLE handle,
3070 3070 HBA_WWN hbaPortWWN,
3071 3071 HBA_WWN wwn,
3072 3072 HBA_UINT32 domain,
3073 3073 void *pRspBuffer,
3074 3074 HBA_UINT32 *pRspBufferSize)
3075 3075 {
3076 3076 HBA_STATUS status;
3077 3077 HBA_LIBRARY_INFO *lib_infop;
3078 3078 HBA_HANDLE vendorHandle;
3079 3079 HBASendSRLFunc registeredfunc;
3080 3080
3081 3081 DEBUG(2, "HBA_SendSRL to wwn:%s domain:%d", WWN2STR1(&wwn), domain, 0);
3082 3082
3083 3083 CHECKLIBRARY();
3084 3084 registeredfunc = FUNCCOMMON(lib_infop, SendSRLHandler);
3085 3085 if (registeredfunc != NULL) {
3086 3086 status = (registeredfunc)(
3087 3087 vendorHandle, hbaPortWWN, wwn, domain,
3088 3088 pRspBuffer, pRspBufferSize);
3089 3089 } else {
3090 3090 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3091 3091 }
3092 3092 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3093 3093 }
3094 3094 HBA_STATUS
3095 3095 HBA_SendRLS(
3096 3096 HBA_HANDLE handle,
3097 3097 HBA_WWN hbaPortWWN,
3098 3098 HBA_WWN destWWN,
3099 3099 void *pRspBuffer,
3100 3100 HBA_UINT32 *pRspBufferSize)
3101 3101 {
3102 3102 HBA_STATUS status;
3103 3103 HBA_LIBRARY_INFO *lib_infop;
3104 3104 HBA_HANDLE vendorHandle;
3105 3105 HBASendRLSFunc registeredfunc;
3106 3106
3107 3107 DEBUG(2, "HBA_SendRLS dest_wwn: %s",
3108 3108 WWN2STR1(&destWWN), 0, 0);
3109 3109
3110 3110 CHECKLIBRARY();
3111 3111 registeredfunc = FUNCCOMMON(lib_infop, SendRLSHandler);
3112 3112 if (registeredfunc != NULL) {
3113 3113 status = (registeredfunc)(
3114 3114 vendorHandle, hbaPortWWN, destWWN,
3115 3115 pRspBuffer, pRspBufferSize);
3116 3116 } else {
3117 3117 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3118 3118 }
3119 3119 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3120 3120 }
3121 3121
3122 3122 HBA_STATUS
3123 3123 HBA_SendLIRR(
3124 3124 HBA_HANDLE handle,
3125 3125 HBA_WWN sourceWWN,
3126 3126 HBA_WWN destWWN,
3127 3127 HBA_UINT8 function,
3128 3128 HBA_UINT8 type,
3129 3129 void *pRspBuffer,
3130 3130 HBA_UINT32 *pRspBufferSize)
3131 3131 {
3132 3132 HBA_STATUS status;
3133 3133 HBA_LIBRARY_INFO *lib_infop;
3134 3134 HBA_HANDLE vendorHandle;
3135 3135 HBASendLIRRFunc registeredfunc;
3136 3136
3137 3137 DEBUG(2, "HBA_SendLIRR destWWN:%s", WWN2STR1(&destWWN), 0, 0);
3138 3138
3139 3139 CHECKLIBRARY();
3140 3140 registeredfunc = FUNCCOMMON(lib_infop, SendLIRRHandler);
3141 3141 if (registeredfunc != NULL) {
3142 3142 status = (registeredfunc)(
3143 3143 vendorHandle, sourceWWN, destWWN, function, type,
3144 3144 pRspBuffer, pRspBufferSize);
3145 3145 } else {
3146 3146 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3147 3147 }
3148 3148 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3149 3149 }
3150 3150
3151 3151 HBA_STATUS
3152 3152 HBA_GetBindingCapability(
3153 3153 HBA_HANDLE handle,
3154 3154 HBA_WWN hbaPortWWN,
3155 3155 HBA_BIND_CAPABILITY *pcapability)
3156 3156 {
3157 3157 HBA_STATUS status;
3158 3158 HBA_LIBRARY_INFO *lib_infop;
3159 3159 HBA_HANDLE vendorHandle;
3160 3160 HBAGetBindingCapabilityFunc
3161 3161 registeredfunc;
3162 3162
3163 3163 DEBUG(2, "HBA_GetBindingCapability", 0, 0, 0);
3164 3164
3165 3165 CHECKLIBRARYANDVERSION(HBAAPIV2);
3166 3166
3167 3167 registeredfunc =
3168 3168 lib_infop->ftable.functionTable.GetBindingCapabilityHandler;
3169 3169 if (registeredfunc != NULL) {
3170 3170 status = (registeredfunc)(vendorHandle, hbaPortWWN, pcapability);
3171 3171 } else {
3172 3172 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3173 3173 }
3174 3174 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3175 3175 }
3176 3176
3177 3177 HBA_STATUS
3178 3178 HBA_GetBindingSupport(
3179 3179 HBA_HANDLE handle,
3180 3180 HBA_WWN hbaPortWWN,
3181 3181 HBA_BIND_CAPABILITY *pcapability)
3182 3182 {
3183 3183 HBA_STATUS status;
3184 3184 HBA_LIBRARY_INFO *lib_infop;
3185 3185 HBA_HANDLE vendorHandle;
3186 3186 HBAGetBindingSupportFunc
3187 3187 registeredfunc;
3188 3188
3189 3189 DEBUG(2, "HBA_GetBindingSupport", 0, 0, 0);
3190 3190
3191 3191 CHECKLIBRARYANDVERSION(HBAAPIV2);
3192 3192
3193 3193 registeredfunc =
3194 3194 lib_infop->ftable.functionTable.GetBindingSupportHandler;
3195 3195 if (registeredfunc != NULL) {
3196 3196 status = (registeredfunc)(vendorHandle, hbaPortWWN, pcapability);
3197 3197 } else {
3198 3198 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3199 3199 }
3200 3200 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3201 3201 }
3202 3202
3203 3203 HBA_STATUS
3204 3204 HBA_SetBindingSupport(
3205 3205 HBA_HANDLE handle,
3206 3206 HBA_WWN hbaPortWWN,
3207 3207 HBA_BIND_CAPABILITY capability)
3208 3208 {
3209 3209 HBA_STATUS status;
3210 3210 HBA_LIBRARY_INFO *lib_infop;
3211 3211 HBA_HANDLE vendorHandle;
3212 3212 HBASetBindingSupportFunc
3213 3213 registeredfunc;
3214 3214
3215 3215 DEBUG(2, "HBA_SetBindingSupport", 0, 0, 0);
3216 3216
3217 3217 CHECKLIBRARYANDVERSION(HBAAPIV2);
3218 3218
3219 3219 registeredfunc =
3220 3220 lib_infop->ftable.functionTable.SetBindingSupportHandler;
3221 3221 if (registeredfunc != NULL) {
3222 3222 status = (registeredfunc)(vendorHandle, hbaPortWWN, capability);
3223 3223 } else {
3224 3224 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3225 3225 }
3226 3226 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3227 3227 }
3228 3228
3229 3229 HBA_STATUS
3230 3230 HBA_SetPersistentBindingV2(
3231 3231 HBA_HANDLE handle,
3232 3232 HBA_WWN hbaPortWWN,
3233 3233 const HBA_FCPBINDING2 *pbinding)
3234 3234 {
3235 3235 HBA_STATUS status;
3236 3236 HBA_LIBRARY_INFO *lib_infop;
3237 3237 HBA_HANDLE vendorHandle;
3238 3238 HBASetPersistentBindingV2Func
3239 3239 registeredfunc;
3240 3240
3241 3241 DEBUG(2, "HBA_SetPersistentBindingV2 port: %s",
3242 3242 WWN2STR1(&hbaPortWWN), 0, 0);
3243 3243
3244 3244 CHECKLIBRARYANDVERSION(HBAAPIV2);
3245 3245
3246 3246 registeredfunc =
3247 3247 lib_infop->ftable.functionTable.SetPersistentBindingV2Handler;
3248 3248 if (registeredfunc != NULL) {
3249 3249 status = (registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
3250 3250 } else {
3251 3251 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3252 3252 }
3253 3253 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3254 3254 }
3255 3255
3256 3256 HBA_STATUS
3257 3257 HBA_GetPersistentBindingV2(
3258 3258 HBA_HANDLE handle,
3259 3259 HBA_WWN hbaPortWWN,
3260 3260 HBA_FCPBINDING2 *pbinding)
3261 3261 {
3262 3262 HBA_STATUS status;
3263 3263 HBA_LIBRARY_INFO *lib_infop;
3264 3264 HBA_HANDLE vendorHandle;
3265 3265 HBAGetPersistentBindingV2Func
3266 3266 registeredfunc;
3267 3267
3268 3268 DEBUG(2, "HBA_GetPersistentBindingV2 port: %s",
3269 3269 WWN2STR1(&hbaPortWWN), 0, 0);
3270 3270
3271 3271 CHECKLIBRARYANDVERSION(HBAAPIV2);
3272 3272
3273 3273 registeredfunc =
3274 3274 lib_infop->ftable.functionTable.GetPersistentBindingV2Handler;
3275 3275 if (registeredfunc != NULL) {
3276 3276 status = (registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
3277 3277 } else {
3278 3278 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3279 3279 }
3280 3280 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3281 3281 }
3282 3282
3283 3283 HBA_STATUS
3284 3284 HBA_RemovePersistentBinding(
3285 3285 HBA_HANDLE handle,
3286 3286 HBA_WWN hbaPortWWN,
3287 3287 const HBA_FCPBINDING2
3288 3288 *pbinding)
3289 3289 {
3290 3290 HBA_STATUS status;
3291 3291 HBA_LIBRARY_INFO *lib_infop;
3292 3292 HBA_HANDLE vendorHandle;
3293 3293 HBARemovePersistentBindingFunc
3294 3294 registeredfunc;
3295 3295
3296 3296 DEBUG(2, "HBA_RemovePersistentBinding", 0, 0, 0);
3297 3297
3298 3298 CHECKLIBRARYANDVERSION(HBAAPIV2);
3299 3299
3300 3300 registeredfunc =
3301 3301 lib_infop->ftable.functionTable.RemovePersistentBindingHandler;
3302 3302 if (registeredfunc != NULL) {
3303 3303 status = (registeredfunc)(vendorHandle, hbaPortWWN, pbinding);
3304 3304 } else {
3305 3305 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3306 3306 }
3307 3307 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3308 3308 }
3309 3309
3310 3310 HBA_STATUS
3311 3311 HBA_RemoveAllPersistentBindings(
3312 3312 HBA_HANDLE handle,
3313 3313 HBA_WWN hbaPortWWN)
3314 3314 {
3315 3315 HBA_STATUS status;
3316 3316 HBA_LIBRARY_INFO *lib_infop;
3317 3317 HBA_HANDLE vendorHandle;
3318 3318 HBARemoveAllPersistentBindingsFunc
3319 3319 registeredfunc;
3320 3320
3321 3321 DEBUG(2, "HBA_RemoveAllPersistentBindings", 0, 0, 0);
3322 3322
3323 3323 CHECKLIBRARYANDVERSION(HBAAPIV2);
3324 3324
3325 3325 registeredfunc =
3326 3326 lib_infop->ftable.functionTable.RemoveAllPersistentBindingsHandler;
3327 3327 if (registeredfunc != NULL) {
3328 3328 status = (registeredfunc)(vendorHandle, hbaPortWWN);
3329 3329 } else {
3330 3330 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3331 3331 }
3332 3332 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3333 3333 }
3334 3334
3335 3335 HBA_STATUS
3336 3336 HBA_GetFC4Statistics(
3337 3337 HBA_HANDLE handle,
3338 3338 HBA_WWN portWWN,
3339 3339 HBA_UINT8 FC4type,
3340 3340 HBA_FC4STATISTICS *pstatistics)
3341 3341 {
3342 3342 HBA_STATUS status;
3343 3343 HBA_LIBRARY_INFO *lib_infop;
3344 3344 HBA_HANDLE vendorHandle;
3345 3345 HBAGetFC4StatisticsFunc
3346 3346 registeredfunc;
3347 3347
3348 3348 DEBUG(2, "HBA_GetFC4Statistics port: %s", WWN2STR1(&portWWN), 0, 0);
3349 3349
3350 3350 CHECKLIBRARYANDVERSION(HBAAPIV2);
3351 3351
3352 3352 registeredfunc =
3353 3353 lib_infop->ftable.functionTable.GetFC4StatisticsHandler;
3354 3354 if (registeredfunc != NULL) {
3355 3355 status = (registeredfunc)
3356 3356 (vendorHandle, portWWN, FC4type, pstatistics);
3357 3357 } else {
3358 3358 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3359 3359 }
3360 3360 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3361 3361 }
3362 3362
3363 3363 HBA_STATUS
3364 3364 HBA_GetFCPStatistics(
3365 3365 HBA_HANDLE handle,
3366 3366 const HBA_SCSIID *lunit,
3367 3367 HBA_FC4STATISTICS *pstatistics)
3368 3368 {
3369 3369 HBA_STATUS status;
3370 3370 HBA_LIBRARY_INFO *lib_infop;
3371 3371 HBA_HANDLE vendorHandle;
3372 3372 HBAGetFCPStatisticsFunc
3373 3373 registeredfunc;
3374 3374
3375 3375 DEBUG(2, "HBA_GetFCPStatistics", 0, 0, 0);
3376 3376
3377 3377 CHECKLIBRARYANDVERSION(HBAAPIV2);
3378 3378
3379 3379 registeredfunc =
3380 3380 lib_infop->ftable.functionTable.GetFCPStatisticsHandler;
3381 3381 if (registeredfunc != NULL) {
3382 3382 status = (registeredfunc)(vendorHandle, lunit, pstatistics);
3383 3383 } else {
3384 3384 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3385 3385 }
3386 3386 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3387 3387 }
3388 3388
3389 3389 HBA_UINT32
3390 3390 HBA_GetVendorLibraryAttributes(
3391 3391 HBA_UINT32 adapter_index,
3392 3392 HBA_LIBRARYATTRIBUTES *attributes)
3393 3393 {
3394 3394 HBA_ADAPTER_INFO *adapt_infop;
3395 3395 HBAGetVendorLibraryAttributesFunc
3396 3396 registeredfunc;
3397 3397 HBA_UINT32 ret = 0;
3398 3398
3399 3399 DEBUG(2, "HBA_GetVendorLibraryAttributes adapterindex:%d",
3400 3400 adapter_index, 0, 0);
3401 3401 if (_hbaapi_librarylist == NULL) {
3402 3402 DEBUG(1, "HBAAPI not loaded yet.", 0, 0, 0);
3403 3403 return (0);
3404 3404 }
3405 3405
3406 3406 if (attributes == NULL) {
3407 3407 DEBUG(1,
3408 3408 "HBA_GetVendorLibraryAttributes: NULL pointer attributes",
3409 3409 0, 0, 0);
3410 3410 return (HBA_STATUS_ERROR_ARG);
3411 3411 }
3412 3412
3413 3413 (void) memset(attributes, 0, sizeof (HBA_LIBRARYATTRIBUTES));
3414 3414
3415 3415 GRAB_MUTEX(&_hbaapi_LL_mutex);
3416 3416 GRAB_MUTEX(&_hbaapi_AL_mutex);
3417 3417 for (adapt_infop = _hbaapi_adapterlist;
3418 3418 adapt_infop != NULL;
3419 3419 adapt_infop = adapt_infop->next) {
3420 3420
3421 3421 if (adapt_infop->index == adapter_index) {
3422 3422
3423 3423 if (adapt_infop->library->version == SMHBA) {
3424 3424 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3425 3425 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
3426 3426 HBA_STATUS_ERROR_INCOMPATIBLE);
3427 3427 }
3428 3428
3429 3429 registeredfunc = adapt_infop->library->
3430 3430 ftable.functionTable.GetVendorLibraryAttributesHandler;
3431 3431 if (registeredfunc != NULL) {
3432 3432 ret = (registeredfunc)(attributes);
3433 3433 } else {
3434 3434 /* Version 1 libary? */
3435 3435 HBAGetVersionFunc GetVersionFunc;
3436 3436 GetVersionFunc = adapt_infop->library->
3437 3437 ftable.functionTable.GetVersionHandler;
3438 3438 if (GetVersionFunc != NULL) {
3439 3439 ret = ((GetVersionFunc)());
3440 3440 }
3441 3441 #ifdef NOTDEF
3442 3442 else {
3443 3443 /* This should not happen, dont think its going to */
3444 3444 }
3445 3445 #endif
3446 3446 }
3447 3447 if (attributes->LibPath[0] == '\0') {
3448 3448 if (strlen(adapt_infop->library->LibraryPath) < 256) {
3449 3449 (void) strcpy(attributes->LibPath,
3450 3450 adapt_infop->library->LibraryPath);
3451 3451 }
3452 3452 }
3453 3453 break;
3454 3454 }
3455 3455 }
3456 3456 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3457 3457 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, ret);
3458 3458 }
3459 3459
3460 3460
3461 3461 /*
3462 3462 * This function returns SM-HBA version that the warpper library implemented.
3463 3463 */
3464 3464 HBA_UINT32
3465 3465 SMHBA_GetVersion() {
3466 3466 DEBUG(2, "SMHBA_GetVersion", 0, 0, 0);
3467 3467 return (SMHBA_LIBVERSION);
3468 3468 }
3469 3469
3470 3470 /*
3471 3471 * This function returns the attributes for the warpper library.
3472 3472 */
3473 3473 HBA_UINT32
3474 3474 SMHBA_GetWrapperLibraryAttributes(
3475 3475 SMHBA_LIBRARYATTRIBUTES *attributes)
3476 3476 {
3477 3477
3478 3478 struct timeval tv;
3479 3479 struct tm tp;
3480 3480
3481 3481 DEBUG(2, "SMHBA_GetWrapperLibraryAttributes", 0, 0, 0);
3482 3482
3483 3483 if (attributes == NULL) {
3484 3484 DEBUG(1, "SMHBA_GetWrapperLibraryAttributes: "
3485 3485 "NULL pointer attributes",
3486 3486 0, 0, 0);
3487 3487 return (HBA_STATUS_ERROR_ARG);
3488 3488 }
3489 3489
3490 3490 (void) memset(attributes, 0, sizeof (SMHBA_LIBRARYATTRIBUTES));
3491 3491
3492 3492 #if defined(SOLARIS)
3493 3493 if ((handle = dlopen("libSMHBAAPI.so", RTLD_NOW)) != NULL) {
3494 3494 if (dlinfo(handle, RTLD_DI_LINKMAP, &map) >= 0) {
3495 3495 for (mp = map; mp != NULL; mp = mp->l_next) {
3496 3496 if (strlen(map->l_name) < 256) {
3497 3497 (void) strcpy(attributes->LibPath, map->l_name);
3498 3498 }
3499 3499 }
3500 3500 }
3501 3501 }
3502 3502
3503 3503 #endif
3504 3504
3505 3505 #if defined(VENDOR)
3506 3506 (void) strcpy(attributes->VName, VENDOR);
3507 3507 #else
3508 3508 attributes->VName[0] = '\0';
3509 3509 #endif
3510 3510 #if defined(VERSION)
3511 3511 (void) strcpy(attributes->VVersion, VERSION);
3512 3512 #else
3513 3513 attributes->VVersion[0] = '\0';
3514 3514 #endif
3515 3515
3516 3516 if (gettimeofday(&tv, (void *)0) == 0) {
3517 3517 if (localtime_r(&tv.tv_sec, &tp) != NULL) {
3518 3518 attributes->build_date.tm_mday = tp.tm_mday;
3519 3519 attributes->build_date.tm_mon = tp.tm_mon;
3520 3520 attributes->build_date.tm_year = tp.tm_year;
3521 3521 } else {
3522 3522 (void) memset(&attributes->build_date, 0,
3523 3523 sizeof (attributes->build_date));
3524 3524 }
3525 3525 (void) memset(&attributes->build_date, 0,
3526 3526 sizeof (attributes->build_date));
3527 3527 }
3528 3528
3529 3529 return (1);
3530 3530 }
3531 3531
3532 3532 /*
3533 3533 * This function returns the attributes for the warpper library.
3534 3534 */
3535 3535 HBA_UINT32
3536 3536 SMHBA_GetVendorLibraryAttributes(
3537 3537 HBA_UINT32 adapter_index,
3538 3538 SMHBA_LIBRARYATTRIBUTES *attributes)
3539 3539 {
3540 3540 HBA_ADAPTER_INFO *adapt_infop;
3541 3541 SMHBAGetVendorLibraryAttributesFunc
3542 3542 registeredfunc;
3543 3543 HBA_UINT32 ret = 0;
3544 3544
3545 3545 DEBUG(2, "SMHBA_GetVendorLibraryAttributes adapterindex:%d",
3546 3546 adapter_index, 0, 0);
3547 3547 if (_hbaapi_librarylist == NULL) {
3548 3548 DEBUG(1, "SMHBAAPI not loaded yet.", 0, 0, 0);
3549 3549 return (0);
3550 3550 }
3551 3551
3552 3552 if (attributes == NULL) {
3553 3553 DEBUG(1, "SMHBA_GetVendorLibraryAttributes: "
3554 3554 "NULL pointer attributes",
3555 3555 0, 0, 0);
3556 3556 return (HBA_STATUS_ERROR_ARG);
3557 3557 }
3558 3558
3559 3559 (void) memset(attributes, 0, sizeof (SMHBA_LIBRARYATTRIBUTES));
3560 3560
3561 3561 GRAB_MUTEX(&_hbaapi_LL_mutex);
3562 3562 GRAB_MUTEX(&_hbaapi_AL_mutex);
3563 3563 for (adapt_infop = _hbaapi_adapterlist;
3564 3564 adapt_infop != NULL;
3565 3565 adapt_infop = adapt_infop->next) {
3566 3566
3567 3567 if (adapt_infop->index == adapter_index) {
3568 3568
3569 3569 if (adapt_infop->library->version != SMHBA) {
3570 3570 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3571 3571 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex,
3572 3572 HBA_STATUS_ERROR_INCOMPATIBLE);
3573 3573 }
3574 3574
3575 3575 registeredfunc = adapt_infop->library->
3576 3576 ftable.smhbafunctionTable.GetVendorLibraryAttributesHandler;
3577 3577 if (registeredfunc != NULL) {
3578 3578 ret = (registeredfunc)(attributes);
3579 3579 #ifdef NOTDEF
3580 3580 } else {
3581 3581 /* This should not happen since the VSL is already loaded. */
3582 3582 #endif
3583 3583 }
3584 3584 if (attributes->LibPath[0] == '\0') {
3585 3585 if (strlen(adapt_infop->library->LibraryPath) < 256) {
3586 3586 (void) strcpy(attributes->LibPath,
3587 3587 adapt_infop->library->LibraryPath);
3588 3588 }
3589 3589 }
3590 3590 break;
3591 3591 }
3592 3592 }
3593 3593 RELEASE_MUTEX(&_hbaapi_AL_mutex);
3594 3594 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, ret);
3595 3595 }
3596 3596
3597 3597 HBA_STATUS
3598 3598 SMHBA_GetAdapterAttributes(
3599 3599 HBA_HANDLE handle,
3600 3600 SMHBA_ADAPTERATTRIBUTES *hbaattributes)
3601 3601 {
3602 3602 HBA_STATUS status;
3603 3603 HBA_LIBRARY_INFO *lib_infop;
3604 3604 HBA_HANDLE vendorHandle;
3605 3605 SMHBAGetAdapterAttributesFunc GetAdapterAttributesFunc;
3606 3606
3607 3607 DEBUG(2, "SMHBA_GetAdapterAttributes", 0, 0, 0);
3608 3608
3609 3609 CHECKLIBRARYANDVERSION(SMHBA);
3610 3610
3611 3611 GetAdapterAttributesFunc =
3612 3612 lib_infop->ftable.smhbafunctionTable.GetAdapterAttributesHandler;
3613 3613 if (GetAdapterAttributesFunc != NULL) {
3614 3614 status = ((GetAdapterAttributesFunc)(vendorHandle, hbaattributes));
3615 3615 } else {
3616 3616 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3617 3617 }
3618 3618 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3619 3619 }
3620 3620
3621 3621 HBA_STATUS
3622 3622 SMHBA_GetNumberOfPorts(
3623 3623 HBA_HANDLE handle,
3624 3624 HBA_UINT32 *numberofports)
3625 3625 {
3626 3626 HBA_STATUS status;
3627 3627 HBA_LIBRARY_INFO *lib_infop;
3628 3628 HBA_HANDLE vendorHandle;
3629 3629 SMHBAGetNumberOfPortsFunc GetNumberOfPortsFunc;
3630 3630
3631 3631 DEBUG(2, "SMHBA_GetAdapterAttributes", 0, 0, 0);
3632 3632
3633 3633 CHECKLIBRARYANDVERSION(SMHBA);
3634 3634
3635 3635 GetNumberOfPortsFunc =
3636 3636 lib_infop->ftable.smhbafunctionTable.GetNumberOfPortsHandler;
3637 3637 if (GetNumberOfPortsFunc != NULL) {
3638 3638 status = ((GetNumberOfPortsFunc)(vendorHandle, numberofports));
3639 3639 } else {
3640 3640 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3641 3641 }
3642 3642 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3643 3643 }
3644 3644
3645 3645 HBA_STATUS
3646 3646 SMHBA_GetPortType(
3647 3647 HBA_HANDLE handle,
3648 3648 HBA_UINT32 portindex,
3649 3649 HBA_PORTTYPE *porttype)
3650 3650 {
3651 3651 HBA_STATUS status;
3652 3652 HBA_LIBRARY_INFO *lib_infop;
3653 3653 HBA_HANDLE vendorHandle;
3654 3654 SMHBAGetPortTypeFunc GetPortTypeFunc;
3655 3655
3656 3656 DEBUG(2, "SMHBA_GetAdapterAttributes", 0, 0, 0);
3657 3657
3658 3658 CHECKLIBRARYANDVERSION(SMHBA);
3659 3659
3660 3660 GetPortTypeFunc =
3661 3661 lib_infop->ftable.smhbafunctionTable.GetPortTypeHandler;
3662 3662 if (GetPortTypeFunc != NULL) {
3663 3663 status = ((GetPortTypeFunc)(vendorHandle, portindex, porttype));
3664 3664 } else {
3665 3665 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3666 3666 }
3667 3667 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3668 3668 }
3669 3669
3670 3670 HBA_STATUS
3671 3671 SMHBA_GetAdapterPortAttributes(
3672 3672 HBA_HANDLE handle,
3673 3673 HBA_UINT32 portindex,
3674 3674 SMHBA_PORTATTRIBUTES *portattributes)
3675 3675 {
3676 3676 HBA_STATUS status;
3677 3677 HBA_LIBRARY_INFO *lib_infop;
3678 3678 HBA_HANDLE vendorHandle;
3679 3679 SMHBAGetAdapterPortAttributesFunc
3680 3680 GetAdapterPortAttributesFunc;
3681 3681
3682 3682 DEBUG(2, "SMHBA_GetAdapterPortAttributes", 0, 0, 0);
3683 3683
3684 3684 CHECKLIBRARYANDVERSION(SMHBA);
3685 3685
3686 3686 GetAdapterPortAttributesFunc =
3687 3687 lib_infop->ftable.smhbafunctionTable.\
3688 3688 GetAdapterPortAttributesHandler;
3689 3689 if (GetAdapterPortAttributesFunc != NULL) {
3690 3690 status = ((GetAdapterPortAttributesFunc)
3691 3691 (vendorHandle, portindex, portattributes));
3692 3692 } else {
3693 3693 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3694 3694 }
3695 3695 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3696 3696 }
3697 3697
3698 3698 HBA_STATUS
3699 3699 SMHBA_GetDiscoveredPortAttributes(
3700 3700 HBA_HANDLE handle,
3701 3701 HBA_UINT32 portindex,
3702 3702 HBA_UINT32 discoveredportindex,
3703 3703 SMHBA_PORTATTRIBUTES *portattributes)
3704 3704 {
3705 3705 HBA_STATUS status;
3706 3706 HBA_LIBRARY_INFO *lib_infop;
3707 3707 HBA_HANDLE vendorHandle;
3708 3708 SMHBAGetDiscoveredPortAttributesFunc
3709 3709 GetDiscoveredPortAttributesFunc;
3710 3710
3711 3711 DEBUG(2, "SMHBA_GetDiscoveredPortAttributes", 0, 0, 0);
3712 3712
3713 3713 CHECKLIBRARYANDVERSION(SMHBA);
3714 3714
3715 3715 GetDiscoveredPortAttributesFunc =
3716 3716 lib_infop->ftable.smhbafunctionTable.\
3717 3717 GetDiscoveredPortAttributesHandler;
3718 3718 if (GetDiscoveredPortAttributesFunc != NULL) {
3719 3719 status = ((GetDiscoveredPortAttributesFunc)
3720 3720 (vendorHandle, portindex, discoveredportindex,
3721 3721 portattributes));
3722 3722 } else {
3723 3723 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3724 3724 }
3725 3725 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3726 3726 }
3727 3727
3728 3728 HBA_STATUS
3729 3729 SMHBA_GetPortAttributesByWWN(
3730 3730 HBA_HANDLE handle,
3731 3731 HBA_WWN portWWN,
3732 3732 HBA_WWN domainPortWWN,
3733 3733 SMHBA_PORTATTRIBUTES *portattributes)
3734 3734 {
3735 3735 HBA_STATUS status;
3736 3736 HBA_LIBRARY_INFO *lib_infop;
3737 3737 HBA_HANDLE vendorHandle;
3738 3738 SMHBAGetPortAttributesByWWNFunc
3739 3739 GetPortAttributesByWWNFunc;
3740 3740
3741 3741 DEBUG(2, "SMHBA_GetPortAttributesByWWN: %s", WWN2STR1(&portWWN), 0, 0);
3742 3742
3743 3743 CHECKLIBRARYANDVERSION(SMHBA);
3744 3744
3745 3745 GetPortAttributesByWWNFunc =
3746 3746 lib_infop->ftable.smhbafunctionTable.GetPortAttributesByWWNHandler;
3747 3747 if (GetPortAttributesByWWNFunc != NULL) {
3748 3748 status = ((GetPortAttributesByWWNFunc)
3749 3749 (vendorHandle, portWWN, domainPortWWN, portattributes));
3750 3750 } else {
3751 3751 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3752 3752 }
3753 3753 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3754 3754 }
3755 3755
3756 3756 HBA_STATUS
3757 3757 SMHBA_GetFCPhyAttributes(
3758 3758 HBA_HANDLE handle,
3759 3759 HBA_UINT32 portindex,
3760 3760 HBA_UINT32 phyindex,
3761 3761 SMHBA_FC_PHY *phytype)
3762 3762 {
3763 3763 HBA_STATUS status;
3764 3764 HBA_LIBRARY_INFO *lib_infop;
3765 3765 HBA_HANDLE vendorHandle;
3766 3766 SMHBAGetFCPhyAttributesFunc GetFCPhyAttributesFunc;
3767 3767
3768 3768 DEBUG(2, "SMHBA_GetFCPhyAttributesByWWN", 0, 0, 0);
3769 3769
3770 3770 CHECKLIBRARYANDVERSION(SMHBA);
3771 3771
3772 3772 GetFCPhyAttributesFunc =
3773 3773 lib_infop->ftable.smhbafunctionTable.GetFCPhyAttributesHandler;
3774 3774 if (GetFCPhyAttributesFunc != NULL) {
3775 3775 status = ((GetFCPhyAttributesFunc)
3776 3776 (vendorHandle, portindex, phyindex, phytype));
3777 3777 } else {
3778 3778 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3779 3779 }
3780 3780 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3781 3781 }
3782 3782
3783 3783 HBA_STATUS
3784 3784 SMHBA_GetSASPhyAttributes(
3785 3785 HBA_HANDLE handle,
3786 3786 HBA_UINT32 portindex,
3787 3787 HBA_UINT32 phyindex,
3788 3788 SMHBA_SAS_PHY *phytype)
3789 3789 {
3790 3790 HBA_STATUS status;
3791 3791 HBA_LIBRARY_INFO *lib_infop;
3792 3792 HBA_HANDLE vendorHandle;
3793 3793 SMHBAGetSASPhyAttributesFunc GetSASPhyAttributesFunc;
3794 3794
3795 3795 DEBUG(2, "SMHBA_GetFCPhyAttributesByWWN", 0, 0, 0);
3796 3796
3797 3797 CHECKLIBRARYANDVERSION(SMHBA);
3798 3798
3799 3799 GetSASPhyAttributesFunc =
3800 3800 lib_infop->ftable.smhbafunctionTable.GetSASPhyAttributesHandler;
3801 3801 if (GetSASPhyAttributesFunc != NULL) {
3802 3802 status = ((GetSASPhyAttributesFunc)
3803 3803 (vendorHandle, portindex, phyindex, phytype));
3804 3804 } else {
3805 3805 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3806 3806 }
3807 3807 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3808 3808 }
3809 3809
3810 3810 HBA_STATUS
3811 3811 SMHBA_GetProtocolStatistics(
3812 3812 HBA_HANDLE handle,
3813 3813 HBA_UINT32 portindex,
3814 3814 HBA_UINT32 protocoltype,
3815 3815 SMHBA_PROTOCOLSTATISTICS *pProtocolStatistics)
3816 3816 {
3817 3817 HBA_STATUS status;
3818 3818 HBA_LIBRARY_INFO *lib_infop;
3819 3819 HBA_HANDLE vendorHandle;
3820 3820 SMHBAGetProtocolStatisticsFunc
3821 3821 GetProtocolStatisticsFunc;
3822 3822
3823 3823 DEBUG(2, "SMHBA_GetProtocolStatistics port index: %d protocol type: %d",
3824 3824 portindex, protocoltype, 0);
3825 3825
3826 3826 CHECKLIBRARYANDVERSION(SMHBA);
3827 3827
3828 3828 GetProtocolStatisticsFunc =
3829 3829 lib_infop->ftable.smhbafunctionTable.GetProtocolStatisticsHandler;
3830 3830 if (GetProtocolStatisticsFunc != NULL) {
3831 3831 status = (GetProtocolStatisticsFunc)
3832 3832 (vendorHandle, portindex, protocoltype, pProtocolStatistics);
3833 3833 } else {
3834 3834 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3835 3835 }
3836 3836 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3837 3837 }
3838 3838
3839 3839 HBA_STATUS
3840 3840 SMHBA_GetPhyStatistics(
3841 3841 HBA_HANDLE handle,
3842 3842 HBA_UINT32 portindex,
3843 3843 HBA_UINT32 phyindex,
3844 3844 SMHBA_PHYSTATISTICS *pPhyStatistics)
3845 3845 {
3846 3846 HBA_STATUS status;
3847 3847 HBA_LIBRARY_INFO *lib_infop;
3848 3848 HBA_HANDLE vendorHandle;
3849 3849 SMHBAGetPhyStatisticsFunc
3850 3850 GetPhyStatisticsFunc;
3851 3851
3852 3852 DEBUG(2, "SMHBA_GetPhyStatistics port index: %d phy idex: %d",
3853 3853 portindex, phyindex, 0);
3854 3854
3855 3855 CHECKLIBRARYANDVERSION(SMHBA);
3856 3856
3857 3857 GetPhyStatisticsFunc =
3858 3858 lib_infop->ftable.smhbafunctionTable.GetPhyStatisticsHandler;
3859 3859 if (GetPhyStatisticsFunc != NULL) {
3860 3860 status = (GetPhyStatisticsFunc)
3861 3861 (vendorHandle, portindex, phyindex, pPhyStatistics);
3862 3862 } else {
3863 3863 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3864 3864 }
3865 3865 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3866 3866 }
3867 3867
3868 3868 HBA_STATUS
3869 3869 SMHBA_GetBindingCapability(
3870 3870 HBA_HANDLE handle,
3871 3871 HBA_WWN hbaPortWWN,
3872 3872 HBA_WWN domainPortWWN,
3873 3873 SMHBA_BIND_CAPABILITY *pFlags)
3874 3874 {
3875 3875 HBA_STATUS status;
3876 3876 HBA_LIBRARY_INFO *lib_infop;
3877 3877 HBA_HANDLE vendorHandle;
3878 3878 SMHBAGetBindingCapabilityFunc GetBindingCapabilityFunc;
3879 3879
3880 3880 DEBUG(2, "HBA_GetBindingCapability", 0, 0, 0);
3881 3881
3882 3882 CHECKLIBRARYANDVERSION(SMHBA);
3883 3883
3884 3884 GetBindingCapabilityFunc =
3885 3885 lib_infop->ftable.smhbafunctionTable.GetBindingCapabilityHandler;
3886 3886 if (GetBindingCapabilityFunc != NULL) {
3887 3887 status = (GetBindingCapabilityFunc)(vendorHandle, hbaPortWWN,
3888 3888 domainPortWWN, pFlags);
3889 3889 } else {
3890 3890 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3891 3891 }
3892 3892 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3893 3893 }
3894 3894
3895 3895 HBA_STATUS
3896 3896 SMHBA_GetBindingSupport(
3897 3897 HBA_HANDLE handle,
3898 3898 HBA_WWN hbaPortWWN,
3899 3899 HBA_WWN domainPortWWN,
3900 3900 SMHBA_BIND_CAPABILITY *pFlags)
3901 3901 {
3902 3902 HBA_STATUS status;
3903 3903 HBA_LIBRARY_INFO *lib_infop;
3904 3904 HBA_HANDLE vendorHandle;
3905 3905 SMHBAGetBindingSupportFunc
3906 3906 GetBindingSupporFunc;
3907 3907
3908 3908 DEBUG(2, "SMHBA_GetBindingSupport port: %s",
3909 3909 WWN2STR1(&hbaPortWWN), 0, 0);
3910 3910
3911 3911 CHECKLIBRARYANDVERSION(SMHBA);
3912 3912
3913 3913 GetBindingSupporFunc =
3914 3914 lib_infop->ftable.smhbafunctionTable.GetBindingSupportHandler;
3915 3915 if (GetBindingSupporFunc != NULL) {
3916 3916 status = (GetBindingSupporFunc)(vendorHandle,
3917 3917 hbaPortWWN, domainPortWWN, pFlags);
3918 3918 } else {
3919 3919 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3920 3920 }
3921 3921 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3922 3922 }
3923 3923
3924 3924 HBA_STATUS
3925 3925 SMHBA_SetBindingSupport(
3926 3926 HBA_HANDLE handle,
3927 3927 HBA_WWN hbaPortWWN,
3928 3928 HBA_WWN domainPortWWN,
3929 3929 SMHBA_BIND_CAPABILITY flags)
3930 3930 {
3931 3931 HBA_STATUS status;
3932 3932 HBA_LIBRARY_INFO *lib_infop;
3933 3933 HBA_HANDLE vendorHandle;
3934 3934 SMHBASetBindingSupportFunc
3935 3935 SetBindingSupporFunc;
3936 3936
3937 3937 DEBUG(2, "SMHBA_GetBindingSupport port: %s",
3938 3938 WWN2STR1(&hbaPortWWN), 0, 0);
3939 3939
3940 3940 CHECKLIBRARYANDVERSION(HBAAPIV2);
3941 3941
3942 3942 SetBindingSupporFunc =
3943 3943 lib_infop->ftable.smhbafunctionTable.SetBindingSupportHandler;
3944 3944 if (SetBindingSupporFunc != NULL) {
3945 3945 status = (SetBindingSupporFunc)
3946 3946 (vendorHandle, hbaPortWWN, domainPortWWN, flags);
3947 3947 } else {
3948 3948 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3949 3949 }
3950 3950 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3951 3951 }
3952 3952
3953 3953 HBA_STATUS
3954 3954 SMHBA_GetTargetMapping(
3955 3955 HBA_HANDLE handle,
3956 3956 HBA_WWN hbaPortWWN,
3957 3957 HBA_WWN domainPortWWN,
3958 3958 SMHBA_TARGETMAPPING *pMapping)
3959 3959 {
3960 3960 HBA_STATUS status;
3961 3961 HBA_LIBRARY_INFO *lib_infop;
3962 3962 HBA_HANDLE vendorHandle;
3963 3963 SMHBAGetTargetMappingFunc GetTargetMappingFunc;
3964 3964
3965 3965 DEBUG(2, "SMHBA_GetTargetMapping port WWN: %s",
3966 3966 WWN2STR1(&hbaPortWWN), 0, 0);
3967 3967
3968 3968 CHECKLIBRARYANDVERSION(SMHBA);
3969 3969
3970 3970 GetTargetMappingFunc =
3971 3971 lib_infop->ftable.smhbafunctionTable.GetTargetMappingHandler;
3972 3972 if (GetTargetMappingFunc != NULL) {
3973 3973 status = ((GetTargetMappingFunc)(vendorHandle,
3974 3974 hbaPortWWN, domainPortWWN, pMapping));
3975 3975 } else {
3976 3976 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
3977 3977 }
3978 3978 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
3979 3979 }
3980 3980
3981 3981 HBA_STATUS
3982 3982 SMHBA_GetPersistentBinding(
3983 3983 HBA_HANDLE handle,
3984 3984 HBA_WWN hbaPortWWN,
3985 3985 HBA_WWN domainPortWWN,
3986 3986 SMHBA_BINDING *binding)
3987 3987 {
3988 3988 HBA_STATUS status;
3989 3989 HBA_LIBRARY_INFO *lib_infop;
3990 3990 HBA_HANDLE vendorHandle;
3991 3991 SMHBAGetPersistentBindingFunc
3992 3992 GetPersistentBindingFunc;
3993 3993
3994 3994 DEBUG(2, "SMHBA_GetPersistentBinding port WWN: %s",
3995 3995 WWN2STR1(&hbaPortWWN), 0, 0);
3996 3996
3997 3997 CHECKLIBRARYANDVERSION(SMHBA);
3998 3998
3999 3999 GetPersistentBindingFunc =
4000 4000 lib_infop->ftable.smhbafunctionTable.GetPersistentBindingHandler;
4001 4001 if (GetPersistentBindingFunc != NULL) {
4002 4002 status = ((GetPersistentBindingFunc)(vendorHandle,
4003 4003 hbaPortWWN, domainPortWWN, binding));
4004 4004 } else {
4005 4005 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4006 4006 }
4007 4007 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4008 4008 }
4009 4009
4010 4010 HBA_STATUS
4011 4011 SMHBA_SetPersistentBinding(
4012 4012 HBA_HANDLE handle,
4013 4013 HBA_WWN hbaPortWWN,
4014 4014 HBA_WWN domainPortWWN,
4015 4015 const SMHBA_BINDING *binding)
4016 4016 {
4017 4017 HBA_STATUS status;
4018 4018 HBA_LIBRARY_INFO *lib_infop;
4019 4019 HBA_HANDLE vendorHandle;
4020 4020 SMHBASetPersistentBindingFunc
4021 4021 SetPersistentBindingFunc;
4022 4022
4023 4023 DEBUG(2, "SMHBA_SetPersistentBinding port WWN: %s",
4024 4024 WWN2STR1(&hbaPortWWN), 0, 0);
4025 4025
4026 4026 CHECKLIBRARYANDVERSION(SMHBA);
4027 4027
4028 4028 SetPersistentBindingFunc =
4029 4029 lib_infop->ftable.smhbafunctionTable.SetPersistentBindingHandler;
4030 4030 if (SetPersistentBindingFunc != NULL) {
4031 4031 status = ((SetPersistentBindingFunc)(vendorHandle,
4032 4032 hbaPortWWN, domainPortWWN, binding));
4033 4033 } else {
4034 4034 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4035 4035 }
4036 4036 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4037 4037 }
4038 4038
4039 4039 HBA_STATUS
4040 4040 SMHBA_RemovePersistentBinding(
4041 4041 HBA_HANDLE handle,
4042 4042 HBA_WWN hbaPortWWN,
4043 4043 HBA_WWN domainPortWWN,
4044 4044 const SMHBA_BINDING *binding)
4045 4045 {
4046 4046 HBA_STATUS status;
4047 4047 HBA_LIBRARY_INFO *lib_infop;
4048 4048 HBA_HANDLE vendorHandle;
4049 4049 SMHBARemovePersistentBindingFunc
4050 4050 RemovePersistentBindingFunc;
4051 4051
4052 4052 DEBUG(2, "SMHBA_RemovePersistentBinding port WWN: %s",
4053 4053 WWN2STR1(&hbaPortWWN), 0, 0);
4054 4054
4055 4055 CHECKLIBRARYANDVERSION(SMHBA);
4056 4056
4057 4057 RemovePersistentBindingFunc =
4058 4058 lib_infop->ftable.smhbafunctionTable.RemovePersistentBindingHandler;
4059 4059 if (RemovePersistentBindingFunc != NULL) {
4060 4060 status = ((RemovePersistentBindingFunc)(vendorHandle,
4061 4061 hbaPortWWN, domainPortWWN, binding));
4062 4062 } else {
4063 4063 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4064 4064 }
4065 4065 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4066 4066 }
4067 4067
4068 4068 HBA_STATUS
4069 4069 SMHBA_RemoveAllPersistentBindings(
4070 4070 HBA_HANDLE handle,
4071 4071 HBA_WWN hbaPortWWN,
4072 4072 HBA_WWN domainPortWWN)
4073 4073 {
4074 4074 HBA_STATUS status;
4075 4075 HBA_LIBRARY_INFO *lib_infop;
4076 4076 HBA_HANDLE vendorHandle;
4077 4077 SMHBARemoveAllPersistentBindingsFunc
4078 4078 RemoveAllPersistentBindingsFunc;
4079 4079
4080 4080 DEBUG(2, "SMHBA_RemoveAllPersistentBinding port WWN: %s",
4081 4081 WWN2STR1(&hbaPortWWN), 0, 0);
4082 4082
4083 4083 CHECKLIBRARYANDVERSION(SMHBA);
4084 4084
4085 4085 RemoveAllPersistentBindingsFunc =
4086 4086 lib_infop->ftable.smhbafunctionTable.\
4087 4087 RemoveAllPersistentBindingsHandler;
4088 4088 if (RemoveAllPersistentBindingsFunc != NULL) {
4089 4089 status = ((RemoveAllPersistentBindingsFunc)(vendorHandle,
4090 4090 hbaPortWWN, domainPortWWN));
4091 4091 } else {
4092 4092 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4093 4093 }
4094 4094 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4095 4095 }
4096 4096
4097 4097 HBA_STATUS
4098 4098 SMHBA_GetLUNStatistics(
4099 4099 HBA_HANDLE handle,
4100 4100 const HBA_SCSIID *lunit,
4101 4101 SMHBA_PROTOCOLSTATISTICS *statistics)
4102 4102 {
4103 4103 HBA_STATUS status;
4104 4104 HBA_LIBRARY_INFO *lib_infop;
4105 4105 HBA_HANDLE vendorHandle;
4106 4106 SMHBAGetLUNStatisticsFunc GetLUNStatisticsFunc;
4107 4107
4108 4108 DEBUG(2, "SMHBA_GetLUNStatistics", 0, 0, 0);
4109 4109
4110 4110 CHECKLIBRARYANDVERSION(SMHBA);
4111 4111
4112 4112 GetLUNStatisticsFunc =
4113 4113 lib_infop->ftable.smhbafunctionTable.GetLUNStatisticsHandler;
4114 4114 if (GetLUNStatisticsFunc != NULL) {
4115 4115 status = ((GetLUNStatisticsFunc)(vendorHandle, lunit, statistics));
4116 4116 } else {
4117 4117 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4118 4118 }
4119 4119 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4120 4120 }
4121 4121
4122 4122 HBA_STATUS
4123 4123 SMHBA_ScsiInquiry(
4124 4124 HBA_HANDLE handle,
4125 4125 HBA_WWN hbaPortWWN,
4126 4126 HBA_WWN discoveredPortWWN,
4127 4127 HBA_WWN domainPortWWN,
4128 4128 SMHBA_SCSILUN smhbaLUN,
4129 4129 HBA_UINT8 CDB_Byte1,
4130 4130 HBA_UINT8 CDB_Byte2,
4131 4131 void *pRspBuffer,
4132 4132 HBA_UINT32 *pRspBufferSize,
4133 4133 HBA_UINT8 *pScsiStatus,
4134 4134 void *pSenseBuffer,
4135 4135 HBA_UINT32 *pSenseBufferSize)
4136 4136 {
4137 4137 HBA_STATUS status;
4138 4138 HBA_LIBRARY_INFO *lib_infop;
4139 4139 HBA_HANDLE vendorHandle;
4140 4140 SMHBAScsiInquiryFunc ScsiInquiryFunc;
4141 4141
4142 4142 DEBUG(2, "SMHBA_ScsiInquiry to hba port: %s discoveredPortWWN: %s",
4143 4143 WWN2STR1(&hbaPortWWN), WWN2STR1(&discoveredPortWWN), 0);
4144 4144
4145 4145 CHECKLIBRARYANDVERSION(SMHBA);
4146 4146
4147 4147 ScsiInquiryFunc =
4148 4148 lib_infop->ftable.smhbafunctionTable.ScsiInquiryHandler;
4149 4149 if (ScsiInquiryFunc != NULL) {
4150 4150 status = ((ScsiInquiryFunc)(
4151 4151 vendorHandle, hbaPortWWN, discoveredPortWWN, domainPortWWN,
4152 4152 smhbaLUN, CDB_Byte1, CDB_Byte2, pRspBuffer, pRspBufferSize,
4153 4153 pScsiStatus, pSenseBuffer, pSenseBufferSize));
4154 4154 } else {
4155 4155 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4156 4156 }
4157 4157 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4158 4158 }
4159 4159
4160 4160 HBA_STATUS
4161 4161 SMHBA_ScsiReportLUNs(
4162 4162 HBA_HANDLE handle,
4163 4163 HBA_WWN hbaPortWWN,
4164 4164 HBA_WWN discoveredPortWWN,
4165 4165 HBA_WWN domainPortWWN,
4166 4166 void *pRspBuffer,
4167 4167 HBA_UINT32 *pRspBufferSize,
4168 4168 HBA_UINT8 *pScsiStatus,
4169 4169 void *pSenseBuffer,
4170 4170 HBA_UINT32 *pSenseBufferSize)
4171 4171 {
4172 4172 HBA_STATUS status;
4173 4173 HBA_LIBRARY_INFO *lib_infop;
4174 4174 HBA_HANDLE vendorHandle;
4175 4175 SMHBAScsiReportLUNsFunc ScsiReportLUNsFunc;
4176 4176
4177 4177 DEBUG(2, "SMHBA_ScsiReportLuns to hba port: %s discoveredPortWWN: %s",
4178 4178 WWN2STR1(&hbaPortWWN), WWN2STR1(&discoveredPortWWN), 0);
4179 4179
4180 4180 CHECKLIBRARYANDVERSION(SMHBA);
4181 4181
4182 4182 ScsiReportLUNsFunc =
4183 4183 lib_infop->ftable.smhbafunctionTable.ScsiReportLUNsHandler;
4184 4184 if (ScsiReportLUNsFunc != NULL) {
4185 4185 status = ((ScsiReportLUNsFunc)(
4186 4186 vendorHandle, hbaPortWWN, discoveredPortWWN, domainPortWWN,
4187 4187 pRspBuffer, pRspBufferSize, pScsiStatus, pSenseBuffer,
4188 4188 pSenseBufferSize));
4189 4189 } else {
4190 4190 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4191 4191 }
4192 4192 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4193 4193 }
4194 4194
4195 4195 HBA_STATUS
4196 4196 SMHBA_ScsiReadCapacity(
4197 4197 HBA_HANDLE handle,
4198 4198 HBA_WWN hbaPortWWN,
4199 4199 HBA_WWN discoveredPortWWN,
4200 4200 HBA_WWN domainPortWWN,
4201 4201 SMHBA_SCSILUN smhbaLUN,
4202 4202 void *pRspBuffer,
4203 4203 HBA_UINT32 *pRspBufferSize,
4204 4204 HBA_UINT8 *pScsiStatus,
4205 4205 void *pSenseBuffer,
4206 4206 HBA_UINT32 *pSenseBufferSize)
4207 4207 {
4208 4208 HBA_STATUS status;
4209 4209 HBA_LIBRARY_INFO *lib_infop;
4210 4210 HBA_HANDLE vendorHandle;
4211 4211 SMHBAScsiReadCapacityFunc ScsiReadCapacityFunc;
4212 4212
4213 4213 DEBUG(2, "SMHBA_ScsiReadCapacity to hba port: %s discoveredPortWWN: %s",
4214 4214 WWN2STR1(&hbaPortWWN), WWN2STR1(&discoveredPortWWN), 0);
4215 4215
4216 4216 CHECKLIBRARYANDVERSION(SMHBA);
4217 4217
4218 4218 ScsiReadCapacityFunc =
4219 4219 lib_infop->ftable.smhbafunctionTable.ScsiReadCapacityHandler;
4220 4220 if (ScsiReadCapacityFunc != NULL) {
4221 4221 status = ((ScsiReadCapacityFunc)(
4222 4222 vendorHandle, hbaPortWWN, discoveredPortWWN, domainPortWWN,
4223 4223 smhbaLUN, pRspBuffer, pRspBufferSize, pScsiStatus, pSenseBuffer,
4224 4224 pSenseBufferSize));
4225 4225 } else {
4226 4226 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4227 4227 }
4228 4228 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4229 4229 }
4230 4230
4231 4231 HBA_STATUS
4232 4232 SMHBA_SendTEST(
4233 4233 HBA_HANDLE handle,
4234 4234 HBA_WWN hbaPortWWN,
4235 4235 HBA_WWN destWWN,
4236 4236 HBA_UINT32 destFCID,
4237 4237 void *pRspBuffer,
4238 4238 HBA_UINT32 pRspBufferSize)
4239 4239 {
4240 4240 HBA_STATUS status;
4241 4241 HBA_LIBRARY_INFO *lib_infop;
4242 4242 HBA_HANDLE vendorHandle;
4243 4243 SMHBASendTESTFunc SendTESTFunc;
4244 4244
4245 4245 DEBUG(2, "SMHBA_SendTEST, hbaPortWWN: %s destWWN",
4246 4246 WWN2STR1(&hbaPortWWN),
4247 4247 WWN2STR1(&destWWN), 0);
4248 4248
4249 4249 CHECKLIBRARYANDVERSION(SMHBA);
4250 4250
4251 4251 SendTESTFunc = lib_infop->ftable.smhbafunctionTable.SendTESTHandler;
4252 4252 if (SendTESTFunc != NULL) {
4253 4253 status = (SendTESTFunc)
4254 4254 (vendorHandle, hbaPortWWN, destWWN, destFCID,
4255 4255 pRspBuffer, pRspBufferSize);
4256 4256 } else {
4257 4257 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4258 4258 }
4259 4259 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4260 4260 }
4261 4261
4262 4262 HBA_STATUS
4263 4263 SMHBA_SendECHO(
4264 4264 HBA_HANDLE handle,
4265 4265 HBA_WWN hbaPortWWN,
4266 4266 HBA_WWN destWWN,
4267 4267 HBA_UINT32 destFCID,
4268 4268 void *pReqBuffer,
4269 4269 HBA_UINT32 ReqBufferSize,
4270 4270 void *pRspBuffer,
4271 4271 HBA_UINT32 *pRspBufferSize)
4272 4272 {
4273 4273 HBA_STATUS status;
4274 4274 HBA_LIBRARY_INFO *lib_infop;
4275 4275 HBA_HANDLE vendorHandle;
4276 4276 SMHBASendECHOFunc SendECHOFunc;
4277 4277
4278 4278 DEBUG(2, "SMHBA_SendECHO, hbaPortWWN: %s destWWN",
4279 4279 WWN2STR1(&hbaPortWWN), WWN2STR1(&destWWN), 0);
4280 4280
4281 4281 CHECKLIBRARYANDVERSION(SMHBA);
4282 4282
4283 4283 SendECHOFunc = lib_infop->ftable.smhbafunctionTable.SendECHOHandler;
4284 4284 if (SendECHOFunc != NULL) {
4285 4285 status = (SendECHOFunc)
4286 4286 (vendorHandle, hbaPortWWN, destWWN, destFCID,
4287 4287 pReqBuffer, ReqBufferSize, pRspBuffer, pRspBufferSize);
4288 4288 } else {
4289 4289 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4290 4290 }
4291 4291 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4292 4292 }
4293 4293
4294 4294 HBA_STATUS
4295 4295 SMHBA_SendSMPPassThru(
4296 4296 HBA_HANDLE handle,
4297 4297 HBA_WWN hbaPortWWN,
4298 4298 HBA_WWN destWWN,
4299 4299 HBA_WWN domainPortWWN,
4300 4300 void *pReqBuffer,
4301 4301 HBA_UINT32 ReqBufferSize,
4302 4302 void *pRspBuffer,
4303 4303 HBA_UINT32 *pRspBufferSize)
4304 4304 {
4305 4305 HBA_STATUS status;
4306 4306 HBA_LIBRARY_INFO *lib_infop;
4307 4307 HBA_HANDLE vendorHandle;
4308 4308 SMHBASendSMPPassThruFunc SendSMPPassThruFunc;
4309 4309
4310 4310 DEBUG(2, "SMHBA_SendSMPPassThru, hbaPortWWN: %s destWWN: %s",
4311 4311 WWN2STR1(&hbaPortWWN), WWN2STR1(&destWWN), 0);
4312 4312
4313 4313 CHECKLIBRARYANDVERSION(SMHBA);
4314 4314
4315 4315 SendSMPPassThruFunc = lib_infop->ftable.\
4316 4316 smhbafunctionTable.SendSMPPassThruHandler;
4317 4317
4318 4318 if (SendSMPPassThruFunc != NULL) {
4319 4319 status = (SendSMPPassThruFunc)
4320 4320 (vendorHandle, hbaPortWWN, destWWN, domainPortWWN,
4321 4321 pReqBuffer, ReqBufferSize, pRspBuffer, pRspBufferSize);
↓ open down ↓ |
2857 lines elided |
↑ open up ↑ |
4322 4322 } else {
4323 4323 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4324 4324 }
4325 4325 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4326 4326 }
4327 4327
4328 4328 /*
4329 4329 * Following the similar logic of HBAAPI addaspterevents_callback.
4330 4330 *
4331 4331 * Unlike other events Adapter Add Event is not limited to a specific
4332 - * adpater(i.e. no adatper handle is passed for registration) so
4332 + * adapter(i.e. no adapter handle is passed for registration) so
4333 4333 * the event should be passed to all registrants. The routine below
4334 4334 * is passed to the VSLs as a callback and when Adapter Add event is detected
4335 4335 * by VSL it will call smhba_adapteraddevents_callback() which in turn check
4336 4336 * if the passed userdata ptr matches with the one stored in the callback list
4337 4337 * and calls the stored callback.
4338 4338 *
4339 4339 * For the situation that multiple clients are registered for Adapter Add event
4340 4340 * each registration is passed to VSLs so VSL may call
4341 4341 * smhba_adapteraddevents_callback() multiple times or it may call only once
4342 4342 * since the callback function is same. For this implemneation, the userdata
4343 4343 * is stored in HBA_ALLADAPTERSCALLBACK_ELEM so it is expected that VSL call
4344 4344 * smhba_adapteraddevents_callback() only once and
4345 4345 * smhba_adapteraddevents_callback() will call the client callback with proper
4346 4346 * userdata.
4347 4347 */
4348 4348 static void
4349 4349 smhba_adapteraddevents_callback(
4350 4350 /* LINTED E_FUNC_ARG_UNUSED */
4351 4351 void *data,
4352 4352 HBA_WWN PortWWN,
4353 4353 /* LINTED E_FUNC_ARG_UNUSED */
4354 4354 HBA_UINT32 eventType)
4355 4355 {
4356 4356 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
4357 4357
4358 4358 DEBUG(3, "AddAdapterEvent, port:%s", WWN2STR1(&PortWWN), 0, 0);
4359 4359
4360 4360 GRAB_MUTEX(&_smhba_AAE_mutex);
4361 4361 for (cbp = _smhba_adapteraddevents_callback_list;
4362 4362 cbp != NULL;
4363 4363 cbp = cbp->next) {
4364 4364 (*cbp->callback)(cbp->userdata, PortWWN, HBA_EVENT_ADAPTER_ADD);
4365 4365 }
4366 4366 RELEASE_MUTEX(&_smhba_AAE_mutex);
4367 4367
4368 4368 }
4369 4369
4370 4370 HBA_STATUS
4371 4371 SMHBA_RegisterForAdapterAddEvents(
4372 4372 void (*pCallback) (
4373 4373 void *data,
4374 4374 HBA_WWN PortWWN,
4375 4375 HBA_UINT32 eventType),
4376 4376 void *pUserData,
4377 4377 HBA_CALLBACKHANDLE *pCallbackHandle) {
4378 4378
4379 4379 HBA_ALLADAPTERSCALLBACK_ELEM *cbp;
4380 4380 HBA_VENDORCALLBACK_ELEM *vcbp;
4381 4381 HBA_VENDORCALLBACK_ELEM *vendorhandlelist;
4382 4382 SMHBARegisterForAdapterAddEventsFunc registeredfunc;
4383 4383 HBA_STATUS status = HBA_STATUS_OK;
4384 4384 HBA_STATUS failure = HBA_STATUS_OK;
4385 4385 HBA_LIBRARY_INFO *lib_infop;
4386 4386 int registered_cnt = 0;
4387 4387 int vendor_cnt = 0;
4388 4388 int not_supported_cnt = 0;
4389 4389 int status_OK_bar_cnt = 0;
4390 4390 int status_OK_cnt = 0;
4391 4391
4392 4392 DEBUG(2, "SMHBA_RegisterForAdapterAddEvents", 0, 0, 0);
4393 4393 ARE_WE_INITED();
4394 4394
4395 4395 cbp = (HBA_ALLADAPTERSCALLBACK_ELEM *)
4396 4396 calloc(1, sizeof (HBA_ALLADAPTERSCALLBACK_ELEM));
4397 4397 *pCallbackHandle = (HBA_CALLBACKHANDLE) cbp;
4398 4398 if (cbp == NULL) {
4399 4399 return (HBA_STATUS_ERROR);
4400 4400 }
4401 4401
4402 4402 GRAB_MUTEX(&_hbaapi_LL_mutex);
4403 4403 GRAB_MUTEX(&_smhba_AAE_mutex);
4404 4404 cbp->callback = pCallback;
4405 4405 cbp->userdata = pUserData;
4406 4406 cbp->next = _smhba_adapteraddevents_callback_list;
4407 4407 _smhba_adapteraddevents_callback_list = cbp;
4408 4408
4409 4409 /*
4410 4410 * Need to release the mutex now incase the vendor function invokes the
4411 4411 * callback. We will grap the mutex later to attach the vendor handle
4412 4412 * list to the callback structure
4413 4413 */
4414 4414 RELEASE_MUTEX(&_smhba_AAE_mutex);
4415 4415
4416 4416
4417 4417 /*
4418 4418 * now create a list of vendors (vendor libraryies, NOT ADAPTERS)
4419 4419 * that have successfully registerred
4420 4420 */
4421 4421 vendorhandlelist = NULL;
4422 4422 for (lib_infop = _hbaapi_librarylist;
4423 4423 lib_infop != NULL;
4424 4424 lib_infop = lib_infop->next) {
4425 4425
4426 4426 /* only for HBAAPI V2 */
4427 4427 if (lib_infop->version != SMHBA) {
4428 4428 continue;
4429 4429 } else {
4430 4430 vendor_cnt++;
4431 4431 }
4432 4432
4433 4433 registeredfunc =
4434 4434 lib_infop->ftable.smhbafunctionTable.\
4435 4435 RegisterForAdapterAddEventsHandler;
4436 4436 if (registeredfunc == NULL) {
4437 4437 continue;
4438 4438 }
4439 4439
4440 4440 vcbp = (HBA_VENDORCALLBACK_ELEM *)
4441 4441 calloc(1, sizeof (HBA_VENDORCALLBACK_ELEM));
4442 4442 if (vcbp == NULL) {
4443 4443 freevendorhandlelist(vendorhandlelist);
4444 4444 status = HBA_STATUS_ERROR;
4445 4445 break;
4446 4446 }
4447 4447
4448 4448 registered_cnt++;
4449 4449 status = (registeredfunc)(smhba_adapteraddevents_callback,
4450 4450 pUserData, &vcbp->vendorcbhandle);
4451 4451 if (status == HBA_STATUS_ERROR_NOT_SUPPORTED) {
4452 4452 not_supported_cnt++;
4453 4453 free(vcbp);
4454 4454 continue;
4455 4455 } else if (status != HBA_STATUS_OK) {
4456 4456 status_OK_bar_cnt++;
4457 4457 DEBUG(1,
4458 4458 "SMHBA_RegisterForAdapterAddEvents: Library->%s, Error->%d",
4459 4459 lib_infop->LibraryPath, status, 0);
4460 4460 failure = status;
4461 4461 free(vcbp);
4462 4462 continue;
4463 4463 } else {
4464 4464 status_OK_cnt++;
4465 4465 }
4466 4466 vcbp->lib_info = lib_infop;
4467 4467 vcbp->next = vendorhandlelist;
4468 4468 vendorhandlelist = vcbp;
4469 4469 }
4470 4470
4471 4471 if (vendor_cnt == 0) {
4472 4472 /* no SMHBA VSL found. Should be okay?? */
4473 4473 status = HBA_STATUS_ERROR;
4474 4474 } else if (registered_cnt == 0) {
4475 4475 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4476 4476 freevendorhandlelist(vendorhandlelist);
4477 4477 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
4478 4478 } else if (status_OK_cnt == 0 && not_supported_cnt != 0) {
4479 4479 status = HBA_STATUS_ERROR_NOT_SUPPORTED;
4480 4480 } else if (status_OK_cnt == 0) {
4481 4481 /*
4482 4482 * At least one vendor library registered this function, but no
4483 4483 * vendor call succeeded
4484 4484 */
4485 4485 (void) local_remove_callback((HBA_CALLBACKHANDLE) cbp);
4486 4486 status = failure;
4487 4487 } else {
4488 4488 /* we have had atleast some success, now finish up */
4489 4489 GRAB_MUTEX(&_smhba_AAE_mutex);
4490 4490 /*
4491 4491 * this seems silly, but what if another thread called
4492 4492 * the callback remove
4493 4493 */
4494 4494 for (cbp = _smhba_adapteraddevents_callback_list;
4495 4495 cbp != NULL; cbp = cbp->next) {
4496 4496 if ((HBA_CALLBACKHANDLE)cbp == *pCallbackHandle) {
4497 4497 /* yup, its still there, hooray */
4498 4498 cbp->vendorhandlelist = vendorhandlelist;
4499 4499 vendorhandlelist = NULL;
4500 4500 break;
4501 4501 }
4502 4502 }
4503 4503 RELEASE_MUTEX(&_smhba_AAE_mutex);
4504 4504 if (vendorhandlelist != NULL) {
4505 4505 /*
4506 4506 * bummer, somebody removed the callback before we finished
4507 4507 * registration, probably will never happen
4508 4508 */
4509 4509 freevendorhandlelist(vendorhandlelist);
4510 4510 DEBUG(1,
4511 4511 "HBA_RegisterForAdapterAddEvents: HBA_RemoveCallback was "
4512 4512 "called for a handle before registration was finished.",
4513 4513 0, 0, 0);
4514 4514 status = HBA_STATUS_ERROR;
4515 4515 } else {
4516 4516 status = HBA_STATUS_OK;
4517 4517 }
4518 4518 }
4519 4519 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4520 4520 }
4521 4521
4522 4522 /* SMHBA Adapter Events (other than add) ******************************** */
4523 4523 static void
4524 4524 smhba_adapterevents_callback(void *data,
4525 4525 HBA_WWN PortWWN,
4526 4526 HBA_UINT32 eventType)
4527 4527 {
4528 4528 HBA_ADAPTERCALLBACK_ELEM *acbp;
4529 4529
4530 4530 DEBUG(3, "AdapterEvent, port:%s, eventType:%d", WWN2STR1(&PortWWN),
4531 4531 eventType, 0);
4532 4532
4533 4533 GRAB_MUTEX(&_hbaapi_AE_mutex);
4534 4534 for (acbp = _smhba_adapterevents_callback_list;
4535 4535 acbp != NULL;
4536 4536 acbp = acbp->next) {
4537 4537 if (data == (void *)acbp) {
4538 4538 (*acbp->callback)(acbp->userdata, PortWWN, eventType);
4539 4539 break;
4540 4540 }
4541 4541 }
4542 4542 RELEASE_MUTEX(&_hbaapi_AE_mutex);
4543 4543 }
4544 4544
4545 4545 HBA_STATUS
4546 4546 SMHBA_RegisterForAdapterEvents(
4547 4547 void (*pCallback) (
4548 4548 void *data,
4549 4549 HBA_WWN PortWWN,
4550 4550 HBA_UINT32 eventType),
4551 4551 void *pUserData,
4552 4552 HBA_HANDLE handle,
4553 4553 HBA_CALLBACKHANDLE *pCallbackHandle) {
4554 4554
4555 4555 HBA_ADAPTERCALLBACK_ELEM *acbp;
4556 4556 SMHBARegisterForAdapterEventsFunc registeredfunc;
4557 4557 HBA_STATUS status;
4558 4558 HBA_LIBRARY_INFO *lib_infop;
4559 4559 HBA_HANDLE vendorHandle;
4560 4560
4561 4561 DEBUG(2, "SMHBA_RegisterForAdapterEvents", 0, 0, 0);
4562 4562
4563 4563 CHECKLIBRARYANDVERSION(SMHBA);
4564 4564
4565 4565 /* we now have the _hbaapi_LL_mutex */
4566 4566
4567 4567 registeredfunc = lib_infop->ftable.smhbafunctionTable.\
4568 4568 RegisterForAdapterEventsHandler;
4569 4569 if (registeredfunc == NULL) {
4570 4570 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4571 4571 }
4572 4572
4573 4573 /*
4574 4574 * that allocated memory is used both as the handle for the
4575 4575 * caller, and as userdata to the vendor call so that on
4576 4576 * callback the specific registration may be recalled
4577 4577 */
4578 4578 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4579 4579 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4580 4580 if (acbp == NULL) {
4581 4581 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4582 4582 }
4583 4583 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4584 4584 acbp->callback = pCallback;
4585 4585 acbp->userdata = pUserData;
4586 4586 acbp->lib_info = lib_infop;
4587 4587
4588 4588 status = (registeredfunc)(smhba_adapterevents_callback,
4589 4589 (void *)acbp,
4590 4590 vendorHandle,
4591 4591 &acbp->vendorcbhandle);
4592 4592 if (status != HBA_STATUS_OK) {
4593 4593 free(acbp);
4594 4594 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4595 4595 }
4596 4596
4597 4597 GRAB_MUTEX(&_smhba_AE_mutex);
4598 4598 acbp->next = _smhba_adapterevents_callback_list;
4599 4599 _hbaapi_adapterevents_callback_list = acbp;
4600 4600
4601 4601 RELEASE_MUTEX(&_smhba_AE_mutex);
4602 4602 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4603 4603 }
4604 4604
4605 4605 /* Adapter Port Events *********************************************** */
4606 4606 static void
4607 4607 smhba_adapterportevents_callback(void *data,
4608 4608 HBA_WWN PortWWN,
4609 4609 HBA_UINT32 eventType,
4610 4610 HBA_UINT32 fabricPortID)
4611 4611 {
4612 4612 HBA_ADAPTERCALLBACK_ELEM *acbp;
4613 4613
4614 4614 DEBUG(3,
4615 4615 "SMHBA_AdapterPortEvent, port:%s, eventType:%d fabricPortID:0X%06x",
4616 4616 WWN2STR1(&PortWWN), eventType, fabricPortID);
4617 4617
4618 4618 GRAB_MUTEX(&_smhba_APE_mutex);
4619 4619
4620 4620 for (acbp = _smhba_adapterportevents_callback_list;
4621 4621 acbp != NULL;
4622 4622 acbp = acbp->next) {
4623 4623 if (data == (void *)acbp) {
4624 4624 (*acbp->callback)(acbp->userdata, PortWWN,
4625 4625 eventType, fabricPortID);
4626 4626 break;
4627 4627 }
4628 4628 }
4629 4629 RELEASE_MUTEX(&_smhba_APE_mutex);
4630 4630 }
4631 4631
4632 4632 HBA_STATUS
4633 4633 SMHBA_RegisterForAdapterPortEvents(
4634 4634 void (*pCallback) (
4635 4635 void *pData,
4636 4636 HBA_WWN PortWWN,
4637 4637 HBA_UINT32 eventType,
4638 4638 HBA_UINT32 fabricPortID),
4639 4639 void *pUserData,
4640 4640 HBA_HANDLE handle,
4641 4641 HBA_WWN portWWN,
4642 4642 HBA_UINT32 specificEventType,
4643 4643 HBA_CALLBACKHANDLE *pCallbackHandle) {
4644 4644
4645 4645 HBA_ADAPTERCALLBACK_ELEM *acbp;
4646 4646 SMHBARegisterForAdapterPortEventsFunc registeredfunc;
4647 4647 HBA_STATUS status;
4648 4648 HBA_LIBRARY_INFO *lib_infop;
4649 4649 HBA_HANDLE vendorHandle;
4650 4650
4651 4651 DEBUG(2, "SMHBA_RegisterForAdapterPortEvents for port: %s",
4652 4652 WWN2STR1(&portWWN), 0, 0);
4653 4653
4654 4654 CHECKLIBRARYANDVERSION(SMHBA);
4655 4655 /* we now have the _hbaapi_LL_mutex */
4656 4656
4657 4657 registeredfunc =
4658 4658 lib_infop->ftable.smhbafunctionTable.\
4659 4659 RegisterForAdapterPortEventsHandler;
4660 4660 if (registeredfunc == NULL) {
4661 4661 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4662 4662 }
4663 4663
4664 4664 /*
4665 4665 * that allocated memory is used both as the handle for the
4666 4666 * caller, and as userdata to the vendor call so that on
4667 4667 * callback the specific registration may be recalled
4668 4668 */
4669 4669 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4670 4670 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4671 4671 if (acbp == NULL) {
4672 4672 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4673 4673 }
4674 4674 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4675 4675 acbp->callback = pCallback;
4676 4676 acbp->userdata = pUserData;
4677 4677 acbp->lib_info = lib_infop;
4678 4678
4679 4679 status = (registeredfunc)(smhba_adapterportevents_callback,
4680 4680 (void *)acbp,
4681 4681 vendorHandle,
4682 4682 portWWN,
4683 4683 specificEventType,
4684 4684 &acbp->vendorcbhandle);
4685 4685 if (status != HBA_STATUS_OK) {
4686 4686 free(acbp);
4687 4687 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4688 4688 }
4689 4689
4690 4690 GRAB_MUTEX(&_smhba_APE_mutex);
4691 4691 acbp->next = _smhba_adapterportevents_callback_list;
4692 4692 _smhba_adapterportevents_callback_list = acbp;
4693 4693
4694 4694 RELEASE_MUTEX(&_smhba_APE_mutex);
4695 4695 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4696 4696 }
4697 4697
4698 4698 /* SMHBA Adapter Port Stat Events ******************************** */
4699 4699 static void
4700 4700 smhba_adapterportstatevents_callback(void *data,
4701 4701 HBA_WWN portWWN,
4702 4702 HBA_UINT32 protocolType,
4703 4703 HBA_UINT32 eventType)
4704 4704 {
4705 4705 HBA_ADAPTERCALLBACK_ELEM *acbp;
4706 4706
4707 4707 DEBUG(3,
4708 4708 "SMBA_AdapterPortStateEvent, port:%s, eventType:%d",
4709 4709 WWN2STR1(&portWWN), eventType, 0);
4710 4710
4711 4711 GRAB_MUTEX(&_smhba_APSE_mutex);
4712 4712 for (acbp = _smhba_adapterportstatevents_callback_list;
4713 4713 acbp != NULL;
4714 4714 acbp = acbp->next) {
4715 4715 if (data == (void *)acbp) {
4716 4716 (*acbp->callback)(acbp->userdata, portWWN,
4717 4717 protocolType, eventType);
4718 4718 return;
4719 4719 }
4720 4720 }
4721 4721 RELEASE_MUTEX(&_smhba_APSE_mutex);
4722 4722 }
4723 4723
4724 4724 HBA_STATUS
4725 4725 SMHBA_RegisterForAdapterPortStatEvents(
4726 4726 void (*pCallback) (
4727 4727 void *pData,
4728 4728 HBA_WWN portWWN,
4729 4729 HBA_UINT32 protocolType,
4730 4730 HBA_UINT32 eventType),
4731 4731 void *pUserData,
4732 4732 HBA_HANDLE handle,
4733 4733 HBA_WWN portWWN,
4734 4734 HBA_UINT32 protocolType,
4735 4735 SMHBA_PROTOCOLSTATISTICS stats,
4736 4736 HBA_UINT32 statType,
4737 4737 HBA_CALLBACKHANDLE *pCallbackHandle) {
4738 4738
4739 4739 HBA_ADAPTERCALLBACK_ELEM *acbp;
4740 4740 SMHBARegisterForAdapterPortStatEventsFunc
4741 4741 registeredfunc;
4742 4742 HBA_STATUS status;
4743 4743 HBA_LIBRARY_INFO *lib_infop;
4744 4744 HBA_HANDLE vendorHandle;
4745 4745
4746 4746 DEBUG(2, "SMHBA_RegisterForAdapterPortStatEvents for port: %s",
4747 4747 WWN2STR1(&portWWN), 0, 0);
4748 4748
4749 4749 CHECKLIBRARYANDVERSION(SMHBA);
4750 4750 /* we now have the _hbaapi_LL_mutex */
4751 4751
4752 4752 registeredfunc =
4753 4753 lib_infop->ftable.smhbafunctionTable.\
4754 4754 RegisterForAdapterPortStatEventsHandler;
4755 4755 if (registeredfunc == NULL) {
4756 4756 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4757 4757 }
4758 4758
4759 4759 /*
4760 4760 * that allocated memory is used both as the handle for the
4761 4761 * caller, and as userdata to the vendor call so that on
4762 4762 * callback the specific registration may be recalled
4763 4763 */
4764 4764 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4765 4765 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4766 4766 if (acbp == NULL) {
4767 4767 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4768 4768 }
4769 4769 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4770 4770 acbp->callback = pCallback;
4771 4771 acbp->userdata = pUserData;
4772 4772 acbp->lib_info = lib_infop;
4773 4773
4774 4774 status = (registeredfunc)(smhba_adapterportstatevents_callback,
4775 4775 (void *)acbp,
4776 4776 vendorHandle,
4777 4777 portWWN,
4778 4778 protocolType,
4779 4779 stats,
4780 4780 statType,
4781 4781 &acbp->vendorcbhandle);
4782 4782 if (status != HBA_STATUS_OK) {
4783 4783 free(acbp);
4784 4784 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4785 4785 }
4786 4786
4787 4787 GRAB_MUTEX(&_smhba_APSE_mutex);
4788 4788 acbp->next = _smhba_adapterportstatevents_callback_list;
4789 4789 _smhba_adapterportstatevents_callback_list = acbp;
4790 4790
4791 4791 RELEASE_MUTEX(&_smhba_APSE_mutex);
4792 4792 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4793 4793 }
4794 4794
4795 4795 /* SMHBA Adapter Port Phy Stat Events ************************************ */
4796 4796 static void
4797 4797 smhba_adapterphystatevents_callback(void *data,
4798 4798 HBA_WWN portWWN,
4799 4799 HBA_UINT32 phyIndex,
4800 4800 HBA_UINT32 eventType)
4801 4801 {
4802 4802 HBA_ADAPTERCALLBACK_ELEM *acbp;
4803 4803
4804 4804 DEBUG(3,
4805 4805 "SMBA_AdapterPortStateEvent, port:%s, eventType:%d",
4806 4806 WWN2STR1(&portWWN), eventType, 0);
4807 4807
4808 4808 GRAB_MUTEX(&_smhba_APHYSE_mutex);
4809 4809 for (acbp = _smhba_adapterphystatevents_callback_list;
4810 4810 acbp != NULL;
4811 4811 acbp = acbp->next) {
4812 4812 if (data == (void *)acbp) {
4813 4813 (*acbp->callback)(acbp->userdata, portWWN, phyIndex, eventType);
4814 4814 return;
4815 4815 }
4816 4816 }
4817 4817 RELEASE_MUTEX(&_smhba_APHYSE_mutex);
4818 4818 }
4819 4819
4820 4820 HBA_STATUS
4821 4821 SMHBA_RegisterForAdapterPhyStatEvents(
4822 4822 void (*pCallback) (
4823 4823 void *pData,
4824 4824 HBA_WWN portWWN,
4825 4825 HBA_UINT32 phyIndex,
4826 4826 HBA_UINT32 eventType),
4827 4827 void *pUserData,
4828 4828 HBA_HANDLE handle,
4829 4829 HBA_WWN portWWN,
4830 4830 HBA_UINT32 phyIndex,
4831 4831 SMHBA_PHYSTATISTICS stats,
4832 4832 HBA_UINT32 statType,
4833 4833 HBA_CALLBACKHANDLE *pCallbackHandle) {
4834 4834
4835 4835 HBA_ADAPTERCALLBACK_ELEM *acbp;
4836 4836 SMHBARegisterForAdapterPhyStatEventsFunc
4837 4837 registeredfunc;
4838 4838 HBA_STATUS status;
4839 4839 HBA_LIBRARY_INFO *lib_infop;
4840 4840 HBA_HANDLE vendorHandle;
4841 4841
4842 4842 DEBUG(2, "SMHBA_RegisterForAdapterPhyStatEvents for port: %s",
4843 4843 WWN2STR1(&portWWN), 0, 0);
4844 4844
4845 4845 CHECKLIBRARYANDVERSION(SMHBA);
4846 4846 /* we now have the _hbaapi_LL_mutex */
4847 4847
4848 4848 registeredfunc =
4849 4849 lib_infop->ftable.smhbafunctionTable.\
4850 4850 RegisterForAdapterPhyStatEventsHandler;
4851 4851 if (registeredfunc == NULL) {
4852 4852 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4853 4853 }
4854 4854
4855 4855 /*
4856 4856 * that allocated memory is used both as the handle for the
4857 4857 * caller, and as userdata to the vendor call so that on
4858 4858 * callback the specific registration may be recalled
4859 4859 */
4860 4860 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4861 4861 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4862 4862 if (acbp == NULL) {
4863 4863 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4864 4864 }
4865 4865 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4866 4866 acbp->callback = pCallback;
4867 4867 acbp->userdata = pUserData;
4868 4868 acbp->lib_info = lib_infop;
4869 4869
4870 4870 status = (registeredfunc)(smhba_adapterphystatevents_callback,
4871 4871 (void *)acbp,
4872 4872 vendorHandle,
4873 4873 portWWN,
4874 4874 phyIndex,
4875 4875 stats,
4876 4876 statType,
4877 4877 &acbp->vendorcbhandle);
4878 4878 if (status != HBA_STATUS_OK) {
4879 4879 free(acbp);
4880 4880 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4881 4881 }
4882 4882
4883 4883 GRAB_MUTEX(&_smhba_APHYSE_mutex);
4884 4884 acbp->next = _smhba_adapterphystatevents_callback_list;
4885 4885 _smhba_adapterphystatevents_callback_list = acbp;
4886 4886
4887 4887 RELEASE_MUTEX(&_smhba_APHYSE_mutex);
4888 4888 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4889 4889 }
4890 4890
4891 4891 /* SMHBA Target Events ********************************************* */
4892 4892 static void
4893 4893 smhba_targetevents_callback(void *data,
4894 4894 HBA_WWN hbaPortWWN,
4895 4895 HBA_WWN discoveredPortWWN,
4896 4896 HBA_WWN domainPortWWN,
4897 4897 HBA_UINT32 eventType)
4898 4898 {
4899 4899 HBA_ADAPTERCALLBACK_ELEM *acbp;
4900 4900
4901 4901 DEBUG(3, "TargetEvent, hbaPort:%s, discoveredPort:%s eventType:%d",
4902 4902 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), eventType);
4903 4903
4904 4904 GRAB_MUTEX(&_smhba_TE_mutex);
4905 4905 for (acbp = _smhba_targetevents_callback_list;
4906 4906 acbp != NULL;
4907 4907 acbp = acbp->next) {
4908 4908 if (data == (void *)acbp) {
4909 4909 (*acbp->callback)(acbp->userdata, hbaPortWWN,
4910 4910 discoveredPortWWN, domainPortWWN, eventType);
4911 4911 break;
4912 4912 }
4913 4913 }
4914 4914 RELEASE_MUTEX(&_smhba_TE_mutex);
4915 4915 }
4916 4916
4917 4917 HBA_STATUS
4918 4918 SMHBA_RegisterForTargetEvents(
4919 4919 void (*pCallback) (
4920 4920 void *pData,
4921 4921 HBA_WWN hbaPortWWN,
4922 4922 HBA_WWN discoveredPortWWN,
4923 4923 HBA_WWN domainPortWWN,
4924 4924 HBA_UINT32 eventType),
4925 4925 void *pUserData,
4926 4926 HBA_HANDLE handle,
4927 4927 HBA_WWN hbaPortWWN,
4928 4928 HBA_WWN discoveredPortWWN,
4929 4929 HBA_WWN domainPortWWN,
4930 4930 HBA_CALLBACKHANDLE *pCallbackHandle,
4931 4931 HBA_UINT32 allTargets) {
4932 4932
4933 4933 HBA_ADAPTERCALLBACK_ELEM *acbp;
4934 4934 SMHBARegisterForTargetEventsFunc
4935 4935 registeredfunc;
4936 4936 HBA_STATUS status;
4937 4937 HBA_LIBRARY_INFO *lib_infop;
4938 4938 HBA_HANDLE vendorHandle;
4939 4939
4940 4940 DEBUG(2, "SMHBA_RegisterForTargetEvents, hbaPort:"
4941 4941 "%s, discoveredPort: %s",
4942 4942 WWN2STR1(&hbaPortWWN), WWN2STR2(&discoveredPortWWN), 0);
4943 4943
4944 4944 CHECKLIBRARYANDVERSION(SMHBA);
4945 4945 /* we now have the _hbaapi_LL_mutex */
4946 4946
4947 4947 registeredfunc = lib_infop->ftable.smhbafunctionTable.\
4948 4948 RegisterForTargetEventsHandler;
4949 4949
4950 4950 if (registeredfunc == NULL) {
4951 4951 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED);
4952 4952 }
4953 4953
4954 4954 /*
4955 4955 * that allocated memory is used both as the handle for the
4956 4956 * caller, and as userdata to the vendor call so that on
4957 4957 * callback the specific registration may be recalled
4958 4958 */
4959 4959 acbp = (HBA_ADAPTERCALLBACK_ELEM *)
4960 4960 calloc(1, sizeof (HBA_ADAPTERCALLBACK_ELEM));
4961 4961 if (acbp == NULL) {
4962 4962 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR);
4963 4963 }
4964 4964 *pCallbackHandle = (HBA_CALLBACKHANDLE) acbp;
4965 4965 acbp->callback = pCallback;
4966 4966 acbp->userdata = pUserData;
4967 4967 acbp->lib_info = lib_infop;
4968 4968
4969 4969 status = (registeredfunc)(smhba_targetevents_callback,
4970 4970 (void *)acbp,
4971 4971 vendorHandle,
4972 4972 hbaPortWWN,
4973 4973 discoveredPortWWN,
4974 4974 domainPortWWN,
4975 4975 &acbp->vendorcbhandle,
4976 4976 allTargets);
4977 4977 if (status != HBA_STATUS_OK) {
4978 4978 free(acbp);
4979 4979 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status);
4980 4980 }
4981 4981
4982 4982 GRAB_MUTEX(&_smhba_TE_mutex);
4983 4983 acbp->next = _smhba_targetevents_callback_list;
4984 4984 _smhba_targetevents_callback_list = acbp;
4985 4985
4986 4986 RELEASE_MUTEX(&_smhba_TE_mutex);
4987 4987 RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK);
4988 4988 }
↓ open down ↓ |
646 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX