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 2009 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_ep_connect.c
2N/A *
2N/A * PURPOSE: Endpoint management
2N/A * Description: Interfaces in this file are completely described in
2N/A * the DAPL 1.1 API, Chapter 6, section 5
2N/A *
2N/A * $Id: dapl_ep_connect.c,v 1.23 2003/07/31 13:55:18 hobie16 Exp $
2N/A */
2N/A
2N/A#include "dapl.h"
2N/A#include "dapl_ep_util.h"
2N/A#include "dapl_adapter_util.h"
2N/A#include "dapl_evd_util.h"
2N/A
2N/A/*
2N/A * dapl_ep_connect
2N/A *
2N/A * DAPL Requirements Version xxx, 6.5.7
2N/A *
2N/A * Request a connection be established between the local Endpoint
2N/A * and a remote Endpoint. This operation is used by the active/client
2N/A * side of a connection
2N/A *
2N/A * Input:
2N/A * ep_handle
2N/A * remote_ia_address
2N/A * remote_conn_qual
2N/A * timeout
2N/A * private_data_size
2N/A * privaet_data
2N/A * qos
2N/A * connect_flags
2N/A *
2N/A * Output:
2N/A * None
2N/A *
2N/A * Returns:
2N/A * DAT_SUCCESS
2N/A * DAT_INSUFFICIENT_RESOUCRES
2N/A * DAT_INVALID_PARAMETER
2N/A * DAT_MODLE_NOT_SUPPORTED
2N/A */
2N/ADAT_RETURN
2N/Adapl_ep_connect(
2N/A IN DAT_EP_HANDLE ep_handle,
2N/A IN DAT_IA_ADDRESS_PTR remote_ia_address,
2N/A IN DAT_CONN_QUAL remote_conn_qual,
2N/A IN DAT_TIMEOUT timeout,
2N/A IN DAT_COUNT private_data_size,
2N/A IN const DAT_PVOID private_data,
2N/A IN DAT_QOS qos,
2N/A IN DAT_CONNECT_FLAGS connect_flags)
2N/A{
2N/A DAPL_EP *ep_ptr;
2N/A DAPL_PRIVATE prd;
2N/A DAPL_EP alloc_ep;
2N/A DAT_RETURN dat_status;
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_API | DAPL_DBG_TYPE_CM,
2N/A "dapl_ep_connect (%p, {%u.%u.%u.%u}, %X, %d, %d, %p, %x, %x)\n",
2N/A ep_handle,
2N/A remote_ia_address->sa_data[2],
2N/A remote_ia_address->sa_data[3],
2N/A remote_ia_address->sa_data[4],
2N/A remote_ia_address->sa_data[5],
2N/A remote_conn_qual,
2N/A timeout,
2N/A private_data_size,
2N/A private_data,
2N/A qos,
2N/A connect_flags);
2N/A
2N/A dat_status = DAT_SUCCESS;
2N/A ep_ptr = (DAPL_EP *) ep_handle;
2N/A
2N/A /*
2N/A * Verify parameter & state. The connection handle must be good
2N/A * at this point.
2N/A */
2N/A if (DAPL_BAD_HANDLE(ep_ptr, 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
2N/A if (DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
2N/A DAT_INVALID_HANDLE_EVD_CONN);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * If the endpoint needs a QP, associated the QP with it.
2N/A * This needs to be done carefully, in order to:
2N/A * * Avoid allocating under a lock.
2N/A * * Not step on data structures being altered by
2N/A * routines with which we are racing.
2N/A * So we:
2N/A * * Confirm that a new QP is needed and is not forbidden by the
2N/A * current state.
2N/A * * Allocate it into a separate EP.
2N/A * * Take the EP lock.
2N/A * * Reconfirm that the EP is in a state where it needs a QP.
2N/A * * Assign the QP and release the lock.
2N/A */
2N/A if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {
2N/A if (ep_ptr->param.pz_handle == NULL ||
2N/A DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_STATE,
2N/A DAT_INVALID_STATE_EP_NOTREADY);
2N/A goto bail;
2N/A }
2N/A alloc_ep = *ep_ptr;
2N/A
2N/A dat_status = dapls_ib_qp_alloc(ep_ptr->header.owner_ia,
2N/A &alloc_ep, ep_ptr);
2N/A if (dat_status != DAT_SUCCESS) {
2N/A dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_MEMORY);
2N/A goto bail;
2N/A }
2N/A
2N/A dapl_os_lock(&ep_ptr->header.lock);
2N/A /*
2N/A * PZ shouldn't have changed since we're only racing with
2N/A * dapl_cr_accept()
2N/A */
2N/A if (ep_ptr->qp_state != DAPL_QP_STATE_UNATTACHED) {
2N/A /* Bail, cleaning up. */
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A dat_status = dapls_ib_qp_free(ep_ptr->header.owner_ia,
2N/A &alloc_ep);
2N/A if (dat_status != DAT_SUCCESS) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_WARN,
2N/A "ep_connect: ib_qp_free failed with %x\n",
2N/A dat_status);
2N/A }
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 ep_ptr->qp_handle = alloc_ep.qp_handle;
2N/A ep_ptr->qpn = alloc_ep.qpn;
2N/A ep_ptr->qp_state = alloc_ep.qp_state;
2N/A
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A }
2N/A
2N/A /*
2N/A * We do state checks and transitions under lock.
2N/A * The only code we're racing against is dapl_cr_accept.
2N/A */
2N/A dapl_os_lock(&ep_ptr->header.lock);
2N/A
2N/A /*
2N/A * Verify the attributes of the EP handle before we connect it. Test
2N/A * all of the handles to make sure they are currently valid.
2N/A * Specifically:
2N/A * pz_handle required
2N/A * recv_evd_handle optional, but must be valid
2N/A * request_evd_handle optional, but must be valid
2N/A * connect_evd_handle required
2N/A */
2N/A if (ep_ptr->param.pz_handle == NULL ||
2N/A DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ) ||
2N/A ep_ptr->param.connect_evd_handle == NULL ||
2N/A DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle,
2N/A DAPL_MAGIC_EVD) ||
2N/A !(((DAPL_EVD *)ep_ptr->param.connect_evd_handle)->evd_flags &
2N/A DAT_EVD_CONNECTION_FLAG) ||
2N/A (ep_ptr->param.recv_evd_handle != DAT_HANDLE_NULL &&
2N/A (DAPL_BAD_HANDLE(ep_ptr->param.recv_evd_handle,
2N/A DAPL_MAGIC_EVD))) ||
2N/A (ep_ptr->param.request_evd_handle != DAT_HANDLE_NULL &&
2N/A (DAPL_BAD_HANDLE(ep_ptr->param.request_evd_handle,
2N/A DAPL_MAGIC_EVD)))) {
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A dat_status = DAT_ERROR(DAT_INVALID_STATE,
2N/A DAT_INVALID_STATE_EP_NOTREADY);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * Check both the EP state and the QP state: if we don't have a QP
2N/A * we need to attach one now.
2N/A */
2N/A if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {
2N/A dat_status = dapls_ib_qp_alloc(ep_ptr->header.owner_ia,
2N/A ep_ptr, ep_ptr);
2N/A
2N/A if (dat_status != DAT_SUCCESS) {
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
2N/A DAT_RESOURCE_TEP);
2N/A goto bail;
2N/A }
2N/A }
2N/A
2N/A if (ep_ptr->param.ep_state != DAT_EP_STATE_UNCONNECTED) {
2N/A dapl_os_unlock(&ep_ptr->header.lock);
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 if (qos != DAT_QOS_BEST_EFFORT ||
2N/A connect_flags != DAT_CONNECT_DEFAULT_FLAG) {
2N/A /*
2N/A * At this point we only support one QOS level
2N/A */
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A dat_status = DAT_ERROR(DAT_MODEL_NOT_SUPPORTED, 0);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * Verify the private data size doesn't exceed the max
2N/A */
2N/A if (private_data_size > DAPL_CONSUMER_MAX_PRIVATE_DATA_SIZE) {
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG5);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * transition the state before requesting a connection to avoid
2N/A * race conditions
2N/A */
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_ACTIVE_CONNECTION_PENDING;
2N/A
2N/A /*
2N/A * At this point we're committed, and done with the endpoint
2N/A * except for the connect, so we can drop the lock.
2N/A */
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A
2N/A /*
2N/A * fill in the private data
2N/A */
2N/A (void) dapl_os_memzero(&prd, sizeof (DAPL_PRIVATE));
2N/A if (private_data_size > 0)
2N/A (void) dapl_os_memcpy(prd.private_data, private_data,
2N/A private_data_size);
2N/A
2N/A /* Copy the connection qualifiers */
2N/A (void) dapl_os_memcpy(ep_ptr->param.remote_ia_address_ptr,
2N/A remote_ia_address, sizeof (DAT_SOCK_ADDR6));
2N/A ep_ptr->param.remote_port_qual = remote_conn_qual;
2N/A
2N/A dat_status = dapls_ib_connect(ep_handle,
2N/A remote_ia_address, remote_conn_qual,
2N/A private_data_size, &prd, timeout);
2N/A
2N/A if (dat_status != DAT_SUCCESS) {
2N/A DAPL_EVD *evd_ptr;
2N/A
2N/A if (dat_status == DAT_ERROR(DAT_INVALID_ADDRESS,
2N/A DAT_INVALID_ADDRESS_UNREACHABLE)) {
2N/A /* Unreachable IP address */
2N/A evd_ptr = (DAPL_EVD *)ep_ptr->param.connect_evd_handle;
2N/A if (evd_ptr != NULL) {
2N/A (void) dapls_evd_post_connection_event(evd_ptr,
2N/A DAT_CONNECTION_EVENT_UNREACHABLE,
2N/A (DAT_HANDLE) ep_ptr, 0, 0);
2N/A }
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
2N/A dat_status = DAT_SUCCESS;
2N/A } else if (dat_status == DAT_ERROR(DAT_INVALID_PARAMETER,
2N/A DAT_INVALID_ADDRESS_UNREACHABLE)) {
2N/A /* Non-existant connection qualifier */
2N/A evd_ptr = (DAPL_EVD *)ep_ptr->param.connect_evd_handle;
2N/A if (evd_ptr != NULL) {
2N/A (void) dapls_evd_post_connection_event(evd_ptr,
2N/A DAT_CONNECTION_EVENT_NON_PEER_REJECTED,
2N/A (DAT_HANDLE) ep_ptr, 0, 0);
2N/A }
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECTED;
2N/A dat_status = DAT_SUCCESS;
2N/A } else {
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_UNCONNECTED;
2N/A }
2N/A }
2N/A
2N/Abail:
2N/A dapl_dbg_log(DAPL_DBG_TYPE_RTN | DAPL_DBG_TYPE_CM,
2N/A "dapl_ep_connect () returns 0x%x\n", dat_status);
2N/A
2N/A return (dat_status);
2N/A}