xref: /onnv-gate/usr/src/lib/librsm/common/rsmgen.c (revision 6812:febeba71273d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*6812Sraf  * Common Development and Distribution License (the "License").
6*6812Sraf  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211219Sraf 
220Sstevel@tonic-gate /*
23*6812Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241219Sraf  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <stdio.h>
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <unistd.h>
320Sstevel@tonic-gate #include <string.h>
330Sstevel@tonic-gate #include <strings.h>
340Sstevel@tonic-gate #include <sys/types.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <sys/mman.h>
370Sstevel@tonic-gate #include <sys/uio.h>
380Sstevel@tonic-gate #include <sys/sysmacros.h>
390Sstevel@tonic-gate #include <unistd.h>
400Sstevel@tonic-gate #include <errno.h>
410Sstevel@tonic-gate #include <assert.h>
420Sstevel@tonic-gate #include <malloc.h>
430Sstevel@tonic-gate #include <fcntl.h>
440Sstevel@tonic-gate #include <dlfcn.h>
450Sstevel@tonic-gate #include <sched.h>
460Sstevel@tonic-gate 
470Sstevel@tonic-gate #include <rsmapi.h>
480Sstevel@tonic-gate #include <sys/rsm/rsmndi.h>
490Sstevel@tonic-gate #include <rsmlib_in.h>
500Sstevel@tonic-gate #include <sys/rsm/rsm.h>
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /* lint -w2 */
530Sstevel@tonic-gate 
540Sstevel@tonic-gate extern rsm_node_id_t rsm_local_nodeid;
550Sstevel@tonic-gate extern int loopback_getv(rsm_scat_gath_t *);
560Sstevel@tonic-gate extern int loopback_putv(rsm_scat_gath_t *);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate static rsm_ndlib_attr_t _rsm_genlib_attr = {
590Sstevel@tonic-gate 	B_TRUE,		/* mapping needed for put/get */
600Sstevel@tonic-gate 	B_FALSE		/* mapping needed for putv/getv */
610Sstevel@tonic-gate };
620Sstevel@tonic-gate 
630Sstevel@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)640Sstevel@tonic-gate __rsm_import_connect(
650Sstevel@tonic-gate     rsmapi_controller_handle_t controller, rsm_node_id_t node_id,
660Sstevel@tonic-gate     rsm_memseg_id_t segment_id, rsm_permission_t perm,
670Sstevel@tonic-gate     rsm_memseg_import_handle_t *im_memseg) {
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
700Sstevel@tonic-gate 	    "__rsm_import_connect: enter\n"));
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	controller = controller;
730Sstevel@tonic-gate 	node_id = node_id;
740Sstevel@tonic-gate 	segment_id = segment_id;
750Sstevel@tonic-gate 	perm = perm;
760Sstevel@tonic-gate 	im_memseg = im_memseg;
770Sstevel@tonic-gate 
780Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
790Sstevel@tonic-gate 	    "__rsm_import_connect: exit\n"));
800Sstevel@tonic-gate 
810Sstevel@tonic-gate 	return (RSM_SUCCESS);
820Sstevel@tonic-gate }
830Sstevel@tonic-gate 
840Sstevel@tonic-gate static int
__rsm_import_disconnect(rsm_memseg_import_handle_t im_memseg)850Sstevel@tonic-gate __rsm_import_disconnect(rsm_memseg_import_handle_t im_memseg) {
860Sstevel@tonic-gate 
870Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
880Sstevel@tonic-gate 	    "__rsm_import_disconnect: enter\n"));
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	im_memseg = im_memseg;
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
930Sstevel@tonic-gate 	    "__rsm_import_disconnect: exit\n"));
940Sstevel@tonic-gate 
950Sstevel@tonic-gate 	return (RSM_SUCCESS);
960Sstevel@tonic-gate }
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * XXX: one day we ought to rewrite this stuff based on 64byte atomic access.
1000Sstevel@tonic-gate  * We can have a new ops vector that makes that assumption.
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate 
1030Sstevel@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)1040Sstevel@tonic-gate __rsm_get8x8(rsm_memseg_import_handle_t im_memseg, off_t off,
1050Sstevel@tonic-gate     uint8_t *datap,
1060Sstevel@tonic-gate     ulong_t rep_cnt,
1070Sstevel@tonic-gate     boolean_t swap)
1080Sstevel@tonic-gate {
1090Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
1100Sstevel@tonic-gate 	uint8_t *data_addr =
111*6812Sraf 	    (uint8_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
1120Sstevel@tonic-gate 	uint_t i = 0;
1130Sstevel@tonic-gate 	int	e;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 	swap = swap;
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1180Sstevel@tonic-gate 	    "__rsm_import_get8x8: enter\n"));
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1210Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
1220Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
1230Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
1240Sstevel@tonic-gate 			return (e);
1250Sstevel@tonic-gate 		}
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
1290Sstevel@tonic-gate 		datap[i] = data_addr[i];
1300Sstevel@tonic-gate 	}
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1330Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
1340Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
1350Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
1360Sstevel@tonic-gate 			return (e);
1370Sstevel@tonic-gate 		}
1380Sstevel@tonic-gate 	}
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1410Sstevel@tonic-gate 	    "__rsm_import_get8x8: exit\n"));
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	return (RSM_SUCCESS);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@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)1470Sstevel@tonic-gate __rsm_get16x16(rsm_memseg_import_handle_t im_memseg, off_t off,
1480Sstevel@tonic-gate     uint16_t *datap,
1490Sstevel@tonic-gate     ulong_t rep_cnt,
1500Sstevel@tonic-gate     boolean_t swap)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
1530Sstevel@tonic-gate 	uint16_t *data_addr =
1540Sstevel@tonic-gate 	    /* LINTED */
1550Sstevel@tonic-gate 	    (uint16_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
1560Sstevel@tonic-gate 	uint_t i = 0;
1570Sstevel@tonic-gate 	int	e;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	swap = swap;
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1620Sstevel@tonic-gate 	    "__rsm_import_get16x16: enter\n"));
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1650Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
1660Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
1670Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
1680Sstevel@tonic-gate 			return (e);
1690Sstevel@tonic-gate 		}
1700Sstevel@tonic-gate 	}
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
1730Sstevel@tonic-gate 		datap[i] = data_addr[i];
1740Sstevel@tonic-gate 	}
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
1770Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
1780Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
1790Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
1800Sstevel@tonic-gate 			return (e);
1810Sstevel@tonic-gate 		}
1820Sstevel@tonic-gate 	}
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1850Sstevel@tonic-gate 	    "__rsm_import_get16x16: exit\n"));
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	return (RSM_SUCCESS);
1880Sstevel@tonic-gate }
1890Sstevel@tonic-gate 
1900Sstevel@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)1910Sstevel@tonic-gate __rsm_get32x32(rsm_memseg_import_handle_t im_memseg, off_t off,
1920Sstevel@tonic-gate     uint32_t *datap,
1930Sstevel@tonic-gate     ulong_t rep_cnt,
1940Sstevel@tonic-gate     boolean_t swap)
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
1970Sstevel@tonic-gate 	uint32_t *data_addr =
1980Sstevel@tonic-gate 	    /* LINTED */
1990Sstevel@tonic-gate 	    (uint32_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
2000Sstevel@tonic-gate 	uint_t i = 0;
2010Sstevel@tonic-gate 	int	e;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	swap = swap;
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2060Sstevel@tonic-gate 	    "__rsm_import_get32x32: enter\n"));
2070Sstevel@tonic-gate 
2080Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2090Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
2100Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
2110Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
2120Sstevel@tonic-gate 			return (e);
2130Sstevel@tonic-gate 		}
2140Sstevel@tonic-gate 	}
2150Sstevel@tonic-gate 
2160Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
2170Sstevel@tonic-gate 		datap[i] = data_addr[i];
2180Sstevel@tonic-gate 	}
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2210Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
2220Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
2230Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
2240Sstevel@tonic-gate 			return (e);
2250Sstevel@tonic-gate 		}
2260Sstevel@tonic-gate 	}
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2290Sstevel@tonic-gate 	    "__rsm_import_get32x32: exit\n"));
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate 	return (RSM_SUCCESS);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate 
2340Sstevel@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)2350Sstevel@tonic-gate __rsm_get64x64(rsm_memseg_import_handle_t im_memseg, off_t off,
2360Sstevel@tonic-gate     uint64_t *datap,
2370Sstevel@tonic-gate     ulong_t rep_cnt,
2380Sstevel@tonic-gate     boolean_t swap)
2390Sstevel@tonic-gate {
2400Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
2410Sstevel@tonic-gate 	uint64_t *data_addr =
2420Sstevel@tonic-gate 	    /* LINTED */
2430Sstevel@tonic-gate 	    (uint64_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
2440Sstevel@tonic-gate 	uint_t i = 0;
2450Sstevel@tonic-gate 	int	e;
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	swap = swap;
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2500Sstevel@tonic-gate 	    "__rsm_import_get64x64: enter\n"));
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2530Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
2540Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
2550Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
2560Sstevel@tonic-gate 			return (e);
2570Sstevel@tonic-gate 		}
2580Sstevel@tonic-gate 	}
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
2610Sstevel@tonic-gate 		datap[i] = data_addr[i];
2620Sstevel@tonic-gate 	}
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
2650Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
2660Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
2670Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
2680Sstevel@tonic-gate 			return (e);
2690Sstevel@tonic-gate 		}
2700Sstevel@tonic-gate 	}
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2730Sstevel@tonic-gate 	    "__rsm_import_get64x64: exit\n"));
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	return (RSM_SUCCESS);
2760Sstevel@tonic-gate }
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 	/*
2790Sstevel@tonic-gate 	 * import side memory segment operations (write access functions):
2800Sstevel@tonic-gate 	 */
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate /*
2830Sstevel@tonic-gate  * XXX: Each one of the following cases ought to be a separate function loaded
2840Sstevel@tonic-gate  * into a segment access ops vector. We determine the correct function at
2850Sstevel@tonic-gate  * segment connect time. When a new controller is register, we can decode
2860Sstevel@tonic-gate  * it's direct_access_size attribute and load the correct function. For
2870Sstevel@tonic-gate  * loop back we need to create a special ops vector that bypasses all of
2880Sstevel@tonic-gate  * this stuff.
2890Sstevel@tonic-gate  *
2900Sstevel@tonic-gate  * XXX: We need to create a special interrupt queue for the library to handle
2910Sstevel@tonic-gate  * partial writes in the remote process.
2920Sstevel@tonic-gate  */
2930Sstevel@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)2940Sstevel@tonic-gate __rsm_put8x8(rsm_memseg_import_handle_t im_memseg, off_t off,
2950Sstevel@tonic-gate     uint8_t *datap,
2960Sstevel@tonic-gate     ulong_t rep_cnt,
2970Sstevel@tonic-gate     boolean_t swap)
2980Sstevel@tonic-gate {
2990Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
3000Sstevel@tonic-gate 	uint8_t *data_addr =
301*6812Sraf 	    (uint8_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
3020Sstevel@tonic-gate 	uint_t i = 0;
3030Sstevel@tonic-gate 	int	e;
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	swap = swap;
3060Sstevel@tonic-gate 
3070Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3080Sstevel@tonic-gate 	    "__rsm_put8x8: enter\n"));
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3110Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
3120Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
3130Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
3140Sstevel@tonic-gate 			return (e);
3150Sstevel@tonic-gate 		}
3160Sstevel@tonic-gate 	}
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
3190Sstevel@tonic-gate 		data_addr[i] = datap[i];
3200Sstevel@tonic-gate 	}
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3230Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
3240Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
3250Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
3260Sstevel@tonic-gate 			return (e);
3270Sstevel@tonic-gate 		}
3280Sstevel@tonic-gate 	}
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3310Sstevel@tonic-gate 	    "__rsm_put8x8: exit\n"));
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate 	return (RSM_SUCCESS);
3340Sstevel@tonic-gate }
3350Sstevel@tonic-gate 
3360Sstevel@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)3370Sstevel@tonic-gate __rsm_put16x16(rsm_memseg_import_handle_t im_memseg, off_t off,
3380Sstevel@tonic-gate     uint16_t *datap,
3390Sstevel@tonic-gate     ulong_t rep_cnt,
3400Sstevel@tonic-gate     boolean_t swap)
3410Sstevel@tonic-gate {
3420Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
3430Sstevel@tonic-gate 	uint16_t *data_addr =
3440Sstevel@tonic-gate 	    /* LINTED */
3450Sstevel@tonic-gate 	    (uint16_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
3460Sstevel@tonic-gate 	uint_t i = 0;
3470Sstevel@tonic-gate 	int	e;
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	swap = swap;
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3520Sstevel@tonic-gate 	    "__rsm_put16x16: enter\n"));
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3550Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
3560Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
3570Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
3580Sstevel@tonic-gate 			return (e);
3590Sstevel@tonic-gate 		}
3600Sstevel@tonic-gate 	}
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
3630Sstevel@tonic-gate 		data_addr[i] = datap[i];
3640Sstevel@tonic-gate 	}
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3670Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
3680Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
3690Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
3700Sstevel@tonic-gate 			return (e);
3710Sstevel@tonic-gate 		}
3720Sstevel@tonic-gate 	}
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3750Sstevel@tonic-gate 	    "__rsm_put16x16: exit\n"));
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 	return (RSM_SUCCESS);
3780Sstevel@tonic-gate }
3790Sstevel@tonic-gate 
3800Sstevel@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)3810Sstevel@tonic-gate __rsm_put32x32(rsm_memseg_import_handle_t im_memseg, off_t off,
3820Sstevel@tonic-gate     uint32_t *datap,
3830Sstevel@tonic-gate     ulong_t rep_cnt,
3840Sstevel@tonic-gate     boolean_t swap)
3850Sstevel@tonic-gate {
3860Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
3870Sstevel@tonic-gate 	uint32_t *data_addr =
3880Sstevel@tonic-gate 	    /* LINTED */
3890Sstevel@tonic-gate 	    (uint32_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
3900Sstevel@tonic-gate 	uint_t i = 0;
3910Sstevel@tonic-gate 	int	e;
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 	swap = swap;
3940Sstevel@tonic-gate 
3950Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3960Sstevel@tonic-gate 	    "__rsm_put32x32: enter\n"));
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
3990Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
4000Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
4010Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
4020Sstevel@tonic-gate 			return (e);
4030Sstevel@tonic-gate 		}
4040Sstevel@tonic-gate 	}
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
4070Sstevel@tonic-gate 		data_addr[i] = datap[i];
4080Sstevel@tonic-gate 	}
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4110Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
4120Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
4130Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
4140Sstevel@tonic-gate 			return (e);
4150Sstevel@tonic-gate 		}
4160Sstevel@tonic-gate 	}
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4190Sstevel@tonic-gate 	    "__rsm_put32x32: exit\n"));
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 	return (RSM_SUCCESS);
4220Sstevel@tonic-gate }
4230Sstevel@tonic-gate 
4240Sstevel@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)4250Sstevel@tonic-gate __rsm_put64x64(rsm_memseg_import_handle_t im_memseg, off_t off,
4260Sstevel@tonic-gate     uint64_t *datap,
4270Sstevel@tonic-gate     ulong_t rep_cnt,
4280Sstevel@tonic-gate     boolean_t swap)
4290Sstevel@tonic-gate {
4300Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
4310Sstevel@tonic-gate 	uint64_t *data_addr =
4320Sstevel@tonic-gate 	    /* LINTED */
4330Sstevel@tonic-gate 	    (uint64_t *)&seg->rsmseg_vaddr[off - seg->rsmseg_mapoffset];
4340Sstevel@tonic-gate 	uint_t i = 0;
4350Sstevel@tonic-gate 	int	e;
4360Sstevel@tonic-gate 
4370Sstevel@tonic-gate 	swap = swap;
4380Sstevel@tonic-gate 
4390Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4400Sstevel@tonic-gate 	    "__rsm_put64x64: enter\n"));
4410Sstevel@tonic-gate 
4420Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4430Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
4440Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
4450Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
4460Sstevel@tonic-gate 			return (e);
4470Sstevel@tonic-gate 		}
4480Sstevel@tonic-gate 	}
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate 	for (i = 0; i < rep_cnt; i++) {
4510Sstevel@tonic-gate 		data_addr[i] = datap[i];
4520Sstevel@tonic-gate 	}
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4550Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
4560Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
4570Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
4580Sstevel@tonic-gate 			return (e);
4590Sstevel@tonic-gate 		}
4600Sstevel@tonic-gate 	}
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4630Sstevel@tonic-gate 	    "__rsm_put64x64: exit\n"));
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 	return (RSM_SUCCESS);
4660Sstevel@tonic-gate }
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate static int
__rsm_get(rsm_memseg_import_handle_t im_memseg,off_t offset,void * dst_addr,size_t length)4690Sstevel@tonic-gate __rsm_get(rsm_memseg_import_handle_t im_memseg, off_t offset, void *dst_addr,
4700Sstevel@tonic-gate     size_t length)
4710Sstevel@tonic-gate {
4720Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
4730Sstevel@tonic-gate 	int		e;
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4760Sstevel@tonic-gate 	    "__rsm_get: enter\n"));
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4790Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
4800Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
4810Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
4820Sstevel@tonic-gate 			return (e);
4830Sstevel@tonic-gate 		}
4840Sstevel@tonic-gate 	}
4850Sstevel@tonic-gate 
4860Sstevel@tonic-gate 	(void) bcopy(seg->rsmseg_vaddr + offset - seg->rsmseg_mapoffset,
4870Sstevel@tonic-gate 	    dst_addr, length);
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
4900Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
4910Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
4920Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
4930Sstevel@tonic-gate 			return (e);
4940Sstevel@tonic-gate 		}
4950Sstevel@tonic-gate 	}
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4980Sstevel@tonic-gate 	    "__rsm_get: exit\n"));
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate 	return (RSM_SUCCESS);
5010Sstevel@tonic-gate }
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate static int
__rsm_getv(rsm_scat_gath_t * sg_io)5040Sstevel@tonic-gate __rsm_getv(rsm_scat_gath_t *sg_io)
5050Sstevel@tonic-gate {
5060Sstevel@tonic-gate 	rsm_iovec_t 	*iovec = sg_io->iovec;
5070Sstevel@tonic-gate 	rsmka_iovec_t	ka_iovec_arr[RSM_MAX_IOVLEN];
5080Sstevel@tonic-gate 	rsmka_iovec_t	*ka_iovec, *ka_iovec_start;
5090Sstevel@tonic-gate 	rsmka_iovec_t	l_iovec_arr[RSM_MAX_IOVLEN];
5100Sstevel@tonic-gate 	rsmka_iovec_t	*l_iovec, *l_iovec_start;
5110Sstevel@tonic-gate 	rsmseg_handle_t *im_seg_hndl = (rsmseg_handle_t *)sg_io->remote_handle;
5120Sstevel@tonic-gate 	rsmseg_handle_t *seg_hndl;
5130Sstevel@tonic-gate 	int iovec_size = sizeof (rsmka_iovec_t) * sg_io->io_request_count;
5140Sstevel@tonic-gate 	int e, i;
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5170Sstevel@tonic-gate 	    "__rsm_getv: enter\n"));
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate 	/*
5200Sstevel@tonic-gate 	 * Use loopback for single node operations.
5210Sstevel@tonic-gate 	 * replace local handles with virtual addresses
5220Sstevel@tonic-gate 	 */
5230Sstevel@tonic-gate 
5240Sstevel@tonic-gate 	if (im_seg_hndl->rsmseg_nodeid == rsm_local_nodeid) {
5250Sstevel@tonic-gate 		/*
5260Sstevel@tonic-gate 		 * To use the loopback optimization map the segment
5270Sstevel@tonic-gate 		 * here implicitly.
5280Sstevel@tonic-gate 		 */
5290Sstevel@tonic-gate 		if (im_seg_hndl->rsmseg_state == IMPORT_CONNECT) {
5300Sstevel@tonic-gate 			caddr_t	va;
5310Sstevel@tonic-gate 			va = mmap(NULL, im_seg_hndl->rsmseg_size,
5320Sstevel@tonic-gate 			    PROT_READ|PROT_WRITE,
5330Sstevel@tonic-gate 			    MAP_SHARED|MAP_NORESERVE,
5340Sstevel@tonic-gate 			    im_seg_hndl->rsmseg_fd, 0);
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate 			if (va == MAP_FAILED) {
5370Sstevel@tonic-gate 				DBPRINTF((RSM_LIBRARY, RSM_ERR,
5380Sstevel@tonic-gate 				    "implicit map failed:%d\n", errno));
5390Sstevel@tonic-gate 				if (errno == EINVAL)
5400Sstevel@tonic-gate 					return (RSMERR_BAD_MEM_ALIGNMENT);
5410Sstevel@tonic-gate 				else if (errno == ENOMEM || errno == ENXIO ||
542*6812Sraf 				    errno == EOVERFLOW)
543*6812Sraf 					return (RSMERR_BAD_LENGTH);
5440Sstevel@tonic-gate 				else if (errno == EAGAIN)
5450Sstevel@tonic-gate 					return (RSMERR_INSUFFICIENT_RESOURCES);
5460Sstevel@tonic-gate 				else
5470Sstevel@tonic-gate 					return (errno);
5480Sstevel@tonic-gate 			}
5490Sstevel@tonic-gate 
5500Sstevel@tonic-gate 			im_seg_hndl->rsmseg_vaddr = va;
5510Sstevel@tonic-gate 			im_seg_hndl->rsmseg_maplen = im_seg_hndl->rsmseg_size;
5520Sstevel@tonic-gate 			im_seg_hndl->rsmseg_mapoffset = 0;
5530Sstevel@tonic-gate 			im_seg_hndl->rsmseg_state = IMPORT_MAP;
5540Sstevel@tonic-gate 			im_seg_hndl->rsmseg_flags |= RSM_IMPLICIT_MAP;
5550Sstevel@tonic-gate 		}
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 		if (sg_io->io_request_count > RSM_MAX_IOVLEN)
5580Sstevel@tonic-gate 			l_iovec_start = l_iovec = malloc(iovec_size);
5590Sstevel@tonic-gate 		else
5600Sstevel@tonic-gate 			l_iovec_start = l_iovec = l_iovec_arr;
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate 		bcopy((caddr_t)iovec, (caddr_t)l_iovec, iovec_size);
5630Sstevel@tonic-gate 		for (i = 0; i < sg_io->io_request_count; i++) {
5640Sstevel@tonic-gate 			if (l_iovec->io_type == RSM_HANDLE_TYPE) {
5650Sstevel@tonic-gate 				/* Get the surrogate export segment handle */
5660Sstevel@tonic-gate 				seg_hndl = (rsmseg_handle_t *)
5670Sstevel@tonic-gate 				    l_iovec->local.handle;
5680Sstevel@tonic-gate 				l_iovec->local.vaddr = seg_hndl->rsmseg_vaddr;
5690Sstevel@tonic-gate 				l_iovec->io_type = RSM_VA_TYPE;
5700Sstevel@tonic-gate 			}
5710Sstevel@tonic-gate 			l_iovec++;
5720Sstevel@tonic-gate 		}
5730Sstevel@tonic-gate 		sg_io->iovec = (rsm_iovec_t *)l_iovec_start;
5740Sstevel@tonic-gate 		e = loopback_getv(sg_io);
5750Sstevel@tonic-gate 		sg_io->iovec = iovec;
5760Sstevel@tonic-gate 		if (sg_io->io_request_count > RSM_MAX_IOVLEN)
5770Sstevel@tonic-gate 			free(l_iovec_start);
5780Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5790Sstevel@tonic-gate 		    "__rsm_getv: exit\n"));
5800Sstevel@tonic-gate 		return (e);
5810Sstevel@tonic-gate 	}
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate 	/* for the Kernel Agent, replace local handles with segment ids */
5840Sstevel@tonic-gate 	if (sg_io->io_request_count > RSM_MAX_IOVLEN)
5850Sstevel@tonic-gate 		ka_iovec_start = ka_iovec = malloc(iovec_size);
5860Sstevel@tonic-gate 	else
5870Sstevel@tonic-gate 		ka_iovec_start = ka_iovec = ka_iovec_arr;
5880Sstevel@tonic-gate 
5890Sstevel@tonic-gate 	bcopy((caddr_t)iovec, (caddr_t)ka_iovec, iovec_size);
5900Sstevel@tonic-gate 	for (i = 0; i < sg_io->io_request_count; i++) {
5910Sstevel@tonic-gate 		if (ka_iovec->io_type == RSM_HANDLE_TYPE) {
5920Sstevel@tonic-gate 			seg_hndl = (rsmseg_handle_t *)ka_iovec->local.handle;
5930Sstevel@tonic-gate 			ka_iovec->local.segid = seg_hndl->rsmseg_keyid;
5940Sstevel@tonic-gate 		}
5950Sstevel@tonic-gate 		ka_iovec++;
5960Sstevel@tonic-gate 	}
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate 	sg_io->iovec = (rsm_iovec_t *)ka_iovec_start;
5990Sstevel@tonic-gate 	e = ioctl(im_seg_hndl->rsmseg_fd, RSM_IOCTL_GETV, sg_io);
6000Sstevel@tonic-gate 	sg_io->iovec = iovec;
6010Sstevel@tonic-gate 
6020Sstevel@tonic-gate 	if (sg_io->io_request_count > RSM_MAX_IOVLEN)
6030Sstevel@tonic-gate 		free(ka_iovec_start);
6040Sstevel@tonic-gate 
6050Sstevel@tonic-gate 	if (e < 0) {
6060Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
6070Sstevel@tonic-gate 		    " RSM_IOCTL_GETV failed\n"));
6080Sstevel@tonic-gate 		return (errno);
6090Sstevel@tonic-gate 	}
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6120Sstevel@tonic-gate 	    "__rsm_getv: exit\n"));
6130Sstevel@tonic-gate 
6140Sstevel@tonic-gate 	return (RSM_SUCCESS);
6150Sstevel@tonic-gate }
6160Sstevel@tonic-gate 
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate static int
__rsm_put(rsm_memseg_import_handle_t im_memseg,off_t offset,void * src_addr,size_t length)6190Sstevel@tonic-gate __rsm_put(rsm_memseg_import_handle_t im_memseg, off_t offset, void *src_addr,
6200Sstevel@tonic-gate     size_t length)
6210Sstevel@tonic-gate {
6220Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
6230Sstevel@tonic-gate 	int		e;
6240Sstevel@tonic-gate 
6250Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6260Sstevel@tonic-gate 	    "__rsm_put: enter\n"));
6270Sstevel@tonic-gate 
6280Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
6290Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_open_barrier(
6300Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
6310Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
6320Sstevel@tonic-gate 			return (e);
6330Sstevel@tonic-gate 		}
6340Sstevel@tonic-gate 	}
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	bcopy(src_addr, seg->rsmseg_vaddr + offset - seg->rsmseg_mapoffset,
637*6812Sraf 	    length);
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate 	if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
6400Sstevel@tonic-gate 		e = seg->rsmseg_ops->rsm_memseg_import_close_barrier(
6410Sstevel@tonic-gate 		    (rsm_barrier_handle_t)seg->rsmseg_barrier);
6420Sstevel@tonic-gate 		if (e != RSM_SUCCESS) {
6430Sstevel@tonic-gate 			return (e);
6440Sstevel@tonic-gate 		}
6450Sstevel@tonic-gate 	}
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6480Sstevel@tonic-gate 	    "__rsm_put: exit\n"));
6490Sstevel@tonic-gate 
6500Sstevel@tonic-gate 	return (RSM_SUCCESS);
6510Sstevel@tonic-gate }
6520Sstevel@tonic-gate 
6530Sstevel@tonic-gate static int
__rsm_putv(rsm_scat_gath_t * sg_io)6540Sstevel@tonic-gate __rsm_putv(rsm_scat_gath_t *sg_io)
6550Sstevel@tonic-gate {
6560Sstevel@tonic-gate 	rsm_iovec_t 	*iovec = sg_io->iovec;
6570Sstevel@tonic-gate 	rsmka_iovec_t	ka_iovec_arr[RSM_MAX_IOVLEN];
6580Sstevel@tonic-gate 	rsmka_iovec_t	*ka_iovec, *ka_iovec_start;
6590Sstevel@tonic-gate 	rsmka_iovec_t	l_iovec_arr[RSM_MAX_IOVLEN];
6600Sstevel@tonic-gate 	rsmka_iovec_t	*l_iovec, *l_iovec_start;
6610Sstevel@tonic-gate 	rsmseg_handle_t *im_seg_hndl = (rsmseg_handle_t *)sg_io->remote_handle;
6620Sstevel@tonic-gate 	rsmseg_handle_t *seg_hndl;
6630Sstevel@tonic-gate 	int iovec_size = sizeof (rsmka_iovec_t) * sg_io->io_request_count;
6640Sstevel@tonic-gate 	int e, i;
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6670Sstevel@tonic-gate 	    "__rsm_putv: enter\n"));
6680Sstevel@tonic-gate 
6690Sstevel@tonic-gate 	/*
6700Sstevel@tonic-gate 	 * Use loopback for single node operations.
6710Sstevel@tonic-gate 	 * replace local handles with virtual addresses
6720Sstevel@tonic-gate 	 */
6730Sstevel@tonic-gate 
6740Sstevel@tonic-gate 	if (im_seg_hndl->rsmseg_nodeid == rsm_local_nodeid) {
6750Sstevel@tonic-gate 		/*
6760Sstevel@tonic-gate 		 * To use the loopback optimization map the segment
6770Sstevel@tonic-gate 		 * here implicitly.
6780Sstevel@tonic-gate 		 */
6790Sstevel@tonic-gate 		if (im_seg_hndl->rsmseg_state == IMPORT_CONNECT) {
6800Sstevel@tonic-gate 			caddr_t	va;
6810Sstevel@tonic-gate 			va = mmap(NULL, im_seg_hndl->rsmseg_size,
6820Sstevel@tonic-gate 			    PROT_READ|PROT_WRITE,
6830Sstevel@tonic-gate 			    MAP_SHARED|MAP_NORESERVE,
6840Sstevel@tonic-gate 			    im_seg_hndl->rsmseg_fd, 0);
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate 			if (va == MAP_FAILED) {
6870Sstevel@tonic-gate 				DBPRINTF((RSM_LIBRARY, RSM_ERR,
6880Sstevel@tonic-gate 				    "implicit map failed:%d\n", errno));
6890Sstevel@tonic-gate 				if (errno == EINVAL)
6900Sstevel@tonic-gate 					return (RSMERR_BAD_MEM_ALIGNMENT);
6910Sstevel@tonic-gate 				else if (errno == ENOMEM || errno == ENXIO ||
692*6812Sraf 				    errno == EOVERFLOW)
693*6812Sraf 					return (RSMERR_BAD_LENGTH);
6940Sstevel@tonic-gate 				else if (errno == EAGAIN)
6950Sstevel@tonic-gate 					return (RSMERR_INSUFFICIENT_RESOURCES);
6960Sstevel@tonic-gate 				else
6970Sstevel@tonic-gate 					return (errno);
6980Sstevel@tonic-gate 			}
6990Sstevel@tonic-gate 			im_seg_hndl->rsmseg_vaddr = va;
7000Sstevel@tonic-gate 			im_seg_hndl->rsmseg_maplen = im_seg_hndl->rsmseg_size;
7010Sstevel@tonic-gate 			im_seg_hndl->rsmseg_mapoffset = 0;
7020Sstevel@tonic-gate 			im_seg_hndl->rsmseg_state = IMPORT_MAP;
7030Sstevel@tonic-gate 			im_seg_hndl->rsmseg_flags |= RSM_IMPLICIT_MAP;
7040Sstevel@tonic-gate 		}
7050Sstevel@tonic-gate 
7060Sstevel@tonic-gate 		if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7070Sstevel@tonic-gate 			l_iovec_start = l_iovec = malloc(iovec_size);
7080Sstevel@tonic-gate 		else
7090Sstevel@tonic-gate 			l_iovec_start = l_iovec = l_iovec_arr;
7100Sstevel@tonic-gate 
7110Sstevel@tonic-gate 		bcopy((caddr_t)iovec, (caddr_t)l_iovec, iovec_size);
7120Sstevel@tonic-gate 		for (i = 0; i < sg_io->io_request_count; i++) {
7130Sstevel@tonic-gate 			if (l_iovec->io_type == RSM_HANDLE_TYPE) {
7140Sstevel@tonic-gate 				/* Get the surrogate export segment handle */
7150Sstevel@tonic-gate 				seg_hndl = (rsmseg_handle_t *)
716*6812Sraf 				    l_iovec->local.handle;
7170Sstevel@tonic-gate 				l_iovec->local.vaddr = seg_hndl->rsmseg_vaddr;
7180Sstevel@tonic-gate 				l_iovec->io_type = RSM_VA_TYPE;
7190Sstevel@tonic-gate 			}
7200Sstevel@tonic-gate 			l_iovec++;
7210Sstevel@tonic-gate 		}
7220Sstevel@tonic-gate 		sg_io->iovec = (rsm_iovec_t *)l_iovec_start;
7230Sstevel@tonic-gate 		e = loopback_putv(sg_io);
7240Sstevel@tonic-gate 		sg_io->iovec = iovec;
7250Sstevel@tonic-gate 
7260Sstevel@tonic-gate 		if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7270Sstevel@tonic-gate 			free(l_iovec_start);
7280Sstevel@tonic-gate 
7290Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7300Sstevel@tonic-gate 		    "__rsm_putv: exit\n"));
7310Sstevel@tonic-gate 
7320Sstevel@tonic-gate 
7330Sstevel@tonic-gate 		return (e);
7340Sstevel@tonic-gate 	}
7350Sstevel@tonic-gate 
7360Sstevel@tonic-gate 	/* for the Kernel Agent, replace local handles with segment ids */
7370Sstevel@tonic-gate 	if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7380Sstevel@tonic-gate 		ka_iovec_start = ka_iovec = malloc(iovec_size);
7390Sstevel@tonic-gate 	else
7400Sstevel@tonic-gate 		ka_iovec_start = ka_iovec = ka_iovec_arr;
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate 	bcopy((caddr_t)iovec, (caddr_t)ka_iovec, iovec_size);
7430Sstevel@tonic-gate 
7440Sstevel@tonic-gate 	for (i = 0; i < sg_io->io_request_count; i++) {
7450Sstevel@tonic-gate 		if (ka_iovec->io_type == RSM_HANDLE_TYPE) {
7460Sstevel@tonic-gate 			seg_hndl = (rsmseg_handle_t *)ka_iovec->local.handle;
7470Sstevel@tonic-gate 			ka_iovec->local.segid = seg_hndl->rsmseg_keyid;
7480Sstevel@tonic-gate 		}
7490Sstevel@tonic-gate 		ka_iovec++;
7500Sstevel@tonic-gate 	}
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate 	sg_io->iovec = (rsm_iovec_t *)ka_iovec_start;
7530Sstevel@tonic-gate 	e = ioctl(im_seg_hndl->rsmseg_fd, RSM_IOCTL_PUTV, sg_io);
7540Sstevel@tonic-gate 	sg_io->iovec = iovec;
7550Sstevel@tonic-gate 
7560Sstevel@tonic-gate 	if (sg_io->io_request_count > RSM_MAX_IOVLEN)
7570Sstevel@tonic-gate 		free(ka_iovec_start);
7580Sstevel@tonic-gate 
7590Sstevel@tonic-gate 	if (e < 0) {
7600Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
7610Sstevel@tonic-gate 		    " RSM_IOCTL_PUTV failed\n"));
7620Sstevel@tonic-gate 		return (errno);
7630Sstevel@tonic-gate 	}
7640Sstevel@tonic-gate 
7650Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7660Sstevel@tonic-gate 	    "__rsm_putv: exit\n"));
7670Sstevel@tonic-gate 
7680Sstevel@tonic-gate 	return (RSM_SUCCESS);
7690Sstevel@tonic-gate }
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate 	/*
7720Sstevel@tonic-gate 	 * import side memory segment operations (barriers):
7730Sstevel@tonic-gate 	 */
7740Sstevel@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)7750Sstevel@tonic-gate __rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,
7760Sstevel@tonic-gate     rsm_barrier_type_t type,
7770Sstevel@tonic-gate     rsm_barrier_handle_t barrier)
7780Sstevel@tonic-gate {
7790Sstevel@tonic-gate 	rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
7800Sstevel@tonic-gate 	rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
7810Sstevel@tonic-gate 
7820Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7830Sstevel@tonic-gate 	    ""
7840Sstevel@tonic-gate 	    "__rsm_memseg_import_init_barrier: enter\n"));
7850Sstevel@tonic-gate 
7860Sstevel@tonic-gate 	type = type;
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate 	if (!seg) {
7890Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
7900Sstevel@tonic-gate 		    "invalid segment handle\n"));
7910Sstevel@tonic-gate 		return (RSMERR_BAD_SEG_HNDL);
7920Sstevel@tonic-gate 	}
7930Sstevel@tonic-gate 	if (!bar) {
7940Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
7950Sstevel@tonic-gate 		    "invalid barrier handle\n"));
7960Sstevel@tonic-gate 		return (RSMERR_BAD_BARRIER_PTR);
7970Sstevel@tonic-gate 	}
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate 	/* XXX: fix later. We only support span-of-node barriers */
8000Sstevel@tonic-gate 
8010Sstevel@tonic-gate 	bar->rsmgenbar_data = (rsm_barrier_t *)malloc(sizeof (rsm_barrier_t));
8020Sstevel@tonic-gate 	if (bar->rsmgenbar_data == NULL) {
8030Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8040Sstevel@tonic-gate 		    "not enough memory\n"));
8050Sstevel@tonic-gate 		return (RSMERR_INSUFFICIENT_MEM);
8060Sstevel@tonic-gate 	}
8070Sstevel@tonic-gate 	bar->rsmgenbar_seg = seg;
8080Sstevel@tonic-gate 
8090Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8100Sstevel@tonic-gate 	    "__rsm_memseg_import_init_barrier: exit\n"));
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 	return (RSM_SUCCESS);
8130Sstevel@tonic-gate }
8140Sstevel@tonic-gate 
8150Sstevel@tonic-gate static int
__rsm_memseg_import_open_barrier(rsm_barrier_handle_t barrier)8160Sstevel@tonic-gate __rsm_memseg_import_open_barrier(rsm_barrier_handle_t barrier)
8170Sstevel@tonic-gate {
8180Sstevel@tonic-gate 	rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
8190Sstevel@tonic-gate 	rsmseg_handle_t *seg;
8200Sstevel@tonic-gate 	rsm_ioctlmsg_t msg;
8210Sstevel@tonic-gate 
8220Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8230Sstevel@tonic-gate 	    "__rsm_memseg_import_open_barrier: enter\n"));
8240Sstevel@tonic-gate 
8250Sstevel@tonic-gate 	if (!bar) {
8260Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8270Sstevel@tonic-gate 		    "invalid barrier pointer\n"));
8280Sstevel@tonic-gate 		return (RSMERR_BAD_BARRIER_PTR);
8290Sstevel@tonic-gate 	}
8300Sstevel@tonic-gate 
8310Sstevel@tonic-gate 	if ((seg = bar->rsmgenbar_seg) == 0) {
8320Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8330Sstevel@tonic-gate 		    "uninitialized barrier\n"));
8340Sstevel@tonic-gate 		return (RSMERR_BARRIER_UNINITIALIZED);
8350Sstevel@tonic-gate 	}
8360Sstevel@tonic-gate 
8370Sstevel@tonic-gate /* lint -save -e718 -e746 */
8380Sstevel@tonic-gate 	msg.bar = *(bar->rsmgenbar_data);
8390Sstevel@tonic-gate 	if (ioctl(seg->rsmseg_fd,
8400Sstevel@tonic-gate 	    RSM_IOCTL_BAR_OPEN, &msg) < 0) {
8410Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8420Sstevel@tonic-gate 		    " RSM_IOCTL_BAR_OPEN failed\n"));
8430Sstevel@tonic-gate /* lint -restore */
8440Sstevel@tonic-gate 		return (RSMERR_BARRIER_OPEN_FAILED);
8450Sstevel@tonic-gate 	}
8460Sstevel@tonic-gate 
8470Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8480Sstevel@tonic-gate 	    "__rsm_memseg_import_open_barrier: exit\n"));
8490Sstevel@tonic-gate 
8500Sstevel@tonic-gate 	return (RSM_SUCCESS);
8510Sstevel@tonic-gate }
8520Sstevel@tonic-gate 
8530Sstevel@tonic-gate static int
__rsm_memseg_import_order_barrier(rsm_barrier_handle_t barrier)8540Sstevel@tonic-gate __rsm_memseg_import_order_barrier(rsm_barrier_handle_t barrier)
8550Sstevel@tonic-gate {
8560Sstevel@tonic-gate 	rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
8570Sstevel@tonic-gate 	rsmseg_handle_t *seg;
8580Sstevel@tonic-gate 	rsm_ioctlmsg_t msg;
8590Sstevel@tonic-gate 
8600Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8610Sstevel@tonic-gate 	    "__rsm_memseg_import_order_barrier: enter\n"));
8620Sstevel@tonic-gate 
8630Sstevel@tonic-gate 	if (!bar) {
8640Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8650Sstevel@tonic-gate 		    "invalid barrier\n"));
8660Sstevel@tonic-gate 		return (RSMERR_BAD_BARRIER_PTR);
8670Sstevel@tonic-gate 	}
8680Sstevel@tonic-gate 	if ((seg = bar->rsmgenbar_seg) == 0) {
8690Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8700Sstevel@tonic-gate 		    "uninitialized barrier\n"));
8710Sstevel@tonic-gate 		return (RSMERR_BARRIER_UNINITIALIZED);
8720Sstevel@tonic-gate 	}
8730Sstevel@tonic-gate 
8740Sstevel@tonic-gate 	msg.bar = *(bar->rsmgenbar_data);
8750Sstevel@tonic-gate 	if (ioctl(seg->rsmseg_fd, RSM_IOCTL_BAR_ORDER, &msg) < 0) {
8760Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8770Sstevel@tonic-gate 		    "RSM_IOCTL_BAR_ORDER failed\n"));
8780Sstevel@tonic-gate 		return (RSMERR_BARRIER_FAILURE);
8790Sstevel@tonic-gate 	}
8800Sstevel@tonic-gate 
8810Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8820Sstevel@tonic-gate 	    "__rsm_memseg_import_order_barrier: exit\n"));
8830Sstevel@tonic-gate 
8840Sstevel@tonic-gate 	return (RSM_SUCCESS);
8850Sstevel@tonic-gate }
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate static int
__rsm_memseg_import_close_barrier(rsm_barrier_handle_t barrier)8880Sstevel@tonic-gate __rsm_memseg_import_close_barrier(rsm_barrier_handle_t barrier)
8890Sstevel@tonic-gate {
8900Sstevel@tonic-gate 	rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
8910Sstevel@tonic-gate 	rsmseg_handle_t *seg;
8920Sstevel@tonic-gate 	rsm_ioctlmsg_t msg;
8930Sstevel@tonic-gate 
8940Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
8950Sstevel@tonic-gate 	    "__rsm_memseg_import_close_barrier: enter\n"));
8960Sstevel@tonic-gate 
8970Sstevel@tonic-gate 	if (!bar) {
8980Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
8990Sstevel@tonic-gate 		    "invalid barrier\n"));
9000Sstevel@tonic-gate 		return (RSMERR_BAD_BARRIER_PTR);
9010Sstevel@tonic-gate 	}
9020Sstevel@tonic-gate 	if ((seg = bar->rsmgenbar_seg) == 0) {
9030Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
9040Sstevel@tonic-gate 		    "uninitialized barrier\n"));
9050Sstevel@tonic-gate 		return (RSMERR_BARRIER_UNINITIALIZED);
9060Sstevel@tonic-gate 	}
9070Sstevel@tonic-gate 
9080Sstevel@tonic-gate 	msg.bar = *(bar->rsmgenbar_data);
9090Sstevel@tonic-gate 	if (ioctl(seg->rsmseg_fd, RSM_IOCTL_BAR_CLOSE, &msg) < 0) {
9100Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
9110Sstevel@tonic-gate 		    " RSM_IOCTL_BAR_CLOSE failed\n"));
9120Sstevel@tonic-gate 		return (RSMERR_BARRIER_FAILURE);
9130Sstevel@tonic-gate 	}
9140Sstevel@tonic-gate 
9150Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9160Sstevel@tonic-gate 	    "__rsm_memseg_import_close_barrier: exit\n"));
9170Sstevel@tonic-gate 
9180Sstevel@tonic-gate 	return (RSM_SUCCESS);
9190Sstevel@tonic-gate }
9200Sstevel@tonic-gate 
9210Sstevel@tonic-gate static int
__rsm_memseg_import_destroy_barrier(rsm_barrier_handle_t barrier)9220Sstevel@tonic-gate __rsm_memseg_import_destroy_barrier(rsm_barrier_handle_t barrier)
9230Sstevel@tonic-gate {
9240Sstevel@tonic-gate 	rsmgenbar_handle_t *bar = (rsmgenbar_handle_t *)barrier;
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9270Sstevel@tonic-gate 	    "__rsm_memseg_import_destroy_barrier: enter\n"));
9280Sstevel@tonic-gate 
9290Sstevel@tonic-gate 	if (!bar) {
9300Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
9310Sstevel@tonic-gate 		    "invalid barrier\n"));
9320Sstevel@tonic-gate 		return (RSMERR_BAD_BARRIER_PTR);
9330Sstevel@tonic-gate 	}
9340Sstevel@tonic-gate 
9350Sstevel@tonic-gate 	free((void *) bar->rsmgenbar_data);
9360Sstevel@tonic-gate 
9370Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9380Sstevel@tonic-gate 	    "__rsm_memseg_import_destroy_barrier: exit\n"));
9390Sstevel@tonic-gate 
9400Sstevel@tonic-gate 	return (RSM_SUCCESS);
9410Sstevel@tonic-gate }
9420Sstevel@tonic-gate 
9430Sstevel@tonic-gate /* lint -w1 */
9440Sstevel@tonic-gate static int
__rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t * mode)9450Sstevel@tonic-gate __rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,
9460Sstevel@tonic-gate     rsm_barrier_mode_t *mode)
9470Sstevel@tonic-gate {
9480Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9490Sstevel@tonic-gate 	    "__rsm_memseg_import_get_mode: enter\n"));
9500Sstevel@tonic-gate 
9510Sstevel@tonic-gate 	im_memseg = im_memseg; mode = mode;
9520Sstevel@tonic-gate 
9530Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9540Sstevel@tonic-gate 	    "__rsm_memseg_import_get_mode: exit\n"));
9550Sstevel@tonic-gate 
9560Sstevel@tonic-gate 	return (RSM_SUCCESS);
9570Sstevel@tonic-gate }
9580Sstevel@tonic-gate static int
__rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t mode)9590Sstevel@tonic-gate __rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,
9600Sstevel@tonic-gate 				rsm_barrier_mode_t mode)
9610Sstevel@tonic-gate {
9620Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9630Sstevel@tonic-gate 	    "__rsm_memseg_import_set_mode: enter\n"));
9640Sstevel@tonic-gate 
9650Sstevel@tonic-gate 	im_memseg = im_memseg; mode = mode;
9660Sstevel@tonic-gate 
9670Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9680Sstevel@tonic-gate 	    "__rsm_memseg_import_set_mode: exit\n"));
9690Sstevel@tonic-gate 
9700Sstevel@tonic-gate 	return (RSM_SUCCESS);
9710Sstevel@tonic-gate }
9720Sstevel@tonic-gate 
9730Sstevel@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)9740Sstevel@tonic-gate __rsm_create_memory_handle(rsmapi_controller_handle_t controller,
9750Sstevel@tonic-gate     rsm_localmemory_handle_t *local_hndl_p,
9760Sstevel@tonic-gate     caddr_t local_va, size_t len)
9770Sstevel@tonic-gate {
9780Sstevel@tonic-gate 	rsm_memseg_export_handle_t memseg;
9790Sstevel@tonic-gate 	rsmapi_access_entry_t	acl[1];
9800Sstevel@tonic-gate 	rsm_memseg_id_t segid = 0;
9810Sstevel@tonic-gate 	size_t size;
9820Sstevel@tonic-gate 	int e;
9830Sstevel@tonic-gate 
9840Sstevel@tonic-gate 
9850Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
9860Sstevel@tonic-gate 	    "__rsm_create_memory_handle: enter\n"));
9870Sstevel@tonic-gate 
9880Sstevel@tonic-gate 	/*
9890Sstevel@tonic-gate 	 * create a surrogate segment (local memory will be locked down).
9900Sstevel@tonic-gate 	 */
9910Sstevel@tonic-gate 	size =  roundup(len, PAGESIZE);
9920Sstevel@tonic-gate 	e = rsm_memseg_export_create(controller, &memseg,
9930Sstevel@tonic-gate 	    (void *)local_va, size,
9940Sstevel@tonic-gate 	    RSM_ALLOW_REBIND);
9950Sstevel@tonic-gate 	if (e != RSM_SUCCESS) {
9960Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
9970Sstevel@tonic-gate 		    "export create failed\n"));
9980Sstevel@tonic-gate 		return (e);
9990Sstevel@tonic-gate 	}
10000Sstevel@tonic-gate 
10010Sstevel@tonic-gate 	/*
10020Sstevel@tonic-gate 	 * Publish the segment to the local node only.  If the segment
10030Sstevel@tonic-gate 	 * length is very large then don't publish to the adapter driver
10040Sstevel@tonic-gate 	 * because that will consume too much DVMA space - this is indicated
10050Sstevel@tonic-gate 	 * to the Kernel Agent using null permissions.  DVMA binding will
10060Sstevel@tonic-gate 	 * be done when the RDMA is set up.
10070Sstevel@tonic-gate 	 */
10080Sstevel@tonic-gate 	acl[0].ae_node = rsm_local_nodeid;
10090Sstevel@tonic-gate 	if (len > RSM_MAX_HANDLE_DVMA)
10100Sstevel@tonic-gate 		acl[0].ae_permission = 0;
10110Sstevel@tonic-gate 	else
10120Sstevel@tonic-gate 		acl[0].ae_permission = RSM_PERM_RDWR;
10130Sstevel@tonic-gate 
10140Sstevel@tonic-gate 	e = rsm_memseg_export_publish(memseg, &segid, acl, 1);
10150Sstevel@tonic-gate 	if (e != RSM_SUCCESS) {
10160Sstevel@tonic-gate 		DBPRINTF((RSM_LIBRARY, RSM_ERR,
10170Sstevel@tonic-gate 		    "export publish failed\n"));
10180Sstevel@tonic-gate 		rsm_memseg_export_destroy(memseg);
10190Sstevel@tonic-gate 		return (e);
10200Sstevel@tonic-gate 	}
10210Sstevel@tonic-gate 
10220Sstevel@tonic-gate 	/* Use the surrogate seghandle as the local memory handle */
10230Sstevel@tonic-gate 	*local_hndl_p = (rsm_localmemory_handle_t)memseg;
10240Sstevel@tonic-gate 
10250Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10260Sstevel@tonic-gate 	    "__rsm_create_memory_handle: exit\n"));
10270Sstevel@tonic-gate 
10280Sstevel@tonic-gate 	return (e);
10290Sstevel@tonic-gate }
10300Sstevel@tonic-gate 
10310Sstevel@tonic-gate static int
__rsm_free_memory_handle(rsm_localmemory_handle_t local_handle)10320Sstevel@tonic-gate __rsm_free_memory_handle(rsm_localmemory_handle_t local_handle)
10330Sstevel@tonic-gate {
10340Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10350Sstevel@tonic-gate 	    "__rsm_free_memory_handle: enter\n"));
10360Sstevel@tonic-gate 
10370Sstevel@tonic-gate 	rsm_memseg_export_destroy((rsm_memseg_export_handle_t)local_handle);
10380Sstevel@tonic-gate 
10390Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10400Sstevel@tonic-gate 	    "__rsm_free_memory_handle: exit\n"));
10410Sstevel@tonic-gate 
10420Sstevel@tonic-gate 	return (RSM_SUCCESS);
10430Sstevel@tonic-gate }
10440Sstevel@tonic-gate 
10450Sstevel@tonic-gate static int
__rsm_get_lib_attr(rsm_ndlib_attr_t ** libattrp)10460Sstevel@tonic-gate __rsm_get_lib_attr(rsm_ndlib_attr_t **libattrp)
10470Sstevel@tonic-gate {
10480Sstevel@tonic-gate 
10490Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10500Sstevel@tonic-gate 	    "__rsm_get_lib_attr: enter\n"));
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate 	*libattrp = &_rsm_genlib_attr;
10530Sstevel@tonic-gate 
10540Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10550Sstevel@tonic-gate 	    "__rsm_get_lib_attr: exit\n"));
10560Sstevel@tonic-gate 
10570Sstevel@tonic-gate 	return (RSM_SUCCESS);
10580Sstevel@tonic-gate }
10590Sstevel@tonic-gate 
10600Sstevel@tonic-gate static int
__rsm_closedevice(rsmapi_controller_handle_t cntr_handle)10610Sstevel@tonic-gate __rsm_closedevice(rsmapi_controller_handle_t cntr_handle)
10620Sstevel@tonic-gate {
10630Sstevel@tonic-gate 
10640Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10650Sstevel@tonic-gate 	    "__rsm_closedevice: enter\n"));
10660Sstevel@tonic-gate 
10670Sstevel@tonic-gate 	cntr_handle = cntr_handle;
10680Sstevel@tonic-gate 
10690Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10700Sstevel@tonic-gate 	    "__rsm_closedevice: exit\n"));
10710Sstevel@tonic-gate 
10720Sstevel@tonic-gate 	return (RSM_SUCCESS);
10730Sstevel@tonic-gate }
10740Sstevel@tonic-gate 
10750Sstevel@tonic-gate void
__rsmdefault_setops(rsm_segops_t * segops)10760Sstevel@tonic-gate __rsmdefault_setops(rsm_segops_t *segops)
10770Sstevel@tonic-gate {
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
10800Sstevel@tonic-gate 	    "__rsmdefault_setops: enter\n"));
10810Sstevel@tonic-gate 
10820Sstevel@tonic-gate 	if (segops->rsm_memseg_import_connect == NULL) {
10830Sstevel@tonic-gate 		segops->rsm_memseg_import_connect = __rsm_import_connect;
10840Sstevel@tonic-gate 	}
10850Sstevel@tonic-gate 	if (segops->rsm_memseg_import_disconnect == NULL) {
10860Sstevel@tonic-gate 		segops->rsm_memseg_import_disconnect = __rsm_import_disconnect;
10870Sstevel@tonic-gate 	}
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate 	if (segops->rsm_memseg_import_get8 == NULL) {
10900Sstevel@tonic-gate 		segops->rsm_memseg_import_get8 = __rsm_get8x8;
10910Sstevel@tonic-gate 	}
10920Sstevel@tonic-gate 	if (segops->rsm_memseg_import_get16 == NULL) {
10930Sstevel@tonic-gate 		segops->rsm_memseg_import_get16 = __rsm_get16x16;
10940Sstevel@tonic-gate 	}
10950Sstevel@tonic-gate 	if (segops->rsm_memseg_import_get32 == NULL) {
10960Sstevel@tonic-gate 		segops->rsm_memseg_import_get32 = __rsm_get32x32;
10970Sstevel@tonic-gate 	}
10980Sstevel@tonic-gate 	if (segops->rsm_memseg_import_get64 == NULL) {
10990Sstevel@tonic-gate 		segops->rsm_memseg_import_get64 = __rsm_get64x64;
11000Sstevel@tonic-gate 	}
11010Sstevel@tonic-gate 	if (segops->rsm_memseg_import_get == NULL) {
11020Sstevel@tonic-gate 		segops->rsm_memseg_import_get = __rsm_get;
11030Sstevel@tonic-gate 	}
11040Sstevel@tonic-gate 
11050Sstevel@tonic-gate 	if (segops->rsm_memseg_import_put8 == NULL) {
11060Sstevel@tonic-gate 		segops->rsm_memseg_import_put8 = __rsm_put8x8;
11070Sstevel@tonic-gate 	}
11080Sstevel@tonic-gate 	if (segops->rsm_memseg_import_put16 == NULL) {
11090Sstevel@tonic-gate 		segops->rsm_memseg_import_put16 = __rsm_put16x16;
11100Sstevel@tonic-gate 	}
11110Sstevel@tonic-gate 	if (segops->rsm_memseg_import_put32 == NULL) {
11120Sstevel@tonic-gate 		segops->rsm_memseg_import_put32 = __rsm_put32x32;
11130Sstevel@tonic-gate 	}
11140Sstevel@tonic-gate 	if (segops->rsm_memseg_import_put64 == NULL) {
11150Sstevel@tonic-gate 		segops->rsm_memseg_import_put64 = __rsm_put64x64;
11160Sstevel@tonic-gate 	}
11170Sstevel@tonic-gate 	if (segops->rsm_memseg_import_put == NULL) {
11180Sstevel@tonic-gate 		segops->rsm_memseg_import_put = __rsm_put;
11190Sstevel@tonic-gate 	}
11200Sstevel@tonic-gate 
11210Sstevel@tonic-gate 	if (segops->rsm_memseg_import_putv == NULL) {
11220Sstevel@tonic-gate 		segops->rsm_memseg_import_putv = __rsm_putv;
11230Sstevel@tonic-gate 	}
11240Sstevel@tonic-gate 
11250Sstevel@tonic-gate 	if (segops->rsm_memseg_import_getv == NULL) {
11260Sstevel@tonic-gate 		segops->rsm_memseg_import_getv = __rsm_getv;
11270Sstevel@tonic-gate 	}
11280Sstevel@tonic-gate 
11290Sstevel@tonic-gate 	if (segops->rsm_create_localmemory_handle == NULL) {
11300Sstevel@tonic-gate 		segops->rsm_create_localmemory_handle =
11310Sstevel@tonic-gate 		    __rsm_create_memory_handle;
11320Sstevel@tonic-gate 	}
11330Sstevel@tonic-gate 
11340Sstevel@tonic-gate 	if (segops->rsm_free_localmemory_handle == NULL) {
11350Sstevel@tonic-gate 		segops->rsm_free_localmemory_handle =
11360Sstevel@tonic-gate 		    __rsm_free_memory_handle;
11370Sstevel@tonic-gate 	}
11380Sstevel@tonic-gate 
11390Sstevel@tonic-gate 	/* XXX: Need to support barrier functions */
11400Sstevel@tonic-gate 	if (segops->rsm_memseg_import_init_barrier == NULL) {
11410Sstevel@tonic-gate 		segops->rsm_memseg_import_init_barrier =
11420Sstevel@tonic-gate 		    __rsm_memseg_import_init_barrier;
11430Sstevel@tonic-gate 	}
11440Sstevel@tonic-gate 	if (segops->rsm_memseg_import_open_barrier == NULL) {
11450Sstevel@tonic-gate 		segops->rsm_memseg_import_open_barrier =
11460Sstevel@tonic-gate 		    __rsm_memseg_import_open_barrier;
11470Sstevel@tonic-gate 	}
11480Sstevel@tonic-gate 	if (segops->rsm_memseg_import_order_barrier == NULL) {
11490Sstevel@tonic-gate 		segops->rsm_memseg_import_order_barrier =
11500Sstevel@tonic-gate 		    __rsm_memseg_import_order_barrier;
11510Sstevel@tonic-gate 	}
11520Sstevel@tonic-gate 	if (segops->rsm_memseg_import_close_barrier == NULL) {
11530Sstevel@tonic-gate 		segops->rsm_memseg_import_close_barrier =
11540Sstevel@tonic-gate 		    __rsm_memseg_import_close_barrier;
11550Sstevel@tonic-gate 	}
11560Sstevel@tonic-gate 	if (segops->rsm_memseg_import_destroy_barrier == NULL) {
11570Sstevel@tonic-gate 		segops->rsm_memseg_import_destroy_barrier =
11580Sstevel@tonic-gate 		    __rsm_memseg_import_destroy_barrier;
11590Sstevel@tonic-gate 	}
11600Sstevel@tonic-gate 
11610Sstevel@tonic-gate 	if (segops->rsm_memseg_import_get_mode == NULL) {
11620Sstevel@tonic-gate 		segops->rsm_memseg_import_get_mode =
11630Sstevel@tonic-gate 		    __rsm_memseg_import_get_mode;
11640Sstevel@tonic-gate 	}
11650Sstevel@tonic-gate 	if (segops->rsm_memseg_import_set_mode == NULL) {
11660Sstevel@tonic-gate 		segops->rsm_memseg_import_set_mode =
11670Sstevel@tonic-gate 		    __rsm_memseg_import_set_mode;
11680Sstevel@tonic-gate 	}
11690Sstevel@tonic-gate 
11700Sstevel@tonic-gate 	if (segops->rsm_get_lib_attr == NULL) {
11710Sstevel@tonic-gate 		segops->rsm_get_lib_attr =
11720Sstevel@tonic-gate 		    __rsm_get_lib_attr;
11730Sstevel@tonic-gate 	}
11740Sstevel@tonic-gate 
11750Sstevel@tonic-gate 	if (segops->rsm_closedevice == NULL) {
11760Sstevel@tonic-gate 		segops->rsm_closedevice =
11770Sstevel@tonic-gate 		    __rsm_closedevice;
11780Sstevel@tonic-gate 	}
11790Sstevel@tonic-gate 
11800Sstevel@tonic-gate 
11810Sstevel@tonic-gate 	DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
11820Sstevel@tonic-gate 	    "__rsmdefault_setops: exit\n"));
11830Sstevel@tonic-gate 
11840Sstevel@tonic-gate }
1185