xref: /titanic_50/usr/src/lib/udapl/udapl_tavor/common/dapl_cno_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_cno_util.c
34  *
35  * PURPOSE: Manage CNO Info structure
36  *
37  * $Id: dapl_cno_util.c,v 1.6 2003/06/13 12:21:02 sjs2 Exp $
38  */
39 
40 #include "dapl_ia_util.h"
41 #include "dapl_cno_util.h"
42 #include "dapl_adapter_util.h"
43 
44 
45 
46 /*
47  * dapl_cno_alloc
48  *
49  * alloc and initialize an EVD struct
50  *
51  * Input:
52  *	ia
53  *
54  * Returns:
55  *	cno_ptr, or null on failure.
56  */
57 DAPL_CNO *
dapl_cno_alloc(IN DAPL_IA * ia_ptr,IN DAT_OS_WAIT_PROXY_AGENT wait_agent)58 dapl_cno_alloc(
59     IN DAPL_IA				*ia_ptr,
60     IN DAT_OS_WAIT_PROXY_AGENT		wait_agent)
61 {
62 	DAPL_CNO *cno_ptr;
63 
64 	cno_ptr = (DAPL_CNO *) dapl_os_alloc(sizeof (DAPL_CNO));
65 	if (!cno_ptr) {
66 		return (NULL);
67 	}
68 
69 	/* zero the structure */
70 	(void) dapl_os_memzero(cno_ptr, sizeof (DAPL_CNO));
71 
72 	/*
73 	 * Initialize the header.
74 	 */
75 	cno_ptr->header.provider	= ia_ptr->header.provider;
76 	cno_ptr->header.magic		= DAPL_MAGIC_CNO;
77 	cno_ptr->header.handle_type	= DAT_HANDLE_TYPE_CNO;
78 	cno_ptr->header.owner_ia	= ia_ptr;
79 	cno_ptr->header.user_context.as_64  = 0;
80 	cno_ptr->header.user_context.as_ptr = NULL;
81 	dapl_llist_init_entry(&cno_ptr->header.ia_list_entry);
82 	dapl_llist_init_head(&cno_ptr->evd_list_head);
83 	dapl_os_lock_init(&cno_ptr->header.lock);
84 
85 	/*
86 	 * Initialize the body
87 	 */
88 	cno_ptr->cno_waiters = 0;
89 	cno_ptr->cno_ref_count = 0;
90 	cno_ptr->cno_state = DAPL_CNO_STATE_UNTRIGGERED;
91 	cno_ptr->cno_evd_triggered = NULL;
92 	cno_ptr->cno_wait_agent = wait_agent;
93 	(void) dapl_os_wait_object_init(&cno_ptr->cno_wait_object);
94 
95 	return (cno_ptr);
96 }
97 
98 /*
99  * dapl_cno_dealloc
100  *
101  * Free the passed in CNO structure.
102  *
103  * Input:
104  * 	cno_ptr
105  *
106  * Output:
107  * 	none
108  *
109  * Returns:
110  * 	none
111  *
112  */
113 void
dapl_cno_dealloc(IN DAPL_CNO * cno_ptr)114 dapl_cno_dealloc(
115     IN DAPL_CNO *cno_ptr)
116 {
117 	dapl_os_assert(cno_ptr->header.magic == DAPL_MAGIC_CNO);
118 	dapl_os_assert(cno_ptr->cno_ref_count == 0);
119 
120 	/*
121 	 * deinitialize the header
122 	 */
123 	/* reset magic to prevent reuse */
124 	cno_ptr->header.magic = DAPL_MAGIC_INVALID;
125 
126 	(void) dapl_os_wait_object_destroy(&cno_ptr->cno_wait_object);
127 	dapl_os_free(cno_ptr, sizeof (DAPL_CNO));
128 }
129 
130 /*
131  * dapl_cno_trigger
132  *
133  * DAPL Internal routine to trigger the specified CNO.
134  * Called by the callback of some EVD associated with the CNO.
135  *
136  * Input:
137  *	cno_ptr
138  *	evd_ptr		EVD triggering
139  *
140  * Output:
141  *	None
142  *
143  * Returns:
144  *	None
145  */
146 void
dapl_cno_trigger(IN DAPL_CNO * cno_ptr,IN DAPL_EVD * evd_ptr)147 dapl_cno_trigger(
148 	IN DAPL_CNO		*cno_ptr,
149 	IN DAPL_EVD		*evd_ptr) /* ARGSUSED */
150 {
151 	/*
152 	 * In Solaris uDAPL the CNO is triggered in the kernel
153 	 */
154 }
155