xref: /illumos-gate/usr/src/lib/udapl/udapl_tavor/tavor/dapl_tavor_ibtf_mrsync.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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #include "dapl.h"
28 #include "dapl_mr_util.h"
29 #include <dapl_tavor_ibtf_impl.h>
30 
31 DAT_RETURN
dapls_ib_lmr_sync_rdma_common(IN DAT_IA_HANDLE ia_handle,IN const DAT_LMR_TRIPLET * lmr_triplet,IN DAT_VLEN num_segments,IN uint32_t op_type)32 dapls_ib_lmr_sync_rdma_common(
33 	IN	DAT_IA_HANDLE ia_handle,
34 	IN 	const DAT_LMR_TRIPLET *lmr_triplet,
35 	IN	DAT_VLEN num_segments,
36 	IN	uint32_t op_type)
37 {
38 	DAPL_IA		*ia_ptr;
39 	DAPL_LMR	*lmr;
40 	DAT_RETURN	dat_status;
41 	dapl_mr_sync_t	args;
42 	int		i, j;
43 	int		retval;
44 
45 	if (DAPL_BAD_HANDLE(ia_handle, DAPL_MAGIC_IA)) {
46 		return (DAT_ERROR(DAT_INVALID_HANDLE, DAT_INVALID_HANDLE_IA));
47 	}
48 
49 	ia_ptr = (DAPL_IA *)ia_handle;
50 	args.mrs_flags = op_type;
51 
52 	for (i = 0, j = 0; i < num_segments; i++) {
53 		dat_status = dapls_hash_search(
54 		    ia_ptr->hca_ptr->lmr_hash_table,
55 		    lmr_triplet[i].lmr_context, (DAPL_HASH_DATA *)&lmr);
56 
57 		if (dat_status != DAT_SUCCESS) {
58 			return (DAT_ERROR(DAT_INVALID_PARAMETER,
59 			    DAT_INVALID_ARG2));
60 		}
61 
62 		dat_status = dapl_mr_bounds_check(
63 		    dapl_mr_get_address(lmr->param.region_desc,
64 		    lmr->param.mem_type),
65 		    lmr->param.length,
66 		    lmr_triplet[i].virtual_address,
67 		    lmr_triplet[i].segment_length);
68 		if (dat_status != DAT_TRUE) {
69 			return (DAT_ERROR(DAT_INVALID_PARAMETER,
70 			    DAT_INVALID_ARG2));
71 		}
72 		args.mrs_vec[j].mrsv_hkey = lmr->mr_handle->mr_hkey;
73 		args.mrs_vec[j].mrsv_va = lmr_triplet[i].virtual_address;
74 		args.mrs_vec[j].mrsv_len = lmr_triplet[i].segment_length;
75 		j = j + 1;
76 		args.mrs_numseg = j;
77 		if (j == DAPL_MR_PER_SYNC) {
78 			j = 0;
79 			retval = ioctl(ia_ptr->hca_ptr->ib_hca_handle->ia_fd,
80 			    DAPL_MR_SYNC, &args);
81 
82 			if (retval != 0) {
83 				dapl_dbg_log(DAPL_DBG_TYPE_ERR,
84 				    "dapls_ib_lmr_sync: failed %s, retval %d\n",
85 				    strerror(errno), retval);
86 				return (dapls_convert_error(errno, retval));
87 			}
88 		}
89 	}
90 
91 	if (j != 0) {
92 		retval = ioctl(ia_ptr->hca_ptr->ib_hca_handle->ia_fd,
93 		    DAPL_MR_SYNC, &args);
94 		if (retval != 0) {
95 			dapl_dbg_log(DAPL_DBG_TYPE_ERR,
96 			    "dapls_ib_lmr_sync: failed %s, retval %d\n",
97 			    strerror(errno), retval);
98 			return (dapls_convert_error(errno, retval));
99 		}
100 	}
101 	return (DAT_SUCCESS);
102 }
103