9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER START
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * The contents of this file are subject to the terms of the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Common Development and Distribution License (the "License").
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You may not use this file except in compliance with the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * See the License for the specific language governing permissions
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and limitations under the License.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * When distributing Covered Code, include this CDDL HEADER in each
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If applicable, add the following below this CDDL HEADER, with the
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * fields enclosed by brackets "[]" replaced with your own identifying
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * information: Portions Copyright [yyyy] [name of copyright owner]
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * CDDL HEADER END
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Use is subject to license terms.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * PURPOSE: Connection management
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Description: Interfaces in this file are completely described in
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the DAPL 1.1 API, Chapter 6, section 4
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * $Id: dapl_cr_accept.c,v 1.21 2003/08/08 19:20:05 sjs2 Exp $
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * dapl_cr_accept
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAPL Requirements Version xxx, 6.4.2.1
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Establish a connection between active remote side requesting Endpoint
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * and passic side local Endpoint.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * private_data_size
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * private_data
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_SUCCESS
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INVALID_PARAMETER
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_INVALID_ATTRIBUTE
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor "dapl_cr_accept(%p, %p, %d, %p)\n",
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cr_handle, ep_handle, private_data_size, private_data);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (DAPL_BAD_HANDLE(cr_handle, DAPL_MAGIC_CR)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Return an error if we have an ep_handle and the CR already has an
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * EP, indicating this is an RSP connection or PSP_PROVIDER_FLAG was
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * specified.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if ((0 != private_data_size) && (NULL == private_data)) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG4);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Verify the private data size doesn't exceed the max
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (private_data_size > DAPL_CONSUMER_MAX_PRIVATE_DATA_SIZE) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = DAT_ERROR(DAT_INVALID_PARAMETER, DAT_INVALID_ARG3);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * ep_handle is NULL if the user specified DAT_PSP_PROVIDER_FLAG
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * OR this is an RSP connection; retrieve it from the cr.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* ensure this EP isn't connected or in use */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Verify the attributes of the EP handle before we connect it. Test
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * all of the handles to make sure they are currently valid.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Specifically:
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * pz_handle required
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * recv_evd_handle optional, but must be valid
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * request_evd_handle optional, but must be valid
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * connect_evd_handle required
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * We do all verification and state change under lock, at which
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * point the EP state should protect us from most races.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor DAPL_BAD_HANDLE(ep_ptr->param.pz_handle, DAPL_MAGIC_PZ) ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor DAPL_BAD_HANDLE(ep_ptr->param.connect_evd_handle, DAPL_MAGIC_EVD) ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor !(((DAPL_EVD *)ep_ptr->param.connect_evd_handle)->evd_flags &
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (ep_ptr->param.recv_evd_handle != DAT_HANDLE_NULL &&
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (DAPL_BAD_HANDLE(ep_ptr->param.recv_evd_handle, DAPL_MAGIC_EVD))) ||
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (ep_ptr->param.request_evd_handle != DAT_HANDLE_NULL &&
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (DAPL_BAD_HANDLE(ep_ptr->param.request_evd_handle,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor if (ep_ptr->qp_state == DAPL_QP_STATE_UNATTACHED) {
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If we are lazy attaching the QP then we may need to
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * hook it up here. Typically, we run this code only for
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * DAT_PSP_PROVIDER_FLAG
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = dapls_ib_qp_alloc(cr_ptr->header.owner_ia, ep_ptr,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor /* This is not a great error code, but spec allows */
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor entry_ep_handle = cr_ptr->param.local_ep_handle;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ep_ptr->param.ep_state = DAT_EP_STATE_COMPLETION_PENDING;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor ep_ptr->param.remote_ia_address_ptr = cr_ptr->param.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * private data
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (void) dapl_os_memcpy(prd.private_data, private_data,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor (void) dapl_os_memzero(prd.private_data + private_data_size,
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor dat_status = dapls_ib_accept_connection(cr_handle, ep_handle, &prd);
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * If the provider failed, unwind the damage so we are back at
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the initial state.
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor cr_ptr->param.local_ep_handle = entry_ep_handle;
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * Make this CR invalid. We need to hang on to it until
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the connection terminates, but it's destroyed from
9e39c5ba00a55fa05777cc94b148296af305e135Bill Taylor * the app point of view.