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_psp_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_psp_create.c,v 1.16 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_adapter_util.h"
2N/A
2N/A/*
2N/A * dapl_psp_create
2N/A *
2N/A * uDAPL: User Direct Access Program Library Version 1.1, 6.4.1.1
2N/A *
2N/A * Create a persistent Public Service Point that can recieve multiple
2N/A * requests for connections and generate multiple connection request
2N/A * instances that wil be delivered to the specified Event Dispatcher
2N/A * in a notification event.
2N/A *
2N/A * Input:
2N/A * ia_handle
2N/A * conn_qual
2N/A * evd_handle
2N/A * psp_flags
2N/A *
2N/A * Output:
2N/A * psp_handle
2N/A *
2N/A * Returns:
2N/A * DAT_SUCCESS
2N/A * DAT_INSUFFICIENT_RESOURCES
2N/A * DAT_INVALID_PARAMETER
2N/A * DAT_CONN_QUAL_IN_USE
2N/A * DAT_MODEL_NOT_SUPPORTED
2N/A */
2N/ADAT_RETURN
2N/Adapl_psp_create(
2N/A IN DAT_IA_HANDLE ia_handle,
2N/A IN DAT_CONN_QUAL conn_qual,
2N/A IN DAT_EVD_HANDLE evd_handle,
2N/A IN DAT_PSP_FLAGS psp_flags,
2N/A OUT DAT_PSP_HANDLE *psp_handle)
2N/A{
2N/A DAPL_IA *ia_ptr;
2N/A DAPL_SP *sp_ptr;
2N/A DAPL_EVD *evd_ptr;
2N/A DAT_BOOLEAN sp_found;
2N/A DAT_RETURN dat_status;
2N/A
2N/A ia_ptr = (DAPL_IA *)ia_handle;
2N/A dat_status = DAT_SUCCESS;
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
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 (psp_handle == NULL) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG5);
2N/A goto bail;
2N/A }
2N/A
2N/A /* check for invalid psp flags */
2N/A if ((psp_flags != DAT_PSP_CONSUMER_FLAG) &&
2N/A (psp_flags != DAT_PSP_PROVIDER_FLAG)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);
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 /*
2N/A * check for connection qualifier eq 0
2N/A * in IB this is called Null Service ID, use of it in CM is invalid.
2N/A * in tcp/udp, port number 0 is reserved.
2N/A */
2N/A if (!conn_qual) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG2);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * See if we have a quiescent listener to use for this PSP, else
2N/A * create one and set it listening
2N/A */
2N/A sp_ptr = dapls_ia_sp_search(ia_ptr, conn_qual, DAT_TRUE);
2N/A sp_found = DAT_TRUE;
2N/A if (sp_ptr == NULL) {
2N/A /* Allocate PSP */
2N/A sp_found = DAT_FALSE;
2N/A sp_ptr = dapls_sp_alloc(ia_ptr, DAT_TRUE);
2N/A
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 } else if (sp_ptr->listening == DAT_TRUE) {
2N/A dat_status = DAT_ERROR(DAT_CONN_QUAL_IN_USE, 0);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * Fill out the args for a PSP
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 = psp_flags;
2N/A sp_ptr->ep_handle = NULL;
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 * 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_PSP_LISTENING;
2N/A sp_ptr->listening = DAT_TRUE;
2N/A
2N/A /*
2N/A * If this is a new sp we need to add it to the IA queue, and set up
2N/A * a conn_listener.
2N/A */
2N/A if (sp_found == DAT_FALSE) {
2N/A
2N/A /* Link it onto the IA */
2N/A dapl_ia_link_psp(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! The psp_free decrements the EVD refcount for
2N/A * us; we don't * need to do that.
2N/A * But we want to set the listener bits to false,
2N/A * as we know that call failed.
2N/A */
2N/A sp_ptr->state = DAPL_SP_STATE_FREE;
2N/A sp_ptr->listening = DAT_FALSE;
2N/A (void) dapl_psp_free((DAT_PSP_HANDLE) sp_ptr);
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_CM,
2N/A "--> dapl_psp_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 *psp_handle = (DAT_PSP_HANDLE)sp_ptr;
2N/A
2N/Abail:
2N/A return (dat_status);
2N/A}