1fcf3ce44SJohn Forte /************************************************************************* 2fcf3ce44SJohn Forte * Description 3fcf3ce44SJohn Forte * HBAAPILIB-sun.c - Implements the Sun Extention for Target mode 4fcf3ce44SJohn Forte * FCHBA discovery 5fcf3ce44SJohn Forte * 6fcf3ce44SJohn Forte * License: 7fcf3ce44SJohn Forte * The contents of this file are subject to the SNIA Public License 8fcf3ce44SJohn Forte * Version 1.0 (the "License"); you may not use this file except in 9fcf3ce44SJohn Forte * compliance with the License. You may obtain a copy of the License at 10fcf3ce44SJohn Forte * 11*bff3dadcSduo liu - Sun Microsystems - Beijing China * http://www.snia.org/English/Resources/Code/OpenSource.html 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * Software distributed under the License is distributed on an "AS IS" 14fcf3ce44SJohn Forte * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 15fcf3ce44SJohn Forte * the License for the specific language governing rights and limitations 16fcf3ce44SJohn Forte * under the License. 17fcf3ce44SJohn Forte * 18fcf3ce44SJohn Forte ************************************************************************* 19fcf3ce44SJohn Forte */ 20*bff3dadcSduo liu - Sun Microsystems - Beijing China /* 21*bff3dadcSduo liu - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 22*bff3dadcSduo liu - Sun Microsystems - Beijing China * Use is subject to license terms. 23*bff3dadcSduo liu - Sun Microsystems - Beijing China */ 24fcf3ce44SJohn Forte 25fcf3ce44SJohn Forte #ifdef WIN32 26fcf3ce44SJohn Forte #include <windows.h> 27fcf3ce44SJohn Forte #include <string.h> 28fcf3ce44SJohn Forte /* 29fcf3ce44SJohn Forte * Next define forces entry points in the dll to be exported 30fcf3ce44SJohn Forte * See hbaapi.h to see what it does. 31fcf3ce44SJohn Forte */ 32fcf3ce44SJohn Forte #define HBAAPI_EXPORTS 33fcf3ce44SJohn Forte #else 34fcf3ce44SJohn Forte #include <dlfcn.h> 35fcf3ce44SJohn Forte #include <strings.h> 36fcf3ce44SJohn Forte #endif 37fcf3ce44SJohn Forte #include <stdio.h> 38fcf3ce44SJohn Forte #include <time.h> 39fcf3ce44SJohn Forte #include <dlfcn.h> 40fcf3ce44SJohn Forte #include "hbaapi.h" 41fcf3ce44SJohn Forte #include "hbaapi-sun.h" 42fcf3ce44SJohn Forte #include "vendorhbaapi.h" 43fcf3ce44SJohn Forte #include <stdlib.h> 44fcf3ce44SJohn Forte #ifdef USESYSLOG 45fcf3ce44SJohn Forte #include <syslog.h> 46fcf3ce44SJohn Forte #endif 47fcf3ce44SJohn Forte 48fcf3ce44SJohn Forte 49fcf3ce44SJohn Forte /* 50fcf3ce44SJohn Forte * LIBRARY_NUM is a shortcut to figure out which library we need to call. 51fcf3ce44SJohn Forte * The top 16 bits of handle are the library index 52fcf3ce44SJohn Forte */ 53fcf3ce44SJohn Forte #define LIBRARY_NUM(handle) ((handle)>>16) 54fcf3ce44SJohn Forte 55fcf3ce44SJohn Forte /* 56fcf3ce44SJohn Forte * VENDOR_HANDLE turns a global library handle into a vendor specific handle, 57fcf3ce44SJohn Forte * with all upper 16 bits set to 0 58fcf3ce44SJohn Forte */ 59fcf3ce44SJohn Forte #define VENDOR_HANDLE(handle) ((handle)&0xFFFF) 60fcf3ce44SJohn Forte 61fcf3ce44SJohn Forte #define HBA_HANDLE_FROM_LOCAL(library, vendor) \ 62fcf3ce44SJohn Forte (((library)<<16) | ((vendor)&0x0000FFFF)) 63fcf3ce44SJohn Forte 64fcf3ce44SJohn Forte extern int _hbaapi_debuglevel; 65fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) 66fcf3ce44SJohn Forte 67fcf3ce44SJohn Forte #if defined(USESYSLOG) && defined(USELOGFILE) 68fcf3ce44SJohn Forte extern FILE *_hbaapi_debug_fd; 69fcf3ce44SJohn Forte extern int _hbaapi_sysloginit; 70fcf3ce44SJohn Forte #undef DEBUG 71fcf3ce44SJohn Forte #ifdef WIN32 72fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3)\ 73fcf3ce44SJohn Forte if ((L) <= _hbaapi_debuglevel) {\ 74fcf3ce44SJohn Forte if(_hbaapi_sysloginit == 0) {\ 75fcf3ce44SJohn Forte openlog("HBAAPI", LOG_PID|LOG_ODELAY ,LOG_USER);\ 76fcf3ce44SJohn Forte _hbaapi_sysloginit = 1;\ 77fcf3ce44SJohn Forte }\ 78fcf3ce44SJohn Forte syslog (LOG_INFO, (STR), (A1), (A2), (A3));\ 79fcf3ce44SJohn Forte if(_hbaapi_debug_fd == NULL) {\ 80fcf3ce44SJohn Forte char _logFile[MAX_PATH]; \ 81fcf3ce44SJohn Forte GetTempPath(MAX_PATH, _logFile); \ 82fcf3ce44SJohn Forte strcat(_logFile, "HBAAPI.log"); \ 83fcf3ce44SJohn Forte _hbaapi_debug_fd = fopen(_logFile, "a");\ 84fcf3ce44SJohn Forte }\ 85fcf3ce44SJohn Forte if(_hbaapi_debug_fd != NULL) {\ 86fcf3ce44SJohn Forte fprintf(_hbaapi_debug_fd, (STR ## "\n"), (A1), (A2), (A3));\ 87fcf3ce44SJohn Forte }\ 88fcf3ce44SJohn Forte } 89fcf3ce44SJohn Forte #else /* WIN32*/ 90fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3)\ 91fcf3ce44SJohn Forte if ((L) <= _hbaapi_debuglevel) {\ 92fcf3ce44SJohn Forte if(_hbaapi_sysloginit == 0) {\ 93fcf3ce44SJohn Forte openlog("HBAAPI", LOG_PID|LOG_ODELAY ,LOG_USER);\ 94fcf3ce44SJohn Forte _hbaapi_sysloginit = 1;\ 95fcf3ce44SJohn Forte }\ 96fcf3ce44SJohn Forte syslog (LOG_INFO, (STR), (A1), (A2), (A3));\ 97fcf3ce44SJohn Forte if(_hbaapi_debug_fd == NULL) {\ 98fcf3ce44SJohn Forte _hbaapi_debug_fd = fopen("/tmp/HBAAPI.log", "a");\ 99fcf3ce44SJohn Forte }\ 100fcf3ce44SJohn Forte if(_hbaapi_debug_fd != NULL) {\ 101fcf3ce44SJohn Forte fprintf(_hbaapi_debug_fd, (STR ## "\n"), (A1), (A2), (A3));\ 102fcf3ce44SJohn Forte }\ 103fcf3ce44SJohn Forte } 104fcf3ce44SJohn Forte #endif /* WIN32*/ 105fcf3ce44SJohn Forte 106fcf3ce44SJohn Forte #else /* Not both USESYSLOG and USELOGFILE */ 107fcf3ce44SJohn Forte #if defined(USESYSLOG) 108fcf3ce44SJohn Forte int _hbaapi_sysloginit = 0; 109fcf3ce44SJohn Forte #undef DEBUG 110fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) \ 111fcf3ce44SJohn Forte if ((L) <= _hbaapi_debuglevel) {\ 112fcf3ce44SJohn Forte if(_hbaapi_sysloginit == 0) {\ 113fcf3ce44SJohn Forte openlog("HBAAPI", LOG_PID|LOG_ODELAY ,LOG_USER);\ 114fcf3ce44SJohn Forte _hbaapi_sysloginit = 1;\ 115fcf3ce44SJohn Forte }\ 116fcf3ce44SJohn Forte syslog (LOG_INFO, (STR), (A1), (A2), (A3));\ 117fcf3ce44SJohn Forte } 118fcf3ce44SJohn Forte #endif /* USESYSLOG */ 119fcf3ce44SJohn Forte #if defined(USELOGFILE) 120fcf3ce44SJohn Forte FILE *_hbaapi_debug_fd = NULL; 121fcf3ce44SJohn Forte #undef DEBUG 122fcf3ce44SJohn Forte #ifdef WIN32 123fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) \ 124fcf3ce44SJohn Forte if((L) <= _hbaapi_debuglevel) {\ 125fcf3ce44SJohn Forte if(_hbaapi_debug_fd == NULL) {\ 126fcf3ce44SJohn Forte char _logFile[MAX_PATH]; \ 127fcf3ce44SJohn Forte GetTempPath(MAX_PATH, _logFile); \ 128fcf3ce44SJohn Forte strcat(_logFile, "HBAAPI.log"); \ 129fcf3ce44SJohn Forte _hbaapi_debug_fd = fopen(_logFile, "a");\ 130fcf3ce44SJohn Forte }\ 131fcf3ce44SJohn Forte } 132fcf3ce44SJohn Forte #else /* WIN32 */ 133fcf3ce44SJohn Forte #define DEBUG(L, STR, A1, A2, A3) \ 134fcf3ce44SJohn Forte if((L) <= _hbaapi_debuglevel) {\ 135fcf3ce44SJohn Forte if(_hbaapi_debug_fd == NULL) {\ 136fcf3ce44SJohn Forte _hbaapi_debug_fd = fopen("/tmp/HBAAPI.log", "a");\ 137fcf3ce44SJohn Forte }\ 138fcf3ce44SJohn Forte if(_hbaapi_debug_fd != NULL) { \ 139fcf3ce44SJohn Forte fprintf(_hbaapi_debug_fd, (STR) ## "\n", (A1), (A2), (A3));\ 140fcf3ce44SJohn Forte }\ 141fcf3ce44SJohn Forte } 142fcf3ce44SJohn Forte #endif /* WIN32 */ 143fcf3ce44SJohn Forte #endif /* USELOGFILE */ 144fcf3ce44SJohn Forte #endif /* Not both USELOGFILE and USESYSLOG */ 145fcf3ce44SJohn Forte 146fcf3ce44SJohn Forte #ifdef POSIX_THREADS 147fcf3ce44SJohn Forte #include <pthread.h> 148fcf3ce44SJohn Forte /* 149fcf3ce44SJohn Forte * When multiple mutex's are grabed, they must be always be grabbed in 150fcf3ce44SJohn Forte * the same order, or deadlock can result. There are three levels 151fcf3ce44SJohn Forte * of mutex's involved in this API. If LL_mutex is grabbed, always grap 152fcf3ce44SJohn Forte * it first. If AL_mutex is grabbed, it may not be grabbed before 153fcf3ce44SJohn Forte * LL_mutex. If grabbed in a multi grab sequence, the mutex's protecting 154fcf3ce44SJohn Forte * the callback lists must always be grabbed last and release before calling 155fcf3ce44SJohn Forte * a vendor specific library function that might invoke a callback function 156fcf3ce44SJohn Forte * on the same thread. 157fcf3ce44SJohn Forte */ 158fcf3ce44SJohn Forte #define GRAB_MUTEX(M) grab_mutex(M) 159fcf3ce44SJohn Forte #define RELEASE_MUTEX(M) release_mutex(M) 160fcf3ce44SJohn Forte #define RELEASE_MUTEX_RETURN(M,RET) release_mutex(M); return(RET) 161fcf3ce44SJohn Forte #elif defined (WIN32) 162fcf3ce44SJohn Forte #define GRAB_MUTEX(m) EnterCriticalSection(m) 163fcf3ce44SJohn Forte #define RELEASE_MUTEX(m) LeaveCriticalSection(m) 164fcf3ce44SJohn Forte #define RELEASE_MUTEX_RETURN(m, RET) LeaveCriticalSection(m); return(RET) 165fcf3ce44SJohn Forte #else 166fcf3ce44SJohn Forte #define GRAB_MUTEX(M) 167fcf3ce44SJohn Forte #define RELEASE_MUTEX(M) 168fcf3ce44SJohn Forte #define RELEASE_MUTEX_RETURN(M,RET) return(RET) 169fcf3ce44SJohn Forte #endif 170fcf3ce44SJohn Forte 171fcf3ce44SJohn Forte /* 172fcf3ce44SJohn Forte * HBA_LIBRARY_STATUS and HBA_LIBRARY_INFO are redefined here. 173fcf3ce44SJohn Forte * Avoid any change in the common code. 174fcf3ce44SJohn Forte */ 175fcf3ce44SJohn Forte typedef enum { 176fcf3ce44SJohn Forte HBA_LIBRARY_UNKNOWN, 177fcf3ce44SJohn Forte HBA_LIBRARY_LOADED, 178fcf3ce44SJohn Forte HBA_LIBRARY_NOT_LOADED 179fcf3ce44SJohn Forte } HBA_LIBRARY_STATUS; 180fcf3ce44SJohn Forte 181fcf3ce44SJohn Forte typedef struct hba_library_info { 182fcf3ce44SJohn Forte struct hba_library_info 183fcf3ce44SJohn Forte *next; 184fcf3ce44SJohn Forte #ifdef WIN32 185fcf3ce44SJohn Forte HINSTANCE hLibrary; /* Handle to a loaded DLL */ 186fcf3ce44SJohn Forte #else 187fcf3ce44SJohn Forte char *LibraryName; 188fcf3ce44SJohn Forte void* hLibrary; /* Handle to a loaded DLL */ 189fcf3ce44SJohn Forte #endif 190fcf3ce44SJohn Forte char *LibraryPath; 191fcf3ce44SJohn Forte HBA_ENTRYPOINTSV2 functionTable; /* Function pointers */ 192fcf3ce44SJohn Forte HBA_LIBRARY_STATUS status; /* info on this library */ 193fcf3ce44SJohn Forte HBA_UINT32 index; 194fcf3ce44SJohn Forte } HBA_LIBRARY_INFO, *PHBA_LIBRARY_INFO; 195fcf3ce44SJohn Forte 196fcf3ce44SJohn Forte #define ARE_WE_INITED() \ 197fcf3ce44SJohn Forte if (_hbaapi_librarylist == NULL) { \ 198fcf3ce44SJohn Forte return(HBA_STATUS_ERROR); \ 199fcf3ce44SJohn Forte } 200fcf3ce44SJohn Forte 201fcf3ce44SJohn Forte extern HBA_LIBRARY_INFO *_hbaapi_librarylist; 202fcf3ce44SJohn Forte extern HBA_UINT32 _hbaapi_total_library_count; 203fcf3ce44SJohn Forte #ifdef POSIX_THREADS 204fcf3ce44SJohn Forte extern pthread_mutex_t _hbaapi_LL_mutex; 205fcf3ce44SJohn Forte #elif defined(WIN32) 206fcf3ce44SJohn Forte extern CRITICAL_SECTION _hbaapi_LL_mutex; 207fcf3ce44SJohn Forte #endif 208fcf3ce44SJohn Forte 209fcf3ce44SJohn Forte /* 210fcf3ce44SJohn Forte * Function type def fop Sun extentions. 211fcf3ce44SJohn Forte */ 212fcf3ce44SJohn Forte typedef HBA_UINT32 (* Sun_HBAGetNumberOfTgtAdaptersFunc)(); 213fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBAGetTgtAdapterNameFunc)(HBA_UINT32, char *); 214fcf3ce44SJohn Forte typedef HBA_HANDLE (* Sun_HBAOpenTgtAdapterFunc)(char *); 215fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBAOpenTgtAdapterByWWNFunc) 216fcf3ce44SJohn Forte (HBA_HANDLE *, HBA_WWN); 217fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBANPIVGetAdapterAttributesFunc) 218fcf3ce44SJohn Forte (HBA_HANDLE, HBA_ADAPTERATTRIBUTES *); 219fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBAGetNPIVPortInfoFunc) 220fcf3ce44SJohn Forte (HBA_HANDLE, HBA_UINT32, HBA_UINT32, HBA_NPIVATTRIBUTES *); 221fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBADeleteNPIVPortFunc) 222fcf3ce44SJohn Forte (HBA_HANDLE, HBA_UINT32, HBA_WWN); 223fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBACreateNPIVPortFunc) 224fcf3ce44SJohn Forte (HBA_HANDLE, HBA_UINT32, HBA_WWN, HBA_WWN, HBA_UINT32 *); 225fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBAAdapterReturnWWNFunc) 226fcf3ce44SJohn Forte (HBA_HANDLE, HBA_UINT32, HBA_WWN *, HBA_WWN *); 227fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBAAdapterCreateWWNFunc) 228fcf3ce44SJohn Forte (HBA_HANDLE, HBA_UINT32, HBA_WWN *, HBA_WWN *, HBA_WWN *, 229fcf3ce44SJohn Forte HBA_INT32); 230fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBAGetPortNPIVAttributesFunc) 231fcf3ce44SJohn Forte (HBA_HANDLE, HBA_UINT32, HBA_PORTNPIVATTRIBUTES *); 232fcf3ce44SJohn Forte typedef HBA_STATUS (* Sun_HBARegisterForAdapterDeviceEventsFunc) 233fcf3ce44SJohn Forte (void (*)(void *, HBA_WWN, HBA_UINT32, HBA_UINT32), 234fcf3ce44SJohn Forte void *, HBA_HANDLE, HBA_WWN, HBA_CALLBACKHANDLE *); 235fcf3ce44SJohn Forte 236fcf3ce44SJohn Forte /* 237fcf3ce44SJohn Forte * Individual adapter (hba) information 238fcf3ce44SJohn Forte * Same as hbaadapter with different structure name. 239fcf3ce44SJohn Forte */ 240fcf3ce44SJohn Forte typedef struct hba_tgtadapter_info { 241fcf3ce44SJohn Forte struct hba_tgtadapter_info 242fcf3ce44SJohn Forte *next; 243fcf3ce44SJohn Forte HBA_STATUS GNstatus; /* status from GetTgtAdapterNameFunc */ 244fcf3ce44SJohn Forte char *name; 245fcf3ce44SJohn Forte HBA_WWN nodeWWN; 246fcf3ce44SJohn Forte HBA_LIBRARY_INFO *library; 247fcf3ce44SJohn Forte HBA_UINT32 index; 248fcf3ce44SJohn Forte } HBA_TGTADAPTER_INFO; 249fcf3ce44SJohn Forte 250fcf3ce44SJohn Forte /* 251fcf3ce44SJohn Forte * Make the list as an array with max size 16 252fcf3ce44SJohn Forte */ 253fcf3ce44SJohn Forte HBA_TGTADAPTER_INFO *_hbaapi_tgtadapterlist; 254fcf3ce44SJohn Forte HBA_UINT32 _hbaapi_total_tgtadapter_count = 0; 255fcf3ce44SJohn Forte #ifdef POSIX_THREADS 256fcf3ce44SJohn Forte pthread_mutex_t _hbaapi_tgtAL_mutex = PTHREAD_MUTEX_INITIALIZER; 257fcf3ce44SJohn Forte #elif defined(WIN32) 258fcf3ce44SJohn Forte CRITICAL_SECTION _hbaapi_tgtAL_mutex; 259fcf3ce44SJohn Forte #endif 260fcf3ce44SJohn Forte 261fcf3ce44SJohn Forte /* 262fcf3ce44SJohn Forte * Common library internal. Mutex handling 263fcf3ce44SJohn Forte */ 264fcf3ce44SJohn Forte #ifdef POSIX_THREADS 265fcf3ce44SJohn Forte static void 266fcf3ce44SJohn Forte grab_mutex(pthread_mutex_t *mp) { 267fcf3ce44SJohn Forte int ret; 268fcf3ce44SJohn Forte if((ret = pthread_mutex_lock(mp)) != 0) { 269fcf3ce44SJohn Forte perror("pthread_mutex_lock - HBAAPI:"); 270fcf3ce44SJohn Forte DEBUG(0, "pthread_mutex_lock returned %d", ret, 0, 0); 271fcf3ce44SJohn Forte } 272fcf3ce44SJohn Forte } 273fcf3ce44SJohn Forte 274fcf3ce44SJohn Forte static void 275fcf3ce44SJohn Forte release_mutex(pthread_mutex_t *mp) { 276fcf3ce44SJohn Forte int ret; 277fcf3ce44SJohn Forte if((ret = pthread_mutex_unlock(mp)) != 0) { 278fcf3ce44SJohn Forte perror("pthread_mutex_unlock - HBAAPI:"); 279fcf3ce44SJohn Forte DEBUG(0, "pthread_mutex_unlock returned %d", ret, 0, 0); 280fcf3ce44SJohn Forte } 281fcf3ce44SJohn Forte } 282fcf3ce44SJohn Forte #endif 283fcf3ce44SJohn Forte 284fcf3ce44SJohn Forte /* 285fcf3ce44SJohn Forte * The API used to use fixed size tables as its primary data structure. 286fcf3ce44SJohn Forte * Indexing from 1 to N identified each adapters. Now the adapters are 287fcf3ce44SJohn Forte * on a linked list. There is a unique "index" foreach each adapter. 288fcf3ce44SJohn Forte * Adapters always keep their index, even if they are removed from the 289fcf3ce44SJohn Forte * hardware. The only time the indexing is reset is on HBA_FreeLibrary 290fcf3ce44SJohn Forte */ 291fcf3ce44SJohn Forte HBA_UINT32 292fcf3ce44SJohn Forte Sun_HBA_GetNumberOfTgtAdapters() 293fcf3ce44SJohn Forte { 294fcf3ce44SJohn Forte int j=0; 295fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 296fcf3ce44SJohn Forte Sun_HBAGetNumberOfTgtAdaptersFunc 297fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = NULL; 298fcf3ce44SJohn Forte Sun_HBAGetTgtAdapterNameFunc 299fcf3ce44SJohn Forte GetTgtAdapterNameFunc = NULL; 300fcf3ce44SJohn Forte HBA_BOOLEAN found_name; 301fcf3ce44SJohn Forte HBA_TGTADAPTER_INFO *adapt_infop; 302fcf3ce44SJohn Forte HBA_STATUS status; 303fcf3ce44SJohn Forte 304fcf3ce44SJohn Forte char adaptername[256]; 305fcf3ce44SJohn Forte int num_adapters; /* local */ 306fcf3ce44SJohn Forte 307fcf3ce44SJohn Forte if(_hbaapi_librarylist == NULL) { 308fcf3ce44SJohn Forte return (0); 309fcf3ce44SJohn Forte } 310fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_LL_mutex); /* pay attention to order */ 311fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_tgtAL_mutex); 312fcf3ce44SJohn Forte 313fcf3ce44SJohn Forte for (lib_infop = _hbaapi_librarylist; 314fcf3ce44SJohn Forte lib_infop != NULL; 315fcf3ce44SJohn Forte lib_infop = lib_infop->next) { 316fcf3ce44SJohn Forte 317fcf3ce44SJohn Forte if (lib_infop->status != HBA_LIBRARY_LOADED) { 318fcf3ce44SJohn Forte continue; 319fcf3ce44SJohn Forte } 320fcf3ce44SJohn Forte 321fcf3ce44SJohn Forte if (lib_infop->hLibrary != NULL) { 322fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = (Sun_HBAGetNumberOfTgtAdaptersFunc) 323fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcGetNumberOfTgtAdapters"); 324fcf3ce44SJohn Forte GetTgtAdapterNameFunc = (Sun_HBAGetTgtAdapterNameFunc) 325fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcGetTgtAdapterName"); 326fcf3ce44SJohn Forte if (GetNumberOfTgtAdaptersFunc == NULL || 327fcf3ce44SJohn Forte GetTgtAdapterNameFunc == NULL) { 328fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = GetTgtAdapterNameFunc = NULL; 329fcf3ce44SJohn Forte continue; 330fcf3ce44SJohn Forte } 331fcf3ce44SJohn Forte } else { 332fcf3ce44SJohn Forte continue; 333fcf3ce44SJohn Forte } 334fcf3ce44SJohn Forte 335fcf3ce44SJohn Forte num_adapters = ((GetNumberOfTgtAdaptersFunc)()); 336fcf3ce44SJohn Forte #ifndef WIN32 337fcf3ce44SJohn Forte DEBUG(1, "HBAAPI: number of target mode adapters for %s = %d\n", 338fcf3ce44SJohn Forte lib_infop->LibraryName, num_adapters, 0); 339fcf3ce44SJohn Forte #else 340fcf3ce44SJohn Forte DEBUG(1, "HBAAPI: number of target mode_adapters for %s = %d\n", 341fcf3ce44SJohn Forte lib_infop->LibraryPath, num_adapters, 0); 342fcf3ce44SJohn Forte #endif 343fcf3ce44SJohn Forte 344fcf3ce44SJohn Forte for (j = 0; j < num_adapters; j++) { 345fcf3ce44SJohn Forte found_name = 0; 346fcf3ce44SJohn Forte status = (GetTgtAdapterNameFunc)(j, (char *)&adaptername); 347fcf3ce44SJohn Forte if(status == HBA_STATUS_OK) { 348fcf3ce44SJohn Forte for(adapt_infop = _hbaapi_tgtadapterlist; 349fcf3ce44SJohn Forte adapt_infop != NULL; 350fcf3ce44SJohn Forte adapt_infop = adapt_infop->next) { 351fcf3ce44SJohn Forte /* 352fcf3ce44SJohn Forte * check for duplicates, really, this may just be a second 353fcf3ce44SJohn Forte * call to this function 354fcf3ce44SJohn Forte * ??? how do we know when a name becomes stale? 355fcf3ce44SJohn Forte */ 356fcf3ce44SJohn Forte if(strcmp(adaptername, adapt_infop->name) == 0) { 357fcf3ce44SJohn Forte /* already got this one */ 358fcf3ce44SJohn Forte found_name++; 359fcf3ce44SJohn Forte break; 360fcf3ce44SJohn Forte } 361fcf3ce44SJohn Forte } 362fcf3ce44SJohn Forte if(found_name != 0) { 363fcf3ce44SJohn Forte continue; 364fcf3ce44SJohn Forte } 365fcf3ce44SJohn Forte } 366fcf3ce44SJohn Forte 367fcf3ce44SJohn Forte adapt_infop = (HBA_TGTADAPTER_INFO *) 368fcf3ce44SJohn Forte calloc(1, sizeof(HBA_TGTADAPTER_INFO)); 369fcf3ce44SJohn Forte if(adapt_infop == NULL) { 370fcf3ce44SJohn Forte #ifndef WIN32 371fcf3ce44SJohn Forte fprintf(stderr, 372fcf3ce44SJohn Forte "HBA_GetNumberOfAdapters: calloc failed on sizeof:%d\n", 373fcf3ce44SJohn Forte sizeof(HBA_TGTADAPTER_INFO)); 374fcf3ce44SJohn Forte #endif 375fcf3ce44SJohn Forte RELEASE_MUTEX(&_hbaapi_tgtAL_mutex); 376fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, 377fcf3ce44SJohn Forte _hbaapi_total_tgtadapter_count); 378fcf3ce44SJohn Forte } 379fcf3ce44SJohn Forte if((adapt_infop->GNstatus = status) == HBA_STATUS_OK) { 380fcf3ce44SJohn Forte adapt_infop->name = strdup(adaptername); 381fcf3ce44SJohn Forte } else { 382fcf3ce44SJohn Forte char dummyname[512]; 383fcf3ce44SJohn Forte sprintf(dummyname, "NULLADAPTER-%s-%03d", 384fcf3ce44SJohn Forte lib_infop->LibraryPath, _hbaapi_total_tgtadapter_count); 385fcf3ce44SJohn Forte dummyname[255] = '\0'; 386fcf3ce44SJohn Forte adapt_infop->name = strdup(dummyname); 387fcf3ce44SJohn Forte } 388fcf3ce44SJohn Forte adapt_infop->library = lib_infop; 389fcf3ce44SJohn Forte adapt_infop->next = _hbaapi_tgtadapterlist; 390fcf3ce44SJohn Forte adapt_infop->index = _hbaapi_total_tgtadapter_count; 391fcf3ce44SJohn Forte _hbaapi_tgtadapterlist = adapt_infop; 392fcf3ce44SJohn Forte _hbaapi_total_tgtadapter_count++; 393fcf3ce44SJohn Forte } 394fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = GetTgtAdapterNameFunc = NULL; 395fcf3ce44SJohn Forte } 396fcf3ce44SJohn Forte RELEASE_MUTEX(&_hbaapi_tgtAL_mutex); 397fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, _hbaapi_total_tgtadapter_count); 398fcf3ce44SJohn Forte } 399fcf3ce44SJohn Forte 400fcf3ce44SJohn Forte HBA_STATUS 401fcf3ce44SJohn Forte Sun_HBA_GetTgtAdapterName( 402fcf3ce44SJohn Forte HBA_UINT32 adapterindex, 403fcf3ce44SJohn Forte char *adaptername) 404fcf3ce44SJohn Forte { 405fcf3ce44SJohn Forte HBA_TGTADAPTER_INFO *adapt_infop; 406fcf3ce44SJohn Forte HBA_STATUS ret = HBA_STATUS_ERROR_ILLEGAL_INDEX; 407fcf3ce44SJohn Forte 408fcf3ce44SJohn Forte if (adaptername == NULL) { 409fcf3ce44SJohn Forte return(HBA_STATUS_ERROR_ARG); 410fcf3ce44SJohn Forte } 411fcf3ce44SJohn Forte /* 412fcf3ce44SJohn Forte * The adapter index is from old code, but we have 413fcf3ce44SJohn Forte * to support it. Go down the list looking for 414fcf3ce44SJohn Forte * the adapter 415fcf3ce44SJohn Forte */ 416fcf3ce44SJohn Forte ARE_WE_INITED(); 417fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_tgtAL_mutex); 418fcf3ce44SJohn Forte *adaptername = '\0'; 419fcf3ce44SJohn Forte for(adapt_infop = _hbaapi_tgtadapterlist; 420fcf3ce44SJohn Forte adapt_infop != NULL; 421fcf3ce44SJohn Forte adapt_infop = adapt_infop->next) { 422fcf3ce44SJohn Forte 423fcf3ce44SJohn Forte if(adapt_infop->index == adapterindex) { 424fcf3ce44SJohn Forte if(adapt_infop->name != NULL && 425fcf3ce44SJohn Forte adapt_infop->GNstatus == HBA_STATUS_OK) { 426fcf3ce44SJohn Forte strcpy(adaptername, adapt_infop->name); 427fcf3ce44SJohn Forte } else { 428fcf3ce44SJohn Forte *adaptername = '\0'; 429fcf3ce44SJohn Forte } 430fcf3ce44SJohn Forte ret = adapt_infop->GNstatus; 431fcf3ce44SJohn Forte break; 432fcf3ce44SJohn Forte } 433fcf3ce44SJohn Forte } 434fcf3ce44SJohn Forte DEBUG(2, "GetAdapterName for index:%d ->%s", adapterindex, adaptername, 0); 435fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, ret); 436fcf3ce44SJohn Forte } 437fcf3ce44SJohn Forte 438fcf3ce44SJohn Forte HBA_HANDLE 439fcf3ce44SJohn Forte Sun_HBA_OpenTgtAdapter(char* adaptername) 440fcf3ce44SJohn Forte { 441fcf3ce44SJohn Forte HBA_HANDLE handle; 442fcf3ce44SJohn Forte Sun_HBAOpenTgtAdapterFunc OpenTgtAdapterFunc; 443fcf3ce44SJohn Forte HBA_TGTADAPTER_INFO *adapt_infop; 444fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 445fcf3ce44SJohn Forte 446fcf3ce44SJohn Forte DEBUG(2, "OpenAdapter: %s", adaptername, 0, 0); 447fcf3ce44SJohn Forte 448fcf3ce44SJohn Forte if(_hbaapi_librarylist == NULL) { 449fcf3ce44SJohn Forte return(HBA_HANDLE_INVALID); 450fcf3ce44SJohn Forte } 451fcf3ce44SJohn Forte if (adaptername == NULL) { 452fcf3ce44SJohn Forte return(HBA_STATUS_ERROR_ARG); 453fcf3ce44SJohn Forte } 454fcf3ce44SJohn Forte handle = HBA_HANDLE_INVALID; 455fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_AL_mutex); 456fcf3ce44SJohn Forte for(adapt_infop = _hbaapi_tgtadapterlist; 457fcf3ce44SJohn Forte adapt_infop != NULL; 458fcf3ce44SJohn Forte adapt_infop = adapt_infop->next) { 459fcf3ce44SJohn Forte if (strcmp(adaptername, adapt_infop->name) != 0) { 460fcf3ce44SJohn Forte continue; 461fcf3ce44SJohn Forte } 462fcf3ce44SJohn Forte lib_infop = adapt_infop->library; 463fcf3ce44SJohn Forte OpenTgtAdapterFunc = (Sun_HBAOpenTgtAdapterFunc) 464fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcOpenTgtAdapter"); 465fcf3ce44SJohn Forte if (OpenTgtAdapterFunc != NULL) { 466fcf3ce44SJohn Forte /* retrieve the vendor handle */ 467fcf3ce44SJohn Forte handle = (OpenTgtAdapterFunc)(adaptername); 468fcf3ce44SJohn Forte if(handle != 0) { 469fcf3ce44SJohn Forte /* or this with the library index to get the common handle */ 470fcf3ce44SJohn Forte handle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle); 471fcf3ce44SJohn Forte } 472fcf3ce44SJohn Forte } 473fcf3ce44SJohn Forte break; 474fcf3ce44SJohn Forte } 475fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_AL_mutex, handle); 476fcf3ce44SJohn Forte } 477fcf3ce44SJohn Forte 478fcf3ce44SJohn Forte /* 479fcf3ce44SJohn Forte * This function ignores the list of known adapters and instead tries 480fcf3ce44SJohn Forte * each vendors open function to see if one of them 481fcf3ce44SJohn Forte * can open an adapter when referenced with a particular WWN 482fcf3ce44SJohn Forte */ 483fcf3ce44SJohn Forte HBA_STATUS 484fcf3ce44SJohn Forte Sun_HBA_OpenTgtAdapterByWWN(HBA_HANDLE *phandle, HBA_WWN nodeWWN) 485fcf3ce44SJohn Forte { 486fcf3ce44SJohn Forte HBA_HANDLE handle; 487fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 488fcf3ce44SJohn Forte Sun_HBAGetNumberOfTgtAdaptersFunc 489fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc; 490fcf3ce44SJohn Forte Sun_HBAOpenTgtAdapterByWWNFunc 491fcf3ce44SJohn Forte OpenTgtAdapterByWWNFunc; 492fcf3ce44SJohn Forte HBA_STATUS status; 493fcf3ce44SJohn Forte 494fcf3ce44SJohn Forte DEBUG(2, "OpenAdapterByWWN: %s", WWN2STR1(&nodeWWN), 0, 0); 495fcf3ce44SJohn Forte 496fcf3ce44SJohn Forte if (phandle == NULL) { 497fcf3ce44SJohn Forte return(HBA_STATUS_ERROR_ARG); 498fcf3ce44SJohn Forte } 499fcf3ce44SJohn Forte 500fcf3ce44SJohn Forte ARE_WE_INITED(); 501fcf3ce44SJohn Forte 502fcf3ce44SJohn Forte *phandle = HBA_HANDLE_INVALID; 503fcf3ce44SJohn Forte 504fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_LL_mutex); 505fcf3ce44SJohn Forte for (lib_infop = _hbaapi_librarylist; 506fcf3ce44SJohn Forte lib_infop != NULL; 507fcf3ce44SJohn Forte lib_infop = lib_infop->next) { 508fcf3ce44SJohn Forte 509fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_ILLEGAL_WWN; 510fcf3ce44SJohn Forte 511fcf3ce44SJohn Forte if (lib_infop->status != HBA_LIBRARY_LOADED) { 512fcf3ce44SJohn Forte continue; 513fcf3ce44SJohn Forte } 514fcf3ce44SJohn Forte 515fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = (Sun_HBAGetNumberOfTgtAdaptersFunc) 516fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcGetNumberOfTgtAdapters"); 517fcf3ce44SJohn Forte OpenTgtAdapterByWWNFunc = (Sun_HBAOpenTgtAdapterByWWNFunc) 518fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcOpenTgtAdapterByWWN"); 519fcf3ce44SJohn Forte if (GetNumberOfTgtAdaptersFunc == NULL || 520fcf3ce44SJohn Forte OpenTgtAdapterByWWNFunc == NULL) { 521fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = OpenTgtAdapterByWWNFunc = NULL; 522fcf3ce44SJohn Forte continue; 523fcf3ce44SJohn Forte } 524fcf3ce44SJohn Forte 525fcf3ce44SJohn Forte (void) ((GetNumberOfTgtAdaptersFunc)()); 526fcf3ce44SJohn Forte 527fcf3ce44SJohn Forte if((status = (OpenTgtAdapterByWWNFunc)(&handle, nodeWWN)) 528fcf3ce44SJohn Forte != HBA_STATUS_OK) { 529fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = OpenTgtAdapterByWWNFunc = NULL; 530fcf3ce44SJohn Forte continue; 531fcf3ce44SJohn Forte } 532fcf3ce44SJohn Forte /* OK, make a vendor non-specific handle */ 533fcf3ce44SJohn Forte *phandle = HBA_HANDLE_FROM_LOCAL(lib_infop->index, handle); 534fcf3ce44SJohn Forte status = HBA_STATUS_OK; 535fcf3ce44SJohn Forte break; 536fcf3ce44SJohn Forte 537fcf3ce44SJohn Forte GetNumberOfTgtAdaptersFunc = OpenTgtAdapterByWWNFunc = NULL; 538fcf3ce44SJohn Forte } 539fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 540fcf3ce44SJohn Forte } 541fcf3ce44SJohn Forte 542fcf3ce44SJohn Forte static HBA_STATUS 543fcf3ce44SJohn Forte HBA_NPIV_CheckLibrary(HBA_HANDLE handle, 544fcf3ce44SJohn Forte HBA_LIBRARY_INFO **lib_infopp, 545fcf3ce44SJohn Forte HBA_HANDLE *vendorhandle) { 546fcf3ce44SJohn Forte HBA_UINT32 libraryIndex; 547fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 548fcf3ce44SJohn Forte 549fcf3ce44SJohn Forte if (vendorhandle == NULL) { 550fcf3ce44SJohn Forte return(HBA_STATUS_ERROR_ARG); 551fcf3ce44SJohn Forte } 552fcf3ce44SJohn Forte if(_hbaapi_librarylist == NULL) { 553fcf3ce44SJohn Forte return(HBA_STATUS_ERROR); 554fcf3ce44SJohn Forte } 555fcf3ce44SJohn Forte libraryIndex = LIBRARY_NUM(handle); 556fcf3ce44SJohn Forte 557fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_LL_mutex); 558fcf3ce44SJohn Forte for(lib_infop = _hbaapi_librarylist; 559fcf3ce44SJohn Forte lib_infop != NULL; 560fcf3ce44SJohn Forte lib_infop = lib_infop->next) { 561fcf3ce44SJohn Forte if(lib_infop->index == libraryIndex) { 562fcf3ce44SJohn Forte if(lib_infop->status != HBA_LIBRARY_LOADED) { 563fcf3ce44SJohn Forte return HBA_STATUS_ERROR; 564fcf3ce44SJohn Forte } 565fcf3ce44SJohn Forte *lib_infopp = lib_infop; 566fcf3ce44SJohn Forte *vendorhandle = VENDOR_HANDLE(handle); 567fcf3ce44SJohn Forte /* caller will release the mutex */ 568fcf3ce44SJohn Forte return HBA_STATUS_OK; 569fcf3ce44SJohn Forte } 570fcf3ce44SJohn Forte } 571fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_INVALID_HANDLE); 572fcf3ce44SJohn Forte } 573fcf3ce44SJohn Forte #define NPIVCHECKLIBRARY() \ 574fcf3ce44SJohn Forte status = HBA_NPIV_CheckLibrary(handle, &lib_infop, &vendorHandle); \ 575fcf3ce44SJohn Forte if(status != HBA_STATUS_OK) { \ 576fcf3ce44SJohn Forte return(status); \ 577fcf3ce44SJohn Forte } 578fcf3ce44SJohn Forte 579fcf3ce44SJohn Forte HBA_STATUS 580fcf3ce44SJohn Forte Sun_HBA_NPIVGetAdapterAttributes ( 581fcf3ce44SJohn Forte HBA_HANDLE handle, 582fcf3ce44SJohn Forte HBA_ADAPTERATTRIBUTES 583fcf3ce44SJohn Forte *hbaattributes) 584fcf3ce44SJohn Forte { 585fcf3ce44SJohn Forte HBA_STATUS status; 586fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 587fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 588fcf3ce44SJohn Forte Sun_HBANPIVGetAdapterAttributesFunc NPIVGetAdapterAttributesFunc; 589fcf3ce44SJohn Forte 590fcf3ce44SJohn Forte DEBUG(2, "HBA_NPIVGetAdapterAttributes", 0, 0, 0); 591fcf3ce44SJohn Forte 592fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 593fcf3ce44SJohn Forte NPIVGetAdapterAttributesFunc = (Sun_HBANPIVGetAdapterAttributesFunc) 594fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcNPIVGetAdapterAttributes"); 595fcf3ce44SJohn Forte if (NPIVGetAdapterAttributesFunc != NULL) { 596fcf3ce44SJohn Forte status = ((NPIVGetAdapterAttributesFunc)(vendorHandle, 597fcf3ce44SJohn Forte hbaattributes)); 598fcf3ce44SJohn Forte } else { 599fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 600fcf3ce44SJohn Forte } 601fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 602fcf3ce44SJohn Forte } 603fcf3ce44SJohn Forte 604fcf3ce44SJohn Forte HBA_STATUS 605fcf3ce44SJohn Forte Sun_HBA_GetNPIVPortInfo ( 606fcf3ce44SJohn Forte HBA_HANDLE handle, 607fcf3ce44SJohn Forte HBA_UINT32 portindex, 608fcf3ce44SJohn Forte HBA_UINT32 vportindex, 609fcf3ce44SJohn Forte HBA_NPIVATTRIBUTES *attributes) 610fcf3ce44SJohn Forte { 611fcf3ce44SJohn Forte HBA_STATUS status; 612fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 613fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 614fcf3ce44SJohn Forte Sun_HBAGetNPIVPortInfoFunc GetNPIVPortInfoFunc; 615fcf3ce44SJohn Forte 616fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 617fcf3ce44SJohn Forte GetNPIVPortInfoFunc = (Sun_HBAGetNPIVPortInfoFunc) 618fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcGetNPIVPortInfo"); 619fcf3ce44SJohn Forte if (GetNPIVPortInfoFunc != NULL) { 620fcf3ce44SJohn Forte status = ((GetNPIVPortInfoFunc)(vendorHandle, portindex, 621fcf3ce44SJohn Forte vportindex, attributes)); 622fcf3ce44SJohn Forte } else { 623fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 624fcf3ce44SJohn Forte } 625fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 626fcf3ce44SJohn Forte } 627fcf3ce44SJohn Forte 628fcf3ce44SJohn Forte HBA_STATUS 629fcf3ce44SJohn Forte Sun_HBA_DeleteNPIVPort ( 630fcf3ce44SJohn Forte HBA_HANDLE handle, 631fcf3ce44SJohn Forte HBA_UINT32 portindex, 632fcf3ce44SJohn Forte HBA_WWN vportWWN) 633fcf3ce44SJohn Forte { 634fcf3ce44SJohn Forte HBA_STATUS status; 635fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 636fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 637fcf3ce44SJohn Forte Sun_HBADeleteNPIVPortFunc DeleteNPIVPortFunc; 638fcf3ce44SJohn Forte 639fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 640fcf3ce44SJohn Forte DeleteNPIVPortFunc = (Sun_HBADeleteNPIVPortFunc) 641fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcDeleteNPIVPort"); 642fcf3ce44SJohn Forte if (DeleteNPIVPortFunc != NULL) { 643fcf3ce44SJohn Forte status = ((DeleteNPIVPortFunc)(vendorHandle, 644fcf3ce44SJohn Forte portindex, vportWWN)); 645fcf3ce44SJohn Forte } else { 646fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 647fcf3ce44SJohn Forte } 648fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 649fcf3ce44SJohn Forte } 650fcf3ce44SJohn Forte 651fcf3ce44SJohn Forte HBA_STATUS 652fcf3ce44SJohn Forte Sun_HBA_CreateNPIVPort ( 653fcf3ce44SJohn Forte HBA_HANDLE handle, 654fcf3ce44SJohn Forte HBA_UINT32 portindex, 655fcf3ce44SJohn Forte HBA_WWN vnodeWWN, 656fcf3ce44SJohn Forte HBA_WWN vportWWN, 657fcf3ce44SJohn Forte HBA_UINT32 *vportindex) 658fcf3ce44SJohn Forte { 659fcf3ce44SJohn Forte HBA_STATUS status; 660fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 661fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 662fcf3ce44SJohn Forte Sun_HBACreateNPIVPortFunc CreateNPIVPortFunc; 663fcf3ce44SJohn Forte 664fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 665fcf3ce44SJohn Forte CreateNPIVPortFunc = (Sun_HBACreateNPIVPortFunc) 666fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcCreateNPIVPort"); 667fcf3ce44SJohn Forte if (CreateNPIVPortFunc != NULL) { 668fcf3ce44SJohn Forte status = ((CreateNPIVPortFunc)(vendorHandle, 669fcf3ce44SJohn Forte portindex, vnodeWWN, vportWWN, vportindex)); 670fcf3ce44SJohn Forte } else { 671fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 672fcf3ce44SJohn Forte } 673fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 674fcf3ce44SJohn Forte } 675fcf3ce44SJohn Forte 676fcf3ce44SJohn Forte HBA_STATUS 677fcf3ce44SJohn Forte Sun_HBA_GetPortNPIVAttributes ( 678fcf3ce44SJohn Forte HBA_HANDLE handle, 679fcf3ce44SJohn Forte HBA_UINT32 portindex, 680fcf3ce44SJohn Forte HBA_PORTNPIVATTRIBUTES *portnpivattributes) 681fcf3ce44SJohn Forte { 682fcf3ce44SJohn Forte HBA_STATUS status; 683fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 684fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 685fcf3ce44SJohn Forte Sun_HBAGetPortNPIVAttributesFunc GetPortNPIVAttributesFunc; 686fcf3ce44SJohn Forte 687fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 688fcf3ce44SJohn Forte GetPortNPIVAttributesFunc = (Sun_HBAGetPortNPIVAttributesFunc) 689fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcGetPortNPIVAttributes"); 690fcf3ce44SJohn Forte if (GetPortNPIVAttributesFunc != NULL) { 691fcf3ce44SJohn Forte status = ((GetPortNPIVAttributesFunc)( 692fcf3ce44SJohn Forte vendorHandle, portindex, portnpivattributes)); 693fcf3ce44SJohn Forte } else { 694fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 695fcf3ce44SJohn Forte } 696fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 697fcf3ce44SJohn Forte } 698fcf3ce44SJohn Forte 699fcf3ce44SJohn Forte HBA_STATUS 700fcf3ce44SJohn Forte Sun_HBA_AdapterCreateWWN ( 701fcf3ce44SJohn Forte HBA_HANDLE handle, 702fcf3ce44SJohn Forte HBA_UINT32 portindex, 703fcf3ce44SJohn Forte HBA_WWN *nwwn, 704fcf3ce44SJohn Forte HBA_WWN *pwwn, 705fcf3ce44SJohn Forte HBA_WWN *OUI, 706fcf3ce44SJohn Forte HBA_INT32 method) 707fcf3ce44SJohn Forte { 708fcf3ce44SJohn Forte HBA_STATUS status; 709fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 710fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 711fcf3ce44SJohn Forte Sun_HBAAdapterCreateWWNFunc AdapterCreateWWNFunc; 712fcf3ce44SJohn Forte 713fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 714fcf3ce44SJohn Forte AdapterCreateWWNFunc = (Sun_HBAAdapterCreateWWNFunc) 715fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcAdapterCreateWWN"); 716fcf3ce44SJohn Forte if (AdapterCreateWWNFunc != NULL) { 717fcf3ce44SJohn Forte status = ((AdapterCreateWWNFunc)(vendorHandle, 718fcf3ce44SJohn Forte portindex, nwwn, pwwn, OUI, method)); 719fcf3ce44SJohn Forte } else { 720fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 721fcf3ce44SJohn Forte } 722fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 723fcf3ce44SJohn Forte } 724fcf3ce44SJohn Forte 725fcf3ce44SJohn Forte HBA_STATUS 726fcf3ce44SJohn Forte Sun_HBA_AdapterReturnWWN ( 727fcf3ce44SJohn Forte HBA_HANDLE handle, 728fcf3ce44SJohn Forte HBA_UINT32 portindex, 729fcf3ce44SJohn Forte HBA_WWN *nwwn, 730fcf3ce44SJohn Forte HBA_WWN *pwwn) 731fcf3ce44SJohn Forte { 732fcf3ce44SJohn Forte HBA_STATUS status; 733fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 734fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 735fcf3ce44SJohn Forte Sun_HBAAdapterReturnWWNFunc AdapterReturnWWNFunc; 736fcf3ce44SJohn Forte 737fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 738fcf3ce44SJohn Forte AdapterReturnWWNFunc = (Sun_HBAAdapterReturnWWNFunc) 739fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, "Sun_fcAdapterReturnWWN"); 740fcf3ce44SJohn Forte if (AdapterReturnWWNFunc != NULL) { 741fcf3ce44SJohn Forte status = ((AdapterReturnWWNFunc)(vendorHandle, 742fcf3ce44SJohn Forte portindex, nwwn, pwwn)); 743fcf3ce44SJohn Forte } else { 744fcf3ce44SJohn Forte status = HBA_STATUS_ERROR_NOT_SUPPORTED; 745fcf3ce44SJohn Forte } 746fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 747fcf3ce44SJohn Forte } 748fcf3ce44SJohn Forte 749fcf3ce44SJohn Forte typedef struct hba_npivadaptercallback_elem { 750fcf3ce44SJohn Forte struct hba_npivadaptercallback_elem 751fcf3ce44SJohn Forte *next; 752fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_info; 753fcf3ce44SJohn Forte void *userdata; 754fcf3ce44SJohn Forte HBA_CALLBACKHANDLE vendorcbhandle; 755fcf3ce44SJohn Forte void (*callback)(); 756fcf3ce44SJohn Forte } HBA_NPIVADAPTERCALLBACK_ELEM; 757fcf3ce44SJohn Forte extern HBA_NPIVADAPTERCALLBACK_ELEM *_hbaapi_adapterdeviceevents_callback_list; 758fcf3ce44SJohn Forte 759fcf3ce44SJohn Forte /* Adapter Device Events ********************************************************/ 760fcf3ce44SJohn Forte static void 761fcf3ce44SJohn Forte adapterdeviceevents_callback (void *data, 762fcf3ce44SJohn Forte HBA_WWN PortWWN, 763fcf3ce44SJohn Forte HBA_UINT32 eventType, 764fcf3ce44SJohn Forte HBA_UINT32 fabricPortID) 765fcf3ce44SJohn Forte { 766fcf3ce44SJohn Forte HBA_NPIVADAPTERCALLBACK_ELEM *acbp; 767fcf3ce44SJohn Forte 768fcf3ce44SJohn Forte DEBUG(3, "AdapterDeviceEvent, port:%s, eventType:%d fabricPortID:0X%06x", 769fcf3ce44SJohn Forte WWN2STR1(&PortWWN), eventType, fabricPortID); 770fcf3ce44SJohn Forte 771fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_APE_mutex); 772fcf3ce44SJohn Forte 773fcf3ce44SJohn Forte for(acbp = _hbaapi_adapterdeviceevents_callback_list; 774fcf3ce44SJohn Forte acbp != NULL; 775fcf3ce44SJohn Forte acbp = acbp->next) { 776fcf3ce44SJohn Forte if(data == (void *)acbp) { 777fcf3ce44SJohn Forte (*acbp->callback)(acbp->userdata, PortWWN, eventType, fabricPortID); 778fcf3ce44SJohn Forte break; 779fcf3ce44SJohn Forte } 780fcf3ce44SJohn Forte } 781fcf3ce44SJohn Forte RELEASE_MUTEX(&_hbaapi_APE_mutex); 782fcf3ce44SJohn Forte } 783fcf3ce44SJohn Forte 784fcf3ce44SJohn Forte HBA_STATUS 785fcf3ce44SJohn Forte Sun_HBA_RegisterForAdapterDeviceEvents ( 786fcf3ce44SJohn Forte void (*callback) ( 787fcf3ce44SJohn Forte void *data, 788fcf3ce44SJohn Forte HBA_WWN PortWWN, 789fcf3ce44SJohn Forte HBA_UINT32 eventType, 790fcf3ce44SJohn Forte HBA_UINT32 fabricPortID 791fcf3ce44SJohn Forte ), 792fcf3ce44SJohn Forte void *userData, 793fcf3ce44SJohn Forte HBA_HANDLE handle, 794fcf3ce44SJohn Forte HBA_WWN PortWWN, 795fcf3ce44SJohn Forte HBA_CALLBACKHANDLE *callbackHandle) 796fcf3ce44SJohn Forte { 797fcf3ce44SJohn Forte HBA_NPIVADAPTERCALLBACK_ELEM *acbp; 798fcf3ce44SJohn Forte HBA_STATUS status; 799fcf3ce44SJohn Forte HBA_LIBRARY_INFO *lib_infop; 800fcf3ce44SJohn Forte HBA_HANDLE vendorHandle; 801fcf3ce44SJohn Forte Sun_HBARegisterForAdapterDeviceEventsFunc 802fcf3ce44SJohn Forte registeredfunc; 803fcf3ce44SJohn Forte 804fcf3ce44SJohn Forte if (callbackHandle == NULL) { 805fcf3ce44SJohn Forte return(HBA_STATUS_ERROR_ARG); 806fcf3ce44SJohn Forte } 807fcf3ce44SJohn Forte 808fcf3ce44SJohn Forte NPIVCHECKLIBRARY(); 809fcf3ce44SJohn Forte registeredfunc = (Sun_HBARegisterForAdapterDeviceEventsFunc) 810fcf3ce44SJohn Forte dlsym(lib_infop->hLibrary, 811fcf3ce44SJohn Forte "Sun_fcRegisterForAdapterDeviceEvents"); 812fcf3ce44SJohn Forte if (registeredfunc == NULL) { 813fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR_NOT_SUPPORTED); 814fcf3ce44SJohn Forte } 815fcf3ce44SJohn Forte 816fcf3ce44SJohn Forte acbp = (HBA_NPIVADAPTERCALLBACK_ELEM *) 817fcf3ce44SJohn Forte calloc(1, sizeof(HBA_NPIVADAPTERCALLBACK_ELEM)); 818fcf3ce44SJohn Forte 819fcf3ce44SJohn Forte if(acbp == NULL) { 820fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_ERROR); 821fcf3ce44SJohn Forte } 822fcf3ce44SJohn Forte 823fcf3ce44SJohn Forte *callbackHandle = (HBA_CALLBACKHANDLE) acbp; 824fcf3ce44SJohn Forte acbp->callback = callback; 825fcf3ce44SJohn Forte acbp->userdata = userData; 826fcf3ce44SJohn Forte acbp->lib_info = lib_infop; 827fcf3ce44SJohn Forte 828fcf3ce44SJohn Forte status = (registeredfunc)(adapterdeviceevents_callback, 829fcf3ce44SJohn Forte (void *)acbp, 830fcf3ce44SJohn Forte vendorHandle, 831fcf3ce44SJohn Forte PortWWN, 832fcf3ce44SJohn Forte &acbp->vendorcbhandle); 833fcf3ce44SJohn Forte if(status != HBA_STATUS_OK) { 834fcf3ce44SJohn Forte free(acbp); 835fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, status); 836fcf3ce44SJohn Forte } 837fcf3ce44SJohn Forte 838fcf3ce44SJohn Forte GRAB_MUTEX(&_hbaapi_APE_mutex); 839fcf3ce44SJohn Forte acbp->next = _hbaapi_adapterdeviceevents_callback_list; 840fcf3ce44SJohn Forte _hbaapi_adapterdeviceevents_callback_list = acbp; 841fcf3ce44SJohn Forte RELEASE_MUTEX(&_hbaapi_APE_mutex); 842fcf3ce44SJohn Forte 843fcf3ce44SJohn Forte RELEASE_MUTEX_RETURN(&_hbaapi_LL_mutex, HBA_STATUS_OK); 844fcf3ce44SJohn Forte } 845