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_free.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.4
2N/A *
2N/A * $Id: dapl_ep_free.c,v 1.21 2003/07/30 18:13:37 hobie16 Exp $
2N/A */
2N/A
2N/A#include "dapl.h"
2N/A#include "dapl_ia_util.h"
2N/A#include "dapl_ep_util.h"
2N/A#include "dapl_adapter_util.h"
2N/A#include "dapl_ring_buffer_util.h"
2N/A
2N/A/*
2N/A * dapl_ep_free
2N/A *
2N/A * DAPL Requirements Version xxx, 6.5.3
2N/A *
2N/A * Destroy an instance of the Endpoint
2N/A *
2N/A * Input:
2N/A * ep_handle
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_STATE
2N/A */
2N/ADAT_RETURN
2N/Adapl_ep_free(
2N/A IN DAT_EP_HANDLE ep_handle)
2N/A{
2N/A DAPL_EP *ep_ptr;
2N/A DAPL_IA *ia_ptr;
2N/A DAT_EP_PARAM *param;
2N/A DAT_RETURN dat_status = DAT_SUCCESS;
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_API, "dapl_ep_free (%p)\n", ep_handle);
2N/A
2N/A ep_ptr = (DAPL_EP *) ep_handle;
2N/A param = &ep_ptr->param;
2N/A
2N/A /*
2N/A * Verify parameter & state
2N/A */
2N/A if (DAPL_BAD_HANDLE(ep_ptr, DAPL_MAGIC_EP) &&
2N/A !(ep_ptr->header.magic == DAPL_MAGIC_EP_EXIT &&
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED)) {
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->param.ep_state == DAT_EP_STATE_RESERVED ||
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_PASSIVE_CONNECTION_PENDING ||
2N/A ep_ptr->param.ep_state ==
2N/A DAT_EP_STATE_TENTATIVE_CONNECTION_PENDING) {
2N/A dapl_dbg_log(DAPL_DBG_TYPE_WARN,
2N/A "--> dapl_ep_free: invalid state: %x, ep %p\n",
2N/A ep_ptr->param.ep_state, ep_ptr);
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 ia_ptr = ep_ptr->header.owner_ia;
2N/A
2N/A /*
2N/A * If we are connected, issue a disconnect. If we are in the
2N/A * disconnect_pending state, disconnect with the ABRUPT flag
2N/A * set.
2N/A */
2N/A
2N/A /*
2N/A * Do verification of parameters and the state change atomically.
2N/A */
2N/A dapl_os_lock(&ep_ptr->header.lock);
2N/A
2N/A if (ep_ptr->param.ep_state == DAT_EP_STATE_CONNECTED ||
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_ACTIVE_CONNECTION_PENDING ||
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_COMPLETION_PENDING ||
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECT_PENDING) {
2N/A /*
2N/A * Issue the disconnect and return. The DISCONNECT callback
2N/A * will invoke this routine and finish the job
2N/A */
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECT_PENDING;
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_EP,
2N/A "--> dapl_ep_free: disconnecting EP: %x, ep %p\n",
2N/A ep_ptr->param.ep_state, ep_ptr);
2N/A
2N/A dat_status = dapls_ib_disconnect(ep_ptr, DAT_CLOSE_ABRUPT_FLAG);
2N/A ep_ptr->param.ep_state = DAT_EP_STATE_DISCONNECT_PENDING;
2N/A ep_ptr->header.magic = DAPL_MAGIC_EP_EXIT;
2N/A } else {
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A }
2N/A
2N/A /*
2N/A * Release all reference counts and unlink this structure. If we
2N/A * got here from a callback, don't repeat this step
2N/A */
2N/A if (!(ep_ptr->header.magic == DAPL_MAGIC_EP_EXIT &&
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED)) {
2N/A /* Remove link from the IA */
2N/A dapl_ia_unlink_ep(ia_ptr, ep_ptr);
2N/A }
2N/A
2N/A /*
2N/A * If the EP is disconnected tear everything down. Otherwise,
2N/A * disconnect the EP but leave the QP and basic EP structure
2N/A * intact; the callback code will finish the job.
2N/A */
2N/A dapl_os_lock(&ep_ptr->header.lock);
2N/A if (ep_ptr->param.ep_state == DAT_EP_STATE_DISCONNECTED ||
2N/A ep_ptr->param.ep_state == DAT_EP_STATE_UNCONNECTED) {
2N/A /*
2N/A * Update ref counts. Note the user may have used ep_modify
2N/A * to set handles to NULL.
2N/A */
2N/A if (param->pz_handle != NULL) {
2N/A dapl_os_atomic_dec(&((DAPL_PZ *)
2N/A param->pz_handle)->pz_ref_count);
2N/A param->pz_handle = NULL;
2N/A }
2N/A if (param->recv_evd_handle != NULL) {
2N/A dapl_os_atomic_dec(&((DAPL_EVD *)
2N/A param->recv_evd_handle)->evd_ref_count);
2N/A param->recv_evd_handle = NULL;
2N/A }
2N/A if (param->request_evd_handle != NULL) {
2N/A dapl_os_atomic_dec(&((DAPL_EVD *)
2N/A param->request_evd_handle)->evd_ref_count);
2N/A param->request_evd_handle = NULL;
2N/A }
2N/A if (param->connect_evd_handle != NULL) {
2N/A dapl_os_atomic_dec(&((DAPL_EVD *)
2N/A param->connect_evd_handle)->evd_ref_count);
2N/A param->connect_evd_handle = NULL;
2N/A }
2N/A
2N/A if (param->srq_handle != NULL) {
2N/A dapl_os_atomic_dec(&((DAPL_SRQ *)
2N/A param->srq_handle)->srq_ref_count);
2N/A param->srq_handle = NULL;
2N/A }
2N/A
2N/A dapl_dbg_log(DAPL_DBG_TYPE_EP,
2N/A "--> dapl_ep_free: Free EP: %x, ep %p\n",
2N/A ep_ptr->param.ep_state, ep_ptr);
2N/A /*
2N/A * Free the QP. If the EP has never been used,
2N/A * the QP is invalid
2N/A */
2N/A if (ep_ptr->qp_handle != IB_INVALID_HANDLE) {
2N/A dat_status = dapls_ib_qp_free(ia_ptr, ep_ptr);
2N/A /*
2N/A * This should always succeed, but report to the user if
2N/A * there is a problem
2N/A */
2N/A if (dat_status != DAT_SUCCESS) {
2N/A goto bail;
2N/A }
2N/A ep_ptr->qp_handle = IB_INVALID_HANDLE;
2N/A }
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A /* Free the resource */
2N/A dapl_ep_dealloc(ep_ptr);
2N/A } else {
2N/A dapl_os_unlock(&ep_ptr->header.lock);
2N/A }
2N/Abail:
2N/A return (dat_status);
2N/A
2N/A}