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