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 #include "dapl_rmr_util.h"
32 #include "dapl_ia_util.h"
33
34 DAPL_RMR *
dapl_rmr_alloc(IN DAPL_PZ * pz)35 dapl_rmr_alloc(IN DAPL_PZ * pz)
36 {
37 DAPL_RMR *rmr;
38
39 /* Allocate LMR */
40 rmr = (DAPL_RMR *)dapl_os_alloc(sizeof (DAPL_RMR));
41 if (NULL == rmr) {
42 return (NULL);
43 }
44
45 /* zero the structure */
46 (void) dapl_os_memzero(rmr, sizeof (DAPL_RMR));
47
48 /*
49 * initialize the header
50 */
51 rmr->header.provider = pz->header.provider;
52 rmr->header.magic = DAPL_MAGIC_RMR;
53 rmr->header.handle_type = DAT_HANDLE_TYPE_RMR;
54 rmr->header.owner_ia = pz->header.owner_ia;
55 rmr->header.user_context.as_64 = 0;
56 rmr->header.user_context.as_ptr = 0;
57 dapl_llist_init_entry(&rmr->header.ia_list_entry);
58 dapl_ia_link_rmr(rmr->header.owner_ia, rmr);
59 dapl_os_lock_init(&rmr->header.lock);
60
61 /*
62 * initialize the body
63 */
64 rmr->param.ia_handle = (DAT_IA_HANDLE)pz->header.owner_ia;
65 rmr->param.pz_handle = (DAT_PZ_HANDLE)pz;
66 rmr->param.lmr_triplet.lmr_context = 0;
67 rmr->param.lmr_triplet.pad = 0;
68 rmr->param.lmr_triplet.virtual_address = 0;
69 rmr->param.lmr_triplet.segment_length = 0;
70
71 rmr->param.mem_priv = 0;
72 rmr->pz = pz;
73 rmr->lmr = NULL;
74
75 return (rmr);
76 }
77
78 void
dapl_rmr_dealloc(IN DAPL_RMR * rmr)79 dapl_rmr_dealloc(IN DAPL_RMR *rmr)
80 {
81 /* reset magic to prevent reuse */
82 rmr->header.magic = DAPL_MAGIC_INVALID;
83
84 dapl_ia_unlink_rmr(rmr->header.owner_ia, rmr);
85 dapl_os_lock_destroy(&rmr->header.lock);
86
87 dapl_os_free((void *) rmr, sizeof (DAPL_RMR));
88 }
89
90 DAT_BOOLEAN
dapl_rmr_validate_completion_flag(IN DAT_COMPLETION_FLAGS mask,IN DAT_COMPLETION_FLAGS allow,IN DAT_COMPLETION_FLAGS request)91 dapl_rmr_validate_completion_flag(IN DAT_COMPLETION_FLAGS mask,
92 IN DAT_COMPLETION_FLAGS allow,
93 IN DAT_COMPLETION_FLAGS request)
94 {
95 if ((mask & request) && !(mask & allow)) {
96 return (DAT_FALSE);
97 } else {
98 return (DAT_TRUE);
99 }
100 }
101
102 int32_t
dapl_rmr_convert_privileges(IN DAT_MEM_PRIV_FLAGS privileges)103 dapl_rmr_convert_privileges(IN DAT_MEM_PRIV_FLAGS privileges)
104 {
105 int32_t value = 0;
106
107 if (DAT_MEM_PRIV_REMOTE_READ_FLAG & privileges) {
108 value |= IB_BIND_ACCESS_REMOTE_READ;
109 }
110 if (DAT_MEM_PRIV_REMOTE_WRITE_FLAG & privileges) {
111 value |= IB_BIND_ACCESS_REMOTE_WRITE;
112 }
113 return (value);
114 }
115