dapl_rmr_util.c revision 9517:b4839b0aa7a4
167754Smsmith/*
267754Smsmith * CDDL HEADER START
367754Smsmith *
467754Smsmith * The contents of this file are subject to the terms of the
567754Smsmith * Common Development and Distribution License (the "License").
667754Smsmith * You may not use this file except in compliance with the License.
7217365Sjkim *
8245582Sjkim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
970243Smsmith * or http://www.opensolaris.org/os/licensing.
1067754Smsmith * See the License for the specific language governing permissions
11217365Sjkim * and limitations under the License.
12217365Sjkim *
13217365Sjkim * When distributing Covered Code, include this CDDL HEADER in each
14217365Sjkim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15217365Sjkim * If applicable, add the following below this CDDL HEADER, with the
16217365Sjkim * fields enclosed by brackets "[]" replaced with your own identifying
17217365Sjkim * information: Portions Copyright [yyyy] [name of copyright owner]
18217365Sjkim *
19217365Sjkim * CDDL HEADER END
20217365Sjkim */
21217365Sjkim
22217365Sjkim/*
23217365Sjkim * Copyright (c) 2002-2003, Network Appliance, Inc. All rights reserved.
24217365Sjkim */
2567754Smsmith
26217365Sjkim/*
27217365Sjkim * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28217365Sjkim * Use is subject to license terms.
2967754Smsmith */
30217365Sjkim
31217365Sjkim#include "dapl_rmr_util.h"
32217365Sjkim#include "dapl_ia_util.h"
33217365Sjkim
34217365SjkimDAPL_RMR *
35217365Sjkimdapl_rmr_alloc(IN DAPL_PZ * pz)
36217365Sjkim{
37217365Sjkim	DAPL_RMR *rmr;
38217365Sjkim
39217365Sjkim	/* Allocate LMR */
40217365Sjkim	rmr = (DAPL_RMR *)dapl_os_alloc(sizeof (DAPL_RMR));
41217365Sjkim	if (NULL == rmr) {
42217365Sjkim		return (NULL);
4367754Smsmith	}
4467754Smsmith
4567754Smsmith	/* zero the structure */
4667754Smsmith	(void) dapl_os_memzero(rmr, sizeof (DAPL_RMR));
47193341Sjkim
48193341Sjkim	/*
49193341Sjkim	 * initialize the header
50193341Sjkim	 */
51193341Sjkim	rmr->header.provider = pz->header.provider;
5267754Smsmith	rmr->header.magic = DAPL_MAGIC_RMR;
5377424Smsmith	rmr->header.handle_type = DAT_HANDLE_TYPE_RMR;
5491116Smsmith	rmr->header.owner_ia = pz->header.owner_ia;
5567754Smsmith	rmr->header.user_context.as_64 = 0;
56151937Sjkim	rmr->header.user_context.as_ptr = 0;
5767754Smsmith	dapl_llist_init_entry(&rmr->header.ia_list_entry);
58151937Sjkim	dapl_ia_link_rmr(rmr->header.owner_ia, rmr);
59151937Sjkim	dapl_os_lock_init(&rmr->header.lock);
60151937Sjkim
61151937Sjkim	/*
62151937Sjkim	 * initialize the body
63151937Sjkim	 */
64151937Sjkim	rmr->param.ia_handle = (DAT_IA_HANDLE)pz->header.owner_ia;
65151937Sjkim	rmr->param.pz_handle = (DAT_PZ_HANDLE)pz;
66151937Sjkim	rmr->param.lmr_triplet.lmr_context = 0;
67151937Sjkim	rmr->param.lmr_triplet.pad = 0;
68151937Sjkim	rmr->param.lmr_triplet.virtual_address = 0;
69151937Sjkim	rmr->param.lmr_triplet.segment_length = 0;
70151937Sjkim
71151937Sjkim	rmr->param.mem_priv = 0;
72167802Sjkim	rmr->pz = pz;
73167802Sjkim	rmr->lmr = NULL;
74167802Sjkim
75167802Sjkim	return (rmr);
76167802Sjkim}
77167802Sjkim
78151937Sjkimvoid
79167802Sjkimdapl_rmr_dealloc(IN DAPL_RMR *rmr)
8067754Smsmith{
8167754Smsmith	/* reset magic to prevent reuse */
8267754Smsmith	rmr->header.magic = DAPL_MAGIC_INVALID;
8367754Smsmith
8467754Smsmith	dapl_ia_unlink_rmr(rmr->header.owner_ia, rmr);
8567754Smsmith	dapl_os_lock_destroy(&rmr->header.lock);
8667754Smsmith
8767754Smsmith	dapl_os_free((void *) rmr, sizeof (DAPL_RMR));
8867754Smsmith}
8967754Smsmith
9067754SmsmithDAT_BOOLEAN
9167754Smsmithdapl_rmr_validate_completion_flag(IN DAT_COMPLETION_FLAGS mask,
9267754Smsmith	IN DAT_COMPLETION_FLAGS allow,
9367754Smsmith	IN DAT_COMPLETION_FLAGS request)
9467754Smsmith{
9567754Smsmith	if ((mask & request) && !(mask & allow)) {
9667754Smsmith		return (DAT_FALSE);
9767754Smsmith	} else {
9867754Smsmith		return (DAT_TRUE);
9967754Smsmith	}
10067754Smsmith}
101167802Sjkim
10267754Smsmithint32_t
10367754Smsmithdapl_rmr_convert_privileges(IN DAT_MEM_PRIV_FLAGS privileges)
10482367Smsmith{
10582367Smsmith	int32_t value = 0;
106138287Smarks
107245582Sjkim	if (DAT_MEM_PRIV_REMOTE_READ_FLAG & privileges) {
10867754Smsmith		value |= IB_BIND_ACCESS_REMOTE_READ;
10999146Siwasaki	}
11067754Smsmith	if (DAT_MEM_PRIV_REMOTE_WRITE_FLAG & privileges) {
11199146Siwasaki		value |= IB_BIND_ACCESS_REMOTE_WRITE;
11267754Smsmith	}
11367754Smsmith	return (value);
11467754Smsmith}
11567754Smsmith