/*************************************************************************
* Description
* HBAAPILIB-sun.c - Implements the Sun Extention for Target mode
* FCHBA discovery
*
* License:
* The contents of this file are subject to the SNIA Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
*************************************************************************
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifdef WIN32
#include <windows.h>
#include <string.h>
/*
* Next define forces entry points in the dll to be exported
* See hbaapi.h to see what it does.
*/
#define HBAAPI_EXPORTS
#else
#include <dlfcn.h>
#include <strings.h>
#endif
#include <stdio.h>
#include <time.h>
#include <dlfcn.h>
#include "hbaapi.h"
#include "hbaapi-sun.h"
#include "vendorhbaapi.h"
#include <stdlib.h>
#ifdef USESYSLOG
#include <syslog.h>
#endif
/*
* LIBRARY_NUM is a shortcut to figure out which library we need to call.
* The top 16 bits of handle are the library index
*/
/*
* VENDOR_HANDLE turns a global library handle into a vendor specific handle,
* with all upper 16 bits set to 0
*/
extern int _hbaapi_debuglevel;
#if defined(USESYSLOG) && defined(USELOGFILE)
extern FILE *_hbaapi_debug_fd;
extern int _hbaapi_sysloginit;
#ifdef WIN32
if ((L) <= _hbaapi_debuglevel) {\
if(_hbaapi_sysloginit == 0) {\
_hbaapi_sysloginit = 1;\
}\
if(_hbaapi_debug_fd == NULL) {\
}\
if(_hbaapi_debug_fd != NULL) {\
}\
}
#else /* WIN32*/
if ((L) <= _hbaapi_debuglevel) {\
if(_hbaapi_sysloginit == 0) {\
_hbaapi_sysloginit = 1;\
}\
if(_hbaapi_debug_fd == NULL) {\
}\
if(_hbaapi_debug_fd != NULL) {\
}\
}
#endif /* WIN32*/
#else /* Not both USESYSLOG and USELOGFILE */
#if defined(USESYSLOG)
int _hbaapi_sysloginit = 0;
if ((L) <= _hbaapi_debuglevel) {\
if(_hbaapi_sysloginit == 0) {\
_hbaapi_sysloginit = 1;\
}\
}
#endif /* USESYSLOG */
#if defined(USELOGFILE)
#ifdef WIN32
if((L) <= _hbaapi_debuglevel) {\
if(_hbaapi_debug_fd == NULL) {\
}\
}
#else /* WIN32 */
if((L) <= _hbaapi_debuglevel) {\
if(_hbaapi_debug_fd == NULL) {\
}\
if(_hbaapi_debug_fd != NULL) { \
}\
}
#endif /* WIN32 */
#endif /* USELOGFILE */
#endif /* Not both USELOGFILE and USESYSLOG */
#ifdef POSIX_THREADS
#include <pthread.h>
/*
* When multiple mutex's are grabed, they must be always be grabbed in
* the same order, or deadlock can result. There are three levels
* of mutex's involved in this API. If LL_mutex is grabbed, always grap
* it first. If AL_mutex is grabbed, it may not be grabbed before
* LL_mutex. If grabbed in a multi grab sequence, the mutex's protecting
* the callback lists must always be grabbed last and release before calling
* a vendor specific library function that might invoke a callback function
* on the same thread.
*/
#else
#define GRAB_MUTEX(M)
#define RELEASE_MUTEX(M)
#endif
/*
* HBA_LIBRARY_STATUS and HBA_LIBRARY_INFO are redefined here.
* Avoid any change in the common code.
*/
typedef enum {
typedef struct hba_library_info {
struct hba_library_info
*next;
#ifdef WIN32
#else
char *LibraryName;
#endif
char *LibraryPath;
#define ARE_WE_INITED() \
if (_hbaapi_librarylist == NULL) { \
return(HBA_STATUS_ERROR); \
}
extern HBA_LIBRARY_INFO *_hbaapi_librarylist;
#ifdef POSIX_THREADS
extern pthread_mutex_t _hbaapi_LL_mutex;
extern CRITICAL_SECTION _hbaapi_LL_mutex;
#endif
/*
* Function type def fop Sun extentions.
*/
(HBA_HANDLE *, HBA_WWN);
/*
* Individual adapter (hba) information
* Same as hbaadapter with different structure name.
*/
typedef struct hba_tgtadapter_info {
struct hba_tgtadapter_info
*next;
char *name;
/*
* Make the list as an array with max size 16
*/
#ifdef POSIX_THREADS
#endif
/*
* Common library internal. Mutex handling
*/
#ifdef POSIX_THREADS
static void
int ret;
perror("pthread_mutex_lock - HBAAPI:");
}
}
static void
int ret;
perror("pthread_mutex_unlock - HBAAPI:");
}
}
#endif
/*
* The API used to use fixed size tables as its primary data structure.
* Indexing from 1 to N identified each adapters. Now the adapters are
* on a linked list. There is a unique "index" foreach each adapter.
* Adapters always keep their index, even if they are removed from the
* hardware. The only time the indexing is reset is on HBA_FreeLibrary
*/
{
int j=0;
if(_hbaapi_librarylist == NULL) {
return (0);
}
for (lib_infop = _hbaapi_librarylist;
continue;
}
if (GetNumberOfTgtAdaptersFunc == NULL ||
GetTgtAdapterNameFunc == NULL) {
continue;
}
} else {
continue;
}
num_adapters = ((GetNumberOfTgtAdaptersFunc)());
#ifndef WIN32
#else
#endif
for (j = 0; j < num_adapters; j++) {
found_name = 0;
if(status == HBA_STATUS_OK) {
adapt_infop != NULL;
/*
* check for duplicates, really, this may just be a second
* call to this function
* ??? how do we know when a name becomes stale?
*/
/* already got this one */
found_name++;
break;
}
}
if(found_name != 0) {
continue;
}
}
if(adapt_infop == NULL) {
#ifndef WIN32
"HBA_GetNumberOfAdapters: calloc failed on sizeof:%d\n",
sizeof(HBA_TGTADAPTER_INFO));
#endif
}
} else {
}
}
}
}
char *adaptername)
{
if (adaptername == NULL) {
return(HBA_STATUS_ERROR_ARG);
}
/*
* The adapter index is from old code, but we have
* to support it. Go down the list looking for
* the adapter
*/
*adaptername = '\0';
adapt_infop != NULL;
} else {
*adaptername = '\0';
}
break;
}
}
}
{
if(_hbaapi_librarylist == NULL) {
return(HBA_HANDLE_INVALID);
}
if (adaptername == NULL) {
return(HBA_STATUS_ERROR_ARG);
}
adapt_infop != NULL;
continue;
}
if (OpenTgtAdapterFunc != NULL) {
/* retrieve the vendor handle */
if(handle != 0) {
/* or this with the library index to get the common handle */
}
}
break;
}
}
/*
* This function ignores the list of known adapters and instead tries
* each vendors open function to see if one of them
* can open an adapter when referenced with a particular WWN
*/
{
return(HBA_STATUS_ERROR_ARG);
}
for (lib_infop = _hbaapi_librarylist;
continue;
}
if (GetNumberOfTgtAdaptersFunc == NULL ||
OpenTgtAdapterByWWNFunc == NULL) {
continue;
}
(void) ((GetNumberOfTgtAdaptersFunc)());
!= HBA_STATUS_OK) {
continue;
}
/* OK, make a vendor non-specific handle */
break;
}
}
static HBA_STATUS
if (vendorhandle == NULL) {
return(HBA_STATUS_ERROR_ARG);
}
if(_hbaapi_librarylist == NULL) {
return(HBA_STATUS_ERROR);
}
for(lib_infop = _hbaapi_librarylist;
return HBA_STATUS_ERROR;
}
*lib_infopp = lib_infop;
/* caller will release the mutex */
return HBA_STATUS_OK;
}
}
}
#define NPIVCHECKLIBRARY() \
if(status != HBA_STATUS_OK) { \
return(status); \
}
{
if (NPIVGetAdapterAttributesFunc != NULL) {
} else {
}
}
{
if (GetNPIVPortInfoFunc != NULL) {
vportindex, attributes));
} else {
}
}
{
if (DeleteNPIVPortFunc != NULL) {
} else {
}
}
{
if (CreateNPIVPortFunc != NULL) {
} else {
}
}
{
if (GetPortNPIVAttributesFunc != NULL) {
} else {
}
}
{
if (AdapterCreateWWNFunc != NULL) {
} else {
}
}
{
if (AdapterReturnWWNFunc != NULL) {
} else {
}
}
typedef struct hba_npivadaptercallback_elem {
struct hba_npivadaptercallback_elem
*next;
void *userdata;
void (*callback)();
/* Adapter Device Events ********************************************************/
static void
{
break;
}
}
}
void (*callback) (
void *data,
),
void *userData,
{
if (callbackHandle == NULL) {
return(HBA_STATUS_ERROR_ARG);
}
"Sun_fcRegisterForAdapterDeviceEvents");
if (registeredfunc == NULL) {
}
}
(void *)acbp,
&acbp->vendorcbhandle);
if(status != HBA_STATUS_OK) {
}
}
{
if (DoForceLipFunc != NULL) {
} else {
}
}