xref: /onnv-gate/usr/src/lib/udapl/udapl_tavor/common/dapl_cookie.c (revision 9517:b4839b0aa7a4)
1*9517SBill.Taylor@Sun.COM /*
2*9517SBill.Taylor@Sun.COM  * CDDL HEADER START
3*9517SBill.Taylor@Sun.COM  *
4*9517SBill.Taylor@Sun.COM  * The contents of this file are subject to the terms of the
5*9517SBill.Taylor@Sun.COM  * Common Development and Distribution License (the "License").
6*9517SBill.Taylor@Sun.COM  * You may not use this file except in compliance with the License.
7*9517SBill.Taylor@Sun.COM  *
8*9517SBill.Taylor@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9517SBill.Taylor@Sun.COM  * or http://www.opensolaris.org/os/licensing.
10*9517SBill.Taylor@Sun.COM  * See the License for the specific language governing permissions
11*9517SBill.Taylor@Sun.COM  * and limitations under the License.
12*9517SBill.Taylor@Sun.COM  *
13*9517SBill.Taylor@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
14*9517SBill.Taylor@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9517SBill.Taylor@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
16*9517SBill.Taylor@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
17*9517SBill.Taylor@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
18*9517SBill.Taylor@Sun.COM  *
19*9517SBill.Taylor@Sun.COM  * CDDL HEADER END
20*9517SBill.Taylor@Sun.COM  */
21*9517SBill.Taylor@Sun.COM 
22*9517SBill.Taylor@Sun.COM /*
23*9517SBill.Taylor@Sun.COM  * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24*9517SBill.Taylor@Sun.COM  */
25*9517SBill.Taylor@Sun.COM 
26*9517SBill.Taylor@Sun.COM /*
27*9517SBill.Taylor@Sun.COM  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
28*9517SBill.Taylor@Sun.COM  * Use is subject to license terms.
29*9517SBill.Taylor@Sun.COM  */
30*9517SBill.Taylor@Sun.COM 
31*9517SBill.Taylor@Sun.COM /*
32*9517SBill.Taylor@Sun.COM  *
33*9517SBill.Taylor@Sun.COM  * MODULE: dapl_cookie.c
34*9517SBill.Taylor@Sun.COM  *
35*9517SBill.Taylor@Sun.COM  * PURPOSE: Manage CQE cookie structures
36*9517SBill.Taylor@Sun.COM  *
37*9517SBill.Taylor@Sun.COM  * The DAPL spec requires that all a cookies passed to a posting operation
38*9517SBill.Taylor@Sun.COM  * be returned in the operation's corresponding completion.
39*9517SBill.Taylor@Sun.COM  *
40*9517SBill.Taylor@Sun.COM  * Implementing this feature is complicated by the user's ability to
41*9517SBill.Taylor@Sun.COM  * suppress event generation for specific operations. When these operations
42*9517SBill.Taylor@Sun.COM  * complete successfully, the provider does not have an easy way to
43*9517SBill.Taylor@Sun.COM  * deallocate resources devoted to storing context data for these operations.
44*9517SBill.Taylor@Sun.COM  *
45*9517SBill.Taylor@Sun.COM  * To support this feature, a pool of memory is allocated up front large
46*9517SBill.Taylor@Sun.COM  * enough to hold cookie data for the maximum number of operations possible
47*9517SBill.Taylor@Sun.COM  * on an endpoint.
48*9517SBill.Taylor@Sun.COM  *
49*9517SBill.Taylor@Sun.COM  * Two pieces of information are maintained to manage cookie allocation:
50*9517SBill.Taylor@Sun.COM  *
51*9517SBill.Taylor@Sun.COM  * head index : index of next unallocated cookie
52*9517SBill.Taylor@Sun.COM  * tail index : index of last unallocated cookie
53*9517SBill.Taylor@Sun.COM  *
54*9517SBill.Taylor@Sun.COM  * Each cookie store its index in this memory pool.
55*9517SBill.Taylor@Sun.COM  *
56*9517SBill.Taylor@Sun.COM  * When an event is received, the index stored in the event's cookie will be
57*9517SBill.Taylor@Sun.COM  * used to update the tail. This will implicitly deallocate all of the cookies
58*9517SBill.Taylor@Sun.COM  * "between" the old tail and the new tail.
59*9517SBill.Taylor@Sun.COM  *
60*9517SBill.Taylor@Sun.COM  * The implementation relies on the following assumptions:
61*9517SBill.Taylor@Sun.COM  *
62*9517SBill.Taylor@Sun.COM  * - there can be only 1 thread in dat_ep_post_send(), dat_ep_post_rdma_write(),
63*9517SBill.Taylor@Sun.COM  *   dat_ep_post_rdma_read(), or dat_rmr_bind() at a time, therefore
64*9517SBill.Taylor@Sun.COM  *   dapls_cb_get() does not need to be thread safe when manipulating
65*9517SBill.Taylor@Sun.COM  *   request data structures.
66*9517SBill.Taylor@Sun.COM  *
67*9517SBill.Taylor@Sun.COM  * - there can be only 1 thread in dat_ep_post_recv(), therefore
68*9517SBill.Taylor@Sun.COM  *   dapls_cb_get() does not need to be thread safe when manipulating
69*9517SBill.Taylor@Sun.COM  *   receive data structures.
70*9517SBill.Taylor@Sun.COM  *
71*9517SBill.Taylor@Sun.COM  * - there can be only 1 thread generating completions for a given EP's request
72*9517SBill.Taylor@Sun.COM  *   opeartions, therefore dapls_cb_put() does not need to be thread safe when
73*9517SBill.Taylor@Sun.COM  *   manipulating request data structures.
74*9517SBill.Taylor@Sun.COM  *
75*9517SBill.Taylor@Sun.COM  * - there can be only 1 thread generating completions for a given EP's receive
76*9517SBill.Taylor@Sun.COM  *   opeartions therefore dapls_cb_put() does not need to be thread safe when
77*9517SBill.Taylor@Sun.COM  *   manipulating receive data structures.
78*9517SBill.Taylor@Sun.COM  *
79*9517SBill.Taylor@Sun.COM  * - completions are delivered in order
80*9517SBill.Taylor@Sun.COM  *
81*9517SBill.Taylor@Sun.COM  * $Id: dapl_cookie.c,v 1.13 2003/06/16 17:53:32 sjs2 Exp $
82*9517SBill.Taylor@Sun.COM  */
83*9517SBill.Taylor@Sun.COM 
84*9517SBill.Taylor@Sun.COM #include "dapl_cookie.h"
85*9517SBill.Taylor@Sun.COM #include "dapl_ring_buffer_util.h"
86*9517SBill.Taylor@Sun.COM 
87*9517SBill.Taylor@Sun.COM /*
88*9517SBill.Taylor@Sun.COM  *
89*9517SBill.Taylor@Sun.COM  * Function Prototypes
90*9517SBill.Taylor@Sun.COM  *
91*9517SBill.Taylor@Sun.COM  */
92*9517SBill.Taylor@Sun.COM 
93*9517SBill.Taylor@Sun.COM DAT_RETURN
94*9517SBill.Taylor@Sun.COM dapls_cb_get(
95*9517SBill.Taylor@Sun.COM 	DAPL_COOKIE_BUFFER		*buffer,
96*9517SBill.Taylor@Sun.COM 	DAPL_COOKIE 		**cookie_ptr);
97*9517SBill.Taylor@Sun.COM 
98*9517SBill.Taylor@Sun.COM DAT_RETURN
99*9517SBill.Taylor@Sun.COM dapls_cb_put(
100*9517SBill.Taylor@Sun.COM 	DAPL_COOKIE_BUFFER		*buffer,
101*9517SBill.Taylor@Sun.COM 	DAPL_COOKIE 		*cookie);
102*9517SBill.Taylor@Sun.COM 
103*9517SBill.Taylor@Sun.COM 
104*9517SBill.Taylor@Sun.COM /*
105*9517SBill.Taylor@Sun.COM  *
106*9517SBill.Taylor@Sun.COM  * Function Definitions
107*9517SBill.Taylor@Sun.COM  *
108*9517SBill.Taylor@Sun.COM  */
109*9517SBill.Taylor@Sun.COM 
110*9517SBill.Taylor@Sun.COM /*
111*9517SBill.Taylor@Sun.COM  * dapls_cb_create
112*9517SBill.Taylor@Sun.COM  *
113*9517SBill.Taylor@Sun.COM  * Given a DAPL_COOKIE_BUFFER, allocate and initialize memory for
114*9517SBill.Taylor@Sun.COM  * the data structure.
115*9517SBill.Taylor@Sun.COM  *
116*9517SBill.Taylor@Sun.COM  * Input:
117*9517SBill.Taylor@Sun.COM  *	buffer		pointer to DAPL_COOKIE_BUFFER
118*9517SBill.Taylor@Sun.COM  *	ep		endpoint to associate with cookies
119*9517SBill.Taylor@Sun.COM  *	size		number of elements to allocate & manage
120*9517SBill.Taylor@Sun.COM  *
121*9517SBill.Taylor@Sun.COM  * Output:
122*9517SBill.Taylor@Sun.COM  *	none
123*9517SBill.Taylor@Sun.COM  *
124*9517SBill.Taylor@Sun.COM  * Returns:
125*9517SBill.Taylor@Sun.COM  *	DAT_SUCCESS
126*9517SBill.Taylor@Sun.COM  *	DAT_INSUFFICIENT_RESOURCES
127*9517SBill.Taylor@Sun.COM  *
128*9517SBill.Taylor@Sun.COM  */
129*9517SBill.Taylor@Sun.COM DAT_RETURN
dapls_cb_create(IN DAPL_COOKIE_BUFFER * buffer,IN void * queue,IN DAPL_COOKIE_QUEUE_TYPE type,IN DAT_COUNT size)130*9517SBill.Taylor@Sun.COM dapls_cb_create(
131*9517SBill.Taylor@Sun.COM 	IN	DAPL_COOKIE_BUFFER	*buffer,
132*9517SBill.Taylor@Sun.COM 	IN	void			*queue,
133*9517SBill.Taylor@Sun.COM 	IN	DAPL_COOKIE_QUEUE_TYPE	type,
134*9517SBill.Taylor@Sun.COM 	IN	DAT_COUNT		size)
135*9517SBill.Taylor@Sun.COM 
136*9517SBill.Taylor@Sun.COM {
137*9517SBill.Taylor@Sun.COM 	DAT_COUNT 			i;
138*9517SBill.Taylor@Sun.COM 
139*9517SBill.Taylor@Sun.COM 	/*
140*9517SBill.Taylor@Sun.COM 	 * allocate one additional entry so that the tail
141*9517SBill.Taylor@Sun.COM 	 * can always point at an empty location
142*9517SBill.Taylor@Sun.COM 	 */
143*9517SBill.Taylor@Sun.COM 	size++;
144*9517SBill.Taylor@Sun.COM 	/* round up to multiple of 2 */
145*9517SBill.Taylor@Sun.COM 	i = 2;
146*9517SBill.Taylor@Sun.COM 	while (size > i) {
147*9517SBill.Taylor@Sun.COM 	    i <<= 1;
148*9517SBill.Taylor@Sun.COM 	}
149*9517SBill.Taylor@Sun.COM 	size = i;
150*9517SBill.Taylor@Sun.COM 
151*9517SBill.Taylor@Sun.COM 	buffer->pool = dapl_os_alloc(size * sizeof (DAPL_COOKIE));
152*9517SBill.Taylor@Sun.COM 	if (NULL != buffer->pool) {
153*9517SBill.Taylor@Sun.COM 		buffer->pool_size = size;
154*9517SBill.Taylor@Sun.COM 		buffer->head = 0;
155*9517SBill.Taylor@Sun.COM 		buffer->tail = 0;
156*9517SBill.Taylor@Sun.COM 
157*9517SBill.Taylor@Sun.COM 		for (i = 0; i < size; i++) {
158*9517SBill.Taylor@Sun.COM 			buffer->pool[i].index = i;
159*9517SBill.Taylor@Sun.COM 			buffer->pool[i].queue_type = type;
160*9517SBill.Taylor@Sun.COM 			if (type == DAPL_COOKIE_QUEUE_EP) {
161*9517SBill.Taylor@Sun.COM 				buffer->pool[i].queue.ep = queue;
162*9517SBill.Taylor@Sun.COM 			} else {
163*9517SBill.Taylor@Sun.COM 				buffer->pool[i].queue.srq = queue;
164*9517SBill.Taylor@Sun.COM 			}
165*9517SBill.Taylor@Sun.COM 		}
166*9517SBill.Taylor@Sun.COM 
167*9517SBill.Taylor@Sun.COM 		return (DAT_SUCCESS);
168*9517SBill.Taylor@Sun.COM 	} else {
169*9517SBill.Taylor@Sun.COM 		return (DAT_INSUFFICIENT_RESOURCES);
170*9517SBill.Taylor@Sun.COM 	}
171*9517SBill.Taylor@Sun.COM }
172*9517SBill.Taylor@Sun.COM 
173*9517SBill.Taylor@Sun.COM /*
174*9517SBill.Taylor@Sun.COM  * dapls_cb_resize
175*9517SBill.Taylor@Sun.COM  *
176*9517SBill.Taylor@Sun.COM  * Given a DAPL_COOKIE_BUFFER, reallocate a larger buffer and initialize
177*9517SBill.Taylor@Sun.COM  * memory for the data structure from an old one
178*9517SBill.Taylor@Sun.COM  *
179*9517SBill.Taylor@Sun.COM  * Input:
180*9517SBill.Taylor@Sun.COM  *	curr_buffer     pointer to existing DAPL_COOKIE_BUFFER
181*9517SBill.Taylor@Sun.COM  *	new_size	new number of elements to allocate & manage,
182*9517SBill.Taylor@Sun.COM  *			has to be > current buffer's size
183*9517SBill.Taylor@Sun.COM  *	new_buffer	pointer to the newly allocated cookie buffer
184*9517SBill.Taylor@Sun.COM  *
185*9517SBill.Taylor@Sun.COM  * Output:
186*9517SBill.Taylor@Sun.COM  *	none
187*9517SBill.Taylor@Sun.COM  *
188*9517SBill.Taylor@Sun.COM  * Returns:
189*9517SBill.Taylor@Sun.COM  *	DAT_SUCCESS
190*9517SBill.Taylor@Sun.COM  *	DAT_INVALID_PARAMETER
191*9517SBill.Taylor@Sun.COM  *	DAT_INSUFFICIENT_RESOURCES
192*9517SBill.Taylor@Sun.COM  *
193*9517SBill.Taylor@Sun.COM  */
194*9517SBill.Taylor@Sun.COM DAT_RETURN
dapls_cb_resize(IN DAPL_COOKIE_BUFFER * curr_buffer,IN DAT_COUNT new_size,IN DAPL_COOKIE_BUFFER * new_buffer)195*9517SBill.Taylor@Sun.COM dapls_cb_resize(
196*9517SBill.Taylor@Sun.COM 	IN	DAPL_COOKIE_BUFFER	*curr_buffer,
197*9517SBill.Taylor@Sun.COM 	IN	DAT_COUNT		new_size,
198*9517SBill.Taylor@Sun.COM 	IN	DAPL_COOKIE_BUFFER	*new_buffer)
199*9517SBill.Taylor@Sun.COM {
200*9517SBill.Taylor@Sun.COM 	int		index;
201*9517SBill.Taylor@Sun.COM 	DAPL_ATOMIC	head;
202*9517SBill.Taylor@Sun.COM 	DAPL_ATOMIC	tail;
203*9517SBill.Taylor@Sun.COM 
204*9517SBill.Taylor@Sun.COM 	DAT_RETURN	dat_return;
205*9517SBill.Taylor@Sun.COM 
206*9517SBill.Taylor@Sun.COM 	if (new_size < curr_buffer->pool_size) {
207*9517SBill.Taylor@Sun.COM 		return (DAT_ERROR(DAT_INVALID_PARAMETER, 0));
208*9517SBill.Taylor@Sun.COM 	}
209*9517SBill.Taylor@Sun.COM 
210*9517SBill.Taylor@Sun.COM 	/*
211*9517SBill.Taylor@Sun.COM 	 * create a new cookie buffer, the queue type and queue ptr remain the
212*9517SBill.Taylor@Sun.COM 	 * same as the curr_buffer so use the values from there
213*9517SBill.Taylor@Sun.COM 	 */
214*9517SBill.Taylor@Sun.COM 	dat_return = dapls_cb_create(new_buffer,
215*9517SBill.Taylor@Sun.COM 	    curr_buffer->pool[0].queue.ptr, curr_buffer->pool[0].queue_type,
216*9517SBill.Taylor@Sun.COM 	    new_size);
217*9517SBill.Taylor@Sun.COM 
218*9517SBill.Taylor@Sun.COM 	if (dat_return != DAT_SUCCESS) {
219*9517SBill.Taylor@Sun.COM 		return (dat_return);
220*9517SBill.Taylor@Sun.COM 	}
221*9517SBill.Taylor@Sun.COM 
222*9517SBill.Taylor@Sun.COM 	/* copy all the free cookies to the new buffer */
223*9517SBill.Taylor@Sun.COM 	head = curr_buffer->head;
224*9517SBill.Taylor@Sun.COM 	tail = curr_buffer->tail;
225*9517SBill.Taylor@Sun.COM 	index = 0;
226*9517SBill.Taylor@Sun.COM 	while (head != tail) {
227*9517SBill.Taylor@Sun.COM 		new_buffer->pool[index] = curr_buffer->pool[head];
228*9517SBill.Taylor@Sun.COM 		head = (head + 1) % curr_buffer->pool_size;
229*9517SBill.Taylor@Sun.COM 		index++;
230*9517SBill.Taylor@Sun.COM 	}
231*9517SBill.Taylor@Sun.COM 	new_buffer->head = 0;
232*9517SBill.Taylor@Sun.COM 	new_buffer->tail = index;
233*9517SBill.Taylor@Sun.COM 
234*9517SBill.Taylor@Sun.COM 	return (DAT_SUCCESS);
235*9517SBill.Taylor@Sun.COM }
236*9517SBill.Taylor@Sun.COM 
237*9517SBill.Taylor@Sun.COM /*
238*9517SBill.Taylor@Sun.COM  * dapls_cb_free
239*9517SBill.Taylor@Sun.COM  *
240*9517SBill.Taylor@Sun.COM  * Free the data structure
241*9517SBill.Taylor@Sun.COM  *
242*9517SBill.Taylor@Sun.COM  * Input:
243*9517SBill.Taylor@Sun.COM  *	buffer		pointer to DAPL_COOKIE_BUFFER
244*9517SBill.Taylor@Sun.COM  *
245*9517SBill.Taylor@Sun.COM  * Output:
246*9517SBill.Taylor@Sun.COM  *	none
247*9517SBill.Taylor@Sun.COM  *
248*9517SBill.Taylor@Sun.COM  * Returns:
249*9517SBill.Taylor@Sun.COM  *	none
250*9517SBill.Taylor@Sun.COM  *
251*9517SBill.Taylor@Sun.COM  */
252*9517SBill.Taylor@Sun.COM void
dapls_cb_free(IN DAPL_COOKIE_BUFFER * buffer)253*9517SBill.Taylor@Sun.COM dapls_cb_free(
254*9517SBill.Taylor@Sun.COM 	IN  DAPL_COOKIE_BUFFER	*buffer)
255*9517SBill.Taylor@Sun.COM {
256*9517SBill.Taylor@Sun.COM 	if (NULL != buffer->pool) {
257*9517SBill.Taylor@Sun.COM 		dapl_os_free(buffer->pool, buffer->pool_size *
258*9517SBill.Taylor@Sun.COM 		    sizeof (DAPL_COOKIE));
259*9517SBill.Taylor@Sun.COM 	}
260*9517SBill.Taylor@Sun.COM }
261*9517SBill.Taylor@Sun.COM 
262*9517SBill.Taylor@Sun.COM 
263*9517SBill.Taylor@Sun.COM /*
264*9517SBill.Taylor@Sun.COM  * dapls_cb_get
265*9517SBill.Taylor@Sun.COM  *
266*9517SBill.Taylor@Sun.COM  * Remove an entry from the buffer
267*9517SBill.Taylor@Sun.COM  *
268*9517SBill.Taylor@Sun.COM  * Input:
269*9517SBill.Taylor@Sun.COM  *	buffer		pointer to DAPL_COOKIE_BUFFER
270*9517SBill.Taylor@Sun.COM  *
271*9517SBill.Taylor@Sun.COM  * Output:
272*9517SBill.Taylor@Sun.COM  *      cookie_ptr 	pointer to pointer to cookie
273*9517SBill.Taylor@Sun.COM  *
274*9517SBill.Taylor@Sun.COM  * Returns:
275*9517SBill.Taylor@Sun.COM  *	DAT_SUCCESS
276*9517SBill.Taylor@Sun.COM  * 	DAT_INVALID_PARAMETER
277*9517SBill.Taylor@Sun.COM  *	DAT_INSUFFICIENT_RESOURCES
278*9517SBill.Taylor@Sun.COM  *
279*9517SBill.Taylor@Sun.COM  */
280*9517SBill.Taylor@Sun.COM DAT_RETURN
dapls_cb_get(IN DAPL_COOKIE_BUFFER * buffer,OUT DAPL_COOKIE ** cookie_ptr)281*9517SBill.Taylor@Sun.COM dapls_cb_get(
282*9517SBill.Taylor@Sun.COM 	IN  DAPL_COOKIE_BUFFER	*buffer,
283*9517SBill.Taylor@Sun.COM 	OUT DAPL_COOKIE 		**cookie_ptr)
284*9517SBill.Taylor@Sun.COM {
285*9517SBill.Taylor@Sun.COM 	DAT_RETURN	dat_status;
286*9517SBill.Taylor@Sun.COM 	DAT_COUNT	new_head;
287*9517SBill.Taylor@Sun.COM 
288*9517SBill.Taylor@Sun.COM 	dapl_os_assert(NULL != cookie_ptr);
289*9517SBill.Taylor@Sun.COM 
290*9517SBill.Taylor@Sun.COM 	new_head = (buffer->head + 1) % buffer->pool_size;
291*9517SBill.Taylor@Sun.COM 
292*9517SBill.Taylor@Sun.COM 	if (new_head == buffer->tail) {
293*9517SBill.Taylor@Sun.COM 		dat_status = DAT_INSUFFICIENT_RESOURCES;
294*9517SBill.Taylor@Sun.COM 		goto bail;
295*9517SBill.Taylor@Sun.COM 	} else {
296*9517SBill.Taylor@Sun.COM 		buffer->head = new_head;
297*9517SBill.Taylor@Sun.COM 		*cookie_ptr = &buffer->pool[buffer->head];
298*9517SBill.Taylor@Sun.COM 		dat_status = DAT_SUCCESS;
299*9517SBill.Taylor@Sun.COM 	}
300*9517SBill.Taylor@Sun.COM 
301*9517SBill.Taylor@Sun.COM bail:
302*9517SBill.Taylor@Sun.COM 	return (dat_status);
303*9517SBill.Taylor@Sun.COM }
304*9517SBill.Taylor@Sun.COM 
305*9517SBill.Taylor@Sun.COM /*
306*9517SBill.Taylor@Sun.COM  * dapls_cb_put
307*9517SBill.Taylor@Sun.COM  *
308*9517SBill.Taylor@Sun.COM  * Add entry(s) to the buffer
309*9517SBill.Taylor@Sun.COM  *
310*9517SBill.Taylor@Sun.COM  * Input:
311*9517SBill.Taylor@Sun.COM  *	buffer		pointer to DAPL_COOKIE_BUFFER
312*9517SBill.Taylor@Sun.COM  *      cookie 		pointer to cookie
313*9517SBill.Taylor@Sun.COM  *
314*9517SBill.Taylor@Sun.COM  * Output:
315*9517SBill.Taylor@Sun.COM  *	entry		entry removed from the ring buffer
316*9517SBill.Taylor@Sun.COM  *
317*9517SBill.Taylor@Sun.COM  * Returns:
318*9517SBill.Taylor@Sun.COM  *	DAT_SUCCESS
319*9517SBill.Taylor@Sun.COM  *	DAT_INSUFFICIENT_EMPTY
320*9517SBill.Taylor@Sun.COM  *
321*9517SBill.Taylor@Sun.COM  */
322*9517SBill.Taylor@Sun.COM DAT_RETURN
dapls_cb_put(IN DAPL_COOKIE_BUFFER * buffer,IN DAPL_COOKIE * cookie)323*9517SBill.Taylor@Sun.COM dapls_cb_put(
324*9517SBill.Taylor@Sun.COM 	IN  DAPL_COOKIE_BUFFER	*buffer,
325*9517SBill.Taylor@Sun.COM 	IN  DAPL_COOKIE 	*cookie)
326*9517SBill.Taylor@Sun.COM {
327*9517SBill.Taylor@Sun.COM 	buffer->tail = cookie->index;
328*9517SBill.Taylor@Sun.COM 
329*9517SBill.Taylor@Sun.COM 	return (DAT_SUCCESS);
330*9517SBill.Taylor@Sun.COM }
331*9517SBill.Taylor@Sun.COM 
332*9517SBill.Taylor@Sun.COM /*
333*9517SBill.Taylor@Sun.COM  * dapls_rmr_cookie_alloc
334*9517SBill.Taylor@Sun.COM  *
335*9517SBill.Taylor@Sun.COM  * Allocate an RMR Bind cookie
336*9517SBill.Taylor@Sun.COM  *
337*9517SBill.Taylor@Sun.COM  * Input:
338*9517SBill.Taylor@Sun.COM  *	buffer		pointer to DAPL_COOKIE_BUFFER
339*9517SBill.Taylor@Sun.COM  *      rmr 		rmr to associate with the cookie
340*9517SBill.Taylor@Sun.COM  *      user_cookie     user's cookie data
341*9517SBill.Taylor@Sun.COM  *
342*9517SBill.Taylor@Sun.COM  * Output:
343*9517SBill.Taylor@Sun.COM  *	cookie_ptr	pointer to pointer to allocated cookie
344*9517SBill.Taylor@Sun.COM  *
345*9517SBill.Taylor@Sun.COM  * Returns:
346*9517SBill.Taylor@Sun.COM  *	DAT_SUCCESS
347*9517SBill.Taylor@Sun.COM  *	DAT_INSUFFICIENT_EMPTY
348*9517SBill.Taylor@Sun.COM  *
349*9517SBill.Taylor@Sun.COM  */
350*9517SBill.Taylor@Sun.COM DAT_RETURN
dapls_rmr_cookie_alloc(IN DAPL_COOKIE_BUFFER * buffer,IN DAPL_RMR * rmr,IN DAT_RMR_COOKIE user_cookie,OUT DAPL_COOKIE ** cookie_ptr)351*9517SBill.Taylor@Sun.COM dapls_rmr_cookie_alloc(
352*9517SBill.Taylor@Sun.COM 	IN DAPL_COOKIE_BUFFER	*buffer,
353*9517SBill.Taylor@Sun.COM 	IN DAPL_RMR		*rmr,
354*9517SBill.Taylor@Sun.COM 	IN DAT_RMR_COOKIE	user_cookie,
355*9517SBill.Taylor@Sun.COM 	OUT DAPL_COOKIE 	**cookie_ptr)
356*9517SBill.Taylor@Sun.COM {
357*9517SBill.Taylor@Sun.COM 	DAPL_COOKIE 		*cookie;
358*9517SBill.Taylor@Sun.COM 	DAT_RETURN		dat_status;
359*9517SBill.Taylor@Sun.COM 
360*9517SBill.Taylor@Sun.COM 	if (DAT_SUCCESS != dapls_cb_get(buffer, &cookie)) {
361*9517SBill.Taylor@Sun.COM 		*cookie_ptr = NULL;
362*9517SBill.Taylor@Sun.COM 		dat_status = DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
363*9517SBill.Taylor@Sun.COM 		    DAT_RESOURCE_MEMORY);
364*9517SBill.Taylor@Sun.COM 		goto bail;
365*9517SBill.Taylor@Sun.COM 	}
366*9517SBill.Taylor@Sun.COM 
367*9517SBill.Taylor@Sun.COM 	dat_status = DAT_SUCCESS;
368*9517SBill.Taylor@Sun.COM 	cookie->type = DAPL_COOKIE_TYPE_RMR;
369*9517SBill.Taylor@Sun.COM 	cookie->val.rmr.rmr = rmr;
370*9517SBill.Taylor@Sun.COM 	cookie->val.rmr.cookie = user_cookie;
371*9517SBill.Taylor@Sun.COM 	*cookie_ptr =  cookie;
372*9517SBill.Taylor@Sun.COM 
373*9517SBill.Taylor@Sun.COM bail:
374*9517SBill.Taylor@Sun.COM 	return (dat_status);
375*9517SBill.Taylor@Sun.COM }
376*9517SBill.Taylor@Sun.COM 
377*9517SBill.Taylor@Sun.COM 
378*9517SBill.Taylor@Sun.COM /*
379*9517SBill.Taylor@Sun.COM  * dapls_dto_cookie_alloc
380*9517SBill.Taylor@Sun.COM  *
381*9517SBill.Taylor@Sun.COM  * Allocate a DTO cookie
382*9517SBill.Taylor@Sun.COM  *
383*9517SBill.Taylor@Sun.COM  * Input:
384*9517SBill.Taylor@Sun.COM  *	buffer		pointer to DAPL_COOKIE_BUFFER
385*9517SBill.Taylor@Sun.COM  * 	type 		DTO type
386*9517SBill.Taylor@Sun.COM  *      user_cookie     user's cookie data
387*9517SBill.Taylor@Sun.COM  *
388*9517SBill.Taylor@Sun.COM  * Output:
389*9517SBill.Taylor@Sun.COM  *	cookie_ptr	pointer to pointer to allocated cookie
390*9517SBill.Taylor@Sun.COM  *
391*9517SBill.Taylor@Sun.COM  * Returns:
392*9517SBill.Taylor@Sun.COM  *	DAT_SUCCESS
393*9517SBill.Taylor@Sun.COM  *	DAT_INSUFFICIENT_EMPTY
394*9517SBill.Taylor@Sun.COM  *
395*9517SBill.Taylor@Sun.COM  */
396*9517SBill.Taylor@Sun.COM DAT_RETURN
dapls_dto_cookie_alloc(IN DAPL_COOKIE_BUFFER * buffer,IN DAPL_DTO_TYPE type,IN DAT_DTO_COOKIE user_cookie,OUT DAPL_COOKIE ** cookie_ptr)397*9517SBill.Taylor@Sun.COM dapls_dto_cookie_alloc(
398*9517SBill.Taylor@Sun.COM 	IN DAPL_COOKIE_BUFFER	*buffer,
399*9517SBill.Taylor@Sun.COM 	IN DAPL_DTO_TYPE	type,
400*9517SBill.Taylor@Sun.COM 	IN DAT_DTO_COOKIE	user_cookie,
401*9517SBill.Taylor@Sun.COM 	OUT DAPL_COOKIE		**cookie_ptr)
402*9517SBill.Taylor@Sun.COM {
403*9517SBill.Taylor@Sun.COM 	DAPL_COOKIE 		*cookie;
404*9517SBill.Taylor@Sun.COM 
405*9517SBill.Taylor@Sun.COM 	if (DAT_SUCCESS != dapls_cb_get(buffer, &cookie)) {
406*9517SBill.Taylor@Sun.COM 		*cookie_ptr = NULL;
407*9517SBill.Taylor@Sun.COM 		return (DAT_ERROR(DAT_INSUFFICIENT_RESOURCES,
408*9517SBill.Taylor@Sun.COM 		    DAT_RESOURCE_MEMORY));
409*9517SBill.Taylor@Sun.COM 	}
410*9517SBill.Taylor@Sun.COM 	cookie->type = DAPL_COOKIE_TYPE_DTO;
411*9517SBill.Taylor@Sun.COM 	cookie->val.dto.type = type;
412*9517SBill.Taylor@Sun.COM 	cookie->val.dto.cookie = user_cookie;
413*9517SBill.Taylor@Sun.COM 	cookie->val.dto.size = 0;
414*9517SBill.Taylor@Sun.COM 
415*9517SBill.Taylor@Sun.COM 	*cookie_ptr = cookie;
416*9517SBill.Taylor@Sun.COM 	return (DAT_SUCCESS);
417*9517SBill.Taylor@Sun.COM }
418*9517SBill.Taylor@Sun.COM 
419*9517SBill.Taylor@Sun.COM void
dapls_cookie_dealloc(IN DAPL_COOKIE_BUFFER * buffer,IN DAPL_COOKIE * cookie)420*9517SBill.Taylor@Sun.COM dapls_cookie_dealloc(
421*9517SBill.Taylor@Sun.COM 	IN  DAPL_COOKIE_BUFFER	*buffer,
422*9517SBill.Taylor@Sun.COM 	IN 	DAPL_COOKIE	*cookie)
423*9517SBill.Taylor@Sun.COM {
424*9517SBill.Taylor@Sun.COM 	buffer->tail = cookie->index;
425*9517SBill.Taylor@Sun.COM }
426