xref: /illumos-gate/usr/src/lib/udapl/udapl_tavor/common/dapl_cr_util.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 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 /*
32  *
33  * MODULE: dapl_cr_util.c
34  *
35  * PURPOSE: Manage CR (Connection Request) structure
36  *
37  * $Id: dapl_cr_util.c,v 1.7 2003/08/08 19:20:05 sjs2 Exp $
38  */
39 
40 #include "dapl.h"
41 #include "dapl_cr_util.h"
42 
43 /*
44  * dapls_cr_create
45  *
46  * Create a CR. Part of the passive side of a connection
47  *
48  * Input:
49  * 	ia_ptr
50  *	cno_ptr
51  *	qlen
52  *	evd_flags
53  *
54  * Output:
55  * 	evd_ptr_ptr
56  *
57  * Returns:
58  * 	none
59  *
60  */
61 
62 DAPL_CR	*
dapls_cr_alloc(DAPL_IA * ia_ptr)63 dapls_cr_alloc(
64 	DAPL_IA	*ia_ptr)
65 {
66 	DAPL_CR	*cr_ptr;
67 
68 	/* Allocate EP */
69 	cr_ptr = (DAPL_CR *)dapl_os_alloc(sizeof (DAPL_CR));
70 	if (cr_ptr == NULL) {
71 		return (NULL);
72 	}
73 
74 	/* zero the structure */
75 	(void) dapl_os_memzero(cr_ptr, sizeof (DAPL_CR));
76 
77 	/*
78 	 * initialize the header
79 	 */
80 	cr_ptr->header.provider = ia_ptr->header.provider;
81 	cr_ptr->header.magic = DAPL_MAGIC_CR;
82 	cr_ptr->header.handle_type = DAT_HANDLE_TYPE_CR;
83 	cr_ptr->header.owner_ia = ia_ptr;
84 	cr_ptr->header.user_context.as_64 = 0;
85 	cr_ptr->header.user_context.as_ptr = NULL;
86 	dapl_llist_init_entry(&cr_ptr->header.ia_list_entry);
87 	dapl_os_lock_init(&cr_ptr->header.lock);
88 
89 	return (cr_ptr);
90 }
91 
92 
93 /*
94  * dapls_cr_free
95  *
96  * Free the passed in EP structure.
97  *
98  * Input:
99  * 	entry point pointer
100  *
101  * Output:
102  * 	none
103  *
104  * Returns:
105  * 	none
106  *
107  */
108 void
dapls_cr_free(IN DAPL_CR * cr_ptr)109 dapls_cr_free(
110 	IN DAPL_CR *cr_ptr)
111 {
112 	dapl_os_assert(cr_ptr->header.magic == DAPL_MAGIC_CR ||
113 	    cr_ptr->header.magic == DAPL_MAGIC_CR_DESTROYED);
114 
115 	/* reset magic to prevent reuse */
116 	cr_ptr->header.magic = DAPL_MAGIC_INVALID;
117 	dapl_os_free(cr_ptr, sizeof (DAPL_CR));
118 }
119