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_cr_accept.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_cr_accept.c,v 1.21 2003/08/08 19:20:05 sjs2 Exp $
2N/A */
2N/A
2N/A#include "dapl.h"
2N/A#include "dapl_adapter_util.h"
2N/A
2N/A/*
2N/A * dapl_cr_accept
2N/A *
2N/A * DAPL Requirements Version xxx, 6.4.2.1
2N/A *
2N/A * Establish a connection between active remote side requesting Endpoint
2N/A * and passic side local Endpoint.
2N/A *
2N/A * Input:
2N/A * cr_handle
2N/A * ep_handle
2N/A * private_data_size
2N/A * private_data
2N/A *
2N/A * Output:
2N/A * none
2N/A *
2N/A * Returns:
2N/A * DAT_SUCCESS
2N/A * DAT_INVALID_PARAMETER
2N/A * DAT_INVALID_ATTRIBUTE
2N/A */
2N/ADAT_RETURN
2N/Adapl_cr_accept(
2N/A IN DAT_CR_HANDLE cr_handle,
2N/A IN DAT_EP_HANDLE ep_handle,
2N/A IN DAT_COUNT private_data_size,
2N/A IN const DAT_PVOID private_data)
2N/A{
2N/A DAPL_EP *ep_ptr;
2N/A DAT_RETURN dat_status;
2N/A DAPL_PRIVATE prd;
2N/A DAPL_CR *cr_ptr;
2N/A DAT_EP_STATE entry_ep_state;
2N/A DAT_EP_HANDLE entry_ep_handle;
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_API,
2N/A "dapl_cr_accept(%p, %p, %d, %p)\n",
2N/A cr_handle, ep_handle, private_data_size, private_data);
2N/A
2N/A if (DAPL_BAD_HANDLE(cr_handle, DAPL_MAGIC_CR)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
2N/A DAT_INVALID_HANDLE_CR);
2N/A goto bail;
2N/A }
2N/A
2N/A cr_ptr = (DAPL_CR *) cr_handle;
2N/A
2N/A /*
2N/A * Return an error if we have an ep_handle and the CR already has an
2N/A * EP, indicating this is an RSP connection or PSP_PROVIDER_FLAG was
2N/A * specified.
2N/A */
2N/A if (ep_handle != NULL &&
2N/A (DAPL_BAD_HANDLE(ep_handle, DAPL_MAGIC_EP) ||
2N/A cr_ptr->param.local_ep_handle != NULL)) {
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 ((0 != private_data_size) && (NULL == private_data)) {
2N/A dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);
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 dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3);
2N/A goto bail;
2N/A }
2N/A
2N/A /*
2N/A * ep_handle is NULL if the user specified DAT_PSP_PROVIDER_FLAG
2N/A * OR this is an RSP connection; retrieve it from the cr.
2N/A */
2N/A if (ep_handle == NULL) {
2N/A ep_handle = cr_ptr->param.local_ep_handle;
2N/A if ((((DAPL_EP *) ep_handle)->param.ep_state !=
2N/A DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING) &&
2N/A (((DAPL_EP *)ep_handle)->param.ep_state !=
2N/A DAT_EP_STATE_PASSIVE_CONNECTION_PENDING)) {
2N/A return (DAT_INVALID_STATE);
2N/A }
2N/A } else {
2N/A /* ensure this EP isn't connected or in use */
2N/A if (((DAPL_EP *)ep_handle)->param.ep_state !=
2N/A DAT_EP_STATE_UNCONNECTED) {
2N/A return (DAT_INVALID_STATE);
2N/A }
2N/A }
2N/A
2N/A ep_ptr = (DAPL_EP *) ep_handle;
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 * We do all verification and state change under lock, at which
2N/A * point the EP state should protect us from most races.
2N/A */
2N/A dapl_os_lock(&ep_ptr->header.lock);
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, 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, 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_HANDLE,
2N/A DAT_INVALID_HANDLE_EP);
2N/A goto bail;
2N/A }
2N/A
2N/A if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {
2N/A /*
2N/A * If we are lazy attaching the QP then we may need to
2N/A * hook it up here. Typically, we run this code only for
2N/A * DAT_PSP_PROVIDER_FLAG
2N/A */
2N/A dat_status = dapls_ib_qp_alloc(cr_ptr->header.owner_ia, ep_ptr,
2N/A ep_ptr);
2N/A
2N/A if (dat_status != DAT_SUCCESS) {
2N/A /* This is not a great error code, but spec allows */
2N/A dapl_os_unlock(&ep_ptr->header.lock);
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
2N/A entry_ep_state = ep_ptr->param.ep_state;
2N/A entry_ep_handle = cr_ptr->param.local_ep_handle;
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_COMPLETION_PENDING;
2N/A ep_ptr->cm_handle = cr_ptr->ib_cm_handle;
2N/A ep_ptr->cr_ptr = cr_ptr;
2N/A ep_ptr->param.remote_ia_address_ptr = cr_ptr->param.
2N/A remote_ia_address_ptr;
2N/A cr_ptr->param.local_ep_handle = ep_handle;
2N/A
2N/A /*
2N/A * private data
2N/A */
2N/A (void) dapl_os_memcpy(prd.private_data, private_data,
2N/A private_data_size);
2N/A (void) dapl_os_memzero(prd.private_data + private_data_size,
2N/A sizeof (DAPL_PRIVATE) - private_data_size);
2N/A
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A
2N/A dat_status = dapls_ib_accept_connection(cr_handle, ep_handle, &prd);
2N/A
2N/A /*
2N/A * If the provider failed, unwind the damage so we are back at
2N/A * the initial state.
2N/A */
2N/A if (dat_status != DAT_SUCCESS) {
2N/A ep_ptr->param.ep_state = entry_ep_state;
2N/A cr_ptr->param.local_ep_handle = entry_ep_handle;
2N/A } else {
2N/A /*
2N/A * Make this CR invalid. We need to hang on to it until
2N/A * the connection terminates, but it's destroyed from
2N/A * the app point of view.
2N/A */
2N/A cr_ptr->header.magic = DAPL_MAGIC_CR_DESTROYED;
2N/A }
2N/A
2N/Abail:
2N/A return (dat_status);
2N/A}