17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7257d1b4Sraf * Common Development and Distribution License (the "License").
6*7257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21e8031f0aSraf
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24e8031f0aSraf * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <strings.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/mman.h>
377c478bd9Sstevel@tonic-gate #include <sys/uio.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <unistd.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <assert.h>
427c478bd9Sstevel@tonic-gate #include <malloc.h>
437c478bd9Sstevel@tonic-gate #include <fcntl.h>
447c478bd9Sstevel@tonic-gate #include <dlfcn.h>
457c478bd9Sstevel@tonic-gate #include <sched.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #include <rsmapi.h>
487c478bd9Sstevel@tonic-gate #include <sys/rsm/rsmndi.h>
497c478bd9Sstevel@tonic-gate #include <rsmlib_in.h>
507c478bd9Sstevel@tonic-gate #include <sys/rsm/rsm.h>
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate /* lint -w2 */
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate extern rsm_node_id_t rsm_local_nodeid;
557c478bd9Sstevel@tonic-gate extern int loopback_getv(rsm_scat_gath_t *);
567c478bd9Sstevel@tonic-gate extern int loopback_putv(rsm_scat_gath_t *);
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate static rsm_ndlib_attr_t _rsm_genlib_attr = {
597c478bd9Sstevel@tonic-gate B_TRUE, /* mapping needed for put/get */
607c478bd9Sstevel@tonic-gate B_FALSE /* mapping needed for putv/getv */
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate
637c478bd9Sstevel@tonic-gate static int
__rsm_import_connect(rsmapi_controller_handle_t controller,rsm_node_id_t node_id,rsm_memseg_id_t segment_id,rsm_permission_t perm,rsm_memseg_import_handle_t * im_memseg)647c478bd9Sstevel@tonic-gate __rsm_import_connect(
657c478bd9Sstevel@tonic-gate rsmapi_controller_handle_t controller, rsm_node_id_t node_id,
667c478bd9Sstevel@tonic-gate rsm_memseg_id_t segment_id, rsm_permission_t perm,
677c478bd9Sstevel@tonic-gate rsm_memseg_import_handle_t *im_memseg) {
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
707c478bd9Sstevel@tonic-gate "__rsm_import_connect: enter\n"));
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate controller = controller;
737c478bd9Sstevel@tonic-gate node_id = node_id;
747c478bd9Sstevel@tonic-gate segment_id = segment_id;
757c478bd9Sstevel@tonic-gate perm = perm;
767c478bd9Sstevel@tonic-gate im_memseg = im_memseg;
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
797c478bd9Sstevel@tonic-gate "__rsm_import_connect: exit\n"));
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
827c478bd9Sstevel@tonic-gate }
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate static int
__rsm_import_disconnect(rsm_memseg_import_handle_t im_memseg)857c478bd9Sstevel@tonic-gate __rsm_import_disconnect(rsm_memseg_import_handle_t im_memseg) {
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
887c478bd9Sstevel@tonic-gate "__rsm_import_disconnect: enter\n"));
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate im_memseg = im_memseg;
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
937c478bd9Sstevel@tonic-gate "__rsm_import_disconnect: exit\n"));
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
967c478bd9Sstevel@tonic-gate }
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate /*
997c478bd9Sstevel@tonic-gate * XXX: one day we ought to rewrite this stuff based on 64byte atomic access.
1007c478bd9Sstevel@tonic-gate * We can have a new ops vector that makes that assumption.
1017c478bd9Sstevel@tonic-gate */
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate static int
__rsm_get8x8(rsm_memseg_import_handle_t im_memseg,off_t off,uint8_t * datap,ulong_t rep_cnt,boolean_t swap)1047c478bd9Sstevel@tonic-gate __rsm_get8x8(rsm_memseg_import_handle_t im_memseg, off_t off,
1057c478bd9Sstevel@tonic-gate uint8_t *datap,
1067c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
1077c478bd9Sstevel@tonic-gate boolean_t swap)
1087c478bd9Sstevel@tonic-gate {
1097c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
1107c478bd9Sstevel@tonic-gate uint8_t *data_addr =
1117c478bd9Sstevel@tonic-gate (uint8_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
1127c478bd9Sstevel@tonic-gate uint_t i = 0;
1137c478bd9Sstevel@tonic-gate int e;
1147c478bd9Sstevel@tonic-gate
1157c478bd9Sstevel@tonic-gate swap = swap;
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1187c478bd9Sstevel@tonic-gate "__rsm_import_get8x8: enter\n"));
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1217c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
1227c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
1237c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
1247c478bd9Sstevel@tonic-gate return (e);
1257c478bd9Sstevel@tonic-gate }
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
1297c478bd9Sstevel@tonic-gate datap[i] = data_addr[i];
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1337c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
1347c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
1357c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
1367c478bd9Sstevel@tonic-gate return (e);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1417c478bd9Sstevel@tonic-gate "__rsm_import_get8x8: exit\n"));
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate static int
__rsm_get16x16(rsm_memseg_import_handle_t im_memseg,off_t off,uint16_t * datap,ulong_t rep_cnt,boolean_t swap)1477c478bd9Sstevel@tonic-gate __rsm_get16x16(rsm_memseg_import_handle_t im_memseg, off_t off,
1487c478bd9Sstevel@tonic-gate uint16_t *datap,
1497c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
1507c478bd9Sstevel@tonic-gate boolean_t swap)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
1537c478bd9Sstevel@tonic-gate uint16_t *data_addr =
1547c478bd9Sstevel@tonic-gate /* LINTED */
1557c478bd9Sstevel@tonic-gate (uint16_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
1567c478bd9Sstevel@tonic-gate uint_t i = 0;
1577c478bd9Sstevel@tonic-gate int e;
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate swap = swap;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1627c478bd9Sstevel@tonic-gate "__rsm_import_get16x16: enter\n"));
1637c478bd9Sstevel@tonic-gate
1647c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1657c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
1667c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
1677c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
1687c478bd9Sstevel@tonic-gate return (e);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate }
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
1737c478bd9Sstevel@tonic-gate datap[i] = data_addr[i];
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1777c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
1787c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
1797c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
1807c478bd9Sstevel@tonic-gate return (e);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate }
1837c478bd9Sstevel@tonic-gate
1847c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1857c478bd9Sstevel@tonic-gate "__rsm_import_get16x16: exit\n"));
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate static int
__rsm_get32x32(rsm_memseg_import_handle_t im_memseg,off_t off,uint32_t * datap,ulong_t rep_cnt,boolean_t swap)1917c478bd9Sstevel@tonic-gate __rsm_get32x32(rsm_memseg_import_handle_t im_memseg, off_t off,
1927c478bd9Sstevel@tonic-gate uint32_t *datap,
1937c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
1947c478bd9Sstevel@tonic-gate boolean_t swap)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
1977c478bd9Sstevel@tonic-gate uint32_t *data_addr =
1987c478bd9Sstevel@tonic-gate /* LINTED */
1997c478bd9Sstevel@tonic-gate (uint32_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
2007c478bd9Sstevel@tonic-gate uint_t i = 0;
2017c478bd9Sstevel@tonic-gate int e;
2027c478bd9Sstevel@tonic-gate
2037c478bd9Sstevel@tonic-gate swap = swap;
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2067c478bd9Sstevel@tonic-gate "__rsm_import_get32x32: enter\n"));
2077c478bd9Sstevel@tonic-gate
2087c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2097c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
2107c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
2117c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
2127c478bd9Sstevel@tonic-gate return (e);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
2177c478bd9Sstevel@tonic-gate datap[i] = data_addr[i];
2187c478bd9Sstevel@tonic-gate }
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2217c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
2227c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
2237c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
2247c478bd9Sstevel@tonic-gate return (e);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate
2287c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2297c478bd9Sstevel@tonic-gate "__rsm_import_get32x32: exit\n"));
2307c478bd9Sstevel@tonic-gate
2317c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate static int
__rsm_get64x64(rsm_memseg_import_handle_t im_memseg,off_t off,uint64_t * datap,ulong_t rep_cnt,boolean_t swap)2357c478bd9Sstevel@tonic-gate __rsm_get64x64(rsm_memseg_import_handle_t im_memseg, off_t off,
2367c478bd9Sstevel@tonic-gate uint64_t *datap,
2377c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
2387c478bd9Sstevel@tonic-gate boolean_t swap)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
2417c478bd9Sstevel@tonic-gate uint64_t *data_addr =
2427c478bd9Sstevel@tonic-gate /* LINTED */
2437c478bd9Sstevel@tonic-gate (uint64_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
2447c478bd9Sstevel@tonic-gate uint_t i = 0;
2457c478bd9Sstevel@tonic-gate int e;
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate swap = swap;
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2507c478bd9Sstevel@tonic-gate "__rsm_import_get64x64: enter\n"));
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2537c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
2547c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
2557c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
2567c478bd9Sstevel@tonic-gate return (e);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
2617c478bd9Sstevel@tonic-gate datap[i] = data_addr[i];
2627c478bd9Sstevel@tonic-gate }
2637c478bd9Sstevel@tonic-gate
2647c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2657c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
2667c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
2677c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
2687c478bd9Sstevel@tonic-gate return (e);
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate }
2717c478bd9Sstevel@tonic-gate
2727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2737c478bd9Sstevel@tonic-gate "__rsm_import_get64x64: exit\n"));
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate * import side memory segment operations (write access functions):
2807c478bd9Sstevel@tonic-gate */
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate * XXX: Each one of the following cases ought to be a separate function loaded
2847c478bd9Sstevel@tonic-gate * into a segment access ops vector. We determine the correct function at
2857c478bd9Sstevel@tonic-gate * segment connect time. When a new controller is register, we can decode
2867c478bd9Sstevel@tonic-gate * it's direct_access_size attribute and load the correct function. For
2877c478bd9Sstevel@tonic-gate * loop back we need to create a special ops vector that bypasses all of
2887c478bd9Sstevel@tonic-gate * this stuff.
2897c478bd9Sstevel@tonic-gate *
2907c478bd9Sstevel@tonic-gate * XXX: We need to create a special interrupt queue for the library to handle
2917c478bd9Sstevel@tonic-gate * partial writes in the remote process.
2927c478bd9Sstevel@tonic-gate */
2937c478bd9Sstevel@tonic-gate static int
__rsm_put8x8(rsm_memseg_import_handle_t im_memseg,off_t off,uint8_t * datap,ulong_t rep_cnt,boolean_t swap)2947c478bd9Sstevel@tonic-gate __rsm_put8x8(rsm_memseg_import_handle_t im_memseg, off_t off,
2957c478bd9Sstevel@tonic-gate uint8_t *datap,
2967c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
2977c478bd9Sstevel@tonic-gate boolean_t swap)
2987c478bd9Sstevel@tonic-gate {
2997c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
3007c478bd9Sstevel@tonic-gate uint8_t *data_addr =
3017c478bd9Sstevel@tonic-gate (uint8_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
3027c478bd9Sstevel@tonic-gate uint_t i = 0;
3037c478bd9Sstevel@tonic-gate int e;
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate swap = swap;
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3087c478bd9Sstevel@tonic-gate "__rsm_put8x8: enter\n"));
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3117c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
3127c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
3137c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
3147c478bd9Sstevel@tonic-gate return (e);
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
3197c478bd9Sstevel@tonic-gate data_addr[i] = datap[i];
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3237c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
3247c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
3257c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
3267c478bd9Sstevel@tonic-gate return (e);
3277c478bd9Sstevel@tonic-gate }
3287c478bd9Sstevel@tonic-gate }
3297c478bd9Sstevel@tonic-gate
3307c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3317c478bd9Sstevel@tonic-gate "__rsm_put8x8: exit\n"));
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate static int
__rsm_put16x16(rsm_memseg_import_handle_t im_memseg,off_t off,uint16_t * datap,ulong_t rep_cnt,boolean_t swap)3377c478bd9Sstevel@tonic-gate __rsm_put16x16(rsm_memseg_import_handle_t im_memseg, off_t off,
3387c478bd9Sstevel@tonic-gate uint16_t *datap,
3397c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
3407c478bd9Sstevel@tonic-gate boolean_t swap)
3417c478bd9Sstevel@tonic-gate {
3427c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
3437c478bd9Sstevel@tonic-gate uint16_t *data_addr =
3447c478bd9Sstevel@tonic-gate /* LINTED */
3457c478bd9Sstevel@tonic-gate (uint16_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
3467c478bd9Sstevel@tonic-gate uint_t i = 0;
3477c478bd9Sstevel@tonic-gate int e;
3487c478bd9Sstevel@tonic-gate
3497c478bd9Sstevel@tonic-gate swap = swap;
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3527c478bd9Sstevel@tonic-gate "__rsm_put16x16: enter\n"));
3537c478bd9Sstevel@tonic-gate
3547c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3557c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
3567c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
3577c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
3587c478bd9Sstevel@tonic-gate return (e);
3597c478bd9Sstevel@tonic-gate }
3607c478bd9Sstevel@tonic-gate }
3617c478bd9Sstevel@tonic-gate
3627c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
3637c478bd9Sstevel@tonic-gate data_addr[i] = datap[i];
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3677c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
3687c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
3697c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
3707c478bd9Sstevel@tonic-gate return (e);
3717c478bd9Sstevel@tonic-gate }
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3757c478bd9Sstevel@tonic-gate "__rsm_put16x16: exit\n"));
3767c478bd9Sstevel@tonic-gate
3777c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
3787c478bd9Sstevel@tonic-gate }
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate static int
__rsm_put32x32(rsm_memseg_import_handle_t im_memseg,off_t off,uint32_t * datap,ulong_t rep_cnt,boolean_t swap)3817c478bd9Sstevel@tonic-gate __rsm_put32x32(rsm_memseg_import_handle_t im_memseg, off_t off,
3827c478bd9Sstevel@tonic-gate uint32_t *datap,
3837c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
3847c478bd9Sstevel@tonic-gate boolean_t swap)
3857c478bd9Sstevel@tonic-gate {
3867c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
3877c478bd9Sstevel@tonic-gate uint32_t *data_addr =
3887c478bd9Sstevel@tonic-gate /* LINTED */
3897c478bd9Sstevel@tonic-gate (uint32_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
3907c478bd9Sstevel@tonic-gate uint_t i = 0;
3917c478bd9Sstevel@tonic-gate int e;
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate swap = swap;
3947c478bd9Sstevel@tonic-gate
3957c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3967c478bd9Sstevel@tonic-gate "__rsm_put32x32: enter\n"));
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3997c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
4007c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
4017c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
4027c478bd9Sstevel@tonic-gate return (e);
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate }
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
4077c478bd9Sstevel@tonic-gate data_addr[i] = datap[i];
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4117c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
4127c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
4137c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
4147c478bd9Sstevel@tonic-gate return (e);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate }
4177c478bd9Sstevel@tonic-gate
4187c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4197c478bd9Sstevel@tonic-gate "__rsm_put32x32: exit\n"));
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
4227c478bd9Sstevel@tonic-gate }
4237c478bd9Sstevel@tonic-gate
4247c478bd9Sstevel@tonic-gate static int
__rsm_put64x64(rsm_memseg_import_handle_t im_memseg,off_t off,uint64_t * datap,ulong_t rep_cnt,boolean_t swap)4257c478bd9Sstevel@tonic-gate __rsm_put64x64(rsm_memseg_import_handle_t im_memseg, off_t off,
4267c478bd9Sstevel@tonic-gate uint64_t *datap,
4277c478bd9Sstevel@tonic-gate ulong_t rep_cnt,
4287c478bd9Sstevel@tonic-gate boolean_t swap)
4297c478bd9Sstevel@tonic-gate {
4307c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
4317c478bd9Sstevel@tonic-gate uint64_t *data_addr =
4327c478bd9Sstevel@tonic-gate /* LINTED */
4337c478bd9Sstevel@tonic-gate (uint64_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
4347c478bd9Sstevel@tonic-gate uint_t i = 0;
4357c478bd9Sstevel@tonic-gate int e;
4367c478bd9Sstevel@tonic-gate
4377c478bd9Sstevel@tonic-gate swap = swap;
4387c478bd9Sstevel@tonic-gate
4397c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4407c478bd9Sstevel@tonic-gate "__rsm_put64x64: enter\n"));
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4437c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
4447c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
4457c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
4467c478bd9Sstevel@tonic-gate return (e);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate for (i = 0; i < rep_cnt; i++) {
4517c478bd9Sstevel@tonic-gate data_addr[i] = datap[i];
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4557c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
4567c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
4577c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
4587c478bd9Sstevel@tonic-gate return (e);
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4637c478bd9Sstevel@tonic-gate "__rsm_put64x64: exit\n"));
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate static int
__rsm_get(rsm_memseg_import_handle_t im_memseg,off_t offset,void * dst_addr,size_t length)4697c478bd9Sstevel@tonic-gate __rsm_get(rsm_memseg_import_handle_t im_memseg, off_t offset, void *dst_addr,
4707c478bd9Sstevel@tonic-gate size_t length)
4717c478bd9Sstevel@tonic-gate {
4727c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
4737c478bd9Sstevel@tonic-gate int e;
4747c478bd9Sstevel@tonic-gate
4757c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4767c478bd9Sstevel@tonic-gate "__rsm_get: enter\n"));
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4797c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
4807c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
4817c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
4827c478bd9Sstevel@tonic-gate return (e);
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate }
4857c478bd9Sstevel@tonic-gate
4867c478bd9Sstevel@tonic-gate (void) bcopy(seg->rsmseg_vaddr + offset - seg->rsmseg_mapoffset,
4877c478bd9Sstevel@tonic-gate dst_addr, length);
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4907c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
4917c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
4927c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
4937c478bd9Sstevel@tonic-gate return (e);
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4987c478bd9Sstevel@tonic-gate "__rsm_get: exit\n"));
4997c478bd9Sstevel@tonic-gate
5007c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
5017c478bd9Sstevel@tonic-gate }
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate static int
__rsm_getv(rsm_scat_gath_t * sg_io)5047c478bd9Sstevel@tonic-gate __rsm_getv(rsm_scat_gath_t *sg_io)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate rsm_iovec_t *iovec = sg_io->iovec;
5077c478bd9Sstevel@tonic-gate rsmka_iovec_t ka_iovec_arr[RSM_MAX_IOVLEN];
5087c478bd9Sstevel@tonic-gate rsmka_iovec_t *ka_iovec, *ka_iovec_start;
5097c478bd9Sstevel@tonic-gate rsmka_iovec_t l_iovec_arr[RSM_MAX_IOVLEN];
5107c478bd9Sstevel@tonic-gate rsmka_iovec_t *l_iovec, *l_iovec_start;
5117c478bd9Sstevel@tonic-gate rsmseg_handle_t *im_seg_hndl = (rsmseg_handle_t *)sg_io->remote_handle;
5127c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg_hndl;
5137c478bd9Sstevel@tonic-gate int iovec_size = sizeof (rsmka_iovec_t) * sg_io->io_request_count;
5147c478bd9Sstevel@tonic-gate int e, i;
5157c478bd9Sstevel@tonic-gate
5167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5177c478bd9Sstevel@tonic-gate "__rsm_getv: enter\n"));
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gate /*
5207c478bd9Sstevel@tonic-gate * Use loopback for single node operations.
5217c478bd9Sstevel@tonic-gate * replace local handles with virtual addresses
5227c478bd9Sstevel@tonic-gate */
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate if (im_seg_hndl->rsmseg_nodeid == rsm_local_nodeid) {
5257c478bd9Sstevel@tonic-gate /*
5267c478bd9Sstevel@tonic-gate * To use the loopback optimization map the segment
5277c478bd9Sstevel@tonic-gate * here implicitly.
5287c478bd9Sstevel@tonic-gate */
5297c478bd9Sstevel@tonic-gate if (im_seg_hndl->rsmseg_state == IMPORT_CONNECT) {
5307c478bd9Sstevel@tonic-gate caddr_t va;
5317c478bd9Sstevel@tonic-gate va = mmap(NULL, im_seg_hndl->rsmseg_size,
5327c478bd9Sstevel@tonic-gate PROT_READ|PROT_WRITE,
5337c478bd9Sstevel@tonic-gate MAP_SHARED|MAP_NORESERVE,
5347c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_fd, 0);
5357c478bd9Sstevel@tonic-gate
5367c478bd9Sstevel@tonic-gate if (va == MAP_FAILED) {
5377c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
5387c478bd9Sstevel@tonic-gate "implicit map failed:%d\n", errno));
5397c478bd9Sstevel@tonic-gate if (errno == EINVAL)
5407c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
5417c478bd9Sstevel@tonic-gate else if (errno == ENOMEM || errno == ENXIO ||
5427c478bd9Sstevel@tonic-gate errno == EOVERFLOW)
5437c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
5447c478bd9Sstevel@tonic-gate else if (errno == EAGAIN)
5457c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
5467c478bd9Sstevel@tonic-gate else
5477c478bd9Sstevel@tonic-gate return (errno);
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate
5507c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_vaddr = va;
5517c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_maplen = im_seg_hndl->rsmseg_size;
5527c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_mapoffset = 0;
5537c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_state = IMPORT_MAP;
5547c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_flags |= RSM_IMPLICIT_MAP;
5557c478bd9Sstevel@tonic-gate }
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
5587c478bd9Sstevel@tonic-gate l_iovec_start = l_iovec = malloc(iovec_size);
5597c478bd9Sstevel@tonic-gate else
5607c478bd9Sstevel@tonic-gate l_iovec_start = l_iovec = l_iovec_arr;
5617c478bd9Sstevel@tonic-gate
5627c478bd9Sstevel@tonic-gate bcopy((caddr_t)iovec, (caddr_t)l_iovec, iovec_size);
5637c478bd9Sstevel@tonic-gate for (i = 0; i < sg_io->io_request_count; i++) {
5647c478bd9Sstevel@tonic-gate if (l_iovec->io_type == RSM_HANDLE_TYPE) {
5657c478bd9Sstevel@tonic-gate /* Get the surrogate export segment handle */
5667c478bd9Sstevel@tonic-gate seg_hndl = (rsmseg_handle_t *)
5677c478bd9Sstevel@tonic-gate l_iovec->local.handle;
5687c478bd9Sstevel@tonic-gate l_iovec->local.vaddr = seg_hndl->rsmseg_vaddr;
5697c478bd9Sstevel@tonic-gate l_iovec->io_type = RSM_VA_TYPE;
5707c478bd9Sstevel@tonic-gate }
5717c478bd9Sstevel@tonic-gate l_iovec++;
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate sg_io->iovec = (rsm_iovec_t *)l_iovec_start;
5747c478bd9Sstevel@tonic-gate e = loopback_getv(sg_io);
5757c478bd9Sstevel@tonic-gate sg_io->iovec = iovec;
5767c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
5777c478bd9Sstevel@tonic-gate free(l_iovec_start);
5787c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5797c478bd9Sstevel@tonic-gate "__rsm_getv: exit\n"));
5807c478bd9Sstevel@tonic-gate return (e);
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate
5837c478bd9Sstevel@tonic-gate /* for the Kernel Agent, replace local handles with segment ids */
5847c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
5857c478bd9Sstevel@tonic-gate ka_iovec_start = ka_iovec = malloc(iovec_size);
5867c478bd9Sstevel@tonic-gate else
5877c478bd9Sstevel@tonic-gate ka_iovec_start = ka_iovec = ka_iovec_arr;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate bcopy((caddr_t)iovec, (caddr_t)ka_iovec, iovec_size);
5907c478bd9Sstevel@tonic-gate for (i = 0; i < sg_io->io_request_count; i++) {
5917c478bd9Sstevel@tonic-gate if (ka_iovec->io_type == RSM_HANDLE_TYPE) {
5927c478bd9Sstevel@tonic-gate seg_hndl = (rsmseg_handle_t *)ka_iovec->local.handle;
5937c478bd9Sstevel@tonic-gate ka_iovec->local.segid = seg_hndl->rsmseg_keyid;
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate ka_iovec++;
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate
5987c478bd9Sstevel@tonic-gate sg_io->iovec = (rsm_iovec_t *)ka_iovec_start;
5997c478bd9Sstevel@tonic-gate e = ioctl(im_seg_hndl->rsmseg_fd, RSM_IOCTL_GETV, sg_io);
6007c478bd9Sstevel@tonic-gate sg_io->iovec = iovec;
6017c478bd9Sstevel@tonic-gate
6027c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
6037c478bd9Sstevel@tonic-gate free(ka_iovec_start);
6047c478bd9Sstevel@tonic-gate
6057c478bd9Sstevel@tonic-gate if (e < 0) {
6067c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6077c478bd9Sstevel@tonic-gate " RSM_IOCTL_GETV failed\n"));
6087c478bd9Sstevel@tonic-gate return (errno);
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6127c478bd9Sstevel@tonic-gate "__rsm_getv: exit\n"));
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
6157c478bd9Sstevel@tonic-gate }
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate static int
__rsm_put(rsm_memseg_import_handle_t im_memseg,off_t offset,void * src_addr,size_t length)6197c478bd9Sstevel@tonic-gate __rsm_put(rsm_memseg_import_handle_t im_memseg, off_t offset, void *src_addr,
6207c478bd9Sstevel@tonic-gate size_t length)
6217c478bd9Sstevel@tonic-gate {
6227c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
6237c478bd9Sstevel@tonic-gate int e;
6247c478bd9Sstevel@tonic-gate
6257c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6267c478bd9Sstevel@tonic-gate "__rsm_put: enter\n"));
6277c478bd9Sstevel@tonic-gate
6287c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
6297c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
6307c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
6317c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
6327c478bd9Sstevel@tonic-gate return (e);
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate bcopy(src_addr, seg->rsmseg_vaddr + offset - seg->rsmseg_mapoffset,
6377c478bd9Sstevel@tonic-gate length);
6387c478bd9Sstevel@tonic-gate
6397c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
6407c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
6417c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)seg->rsmseg_barrier);
6427c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
6437c478bd9Sstevel@tonic-gate return (e);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6487c478bd9Sstevel@tonic-gate "__rsm_put: exit\n"));
6497c478bd9Sstevel@tonic-gate
6507c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
6517c478bd9Sstevel@tonic-gate }
6527c478bd9Sstevel@tonic-gate
6537c478bd9Sstevel@tonic-gate static int
__rsm_putv(rsm_scat_gath_t * sg_io)6547c478bd9Sstevel@tonic-gate __rsm_putv(rsm_scat_gath_t *sg_io)
6557c478bd9Sstevel@tonic-gate {
6567c478bd9Sstevel@tonic-gate rsm_iovec_t *iovec = sg_io->iovec;
6577c478bd9Sstevel@tonic-gate rsmka_iovec_t ka_iovec_arr[RSM_MAX_IOVLEN];
6587c478bd9Sstevel@tonic-gate rsmka_iovec_t *ka_iovec, *ka_iovec_start;
6597c478bd9Sstevel@tonic-gate rsmka_iovec_t l_iovec_arr[RSM_MAX_IOVLEN];
6607c478bd9Sstevel@tonic-gate rsmka_iovec_t *l_iovec, *l_iovec_start;
6617c478bd9Sstevel@tonic-gate rsmseg_handle_t *im_seg_hndl = (rsmseg_handle_t *)sg_io->remote_handle;
6627c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg_hndl;
6637c478bd9Sstevel@tonic-gate int iovec_size = sizeof (rsmka_iovec_t) * sg_io->io_request_count;
6647c478bd9Sstevel@tonic-gate int e, i;
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6677c478bd9Sstevel@tonic-gate "__rsm_putv: enter\n"));
6687c478bd9Sstevel@tonic-gate
6697c478bd9Sstevel@tonic-gate /*
6707c478bd9Sstevel@tonic-gate * Use loopback for single node operations.
6717c478bd9Sstevel@tonic-gate * replace local handles with virtual addresses
6727c478bd9Sstevel@tonic-gate */
6737c478bd9Sstevel@tonic-gate
6747c478bd9Sstevel@tonic-gate if (im_seg_hndl->rsmseg_nodeid == rsm_local_nodeid) {
6757c478bd9Sstevel@tonic-gate /*
6767c478bd9Sstevel@tonic-gate * To use the loopback optimization map the segment
6777c478bd9Sstevel@tonic-gate * here implicitly.
6787c478bd9Sstevel@tonic-gate */
6797c478bd9Sstevel@tonic-gate if (im_seg_hndl->rsmseg_state == IMPORT_CONNECT) {
6807c478bd9Sstevel@tonic-gate caddr_t va;
6817c478bd9Sstevel@tonic-gate va = mmap(NULL, im_seg_hndl->rsmseg_size,
6827c478bd9Sstevel@tonic-gate PROT_READ|PROT_WRITE,
6837c478bd9Sstevel@tonic-gate MAP_SHARED|MAP_NORESERVE,
6847c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_fd, 0);
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate if (va == MAP_FAILED) {
6877c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6887c478bd9Sstevel@tonic-gate "implicit map failed:%d\n", errno));
6897c478bd9Sstevel@tonic-gate if (errno == EINVAL)
6907c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
6917c478bd9Sstevel@tonic-gate else if (errno == ENOMEM || errno == ENXIO ||
6927c478bd9Sstevel@tonic-gate errno == EOVERFLOW)
6937c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
6947c478bd9Sstevel@tonic-gate else if (errno == EAGAIN)
6957c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
6967c478bd9Sstevel@tonic-gate else
6977c478bd9Sstevel@tonic-gate return (errno);
6987c478bd9Sstevel@tonic-gate }
6997c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_vaddr = va;
7007c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_maplen = im_seg_hndl->rsmseg_size;
7017c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_mapoffset = 0;
7027c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_state = IMPORT_MAP;
7037c478bd9Sstevel@tonic-gate im_seg_hndl->rsmseg_flags |= RSM_IMPLICIT_MAP;
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate
7067c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7077c478bd9Sstevel@tonic-gate l_iovec_start = l_iovec = malloc(iovec_size);
7087c478bd9Sstevel@tonic-gate else
7097c478bd9Sstevel@tonic-gate l_iovec_start = l_iovec = l_iovec_arr;
7107c478bd9Sstevel@tonic-gate
7117c478bd9Sstevel@tonic-gate bcopy((caddr_t)iovec, (caddr_t)l_iovec, iovec_size);
7127c478bd9Sstevel@tonic-gate for (i = 0; i < sg_io->io_request_count; i++) {
7137c478bd9Sstevel@tonic-gate if (l_iovec->io_type == RSM_HANDLE_TYPE) {
7147c478bd9Sstevel@tonic-gate /* Get the surrogate export segment handle */
7157c478bd9Sstevel@tonic-gate seg_hndl = (rsmseg_handle_t *)
7167c478bd9Sstevel@tonic-gate l_iovec->local.handle;
7177c478bd9Sstevel@tonic-gate l_iovec->local.vaddr = seg_hndl->rsmseg_vaddr;
7187c478bd9Sstevel@tonic-gate l_iovec->io_type = RSM_VA_TYPE;
7197c478bd9Sstevel@tonic-gate }
7207c478bd9Sstevel@tonic-gate l_iovec++;
7217c478bd9Sstevel@tonic-gate }
7227c478bd9Sstevel@tonic-gate sg_io->iovec = (rsm_iovec_t *)l_iovec_start;
7237c478bd9Sstevel@tonic-gate e = loopback_putv(sg_io);
7247c478bd9Sstevel@tonic-gate sg_io->iovec = iovec;
7257c478bd9Sstevel@tonic-gate
7267c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7277c478bd9Sstevel@tonic-gate free(l_iovec_start);
7287c478bd9Sstevel@tonic-gate
7297c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7307c478bd9Sstevel@tonic-gate "__rsm_putv: exit\n"));
7317c478bd9Sstevel@tonic-gate
7327c478bd9Sstevel@tonic-gate
7337c478bd9Sstevel@tonic-gate return (e);
7347c478bd9Sstevel@tonic-gate }
7357c478bd9Sstevel@tonic-gate
7367c478bd9Sstevel@tonic-gate /* for the Kernel Agent, replace local handles with segment ids */
7377c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7387c478bd9Sstevel@tonic-gate ka_iovec_start = ka_iovec = malloc(iovec_size);
7397c478bd9Sstevel@tonic-gate else
7407c478bd9Sstevel@tonic-gate ka_iovec_start = ka_iovec = ka_iovec_arr;
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate bcopy((caddr_t)iovec, (caddr_t)ka_iovec, iovec_size);
7437c478bd9Sstevel@tonic-gate
7447c478bd9Sstevel@tonic-gate for (i = 0; i < sg_io->io_request_count; i++) {
7457c478bd9Sstevel@tonic-gate if (ka_iovec->io_type == RSM_HANDLE_TYPE) {
7467c478bd9Sstevel@tonic-gate seg_hndl = (rsmseg_handle_t *)ka_iovec->local.handle;
7477c478bd9Sstevel@tonic-gate ka_iovec->local.segid = seg_hndl->rsmseg_keyid;
7487c478bd9Sstevel@tonic-gate }
7497c478bd9Sstevel@tonic-gate ka_iovec++;
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate sg_io->iovec = (rsm_iovec_t *)ka_iovec_start;
7537c478bd9Sstevel@tonic-gate e = ioctl(im_seg_hndl->rsmseg_fd, RSM_IOCTL_PUTV, sg_io);
7547c478bd9Sstevel@tonic-gate sg_io->iovec = iovec;
7557c478bd9Sstevel@tonic-gate
7567c478bd9Sstevel@tonic-gate if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7577c478bd9Sstevel@tonic-gate free(ka_iovec_start);
7587c478bd9Sstevel@tonic-gate
7597c478bd9Sstevel@tonic-gate if (e < 0) {
7607c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7617c478bd9Sstevel@tonic-gate " RSM_IOCTL_PUTV failed\n"));
7627c478bd9Sstevel@tonic-gate return (errno);
7637c478bd9Sstevel@tonic-gate }
7647c478bd9Sstevel@tonic-gate
7657c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7667c478bd9Sstevel@tonic-gate "__rsm_putv: exit\n"));
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate /*
7727c478bd9Sstevel@tonic-gate * import side memory segment operations (barriers):
7737c478bd9Sstevel@tonic-gate */
7747c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,rsm_barrier_type_t type,rsm_barrier_handle_t barrier)7757c478bd9Sstevel@tonic-gate __rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,
7767c478bd9Sstevel@tonic-gate rsm_barrier_type_t type,
7777c478bd9Sstevel@tonic-gate rsm_barrier_handle_t barrier)
7787c478bd9Sstevel@tonic-gate {
7797c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
7807c478bd9Sstevel@tonic-gate rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
7817c478bd9Sstevel@tonic-gate
7827c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7837c478bd9Sstevel@tonic-gate ""
7847c478bd9Sstevel@tonic-gate "__rsm_memseg_import_init_barrier: enter\n"));
7857c478bd9Sstevel@tonic-gate
7867c478bd9Sstevel@tonic-gate type = type;
7877c478bd9Sstevel@tonic-gate
7887c478bd9Sstevel@tonic-gate if (!seg) {
7897c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7907c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
7917c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
7927c478bd9Sstevel@tonic-gate }
7937c478bd9Sstevel@tonic-gate if (!bar) {
7947c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7957c478bd9Sstevel@tonic-gate "invalid barrier handle\n"));
7967c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
7977c478bd9Sstevel@tonic-gate }
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate /* XXX: fix later. We only support span-of-node barriers */
8007c478bd9Sstevel@tonic-gate
8017c478bd9Sstevel@tonic-gate bar->rsmgenbar_data = (rsm_barrier_t *)malloc(sizeof (rsm_barrier_t));
8027c478bd9Sstevel@tonic-gate if (bar->rsmgenbar_data == NULL) {
8037c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8047c478bd9Sstevel@tonic-gate "not enough memory\n"));
8057c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
8067c478bd9Sstevel@tonic-gate }
8077c478bd9Sstevel@tonic-gate bar->rsmgenbar_seg = seg;
8087c478bd9Sstevel@tonic-gate
8097c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8107c478bd9Sstevel@tonic-gate "__rsm_memseg_import_init_barrier: exit\n"));
8117c478bd9Sstevel@tonic-gate
8127c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
8137c478bd9Sstevel@tonic-gate }
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_open_barrier(rsm_barrier_handle_t barrier)8167c478bd9Sstevel@tonic-gate __rsm_memseg_import_open_barrier(rsm_barrier_handle_t barrier)
8177c478bd9Sstevel@tonic-gate {
8187c478bd9Sstevel@tonic-gate rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
8197c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg;
8207c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
8217c478bd9Sstevel@tonic-gate
8227c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8237c478bd9Sstevel@tonic-gate "__rsm_memseg_import_open_barrier: enter\n"));
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate if (!bar) {
8267c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8277c478bd9Sstevel@tonic-gate "invalid barrier pointer\n"));
8287c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
8297c478bd9Sstevel@tonic-gate }
8307c478bd9Sstevel@tonic-gate
8317c478bd9Sstevel@tonic-gate if ((seg = bar->rsmgenbar_seg) == 0) {
8327c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8337c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
8347c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
8357c478bd9Sstevel@tonic-gate }
8367c478bd9Sstevel@tonic-gate
8377c478bd9Sstevel@tonic-gate /* lint -save -e718 -e746 */
8387c478bd9Sstevel@tonic-gate msg.bar = *(bar->rsmgenbar_data);
8397c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd,
8407c478bd9Sstevel@tonic-gate RSM_IOCTL_BAR_OPEN, &msg) < 0) {
8417c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8427c478bd9Sstevel@tonic-gate " RSM_IOCTL_BAR_OPEN failed\n"));
8437c478bd9Sstevel@tonic-gate /* lint -restore */
8447c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_OPEN_FAILED);
8457c478bd9Sstevel@tonic-gate }
8467c478bd9Sstevel@tonic-gate
8477c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8487c478bd9Sstevel@tonic-gate "__rsm_memseg_import_open_barrier: exit\n"));
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
8517c478bd9Sstevel@tonic-gate }
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_order_barrier(rsm_barrier_handle_t barrier)8547c478bd9Sstevel@tonic-gate __rsm_memseg_import_order_barrier(rsm_barrier_handle_t barrier)
8557c478bd9Sstevel@tonic-gate {
8567c478bd9Sstevel@tonic-gate rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
8577c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg;
8587c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
8597c478bd9Sstevel@tonic-gate
8607c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8617c478bd9Sstevel@tonic-gate "__rsm_memseg_import_order_barrier: enter\n"));
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate if (!bar) {
8647c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8657c478bd9Sstevel@tonic-gate "invalid barrier\n"));
8667c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
8677c478bd9Sstevel@tonic-gate }
8687c478bd9Sstevel@tonic-gate if ((seg = bar->rsmgenbar_seg) == 0) {
8697c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8707c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
8717c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate
8747c478bd9Sstevel@tonic-gate msg.bar = *(bar->rsmgenbar_data);
8757c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_BAR_ORDER, &msg) < 0) {
8767c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8777c478bd9Sstevel@tonic-gate "RSM_IOCTL_BAR_ORDER failed\n"));
8787c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_FAILURE);
8797c478bd9Sstevel@tonic-gate }
8807c478bd9Sstevel@tonic-gate
8817c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8827c478bd9Sstevel@tonic-gate "__rsm_memseg_import_order_barrier: exit\n"));
8837c478bd9Sstevel@tonic-gate
8847c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
8857c478bd9Sstevel@tonic-gate }
8867c478bd9Sstevel@tonic-gate
8877c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_close_barrier(rsm_barrier_handle_t barrier)8887c478bd9Sstevel@tonic-gate __rsm_memseg_import_close_barrier(rsm_barrier_handle_t barrier)
8897c478bd9Sstevel@tonic-gate {
8907c478bd9Sstevel@tonic-gate rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
8917c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg;
8927c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
8937c478bd9Sstevel@tonic-gate
8947c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8957c478bd9Sstevel@tonic-gate "__rsm_memseg_import_close_barrier: enter\n"));
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate if (!bar) {
8987c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8997c478bd9Sstevel@tonic-gate "invalid barrier\n"));
9007c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate if ((seg = bar->rsmgenbar_seg) == 0) {
9037c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
9047c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
9057c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
9067c478bd9Sstevel@tonic-gate }
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate msg.bar = *(bar->rsmgenbar_data);
9097c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_BAR_CLOSE, &msg) < 0) {
9107c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
9117c478bd9Sstevel@tonic-gate " RSM_IOCTL_BAR_CLOSE failed\n"));
9127c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_FAILURE);
9137c478bd9Sstevel@tonic-gate }
9147c478bd9Sstevel@tonic-gate
9157c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9167c478bd9Sstevel@tonic-gate "__rsm_memseg_import_close_barrier: exit\n"));
9177c478bd9Sstevel@tonic-gate
9187c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
9197c478bd9Sstevel@tonic-gate }
9207c478bd9Sstevel@tonic-gate
9217c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_destroy_barrier(rsm_barrier_handle_t barrier)9227c478bd9Sstevel@tonic-gate __rsm_memseg_import_destroy_barrier(rsm_barrier_handle_t barrier)
9237c478bd9Sstevel@tonic-gate {
9247c478bd9Sstevel@tonic-gate rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9277c478bd9Sstevel@tonic-gate "__rsm_memseg_import_destroy_barrier: enter\n"));
9287c478bd9Sstevel@tonic-gate
9297c478bd9Sstevel@tonic-gate if (!bar) {
9307c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
9317c478bd9Sstevel@tonic-gate "invalid barrier\n"));
9327c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
9337c478bd9Sstevel@tonic-gate }
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate free((void *) bar->rsmgenbar_data);
9367c478bd9Sstevel@tonic-gate
9377c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9387c478bd9Sstevel@tonic-gate "__rsm_memseg_import_destroy_barrier: exit\n"));
9397c478bd9Sstevel@tonic-gate
9407c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
9417c478bd9Sstevel@tonic-gate }
9427c478bd9Sstevel@tonic-gate
9437c478bd9Sstevel@tonic-gate /* lint -w1 */
9447c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t * mode)9457c478bd9Sstevel@tonic-gate __rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,
9467c478bd9Sstevel@tonic-gate rsm_barrier_mode_t *mode)
9477c478bd9Sstevel@tonic-gate {
9487c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9497c478bd9Sstevel@tonic-gate "__rsm_memseg_import_get_mode: enter\n"));
9507c478bd9Sstevel@tonic-gate
9517c478bd9Sstevel@tonic-gate im_memseg = im_memseg; mode = mode;
9527c478bd9Sstevel@tonic-gate
9537c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9547c478bd9Sstevel@tonic-gate "__rsm_memseg_import_get_mode: exit\n"));
9557c478bd9Sstevel@tonic-gate
9567c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
9577c478bd9Sstevel@tonic-gate }
9587c478bd9Sstevel@tonic-gate static int
__rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t mode)9597c478bd9Sstevel@tonic-gate __rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,
9607c478bd9Sstevel@tonic-gate rsm_barrier_mode_t mode)
9617c478bd9Sstevel@tonic-gate {
9627c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9637c478bd9Sstevel@tonic-gate "__rsm_memseg_import_set_mode: enter\n"));
9647c478bd9Sstevel@tonic-gate
9657c478bd9Sstevel@tonic-gate im_memseg = im_memseg; mode = mode;
9667c478bd9Sstevel@tonic-gate
9677c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9687c478bd9Sstevel@tonic-gate "__rsm_memseg_import_set_mode: exit\n"));
9697c478bd9Sstevel@tonic-gate
9707c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
9717c478bd9Sstevel@tonic-gate }
9727c478bd9Sstevel@tonic-gate
9737c478bd9Sstevel@tonic-gate static int
__rsm_create_memory_handle(rsmapi_controller_handle_t controller,rsm_localmemory_handle_t * local_hndl_p,caddr_t local_va,size_t len)9747c478bd9Sstevel@tonic-gate __rsm_create_memory_handle(rsmapi_controller_handle_t controller,
9757c478bd9Sstevel@tonic-gate rsm_localmemory_handle_t *local_hndl_p,
9767c478bd9Sstevel@tonic-gate caddr_t local_va, size_t len)
9777c478bd9Sstevel@tonic-gate {
9787c478bd9Sstevel@tonic-gate rsm_memseg_export_handle_t memseg;
9797c478bd9Sstevel@tonic-gate rsmapi_access_entry_t acl[1];
9807c478bd9Sstevel@tonic-gate rsm_memseg_id_t segid = 0;
9817c478bd9Sstevel@tonic-gate size_t size;
9827c478bd9Sstevel@tonic-gate int e;
9837c478bd9Sstevel@tonic-gate
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9867c478bd9Sstevel@tonic-gate "__rsm_create_memory_handle: enter\n"));
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate /*
9897c478bd9Sstevel@tonic-gate * create a surrogate segment (local memory will be locked down).
9907c478bd9Sstevel@tonic-gate */
9917c478bd9Sstevel@tonic-gate size = roundup(len, PAGESIZE);
9927c478bd9Sstevel@tonic-gate e = rsm_memseg_export_create(controller, &memseg,
9937c478bd9Sstevel@tonic-gate (void *)local_va, size,
9947c478bd9Sstevel@tonic-gate RSM_ALLOW_REBIND);
9957c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
9967c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
9977c478bd9Sstevel@tonic-gate "export create failed\n"));
9987c478bd9Sstevel@tonic-gate return (e);
9997c478bd9Sstevel@tonic-gate }
10007c478bd9Sstevel@tonic-gate
10017c478bd9Sstevel@tonic-gate /*
10027c478bd9Sstevel@tonic-gate * Publish the segment to the local node only. If the segment
10037c478bd9Sstevel@tonic-gate * length is very large then don't publish to the adapter driver
10047c478bd9Sstevel@tonic-gate * because that will consume too much DVMA space - this is indicated
10057c478bd9Sstevel@tonic-gate * to the Kernel Agent using null permissions. DVMA binding will
10067c478bd9Sstevel@tonic-gate * be done when the RDMA is set up.
10077c478bd9Sstevel@tonic-gate */
10087c478bd9Sstevel@tonic-gate acl[0].ae_node = rsm_local_nodeid;
10097c478bd9Sstevel@tonic-gate if (len > RSM_MAX_HANDLE_DVMA)
10107c478bd9Sstevel@tonic-gate acl[0].ae_permission = 0;
10117c478bd9Sstevel@tonic-gate else
10127c478bd9Sstevel@tonic-gate acl[0].ae_permission = RSM_PERM_RDWR;
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate e = rsm_memseg_export_publish(memseg, &segid, acl, 1);
10157c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
10167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
10177c478bd9Sstevel@tonic-gate "export publish failed\n"));
10187c478bd9Sstevel@tonic-gate rsm_memseg_export_destroy(memseg);
10197c478bd9Sstevel@tonic-gate return (e);
10207c478bd9Sstevel@tonic-gate }
10217c478bd9Sstevel@tonic-gate
10227c478bd9Sstevel@tonic-gate /* Use the surrogate seghandle as the local memory handle */
10237c478bd9Sstevel@tonic-gate *local_hndl_p = (rsm_localmemory_handle_t)memseg;
10247c478bd9Sstevel@tonic-gate
10257c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10267c478bd9Sstevel@tonic-gate "__rsm_create_memory_handle: exit\n"));
10277c478bd9Sstevel@tonic-gate
10287c478bd9Sstevel@tonic-gate return (e);
10297c478bd9Sstevel@tonic-gate }
10307c478bd9Sstevel@tonic-gate
10317c478bd9Sstevel@tonic-gate static int
__rsm_free_memory_handle(rsm_localmemory_handle_t local_handle)10327c478bd9Sstevel@tonic-gate __rsm_free_memory_handle(rsm_localmemory_handle_t local_handle)
10337c478bd9Sstevel@tonic-gate {
10347c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10357c478bd9Sstevel@tonic-gate "__rsm_free_memory_handle: enter\n"));
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate rsm_memseg_export_destroy((rsm_memseg_export_handle_t)local_handle);
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10407c478bd9Sstevel@tonic-gate "__rsm_free_memory_handle: exit\n"));
10417c478bd9Sstevel@tonic-gate
10427c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
10437c478bd9Sstevel@tonic-gate }
10447c478bd9Sstevel@tonic-gate
10457c478bd9Sstevel@tonic-gate static int
__rsm_get_lib_attr(rsm_ndlib_attr_t ** libattrp)10467c478bd9Sstevel@tonic-gate __rsm_get_lib_attr(rsm_ndlib_attr_t **libattrp)
10477c478bd9Sstevel@tonic-gate {
10487c478bd9Sstevel@tonic-gate
10497c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10507c478bd9Sstevel@tonic-gate "__rsm_get_lib_attr: enter\n"));
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate *libattrp = &_rsm_genlib_attr;
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10557c478bd9Sstevel@tonic-gate "__rsm_get_lib_attr: exit\n"));
10567c478bd9Sstevel@tonic-gate
10577c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
10587c478bd9Sstevel@tonic-gate }
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate static int
__rsm_closedevice(rsmapi_controller_handle_t cntr_handle)10617c478bd9Sstevel@tonic-gate __rsm_closedevice(rsmapi_controller_handle_t cntr_handle)
10627c478bd9Sstevel@tonic-gate {
10637c478bd9Sstevel@tonic-gate
10647c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10657c478bd9Sstevel@tonic-gate "__rsm_closedevice: enter\n"));
10667c478bd9Sstevel@tonic-gate
10677c478bd9Sstevel@tonic-gate cntr_handle = cntr_handle;
10687c478bd9Sstevel@tonic-gate
10697c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10707c478bd9Sstevel@tonic-gate "__rsm_closedevice: exit\n"));
10717c478bd9Sstevel@tonic-gate
10727c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
10737c478bd9Sstevel@tonic-gate }
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate void
__rsmdefault_setops(rsm_segops_t * segops)10767c478bd9Sstevel@tonic-gate __rsmdefault_setops(rsm_segops_t *segops)
10777c478bd9Sstevel@tonic-gate {
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10807c478bd9Sstevel@tonic-gate "__rsmdefault_setops: enter\n"));
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_connect == NULL) {
10837c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_connect = __rsm_import_connect;
10847c478bd9Sstevel@tonic-gate }
10857c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_disconnect == NULL) {
10867c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_disconnect = __rsm_import_disconnect;
10877c478bd9Sstevel@tonic-gate }
10887c478bd9Sstevel@tonic-gate
10897c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_get8 == NULL) {
10907c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_get8 = __rsm_get8x8;
10917c478bd9Sstevel@tonic-gate }
10927c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_get16 == NULL) {
10937c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_get16 = __rsm_get16x16;
10947c478bd9Sstevel@tonic-gate }
10957c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_get32 == NULL) {
10967c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_get32 = __rsm_get32x32;
10977c478bd9Sstevel@tonic-gate }
10987c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_get64 == NULL) {
10997c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_get64 = __rsm_get64x64;
11007c478bd9Sstevel@tonic-gate }
11017c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_get == NULL) {
11027c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_get = __rsm_get;
11037c478bd9Sstevel@tonic-gate }
11047c478bd9Sstevel@tonic-gate
11057c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_put8 == NULL) {
11067c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_put8 = __rsm_put8x8;
11077c478bd9Sstevel@tonic-gate }
11087c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_put16 == NULL) {
11097c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_put16 = __rsm_put16x16;
11107c478bd9Sstevel@tonic-gate }
11117c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_put32 == NULL) {
11127c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_put32 = __rsm_put32x32;
11137c478bd9Sstevel@tonic-gate }
11147c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_put64 == NULL) {
11157c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_put64 = __rsm_put64x64;
11167c478bd9Sstevel@tonic-gate }
11177c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_put == NULL) {
11187c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_put = __rsm_put;
11197c478bd9Sstevel@tonic-gate }
11207c478bd9Sstevel@tonic-gate
11217c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_putv == NULL) {
11227c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_putv = __rsm_putv;
11237c478bd9Sstevel@tonic-gate }
11247c478bd9Sstevel@tonic-gate
11257c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_getv == NULL) {
11267c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_getv = __rsm_getv;
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate
11297c478bd9Sstevel@tonic-gate if (segops->rsm_create_localmemory_handle == NULL) {
11307c478bd9Sstevel@tonic-gate segops->rsm_create_localmemory_handle =
11317c478bd9Sstevel@tonic-gate __rsm_create_memory_handle;
11327c478bd9Sstevel@tonic-gate }
11337c478bd9Sstevel@tonic-gate
11347c478bd9Sstevel@tonic-gate if (segops->rsm_free_localmemory_handle == NULL) {
11357c478bd9Sstevel@tonic-gate segops->rsm_free_localmemory_handle =
11367c478bd9Sstevel@tonic-gate __rsm_free_memory_handle;
11377c478bd9Sstevel@tonic-gate }
11387c478bd9Sstevel@tonic-gate
11397c478bd9Sstevel@tonic-gate /* XXX: Need to support barrier functions */
11407c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_init_barrier == NULL) {
11417c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_init_barrier =
11427c478bd9Sstevel@tonic-gate __rsm_memseg_import_init_barrier;
11437c478bd9Sstevel@tonic-gate }
11447c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_open_barrier == NULL) {
11457c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_open_barrier =
11467c478bd9Sstevel@tonic-gate __rsm_memseg_import_open_barrier;
11477c478bd9Sstevel@tonic-gate }
11487c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_order_barrier == NULL) {
11497c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_order_barrier =
11507c478bd9Sstevel@tonic-gate __rsm_memseg_import_order_barrier;
11517c478bd9Sstevel@tonic-gate }
11527c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_close_barrier == NULL) {
11537c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_close_barrier =
11547c478bd9Sstevel@tonic-gate __rsm_memseg_import_close_barrier;
11557c478bd9Sstevel@tonic-gate }
11567c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_destroy_barrier == NULL) {
11577c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_destroy_barrier =
11587c478bd9Sstevel@tonic-gate __rsm_memseg_import_destroy_barrier;
11597c478bd9Sstevel@tonic-gate }
11607c478bd9Sstevel@tonic-gate
11617c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_get_mode == NULL) {
11627c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_get_mode =
11637c478bd9Sstevel@tonic-gate __rsm_memseg_import_get_mode;
11647c478bd9Sstevel@tonic-gate }
11657c478bd9Sstevel@tonic-gate if (segops->rsm_memseg_import_set_mode == NULL) {
11667c478bd9Sstevel@tonic-gate segops->rsm_memseg_import_set_mode =
11677c478bd9Sstevel@tonic-gate __rsm_memseg_import_set_mode;
11687c478bd9Sstevel@tonic-gate }
11697c478bd9Sstevel@tonic-gate
11707c478bd9Sstevel@tonic-gate if (segops->rsm_get_lib_attr == NULL) {
11717c478bd9Sstevel@tonic-gate segops->rsm_get_lib_attr =
11727c478bd9Sstevel@tonic-gate __rsm_get_lib_attr;
11737c478bd9Sstevel@tonic-gate }
11747c478bd9Sstevel@tonic-gate
11757c478bd9Sstevel@tonic-gate if (segops->rsm_closedevice == NULL) {
11767c478bd9Sstevel@tonic-gate segops->rsm_closedevice =
11777c478bd9Sstevel@tonic-gate __rsm_closedevice;
11787c478bd9Sstevel@tonic-gate }
11797c478bd9Sstevel@tonic-gate
11807c478bd9Sstevel@tonic-gate
11817c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
11827c478bd9Sstevel@tonic-gate "__rsmdefault_setops: exit\n"));
11837c478bd9Sstevel@tonic-gate
11847c478bd9Sstevel@tonic-gate }
1185