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_lmr_free.c
34 *
35 * PURPOSE: Memory management
36 * Description: Interfaces in this file are completely described in
37 * the DAPL 1.1 API, Chapter 6, section 6
38 *
39 */
40
41 #include "dapl_lmr_util.h"
42 #include "dapl_adapter_util.h"
43 #include "dapl_ia_util.h"
44
45 /*
46 * dapl_lmr_free
47 *
48 * DAPL Requirements Version xxx, 6.6.3.2
49 *
50 * Destroy an instance of the Local Memory Region
51 *
52 * Input:
53 * lmr_handle
54 *
55 * Output:
56 *
57 * Returns:
58 * DAT_SUCCESS
59 * DAT_INVALID_HANDLE
60 * DAT_INVALID_PARAMETER
61 * DAT_INVALID_STATE
62 */
63
64 DAT_RETURN
dapl_lmr_free(IN DAT_LMR_HANDLE lmr_handle)65 dapl_lmr_free(IN DAT_LMR_HANDLE lmr_handle)
66 {
67 DAPL_LMR *lmr;
68 DAT_RETURN dat_status;
69
70 dapl_dbg_log(DAPL_DBG_TYPE_API, "dapl_lmr_free (%p)\n", lmr_handle);
71
72 if (DAPL_BAD_HANDLE(lmr_handle, DAPL_MAGIC_LMR)) {
73 dat_status = DAT_ERROR(DAT_INVALID_HANDLE,
74 DAT_INVALID_HANDLE_LMR);
75 goto bail;
76 }
77
78 lmr = (DAPL_LMR *)lmr_handle;
79
80 switch (lmr->param.mem_type) {
81 case DAT_MEM_TYPE_VIRTUAL:
82 /* fall through */
83 case DAT_MEM_TYPE_LMR: {
84 DAPL_PZ *pz;
85
86 if (0 != lmr->lmr_ref_count) {
87 return (DAT_INVALID_STATE);
88 }
89
90 dat_status = dapls_hash_remove(
91 lmr->header.owner_ia->hca_ptr->lmr_hash_table,
92 lmr->param.lmr_context, NULL);
93 if (dat_status != DAT_SUCCESS) {
94 goto bail;
95 }
96
97 dat_status = dapls_ib_mr_deregister(lmr);
98
99 if (dat_status == DAT_SUCCESS) {
100 pz = (DAPL_PZ *) lmr->param.pz_handle;
101 dapl_os_atomic_dec(&pz->pz_ref_count);
102
103 dapl_lmr_dealloc(lmr);
104 } else {
105 /*
106 * Deregister failed; put it back in the
107 * hash table.
108 */
109 (void) dapls_hash_insert(lmr->header.owner_ia->
110 hca_ptr->lmr_hash_table,
111 lmr->param.lmr_context, lmr);
112 }
113 break;
114 }
115 case DAT_MEM_TYPE_SHARED_VIRTUAL: {
116 dat_status = DAT_ERROR(DAT_NOT_IMPLEMENTED, 0);
117 break;
118 }
119 default:
120 dat_status = DAT_ERROR(DAT_INVALID_PARAMETER,
121 DAT_INVALID_ARG1);
122 break;
123 }
124 bail:
125 return (dat_status);
126 }
127