1fcf3ce44SJohn Forte /* 2fcf3ce44SJohn Forte * CDDL HEADER START 3fcf3ce44SJohn Forte * 4fcf3ce44SJohn Forte * The contents of this file are subject to the terms of the 5fcf3ce44SJohn Forte * Common Development and Distribution License (the "License"). 6fcf3ce44SJohn Forte * You may not use this file except in compliance with the License. 7fcf3ce44SJohn Forte * 8fcf3ce44SJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fcf3ce44SJohn Forte * or http://www.opensolaris.org/os/licensing. 10fcf3ce44SJohn Forte * See the License for the specific language governing permissions 11fcf3ce44SJohn Forte * and limitations under the License. 12fcf3ce44SJohn Forte * 13fcf3ce44SJohn Forte * When distributing Covered Code, include this CDDL HEADER in each 14fcf3ce44SJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fcf3ce44SJohn Forte * If applicable, add the following below this CDDL HEADER, with the 16fcf3ce44SJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying 17fcf3ce44SJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner] 18fcf3ce44SJohn Forte * 19fcf3ce44SJohn Forte * CDDL HEADER END 20fcf3ce44SJohn Forte */ 21fcf3ce44SJohn Forte /* 22*17d71211SJiri Svoboda * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 23fcf3ce44SJohn Forte */ 24fcf3ce44SJohn Forte 25fcf3ce44SJohn Forte #include "mp_utils.h" 26fcf3ce44SJohn Forte #include <sys/sunddi.h> 27fcf3ce44SJohn Forte 28fcf3ce44SJohn Forte #ifndef OIDLIST 29fcf3ce44SJohn Forte #define OIDLIST "oid" 30fcf3ce44SJohn Forte #endif 31fcf3ce44SJohn Forte 32fcf3ce44SJohn Forte 33fcf3ce44SJohn Forte /* Remove these 5 when this source can compile with sunddi.h */ 34fcf3ce44SJohn Forte #ifndef EC_DDI 35fcf3ce44SJohn Forte #define EC_DDI "EC_ddi" 36fcf3ce44SJohn Forte #endif 37fcf3ce44SJohn Forte 38fcf3ce44SJohn Forte #ifndef ESC_DDI_INITIATOR_REGISTER 39fcf3ce44SJohn Forte #define ESC_DDI_INITIATOR_REGISTER "ESC_ddi_initiator_register" 40fcf3ce44SJohn Forte #endif 41fcf3ce44SJohn Forte 42fcf3ce44SJohn Forte #ifndef ESC_DDI_INITIATOR_UNREGISTER 43fcf3ce44SJohn Forte #define ESC_DDI_INITIATOR_UNREGISTER "ESC_ddi_initiator_unregister" 44fcf3ce44SJohn Forte #endif 45fcf3ce44SJohn Forte 46fcf3ce44SJohn Forte #ifndef DDI_DRIVER_MAJOR 47fcf3ce44SJohn Forte #define DDI_DRIVER_MAJOR "ddi.major" 48fcf3ce44SJohn Forte #endif 49fcf3ce44SJohn Forte 50fcf3ce44SJohn Forte #ifndef DDI_INSTANCE 51fcf3ce44SJohn Forte #define DDI_INSTANCE "ddi.instance" 52fcf3ce44SJohn Forte #endif 53fcf3ce44SJohn Forte 54fcf3ce44SJohn Forte 55fcf3ce44SJohn Forte #define VISA_CHANGE 1 56fcf3ce44SJohn Forte #define PROP_CHANGE 2 57fcf3ce44SJohn Forte 58fcf3ce44SJohn Forte 59fcf3ce44SJohn Forte 60fcf3ce44SJohn Forte MP_STATUS 61fcf3ce44SJohn Forte getStatus4ErrorCode(int driverError) 62fcf3ce44SJohn Forte { 63fcf3ce44SJohn Forte MP_STATUS mpStatus = MP_STATUS_FAILED; 64fcf3ce44SJohn Forte 65fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", "- enter"); 66fcf3ce44SJohn Forte 67fcf3ce44SJohn Forte switch (driverError) { 68fcf3ce44SJohn Forte 69fcf3ce44SJohn Forte case MP_DRVR_INVALID_ID: 70fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 71fcf3ce44SJohn Forte " received mp_errno=MP_DRVR_INVALID_ID" 72fcf3ce44SJohn Forte " from driver call."); 73fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 74fcf3ce44SJohn Forte " returning MP_STATUS_OBJECT_NOT_FOUND" 75fcf3ce44SJohn Forte " to caller."); 76fcf3ce44SJohn Forte mpStatus = MP_STATUS_OBJECT_NOT_FOUND; 77fcf3ce44SJohn Forte break; 78fcf3ce44SJohn Forte 79fcf3ce44SJohn Forte 80fcf3ce44SJohn Forte case MP_DRVR_ID_OBSOLETE: 81fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 82fcf3ce44SJohn Forte " received mp_errno=MP_DRVR_ID_OBSOLETE" 83fcf3ce44SJohn Forte " from driver call."); 84fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 85fcf3ce44SJohn Forte " returning MP_STATUS_OBJECT_NOT_FOUND" 86fcf3ce44SJohn Forte " to caller."); 87fcf3ce44SJohn Forte mpStatus = MP_STATUS_OBJECT_NOT_FOUND; 88fcf3ce44SJohn Forte break; 89fcf3ce44SJohn Forte 90fcf3ce44SJohn Forte 91fcf3ce44SJohn Forte case MP_DRVR_ACCESS_SYMMETRIC: 92fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 93fcf3ce44SJohn Forte " received mp_errno=MP_DRVR_ACCESS_SYMMETRIC" 94fcf3ce44SJohn Forte " from driver call."); 95fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 96fcf3ce44SJohn Forte " returning MP_STATUS_INVALID_PARAMETER" 97fcf3ce44SJohn Forte " to caller."); 98fcf3ce44SJohn Forte mpStatus = MP_STATUS_INVALID_PARAMETER; 99fcf3ce44SJohn Forte break; 100fcf3ce44SJohn Forte 101fcf3ce44SJohn Forte 102fcf3ce44SJohn Forte case MP_DRVR_PATH_UNAVAILABLE: 103fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 104fcf3ce44SJohn Forte " received mp_errno=MP_DRVR_PATH_UNAVAILABLE" 105fcf3ce44SJohn Forte " from driver call."); 106fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 107fcf3ce44SJohn Forte " returning MP_STATUS_PATH_NONOPERATIONAL" 108fcf3ce44SJohn Forte " to caller."); 109fcf3ce44SJohn Forte mpStatus = MP_STATUS_PATH_NONOPERATIONAL; 110fcf3ce44SJohn Forte break; 111fcf3ce44SJohn Forte 112fcf3ce44SJohn Forte 113fcf3ce44SJohn Forte case MP_DRVR_IDS_NOT_ASSOCIATED: 114fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 115fcf3ce44SJohn Forte " received mp_errno=MP_DRVR_IDS_NOT_ASSOCIATED" 116fcf3ce44SJohn Forte " from driver call."); 117fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 118fcf3ce44SJohn Forte " returning MP_STATUS_INVALID_PARAMETER" 119fcf3ce44SJohn Forte " to caller."); 120fcf3ce44SJohn Forte mpStatus = MP_STATUS_INVALID_PARAMETER; 121fcf3ce44SJohn Forte break; 122fcf3ce44SJohn Forte 123fcf3ce44SJohn Forte 124fcf3ce44SJohn Forte case MP_DRVR_ILLEGAL_ACCESS_STATE_REQUEST: 125fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 126fcf3ce44SJohn Forte " received mp_errno=" 127fcf3ce44SJohn Forte "MP_DRVR_ILLEGAL_ACCESS_STATE_REQUEST" 128fcf3ce44SJohn Forte " from driver call."); 129fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 130fcf3ce44SJohn Forte " returning MP_STATUS_INVALID_PARAMETER" 131fcf3ce44SJohn Forte " to caller."); 132fcf3ce44SJohn Forte mpStatus = MP_STATUS_ACCESS_STATE_INVALID; 133fcf3ce44SJohn Forte break; 134fcf3ce44SJohn Forte 135fcf3ce44SJohn Forte 136fcf3ce44SJohn Forte default: 137fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 138fcf3ce44SJohn Forte " - received (unsupported) mp_errno=%d from" 139fcf3ce44SJohn Forte " driver call.", driverError); 140fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", 141fcf3ce44SJohn Forte " - returning MP_STATUS_FAILED to caller."); 142fcf3ce44SJohn Forte mpStatus = MP_STATUS_FAILED; 143fcf3ce44SJohn Forte } 144fcf3ce44SJohn Forte 145fcf3ce44SJohn Forte log(LOG_INFO, "getStatus4ErrorCode()", "- exit"); 146fcf3ce44SJohn Forte 147fcf3ce44SJohn Forte return (mpStatus); 148fcf3ce44SJohn Forte } 149fcf3ce44SJohn Forte 150fcf3ce44SJohn Forte 151fcf3ce44SJohn Forte 152fcf3ce44SJohn Forte MP_OID_LIST 153fcf3ce44SJohn Forte *createOidList(int size) { 154fcf3ce44SJohn Forte 155fcf3ce44SJohn Forte MP_OID_LIST *pOidList = NULL; 156fcf3ce44SJohn Forte 157fcf3ce44SJohn Forte 158fcf3ce44SJohn Forte log(LOG_INFO, "createOidList()", "- enter"); 159fcf3ce44SJohn Forte 160fcf3ce44SJohn Forte 161fcf3ce44SJohn Forte if (size < 1) { 162fcf3ce44SJohn Forte 163fcf3ce44SJohn Forte log(LOG_INFO, "createOidList()", 164fcf3ce44SJohn Forte "requested size is less than 1"); 165fcf3ce44SJohn Forte log(LOG_INFO, "createOidList()", 166fcf3ce44SJohn Forte " - error exit"); 167fcf3ce44SJohn Forte return (NULL); 168fcf3ce44SJohn Forte 169fcf3ce44SJohn Forte } else { 170fcf3ce44SJohn Forte 171fcf3ce44SJohn Forte pOidList = (MP_OID_LIST*)calloc(1, 172fcf3ce44SJohn Forte sizeof (MP_OID_LIST) + 173fcf3ce44SJohn Forte ((size - 1) * 174fcf3ce44SJohn Forte sizeof (MP_OID))); 175fcf3ce44SJohn Forte 176fcf3ce44SJohn Forte if (NULL == pOidList) { 177fcf3ce44SJohn Forte log(LOG_INFO, "createOidList()", 178fcf3ce44SJohn Forte "no memory for pOidList"); 179fcf3ce44SJohn Forte log(LOG_INFO, "createOidList()", 180fcf3ce44SJohn Forte " - error exit"); 181fcf3ce44SJohn Forte return (NULL); 182fcf3ce44SJohn Forte } 183fcf3ce44SJohn Forte 184fcf3ce44SJohn Forte log(LOG_INFO, 185fcf3ce44SJohn Forte "createOidList()", 186fcf3ce44SJohn Forte "- exit(%d)", 187fcf3ce44SJohn Forte size); 188fcf3ce44SJohn Forte 189fcf3ce44SJohn Forte return (pOidList); 190fcf3ce44SJohn Forte } 191fcf3ce44SJohn Forte } 192fcf3ce44SJohn Forte 193fcf3ce44SJohn Forte /* Calls the client callback function, if one is registered */ 194fcf3ce44SJohn Forte static void 195fcf3ce44SJohn Forte notifyClient(sysevent_t *ev) 196fcf3ce44SJohn Forte { 197fcf3ce44SJohn Forte nvlist_t *attr_list = NULL; 198fcf3ce44SJohn Forte 199fcf3ce44SJohn Forte uint64_t *val = NULL; 200fcf3ce44SJohn Forte int32_t *instance = NULL; 201fcf3ce44SJohn Forte int32_t *major = NULL; 202fcf3ce44SJohn Forte 203fcf3ce44SJohn Forte int valAllocated = 0; 204fcf3ce44SJohn Forte 205fcf3ce44SJohn Forte uint_t nelem = 0; 206fcf3ce44SJohn Forte 207fcf3ce44SJohn Forte int i = 0; 208fcf3ce44SJohn Forte int eventType = 0; 209fcf3ce44SJohn Forte int index = -1; 210fcf3ce44SJohn Forte 211fcf3ce44SJohn Forte void *pCallerData = NULL; 212fcf3ce44SJohn Forte 213fcf3ce44SJohn Forte char subClassName[256]; 214fcf3ce44SJohn Forte 215fcf3ce44SJohn Forte MP_BOOL becomingVisible = MP_FALSE; 216fcf3ce44SJohn Forte 217fcf3ce44SJohn Forte MP_OID_LIST *oidList = NULL; 218fcf3ce44SJohn Forte 219fcf3ce44SJohn Forte 220fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- enter"); 221fcf3ce44SJohn Forte 222fcf3ce44SJohn Forte 223fcf3ce44SJohn Forte (void) strncpy(subClassName, sysevent_get_subclass_name(ev), 256); 224fcf3ce44SJohn Forte 225fcf3ce44SJohn Forte if (strstr(subClassName, "change")) { 226fcf3ce44SJohn Forte 227fcf3ce44SJohn Forte eventType = PROP_CHANGE; 228fcf3ce44SJohn Forte 229fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- got a change event"); 230fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", ": [%s]", 231fcf3ce44SJohn Forte subClassName); 232fcf3ce44SJohn Forte 233*17d71211SJiri Svoboda if (strncmp(subClassName, ESC_SUN_MP_PLUGIN_CHANGE, 255) 234*17d71211SJiri Svoboda == 0) { 235*17d71211SJiri Svoboda 236*17d71211SJiri Svoboda index = MP_OBJECT_TYPE_PLUGIN; 237*17d71211SJiri Svoboda 238*17d71211SJiri Svoboda } else if (strncmp(subClassName, ESC_SUN_MP_LU_CHANGE, 255) 239*17d71211SJiri Svoboda == 0) { 240fcf3ce44SJohn Forte 241fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_MULTIPATH_LU; 242fcf3ce44SJohn Forte 243fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_PATH_CHANGE, 255) 244fcf3ce44SJohn Forte == 0) { 245fcf3ce44SJohn Forte 246fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_PATH_LU; 247fcf3ce44SJohn Forte 248fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_INIT_PORT_CHANGE, 249fcf3ce44SJohn Forte 255) == 0) { 250fcf3ce44SJohn Forte 251fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_INITIATOR_PORT; 252fcf3ce44SJohn Forte 253fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_TPG_CHANGE, 255) 254fcf3ce44SJohn Forte == 0) { 255fcf3ce44SJohn Forte 256fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_TARGET_PORT_GROUP; 257fcf3ce44SJohn Forte 258fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_TARGET_PORT_CHANGE, 259fcf3ce44SJohn Forte 255) == 0) { 260fcf3ce44SJohn Forte 261fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_TARGET_PORT; 262fcf3ce44SJohn Forte 263fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_DEV_PROD_CHANGE, 264fcf3ce44SJohn Forte 255) == 0) { 265fcf3ce44SJohn Forte 266fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_DEVICE_PRODUCT; 267fcf3ce44SJohn Forte } 268fcf3ce44SJohn Forte 269fcf3ce44SJohn Forte } else if ((strstr(subClassName, "add")) || 270fcf3ce44SJohn Forte (strstr(subClassName, "initiator_register"))) { 271fcf3ce44SJohn Forte 272fcf3ce44SJohn Forte eventType = VISA_CHANGE; 273fcf3ce44SJohn Forte becomingVisible = MP_TRUE; 274fcf3ce44SJohn Forte 275fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- got a visibility" 276fcf3ce44SJohn Forte " add event"); 277fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", ": [%s]", 278fcf3ce44SJohn Forte subClassName); 279fcf3ce44SJohn Forte 280*17d71211SJiri Svoboda if (strncmp(subClassName, ESC_SUN_MP_LU_ADD, 255) == 0) { 281fcf3ce44SJohn Forte 282fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_MULTIPATH_LU; 283fcf3ce44SJohn Forte 284fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_PATH_ADD, 255) 285fcf3ce44SJohn Forte == 0) { 286fcf3ce44SJohn Forte 287fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_PATH_LU; 288fcf3ce44SJohn Forte 289fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_DDI_INITIATOR_REGISTER, 290fcf3ce44SJohn Forte 244) == 0) { 291fcf3ce44SJohn Forte 292fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_INITIATOR_PORT; 293fcf3ce44SJohn Forte 294fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_TPG_ADD, 295fcf3ce44SJohn Forte 255) == 0) { 296fcf3ce44SJohn Forte 297fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_TARGET_PORT_GROUP; 298fcf3ce44SJohn Forte 299fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_TARGET_PORT_ADD, 300fcf3ce44SJohn Forte 255) == 0) { 301fcf3ce44SJohn Forte 302fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_TARGET_PORT; 303fcf3ce44SJohn Forte 304fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_DEV_PROD_ADD, 255) 305fcf3ce44SJohn Forte == 0) { 306fcf3ce44SJohn Forte 307fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_DEVICE_PRODUCT; 308fcf3ce44SJohn Forte } 309fcf3ce44SJohn Forte 310fcf3ce44SJohn Forte 311fcf3ce44SJohn Forte } else if ((strstr(subClassName, "remove")) || 312fcf3ce44SJohn Forte (strstr(subClassName, "initiator_unregister"))) { 313fcf3ce44SJohn Forte 314fcf3ce44SJohn Forte eventType = VISA_CHANGE; 315fcf3ce44SJohn Forte becomingVisible = MP_FALSE; 316fcf3ce44SJohn Forte 317fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- got a visibility" 318fcf3ce44SJohn Forte " remove event"); 319fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", ": [%s]", 320fcf3ce44SJohn Forte subClassName); 321fcf3ce44SJohn Forte 322*17d71211SJiri Svoboda if (strncmp(subClassName, ESC_SUN_MP_LU_REMOVE, 255) == 0) { 323fcf3ce44SJohn Forte 324fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_MULTIPATH_LU; 325fcf3ce44SJohn Forte 326fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_PATH_REMOVE, 255) 327fcf3ce44SJohn Forte == 0) { 328fcf3ce44SJohn Forte 329fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_PATH_LU; 330fcf3ce44SJohn Forte 331fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_DDI_INITIATOR_UNREGISTER, 332fcf3ce44SJohn Forte 255) == 0) { 333fcf3ce44SJohn Forte 334fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_INITIATOR_PORT; 335fcf3ce44SJohn Forte 336fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_TPG_REMOVE, 255) 337fcf3ce44SJohn Forte == 0) { 338fcf3ce44SJohn Forte 339fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_TARGET_PORT_GROUP; 340fcf3ce44SJohn Forte 341fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_TARGET_PORT_REMOVE, 342fcf3ce44SJohn Forte 255) == 0) { 343fcf3ce44SJohn Forte 344fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_TARGET_PORT; 345fcf3ce44SJohn Forte 346fcf3ce44SJohn Forte } else if (strncmp(subClassName, ESC_SUN_MP_DEV_PROD_REMOVE, 347fcf3ce44SJohn Forte 255) == 0) { 348fcf3ce44SJohn Forte 349fcf3ce44SJohn Forte index = MP_OBJECT_TYPE_DEVICE_PRODUCT; 350fcf3ce44SJohn Forte } 351fcf3ce44SJohn Forte 352fcf3ce44SJohn Forte 353fcf3ce44SJohn Forte } else { 354fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- got an unsupported event"); 355fcf3ce44SJohn Forte return; 356fcf3ce44SJohn Forte } 357fcf3ce44SJohn Forte 358fcf3ce44SJohn Forte if (index < 0) { 359fcf3ce44SJohn Forte 360fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- index is less than zero"); 361fcf3ce44SJohn Forte return; 362fcf3ce44SJohn Forte } 363fcf3ce44SJohn Forte 364fcf3ce44SJohn Forte if (eventType == VISA_CHANGE) { 365fcf3ce44SJohn Forte 366fcf3ce44SJohn Forte (void) pthread_mutex_lock(&g_visa_mutex); 367fcf3ce44SJohn Forte 368fcf3ce44SJohn Forte if (NULL == g_Visibility_Callback_List[index].pClientFn) { 369fcf3ce44SJohn Forte 370fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 371fcf3ce44SJohn Forte "- no visibility change callback to notify"); 372fcf3ce44SJohn Forte 373fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&g_visa_mutex); 374fcf3ce44SJohn Forte 375fcf3ce44SJohn Forte return; 376fcf3ce44SJohn Forte } 377fcf3ce44SJohn Forte 378fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&g_visa_mutex); 379fcf3ce44SJohn Forte } 380fcf3ce44SJohn Forte 381fcf3ce44SJohn Forte if (eventType == PROP_CHANGE) { 382fcf3ce44SJohn Forte 383fcf3ce44SJohn Forte (void) pthread_mutex_lock(&g_prop_mutex); 384fcf3ce44SJohn Forte 385fcf3ce44SJohn Forte if (NULL == g_Property_Callback_List[index].pClientFn) { 386fcf3ce44SJohn Forte 387fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 388fcf3ce44SJohn Forte "- no property change callback to notify"); 389fcf3ce44SJohn Forte 390fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&g_prop_mutex); 391fcf3ce44SJohn Forte 392fcf3ce44SJohn Forte return; 393fcf3ce44SJohn Forte } 394fcf3ce44SJohn Forte 395fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&g_prop_mutex); 396fcf3ce44SJohn Forte } 397fcf3ce44SJohn Forte 398fcf3ce44SJohn Forte (void) sysevent_get_attr_list(ev, &attr_list); 399fcf3ce44SJohn Forte if (NULL != attr_list) { 400fcf3ce44SJohn Forte 401fcf3ce44SJohn Forte if ((VISA_CHANGE == eventType) && 402*17d71211SJiri Svoboda (MP_OBJECT_TYPE_PLUGIN == index)) { 403fcf3ce44SJohn Forte 404fcf3ce44SJohn Forte val = (uint64_t *)malloc(sizeof (uint64_t)); 405fcf3ce44SJohn Forte valAllocated = 1; 406fcf3ce44SJohn Forte 407*17d71211SJiri Svoboda /* 408*17d71211SJiri Svoboda * We have no well-defined way to determine our OSN. 409*17d71211SJiri Svoboda * Currently the common library uses 0 as OSN for every 410*17d71211SJiri Svoboda * plugin, so just use 0. If the OSN assigned by the 411*17d71211SJiri Svoboda * common library changed, this code would have to be 412*17d71211SJiri Svoboda * updated. 413*17d71211SJiri Svoboda */ 414*17d71211SJiri Svoboda *val = 0; 415fcf3ce44SJohn Forte nelem = 1; 416fcf3ce44SJohn Forte 417fcf3ce44SJohn Forte } else if ((VISA_CHANGE == eventType) && 418fcf3ce44SJohn Forte (MP_OBJECT_TYPE_INITIATOR_PORT == index)) { 419fcf3ce44SJohn Forte 420fcf3ce44SJohn Forte (void) nvlist_lookup_int32_array(attr_list, 421fcf3ce44SJohn Forte DDI_INSTANCE, &instance, &nelem); 422fcf3ce44SJohn Forte 423fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 424fcf3ce44SJohn Forte "- event (PHCI_INSTANCE) has [%d] elements", 425fcf3ce44SJohn Forte nelem); 426fcf3ce44SJohn Forte 427fcf3ce44SJohn Forte (void) nvlist_lookup_int32_array(attr_list, 428fcf3ce44SJohn Forte DDI_DRIVER_MAJOR, &major, &nelem); 429fcf3ce44SJohn Forte 430fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 431fcf3ce44SJohn Forte "- event (PHCI_DRIVER_MAJOR) has [%d] elements", 432fcf3ce44SJohn Forte nelem); 433fcf3ce44SJohn Forte 434fcf3ce44SJohn Forte if ((NULL != instance) & (NULL != major)) { 435fcf3ce44SJohn Forte 436fcf3ce44SJohn Forte val = (uint64_t *)malloc(sizeof (uint64_t)); 437fcf3ce44SJohn Forte 438fcf3ce44SJohn Forte valAllocated = 1; 439fcf3ce44SJohn Forte 440fcf3ce44SJohn Forte *val = MP_STORE_INST_TO_ID(*instance, *val); 441fcf3ce44SJohn Forte *val = MP_STORE_MAJOR_TO_ID(*major, *val); 442fcf3ce44SJohn Forte 443fcf3ce44SJohn Forte nelem = 1; 444fcf3ce44SJohn Forte 445fcf3ce44SJohn Forte } else { 446fcf3ce44SJohn Forte 447fcf3ce44SJohn Forte nelem = 0; 448fcf3ce44SJohn Forte } 449fcf3ce44SJohn Forte 450fcf3ce44SJohn Forte } else { 451fcf3ce44SJohn Forte 452fcf3ce44SJohn Forte (void) nvlist_lookup_uint64_array(attr_list, OIDLIST, 453fcf3ce44SJohn Forte &val, &nelem); 454fcf3ce44SJohn Forte 455fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 456fcf3ce44SJohn Forte "- event has [%d] elements", 457fcf3ce44SJohn Forte nelem); 458fcf3ce44SJohn Forte } 459fcf3ce44SJohn Forte 460fcf3ce44SJohn Forte if (nelem > 0) { 461fcf3ce44SJohn Forte 462fcf3ce44SJohn Forte for (i = 0; i < nelem; i++) { 463fcf3ce44SJohn Forte 464fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 465fcf3ce44SJohn Forte "- event [%d] = %llx", 466fcf3ce44SJohn Forte i, val[i]); 467fcf3ce44SJohn Forte } 468fcf3ce44SJohn Forte 469fcf3ce44SJohn Forte oidList = createOidList(nelem); 470fcf3ce44SJohn Forte if (NULL == oidList) { 471fcf3ce44SJohn Forte 472fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 473fcf3ce44SJohn Forte "- unable to create MP_OID_LIST"); 474fcf3ce44SJohn Forte 475fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 476fcf3ce44SJohn Forte "- error exit"); 477fcf3ce44SJohn Forte 478fcf3ce44SJohn Forte nvlist_free(attr_list); 479fcf3ce44SJohn Forte 480fcf3ce44SJohn Forte return; 481fcf3ce44SJohn Forte } 482fcf3ce44SJohn Forte 483fcf3ce44SJohn Forte oidList->oidCount = nelem; 484fcf3ce44SJohn Forte 485fcf3ce44SJohn Forte for (i = 0; i < nelem; i++) { 486fcf3ce44SJohn Forte 487fcf3ce44SJohn Forte oidList->oids[i].objectType = index; 488fcf3ce44SJohn Forte oidList->oids[i].ownerId = g_pluginOwnerID; 489fcf3ce44SJohn Forte oidList->oids[i].objectSequenceNumber = val[i]; 490fcf3ce44SJohn Forte } 491fcf3ce44SJohn Forte 492fcf3ce44SJohn Forte if (valAllocated) { 493fcf3ce44SJohn Forte 494fcf3ce44SJohn Forte free(val); 495fcf3ce44SJohn Forte } 496fcf3ce44SJohn Forte 497fcf3ce44SJohn Forte for (i = 0; i < oidList->oidCount; i++) { 498fcf3ce44SJohn Forte 499fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 500fcf3ce44SJohn Forte "oidList->oids[%d].objectType" 501fcf3ce44SJohn Forte " = %d", 502fcf3ce44SJohn Forte i, oidList->oids[i].objectType); 503fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 504fcf3ce44SJohn Forte "oidList->oids[%d].ownerId" 505fcf3ce44SJohn Forte " = %d", 506fcf3ce44SJohn Forte i, oidList->oids[i].ownerId); 507fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", 508fcf3ce44SJohn Forte "oidList->oids[%d].objectSequenceNumber" 509fcf3ce44SJohn Forte " = %llx", 510*17d71211SJiri Svoboda i, oidList->oids[i].objectSequenceNumber); 511fcf3ce44SJohn Forte } 512fcf3ce44SJohn Forte 513fcf3ce44SJohn Forte if (eventType == PROP_CHANGE) { 514fcf3ce44SJohn Forte 515fcf3ce44SJohn Forte (void) pthread_mutex_lock(&g_prop_mutex); 516fcf3ce44SJohn Forte 517fcf3ce44SJohn Forte pCallerData = g_Property_Callback_List[index]. 518fcf3ce44SJohn Forte pCallerData; 519fcf3ce44SJohn Forte 520fcf3ce44SJohn Forte (g_Property_Callback_List[index].pClientFn) 521fcf3ce44SJohn Forte (oidList, pCallerData); 522fcf3ce44SJohn Forte 523fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&g_prop_mutex); 524fcf3ce44SJohn Forte 525fcf3ce44SJohn Forte } else if (eventType == VISA_CHANGE) { 526fcf3ce44SJohn Forte 527fcf3ce44SJohn Forte (void) pthread_mutex_lock(&g_visa_mutex); 528fcf3ce44SJohn Forte 529fcf3ce44SJohn Forte pCallerData = g_Visibility_Callback_List[index]. 530fcf3ce44SJohn Forte pCallerData; 531fcf3ce44SJohn Forte 532fcf3ce44SJohn Forte (g_Visibility_Callback_List[index].pClientFn) 533fcf3ce44SJohn Forte (becomingVisible, oidList, pCallerData); 534fcf3ce44SJohn Forte 535fcf3ce44SJohn Forte (void) pthread_mutex_unlock(&g_visa_mutex); 536fcf3ce44SJohn Forte 537fcf3ce44SJohn Forte } 538fcf3ce44SJohn Forte } 539fcf3ce44SJohn Forte 540fcf3ce44SJohn Forte nvlist_free(attr_list); 541fcf3ce44SJohn Forte } 542fcf3ce44SJohn Forte 543fcf3ce44SJohn Forte 544fcf3ce44SJohn Forte log(LOG_INFO, "notifyClient()", "- exit"); 545fcf3ce44SJohn Forte } 546fcf3ce44SJohn Forte 547fcf3ce44SJohn Forte /* Event handler called by system */ 548fcf3ce44SJohn Forte static void 549fcf3ce44SJohn Forte sysevent_handler(sysevent_t *ev) 550fcf3ce44SJohn Forte { 551fcf3ce44SJohn Forte log(LOG_INFO, "sysevent_handler()", "- enter"); 552fcf3ce44SJohn Forte 553fcf3ce44SJohn Forte /* Is the event one of ours? */ 554fcf3ce44SJohn Forte if ((strncmp(EC_SUN_MP, sysevent_get_class_name(ev), 9) != 0) && 555fcf3ce44SJohn Forte (strncmp(EC_DEVFS, sysevent_get_class_name(ev), 8) != 0) && 556fcf3ce44SJohn Forte (strncmp(EC_DDI, sysevent_get_class_name(ev), 6) != 0)) { 557fcf3ce44SJohn Forte 558fcf3ce44SJohn Forte return; 559fcf3ce44SJohn Forte } 560fcf3ce44SJohn Forte 561fcf3ce44SJohn Forte /* Notify client if it cares */ 562fcf3ce44SJohn Forte notifyClient(ev); 563fcf3ce44SJohn Forte 564fcf3ce44SJohn Forte 565fcf3ce44SJohn Forte log(LOG_INFO, "sysevent_handler()", "- exit"); 566fcf3ce44SJohn Forte } 567fcf3ce44SJohn Forte 568fcf3ce44SJohn Forte /* Registers the plugin to the sysevent framework */ 569*17d71211SJiri Svoboda MP_STATUS 570*17d71211SJiri Svoboda init_sysevents(void) { 571fcf3ce44SJohn Forte 572fcf3ce44SJohn Forte const char *subclass_list[] = { 573fcf3ce44SJohn Forte 574*17d71211SJiri Svoboda ESC_SUN_MP_PLUGIN_CHANGE, 575*17d71211SJiri Svoboda 576fcf3ce44SJohn Forte ESC_SUN_MP_LU_CHANGE, 577*17d71211SJiri Svoboda ESC_SUN_MP_LU_ADD, 578*17d71211SJiri Svoboda ESC_SUN_MP_LU_REMOVE, 579fcf3ce44SJohn Forte 580fcf3ce44SJohn Forte ESC_SUN_MP_PATH_CHANGE, 581fcf3ce44SJohn Forte ESC_SUN_MP_PATH_ADD, 582fcf3ce44SJohn Forte ESC_SUN_MP_PATH_REMOVE, 583fcf3ce44SJohn Forte 584fcf3ce44SJohn Forte ESC_SUN_MP_INIT_PORT_CHANGE, 585fcf3ce44SJohn Forte 586fcf3ce44SJohn Forte ESC_SUN_MP_TPG_CHANGE, 587fcf3ce44SJohn Forte ESC_SUN_MP_TPG_ADD, 588fcf3ce44SJohn Forte ESC_SUN_MP_TPG_REMOVE, 589fcf3ce44SJohn Forte 590fcf3ce44SJohn Forte ESC_SUN_MP_TARGET_PORT_CHANGE, 591fcf3ce44SJohn Forte ESC_SUN_MP_TARGET_PORT_ADD, 592fcf3ce44SJohn Forte ESC_SUN_MP_TARGET_PORT_REMOVE, 593fcf3ce44SJohn Forte 594fcf3ce44SJohn Forte ESC_SUN_MP_DEV_PROD_CHANGE, 595fcf3ce44SJohn Forte ESC_SUN_MP_DEV_PROD_ADD, 596fcf3ce44SJohn Forte ESC_SUN_MP_DEV_PROD_REMOVE 597fcf3ce44SJohn Forte 598fcf3ce44SJohn Forte }; 599fcf3ce44SJohn Forte 600fcf3ce44SJohn Forte const char *init_port_subclass_list[] = { 601fcf3ce44SJohn Forte 602fcf3ce44SJohn Forte ESC_DDI_INITIATOR_REGISTER, 603fcf3ce44SJohn Forte ESC_DDI_INITIATOR_UNREGISTER 604fcf3ce44SJohn Forte }; 605fcf3ce44SJohn Forte 606fcf3ce44SJohn Forte 607fcf3ce44SJohn Forte 608fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", "- enter"); 609fcf3ce44SJohn Forte 610fcf3ce44SJohn Forte 611fcf3ce44SJohn Forte g_SysEventHandle = sysevent_bind_handle(sysevent_handler); 612fcf3ce44SJohn Forte if (g_SysEventHandle == NULL) { 613fcf3ce44SJohn Forte 614fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", 615fcf3ce44SJohn Forte "- sysevent_bind_handle() failed"); 616fcf3ce44SJohn Forte 617fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", "- error exit"); 618fcf3ce44SJohn Forte 619fcf3ce44SJohn Forte return (MP_STATUS_FAILED); 620fcf3ce44SJohn Forte } 621fcf3ce44SJohn Forte 622fcf3ce44SJohn Forte if (sysevent_subscribe_event(g_SysEventHandle, EC_SUN_MP, 623*17d71211SJiri Svoboda subclass_list, sizeof (subclass_list) / sizeof (subclass_list[0])) 624*17d71211SJiri Svoboda != 0) { 625fcf3ce44SJohn Forte 626fcf3ce44SJohn Forte 627fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", 628fcf3ce44SJohn Forte "- sysevent_subscribe_event() failed for subclass_list"); 629fcf3ce44SJohn Forte 630fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", "- error exit"); 631fcf3ce44SJohn Forte 632fcf3ce44SJohn Forte sysevent_unbind_handle(g_SysEventHandle); 633fcf3ce44SJohn Forte 634fcf3ce44SJohn Forte return (MP_STATUS_FAILED); 635fcf3ce44SJohn Forte } 636fcf3ce44SJohn Forte 637fcf3ce44SJohn Forte if (sysevent_subscribe_event(g_SysEventHandle, EC_DDI, 638*17d71211SJiri Svoboda init_port_subclass_list, sizeof (init_port_subclass_list) / 639*17d71211SJiri Svoboda sizeof (init_port_subclass_list[0])) != 0) { 640fcf3ce44SJohn Forte 641fcf3ce44SJohn Forte 642fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", 643fcf3ce44SJohn Forte "- sysevent_subscribe_event() failed " 644fcf3ce44SJohn Forte "for init_port_subclass_list"); 645fcf3ce44SJohn Forte 646fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", "- error exit"); 647fcf3ce44SJohn Forte 648fcf3ce44SJohn Forte sysevent_unbind_handle(g_SysEventHandle); 649fcf3ce44SJohn Forte 650fcf3ce44SJohn Forte return (MP_STATUS_FAILED); 651fcf3ce44SJohn Forte } 652fcf3ce44SJohn Forte 653fcf3ce44SJohn Forte 654fcf3ce44SJohn Forte log(LOG_INFO, "init_sysevents()", "- exit"); 655fcf3ce44SJohn Forte 656fcf3ce44SJohn Forte return (MP_STATUS_SUCCESS); 657fcf3ce44SJohn Forte } 658