xref: /illumos-gate/usr/src/lib/udapl/udapl_tavor/common/dapl_srq_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 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  *
29  * MODULE: dapl_srq_util.c
30  *
31  * PURPOSE: Shared Receive Queue utility functions.
32  *
33  */
34 
35 #include "dapl.h"
36 #include "dapl_cookie.h"
37 #include "dapl_srq_util.h"
38 
39 /*
40  * dapl_srq_alloc
41  *
42  * Allocate SRQ structure.
43  *
44  * Input:
45  * 	IA, srq_attr
46  *
47  * Output:
48  * 	none
49  *
50  * Returns:
51  * 	Pointer to alloted SRQ
52  *
53  */
54 DAPL_SRQ *
dapl_srq_alloc(IN DAPL_IA * ia_ptr,IN const DAT_SRQ_ATTR * srq_attr)55 dapl_srq_alloc(IN DAPL_IA *ia_ptr, IN const DAT_SRQ_ATTR *srq_attr)
56 {
57 	DAPL_SRQ *srq_ptr;
58 	DAT_RETURN retval;
59 
60 	/* Allocate SRQ */
61 	srq_ptr = (DAPL_SRQ *)dapl_os_alloc(sizeof (DAPL_SRQ));
62 	if (srq_ptr == NULL) {
63 		goto bail;
64 	}
65 
66 	/* zero the structure */
67 	(void) dapl_os_memzero(srq_ptr, sizeof (DAPL_SRQ));
68 
69 	/*
70 	 * initialize the header
71 	 */
72 	srq_ptr->header.provider	= ia_ptr->header.provider;
73 	srq_ptr->header.magic		= DAPL_MAGIC_SRQ;
74 	srq_ptr->header.handle_type	= DAT_HANDLE_TYPE_SRQ;
75 	srq_ptr->header.owner_ia	= ia_ptr;
76 	srq_ptr->header.user_context.as_64	= 0;
77 	dapl_llist_init_entry(&srq_ptr->header.ia_list_entry);
78 	dapl_os_lock_init(&srq_ptr->header.lock);
79 
80 	/* The SRQ ptr is stored in the cookies */
81 	retval = dapls_cb_create(&srq_ptr->recv_buffer, srq_ptr,
82 	    DAPL_COOKIE_QUEUE_SRQ, srq_attr->max_recv_dtos);
83 	if (retval != DAT_SUCCESS) {
84 		dapl_dbg_log(DAPL_DBG_TYPE_ERR, "dapls_srq_alloc cb_create "
85 		    "failed %d\n", retval);
86 		dapl_srq_dealloc(srq_ptr);
87 		srq_ptr = NULL;
88 		goto bail;
89 	}
90 
91 bail:
92 	return (srq_ptr);
93 }
94 
95 /*
96  * dapl_srq_dealloc
97  *
98  * Free the passed in SRQ structure.
99  *
100  * Input:
101  * 	entry point pointer
102  *
103  * Output:
104  * 	none
105  *
106  * Returns:
107  * 	none
108  *
109  */
110 void
dapl_srq_dealloc(IN DAPL_SRQ * srq_ptr)111 dapl_srq_dealloc(IN DAPL_SRQ	*srq_ptr)
112 {
113 	dapl_os_assert(srq_ptr->header.magic == DAPL_MAGIC_SRQ);
114 
115 	/* reset magic to prevent reuse */
116 	srq_ptr->header.magic = DAPL_MAGIC_INVALID;
117 
118 	dapls_cb_free(&srq_ptr->recv_buffer);
119 
120 	dapl_os_lock_destroy(&srq_ptr->header.lock);
121 	dapl_os_free(srq_ptr, sizeof (DAPL_SRQ));
122 }
123