xref: /onnv-gate/usr/src/lib/mpapi/libmpscsi_vhci/common/Initialize.c (revision 12550:ad6d6a75d3d6)
17836SJohn.Forte@Sun.COM /*
27836SJohn.Forte@Sun.COM  * CDDL HEADER START
37836SJohn.Forte@Sun.COM  *
47836SJohn.Forte@Sun.COM  * The contents of this file are subject to the terms of the
57836SJohn.Forte@Sun.COM  * Common Development and Distribution License (the "License").
67836SJohn.Forte@Sun.COM  *  You may not use this file except in compliance with the License.
77836SJohn.Forte@Sun.COM  *
87836SJohn.Forte@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97836SJohn.Forte@Sun.COM  * or http://www.opensolaris.org/os/licensing.
107836SJohn.Forte@Sun.COM  * See the License for the specific language governing permissions
117836SJohn.Forte@Sun.COM  * and limitations under the License.
127836SJohn.Forte@Sun.COM  *
137836SJohn.Forte@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
147836SJohn.Forte@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157836SJohn.Forte@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
167836SJohn.Forte@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
177836SJohn.Forte@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
187836SJohn.Forte@Sun.COM  *
197836SJohn.Forte@Sun.COM  * CDDL HEADER END
207836SJohn.Forte@Sun.COM  */
217836SJohn.Forte@Sun.COM /*
22*12550SJiri.Svoboda@Sun.COM  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
237836SJohn.Forte@Sun.COM  */
247836SJohn.Forte@Sun.COM 
257836SJohn.Forte@Sun.COM 
267836SJohn.Forte@Sun.COM #include <sys/stat.h>
277836SJohn.Forte@Sun.COM #include <fcntl.h>
287836SJohn.Forte@Sun.COM #include <errno.h>
297836SJohn.Forte@Sun.COM 
307836SJohn.Forte@Sun.COM #include "mp_utils.h"
317836SJohn.Forte@Sun.COM 
327836SJohn.Forte@Sun.COM 
337836SJohn.Forte@Sun.COM /*
347836SJohn.Forte@Sun.COM  *	Global Variables
357836SJohn.Forte@Sun.COM  */
367836SJohn.Forte@Sun.COM 
377836SJohn.Forte@Sun.COM MP_UINT32	g_pluginOwnerID = 0;
387836SJohn.Forte@Sun.COM int		g_scsi_vhci_fd  = -1;
397836SJohn.Forte@Sun.COM 
407836SJohn.Forte@Sun.COM PROPERTY_CALLBACK_NODE   g_Property_Callback_List[MP_OBJECT_TYPE_MAX + 1];
417836SJohn.Forte@Sun.COM VISIBILITY_CALLBACK_NODE g_Visibility_Callback_List[MP_OBJECT_TYPE_MAX + 1];
427836SJohn.Forte@Sun.COM 
437836SJohn.Forte@Sun.COM sysevent_handle_t *g_SysEventHandle = NULL;
447836SJohn.Forte@Sun.COM 
457836SJohn.Forte@Sun.COM pthread_mutex_t g_visa_mutex = PTHREAD_MUTEX_INITIALIZER;
467836SJohn.Forte@Sun.COM pthread_mutex_t g_prop_mutex = PTHREAD_MUTEX_INITIALIZER;
477836SJohn.Forte@Sun.COM 
487836SJohn.Forte@Sun.COM /*
497836SJohn.Forte@Sun.COM  *	Called by the common layer to request the plugin to initialize
507836SJohn.Forte@Sun.COM  *	itself.
517836SJohn.Forte@Sun.COM  */
527836SJohn.Forte@Sun.COM 
537836SJohn.Forte@Sun.COM MP_STATUS
Initialize(MP_UINT32 pluginOwnerID)547836SJohn.Forte@Sun.COM Initialize(MP_UINT32 pluginOwnerID)
557836SJohn.Forte@Sun.COM {
567836SJohn.Forte@Sun.COM 	log(LOG_INFO, "Initialize()", " - enter");
577836SJohn.Forte@Sun.COM 
587836SJohn.Forte@Sun.COM 
597836SJohn.Forte@Sun.COM 	(void) memset(&g_Property_Callback_List, 0,
60*12550SJiri.Svoboda@Sun.COM 	    sizeof (PROPERTY_CALLBACK_NODE) * (MP_OBJECT_TYPE_MAX + 1));
617836SJohn.Forte@Sun.COM 
627836SJohn.Forte@Sun.COM 	(void) memset(&g_Visibility_Callback_List, 0,
63*12550SJiri.Svoboda@Sun.COM 	    sizeof (VISIBILITY_CALLBACK_NODE) * (MP_OBJECT_TYPE_MAX + 1));
647836SJohn.Forte@Sun.COM 
657836SJohn.Forte@Sun.COM 	/* Attempt to open the driver that this plugin will make request of. */
667836SJohn.Forte@Sun.COM 	g_scsi_vhci_fd = open("/devices/scsi_vhci:devctl",
677836SJohn.Forte@Sun.COM 	    O_NDELAY | O_RDONLY);
687836SJohn.Forte@Sun.COM 
697836SJohn.Forte@Sun.COM 	if (g_scsi_vhci_fd < 0) {
707836SJohn.Forte@Sun.COM 		log(LOG_INFO, "Initialize()",
717836SJohn.Forte@Sun.COM 		    " - failed to open driver.  error is : %s",
727836SJohn.Forte@Sun.COM 		    strerror(errno));
737836SJohn.Forte@Sun.COM 		log(LOG_INFO, "Initialize()", " - error exit");
74*12550SJiri.Svoboda@Sun.COM 		return (MP_STATUS_FAILED);
757836SJohn.Forte@Sun.COM 	}
767836SJohn.Forte@Sun.COM 
777836SJohn.Forte@Sun.COM 	g_pluginOwnerID = pluginOwnerID;
787836SJohn.Forte@Sun.COM 
797836SJohn.Forte@Sun.COM 	log(LOG_INFO, "Initialize()", " - exit");
807836SJohn.Forte@Sun.COM 
81*12550SJiri.Svoboda@Sun.COM 	return (MP_STATUS_SUCCESS);
827836SJohn.Forte@Sun.COM }
83