xref: /titanic_51/usr/src/lib/udapl/udapl_tavor/common/dapl_cr_reject.c (revision 9e39c5ba00a55fa05777cc94b148296af305e135)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24  */
25 
26 /*
27  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  *
33  * MODULE: dapl_cr_reject.c
34  *
35  * PURPOSE: Connection management
36  * Description: Interfaces in this file are completely described in
37  *		the DAPL 1.1 API, Chapter 6, section 4
38  *
39  * $Id: dapl_cr_reject.c,v 1.10 2003/08/18 12:00:25 sjs2 Exp $
40  */
41 
42 #include "dapl.h"
43 #include "dapl_cr_util.h"
44 #include "dapl_sp_util.h"
45 #include "dapl_adapter_util.h"
46 
47 /*
48  * dapl_cr_reject
49  *
50  * DAPL Requirements Version xxx, 6.4.2.2
51  *
52  * Reject a connection request from the active remote side requesting
53  * an Endpoint.
54  *
55  * Input:
56  *	cr_handle
57  *
58  * Output:
59  *	none
60  *
61  * Returns:
62  *	DAT_SUCCESS
63  *	DAT_INVALID_PARAMETER
64  */
65 
66 DAT_RETURN
67 dapl_cr_reject(
68 	IN DAT_CR_HANDLE cr_handle)
69 {
70 	DAPL_CR *cr_ptr;
71 	DAPL_EP *ep_ptr;
72 	DAT_EP_STATE entry_ep_state;
73 	DAT_EP_HANDLE entry_ep_handle;
74 	DAPL_SP	*sp_ptr;
75 	DAT_RETURN dat_status;
76 
77 	dapl_dbg_log(DAPL_DBG_TYPE_API, "dapl_cr_reject (%p)\n", cr_handle);
78 
79 	if (DAPL_BAD_HANDLE(cr_handle, DAPL_MAGIC_CR)) {
80 		dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
81 		    DAT_INVALID_HANDLE_CR);
82 		goto bail;
83 	}
84 
85 	cr_ptr = (DAPL_CR *)cr_handle;
86 
87 	/*
88 	 * Clean up provider created EP if there is one: only if
89 	 * DAT_PSP_PROVIDER_FLAG was set on the PSP
90 	 */
91 	ep_ptr = (DAPL_EP *)cr_ptr->param.local_ep_handle;
92 	entry_ep_handle = cr_ptr->param.local_ep_handle;
93 	entry_ep_state  = 0;
94 	if (ep_ptr != NULL) {
95 		entry_ep_state = ep_ptr->param.ep_state;
96 		ep_ptr->param.ep_state = DAT_EP_STATE_UNCONNECTED;
97 		cr_ptr->param.local_ep_handle = NULL;
98 	}
99 
100 	dat_status =  dapls_ib_reject_connection(cr_ptr->ib_cm_handle,
101 	    IB_CM_REJ_REASON_CONSUMER_REJ, cr_ptr->sp_ptr);
102 
103 	if (dat_status != DAT_SUCCESS) {
104 		if (ep_ptr != NULL) {
105 			/* Revert our state to the beginning */
106 			ep_ptr->param.ep_state = entry_ep_state;
107 			cr_ptr->param.local_ep_handle = entry_ep_handle;
108 			cr_ptr->param.local_ep_handle = (DAT_EP_HANDLE)ep_ptr;
109 		}
110 	} else {
111 		/*
112 		 * If this EP has been allocated by the provider, clean it up;
113 		 * see DAT 1.1 spec, page 100, lines 3-4 (section 6.4.3.1.1.1).
114 		 * RSP and user-provided EPs are in the control of the user.
115 		 */
116 		sp_ptr = cr_ptr->sp_ptr;
117 		if (ep_ptr != NULL &&
118 		    sp_ptr->psp_flags == DAT_PSP_PROVIDER_FLAG) {
119 			(void) dapl_ep_free(ep_ptr);
120 		}
121 		/* Remove the CR from the queue, then free it */
122 		dapl_sp_remove_cr(cr_ptr->sp_ptr, cr_ptr);
123 		dapls_cr_free(cr_ptr);
124 	}
125 
126 bail:
127 	return (dat_status);
128 }
129