HBAAPILIB-sun.c revision fcf3ce441efd61da9bb2884968af01cb7c1452cc
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/*************************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Description
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * HBAAPILIB-sun.c - Implements the Sun Extention for Target mode
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * FCHBA discovery
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * License:
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin * The contents of this file are subject to the SNIA Public License
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Version 1.0 (the "License"); you may not use this file except in
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * compliance with the License. You may obtain a copy of the License at
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * /http://www.snia.org/English/Resources/Code/OpenSource.html
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Software distributed under the License is distributed on an "AS IS"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the License for the specific language governing rights and limitations
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin *************************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Next define forces entry points in the dll to be exported
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * See hbaapi.h to see what it does.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * LIBRARY_NUM is a shortcut to figure out which library we need to call.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * The top 16 bits of handle are the library index
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * VENDOR_HANDLE turns a global library handle into a vendor specific handle,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * with all upper 16 bits set to 0
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((L) <= _hbaapi_debuglevel) {\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fprintf(_hbaapi_debug_fd, (STR ## "\n"), (A1), (A2), (A3));\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else /* WIN32*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((L) <= _hbaapi_debuglevel) {\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fprintf(_hbaapi_debug_fd, (STR ## "\n"), (A1), (A2), (A3));\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* WIN32*/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else /* Not both USESYSLOG and USELOGFILE */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((L) <= _hbaapi_debuglevel) {\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* USESYSLOG */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#else /* WIN32 */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fprintf(_hbaapi_debug_fd, (STR) ## "\n", (A1), (A2), (A3));\
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* WIN32 */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* USELOGFILE */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#endif /* Not both USELOGFILE and USESYSLOG */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * When multiple mutex's are grabed, they must be always be grabbed in
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the same order, or deadlock can result. There are three levels
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * of mutex's involved in this API. If LL_mutex is grabbed, always grap
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * it first. If AL_mutex is grabbed, it may not be grabbed before
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * LL_mutex. If grabbed in a multi grab sequence, the mutex's protecting
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * the callback lists must always be grabbed last and release before calling
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * a vendor specific library function that might invoke a callback function
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * on the same thread.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define RELEASE_MUTEX_RETURN(M,RET) release_mutex(M); return(RET)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define RELEASE_MUTEX_RETURN(m, RET) LeaveCriticalSection(m); return(RET)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * HBA_LIBRARY_STATUS and HBA_LIBRARY_INFO are redefined here.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Avoid any change in the common code.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef enum {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct hba_library_info {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin HBA_ENTRYPOINTSV2 functionTable; /* Function pointers */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Function type def fop Sun extentions.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef HBA_UINT32 (* Sun_HBAGetNumberOfTgtAdaptersFunc)();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef HBA_STATUS (* Sun_HBAGetTgtAdapterNameFunc)(HBA_UINT32, char *);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef HBA_HANDLE (* Sun_HBAOpenTgtAdapterFunc)(char *);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef HBA_STATUS (* Sun_HBANPIVGetAdapterAttributesFunc)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (HBA_HANDLE, HBA_UINT32, HBA_UINT32, HBA_NPIVATTRIBUTES *);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (HBA_HANDLE, HBA_UINT32, HBA_WWN, HBA_WWN, HBA_UINT32 *);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin (HBA_HANDLE, HBA_UINT32, HBA_WWN *, HBA_WWN *, HBA_WWN *,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef HBA_STATUS (* Sun_HBARegisterForAdapterDeviceEventsFunc)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Individual adapter (hba) information
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Same as hbaadapter with different structure name.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chintypedef struct hba_tgtadapter_info {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin HBA_STATUS GNstatus; /* status from GetTgtAdapterNameFunc */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Make the list as an array with max size 16
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinpthread_mutex_t _hbaapi_tgtAL_mutex = PTHREAD_MUTEX_INITIALIZER;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Common library internal. Mutex handling
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin DEBUG(0, "pthread_mutex_unlock returned %d", ret, 0, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * The API used to use fixed size tables as its primary data structure.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Indexing from 1 to N identified each adapters. Now the adapters are
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * on a linked list. There is a unique "index" foreach each adapter.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Adapters always keep their index, even if they are removed from the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * hardware. The only time the indexing is reset is on HBA_FreeLibrary
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return (0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin GRAB_MUTEX(&_hbaapi_LL_mutex); /* pay attention to order */
#ifndef WIN32
for (j = 0; j < num_adapters; j++) {
found_name = 0;
found_name++;
if(found_name != 0) {
#ifndef WIN32
sizeof(HBA_TGTADAPTER_INFO));
char *adaptername)
return(HBA_STATUS_ERROR_ARG);
return(HBA_HANDLE_INVALID);
return(HBA_STATUS_ERROR_ARG);
if(handle != 0) {
return(HBA_STATUS_ERROR_ARG);
(void) ((GetNumberOfTgtAdaptersFunc)());
!= HBA_STATUS_OK) {
static HBA_STATUS
return(HBA_STATUS_ERROR_ARG);
return(HBA_STATUS_ERROR);
return HBA_STATUS_ERROR;
return HBA_STATUS_OK;
#define NPIVCHECKLIBRARY() \
return(status); \
typedef struct hba_npivadaptercallback_elem {
struct hba_npivadaptercallback_elem
*next;
void *userdata;
void (*callback)();
void (*callback) (
void *data,
void *userData,
return(HBA_STATUS_ERROR_ARG);
(void *)acbp,