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 2003 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_rsp_create.c
2N/A *
2N/A * PURPOSE: Connection management
2N/A * Description: Interfaces in this file are completely described in
2N/A * the DAPL 1.1 API, Chapter 6, section 4
2N/A *
2N/A * $Id: dapl_rsp_create.c,v 1.14 2003/07/25 19:24:11 sjs2 Exp $
2N/A */
2N/A
2N/A#include "dapl.h"
2N/A#include "dapl_sp_util.h"
2N/A#include "dapl_ia_util.h"
2N/A#include "dapl_ep_util.h"
2N/A#include "dapl_adapter_util.h"
2N/A
2N/A/*
2N/A * dapl_rsp_create
2N/A *
2N/A * uDAPL: User Direct Access Program Library Version 1.1, 6.4.3.4.1
2N/A *
2N/A * Create a Resereved Service Point with the specified Endpoint
2N/A * that generates at most one Connection Request that is
2N/A * delivered to the specified Event Dispatcher in a notification
2N/A * event
2N/A *
2N/A * Input:
2N/A * ia_handle
2N/A * conn_qual
2N/A * ep_handle
2N/A * evd_handle
2N/A *
2N/A * Output:
2N/A * rsp_handle
2N/A *
2N/A * Returns:
2N/A * DAT_SUCCESS
2N/A * DAT_INSUFFICIENT_RESOURCES
2N/A * DAT_INVALID_PARAMETER
2N/A * DAT_INVALID_STATE
2N/A * DAT_CONN_QUAL_IN_USE
2N/A */
2N/ADAT_RETURN
2N/Adapl_rsp_create(
2N/A IN DAT_IA_HANDLE ia_handle,
2N/A IN DAT_CONN_QUAL conn_qual,
2N/A IN DAT_EP_HANDLE ep_handle,
2N/A IN DAT_EVD_HANDLE evd_handle,
2N/A OUT DAT_RSP_HANDLE *rsp_handle)
2N/A{
2N/A DAPL_IA *ia_ptr;
2N/A DAPL_SP *sp_ptr;
2N/A DAPL_EVD *evd_ptr;
2N/A DAPL_EP *ep_ptr;
2N/A DAT_BOOLEAN sp_found;
2N/A DAT_RETURN dat_status;
2N/A
2N/A dat_status = DAT_SUCCESS;
2N/A ia_ptr = (DAPL_IA *)ia_handle;
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_CM,
2N/A ">>> dapl_rsp_free conn_qual: %x EP: %p\n",
2N/A conn_qual, ep_handle);
2N/A
2N/A if (DAPL_BAD_HANDLE(ia_ptr, DAPL_MAGIC_IA)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
2N/A DAT_INVALID_HANDLE_IA);
2N/A goto bail;
2N/A }
2N/A if (DAPL_BAD_HANDLE(ep_handle, DAPL_MAGIC_EP)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
2N/A DAT_INVALID_HANDLE_EP);
2N/A goto bail;
2N/A }
2N/A if (DAPL_BAD_HANDLE(evd_handle, DAPL_MAGIC_EVD)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
2N/A DAT_INVALID_HANDLE_EVD_CR);
2N/A goto bail;
2N/A }
2N/A
2N/A if (rsp_handle == NULL) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG5);
2N/A goto bail;
2N/A }
2N/A
2N/A ep_ptr = (DAPL_EP *) ep_handle;
2N/A if (ep_ptr->param.ep_state != DAT_EP_STATE_UNCONNECTED) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_STATE,
2N/A dapls_ep_state_subtype(ep_ptr));
2N/A goto bail;
2N/A }
2N/A
2N/A evd_ptr = (DAPL_EVD *)evd_handle;
2N/A if (!(evd_ptr->evd_flags & DAT_EVD_CR_FLAG)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
2N/A DAT_INVALID_HANDLE_EVD_CR);
2N/A goto bail;
2N/A }
2N/A
2N/A sp_ptr = dapls_ia_sp_search(ia_ptr, conn_qual, DAT_FALSE);
2N/A sp_found = DAT_TRUE;
2N/A if (sp_ptr == NULL) {
2N/A sp_found = DAT_FALSE;
2N/A
2N/A /* Allocate RSP */
2N/A sp_ptr = dapls_sp_alloc(ia_ptr, DAT_FALSE);
2N/A if (sp_ptr == NULL) {
2N/A dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Fill out the RSP args
2N/A */
2N/A sp_ptr->ia_handle = ia_handle;
2N/A sp_ptr->conn_qual = conn_qual;
2N/A sp_ptr->evd_handle = evd_handle;
2N/A sp_ptr->psp_flags = 0;
2N/A sp_ptr->ep_handle = ep_handle;
2N/A
2N/A /*
2N/A * Take a reference on the EVD handle
2N/A */
2N/A (void) dapl_os_atomic_inc(&((DAPL_EVD *)evd_handle)->evd_ref_count);
2N/A
2N/A /*
2N/A * Update the EP state indicating the provider now owns it
2N/A */
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_RESERVED;
2N/A
2N/A /*
2N/A * Set up a listener for a connection. Connections can arrive
2N/A * even before this call returns!
2N/A */
2N/A sp_ptr->state = DAPL_SP_STATE_RSP_LISTENING;
2N/A sp_ptr->listening = DAT_TRUE;
2N/A
2N/A if (sp_found == DAT_FALSE) {
2N/A /* Link it onto the IA */
2N/A dapl_ia_link_rsp(ia_ptr, sp_ptr);
2N/A
2N/A dat_status = dapls_ib_setup_conn_listener(ia_ptr, conn_qual,
2N/A sp_ptr);
2N/A
2N/A if (dat_status != DAT_SUCCESS) {
2N/A /*
2N/A * Have a problem setting up the connection, something
2N/A * wrong!
2N/A * rsp_free will decrement the EVD refcount. Set
2N/A * listening to * false to avoid tearing down the
2N/A * conn_listener which didn't * get set up.
2N/A */
2N/A sp_ptr->listening = DAT_FALSE;
2N/A (void) dapl_rsp_free((DAT_RSP_HANDLE) sp_ptr);
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_CM,
2N/A "--> dapl_rsp_create setup_conn_listener failed: "
2N/A "%x\n",
2N/A dat_status);
2N/A
2N/A goto bail;
2N/A }
2N/A }
2N/A
2N/A /*
2N/A * Return handle to the user
2N/A */
2N/A *rsp_handle = (DAT_RSP_HANDLE)sp_ptr;
2N/A
2N/Abail:
2N/A return (dat_status);
2N/A}