2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A
2N/A/*
2N/A * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/*
2N/A *
2N/A * MODULE: dapl_init.c
2N/A *
2N/A * PURPOSE: Interface Adapter management
2N/A * Description: Interfaces in this file are completely described in
2N/A * the DAPL 1.1 API, Chapter 6, section 2
2N/A *
2N/A * $Id: dapl_init.c,v 1.42 2003/06/30 15:38:20 sjs2 Exp $
2N/A */
2N/A
2N/A#include "dapl.h"
2N/A#include "dapl_hca_util.h"
2N/A#include "dapl_init.h"
2N/A#include "dapl_provider.h"
2N/A#include "dapl_mr_util.h"
2N/A#include "dapl_osd.h" /* needed for g_daplDebugLevel */
2N/A#include "dapl_adapter_util.h"
2N/A#include "dapl_name_service.h"
2N/A#include "dapl_vendor.h"
2N/A
2N/Astatic void dapl_init(void);
2N/Astatic void dapl_fini(void);
2N/A
2N/A#pragma init(dapl_init)
2N/A#pragma fini(dapl_fini)
2N/A
2N/A/*
2N/A * dapl_init
2N/A *
2N/A * initialize this provider
2N/A * includes initialization of all global variables
2N/A * as well as registering all supported IAs with the dat registry
2N/A *
2N/A * This function needs to be called once when the provider is loaded.
2N/A *
2N/A * Input:
2N/A * none
2N/A *
2N/A * Output:
2N/A * none
2N/A *
2N/A * Return Values:
2N/A */
2N/Astatic void
2N/Adapl_init(void)
2N/A{
2N/A DAT_RETURN dat_status;
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "DAPL: Started (dapl_init)\n");
2N/A
2N/A#if defined(DAPL_DBG)
2N/A /* set up debug type */
2N/A g_dapl_dbg_type = dapl_os_get_env_val("DAPL_DBG_TYPE",
2N/A DAPL_DBG_TYPE_ERR | DAPL_DBG_TYPE_WARN);
2N/A /* set up debug level */
2N/A g_dapl_dbg_dest = dapl_os_get_env_val("DAPL_DBG_DEST",
2N/A DAPL_DBG_DEST_STDOUT);
2N/A#endif /* DAPL_DBG */
2N/A
2N/A /* See if the user is on a loopback setup */
2N/A g_dapl_loopback_connection = dapl_os_get_env_bool("DAPL_LOOPBACK");
2N/A dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "DAPL: %s Setting Loopback\n",
2N/A g_dapl_loopback_connection ? "" : "NOT");
2N/A
2N/A dapls_ib_state_init();
2N/A
2N/A /* initialize the provider list */
2N/A dat_status = dapl_provider_list_create();
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR,
2N/A "dapl_provider_list_create failed %d\n", dat_status);
2N/A goto bail;
2N/A }
2N/A
2N/A /* Set up name services */
2N/A dat_status = dapls_ns_init();
2N/A
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR, "dapls_ns_init failed %d\n",
2N/A dat_status);
2N/A goto bail;
2N/A }
2N/A
2N/A return;
2N/A
2N/Abail:
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR, "ERROR: dapl_init failed\n");
2N/A dapl_fini();
2N/A}
2N/A
2N/A/*
2N/A * dapl_fini
2N/A *
2N/A * finalize this provider
2N/A * includes freeing of all global variables
2N/A * as well as deregistering all supported IAs from the dat registry
2N/A *
2N/A * This function needs to be called once when the provider is loaded.
2N/A *
2N/A * Input:
2N/A * none
2N/A *
2N/A * Output:
2N/A * none
2N/A *
2N/A * Return Values:
2N/A */
2N/Astatic void
2N/Adapl_fini(void)
2N/A{
2N/A DAT_RETURN dat_status;
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_UTIL, "DAPL: Stopped (dapl_fini)\n");
2N/A
2N/A /*
2N/A * Free up hca related resources
2N/A */
2N/A dapls_ib_state_fini();
2N/A
2N/A dat_status = dapl_provider_list_destroy();
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR,
2N/A "dapl_provider_list_destroy failed %d\n", dat_status);
2N/A }
2N/A}
2N/A
2N/A/*
2N/A *
2N/A * This function is called by the registry to initialize a provider
2N/A *
2N/A * The instance data string is expected to have the following form:
2N/A *
2N/A * <hca name> <port number>
2N/A *
2N/A */
2N/A/* ARGSUSED */
2N/Avoid
2N/Adat_provider_init(
2N/A IN const DAT_PROVIDER_INFO *provider_info,
2N/A IN const char *instance_data)
2N/A{
2N/A DAT_PROVIDER *provider;
2N/A DAPL_HCA *hca_ptr;
2N/A DAT_RETURN dat_status;
2N/A
2N/A provider = NULL;
2N/A hca_ptr = NULL;
2N/A
2N/A dat_status = dapl_provider_list_insert(provider_info->ia_name,
2N/A &provider);
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR,
2N/A "dat_provider_list_insert failed: %x\n", dat_status);
2N/A goto bail;
2N/A }
2N/A
2N/A hca_ptr = dapl_hca_alloc((char *)provider_info->ia_name, 0);
2N/A if (NULL == hca_ptr) {
2N/A dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A
2N/A provider->extension = hca_ptr;
2N/A
2N/A /* register providers with dat_registry */
2N/A dat_status = dat_registry_add_provider(provider, provider_info);
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR,
2N/A "dat_registry_add_provider failed: %x\n", dat_status);
2N/A goto bail;
2N/A }
2N/A
2N/Abail:
2N/A if (DAT_SUCCESS != dat_status) {
2N/A if (NULL != provider) {
2N/A (void) dapl_provider_list_remove(
2N/A provider_info->ia_name);
2N/A }
2N/A
2N/A if (NULL != hca_ptr) {
2N/A dapl_hca_free(hca_ptr);
2N/A }
2N/A }
2N/A}
2N/A
2N/A
2N/A/*
2N/A *
2N/A * This function is called by the registry to de-initialize a provider
2N/A *
2N/A */
2N/Avoid
2N/Adat_provider_fini(
2N/A IN const DAT_PROVIDER_INFO *provider_info)
2N/A{
2N/A DAT_PROVIDER *provider;
2N/A DAT_RETURN dat_status;
2N/A
2N/A dat_status = dapl_provider_list_search(provider_info->ia_name,
2N/A &provider);
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR,
2N/A "dat_registry_add_provider failed: %x\n", dat_status);
2N/A return;
2N/A }
2N/A
2N/A dat_status = dat_registry_remove_provider(provider, provider_info);
2N/A if (DAT_SUCCESS != dat_status) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_ERR,
2N/A "dat_registry_add_provider failed: %x\n", dat_status);
2N/A }
2N/A
2N/A (void) dapl_provider_list_remove(provider_info->ia_name);
2N/A}
2N/A
2N/A
2N/A
2N/A/*
2N/A * Local variables:
2N/A * c-indent-level: 4
2N/A * c-basic-offset: 4
2N/A * tab-width: 8
2N/A * End:
2N/A */