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
51914Scasper * Common Development and Distribution License (the "License").
61914Scasper * 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.
240Sstevel@tonic-gate * 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 <stdarg.h>
330Sstevel@tonic-gate #include <string.h>
340Sstevel@tonic-gate #include <strings.h>
350Sstevel@tonic-gate #include <ctype.h>
360Sstevel@tonic-gate #include <sys/types.h>
370Sstevel@tonic-gate #include <sys/stat.h>
380Sstevel@tonic-gate #include <sys/mman.h>
390Sstevel@tonic-gate #include <sys/uio.h>
400Sstevel@tonic-gate #include <sys/sysmacros.h>
410Sstevel@tonic-gate #include <sys/resource.h>
420Sstevel@tonic-gate #include <errno.h>
430Sstevel@tonic-gate #include <assert.h>
440Sstevel@tonic-gate #include <fcntl.h>
450Sstevel@tonic-gate #include <dlfcn.h>
460Sstevel@tonic-gate #include <sched.h>
470Sstevel@tonic-gate #include <stropts.h>
480Sstevel@tonic-gate #include <poll.h>
490Sstevel@tonic-gate
500Sstevel@tonic-gate #include <rsmapi.h>
510Sstevel@tonic-gate #include <sys/rsm/rsmndi.h>
520Sstevel@tonic-gate #include <rsmlib_in.h>
530Sstevel@tonic-gate #include <sys/rsm/rsm.h>
540Sstevel@tonic-gate
550Sstevel@tonic-gate /* lint -w2 */
560Sstevel@tonic-gate extern void __rsmloopback_init_ops(rsm_segops_t *);
570Sstevel@tonic-gate extern void __rsmdefault_setops(rsm_segops_t *);
580Sstevel@tonic-gate
590Sstevel@tonic-gate typedef void (*rsm_access_func_t)(void *, void *, rsm_access_size_t);
600Sstevel@tonic-gate
610Sstevel@tonic-gate #ifdef DEBUG
620Sstevel@tonic-gate
630Sstevel@tonic-gate #define RSMLOG_BUF_SIZE 256
640Sstevel@tonic-gate FILE *rsmlog_fd = NULL;
650Sstevel@tonic-gate static mutex_t rsmlog_lock;
660Sstevel@tonic-gate int rsmlibdbg_category = RSM_LIBRARY;
670Sstevel@tonic-gate int rsmlibdbg_level = RSM_ERR;
680Sstevel@tonic-gate void dbg_printf(int category, int level, char *fmt, ...);
690Sstevel@tonic-gate
700Sstevel@tonic-gate #endif /* DEBUG */
710Sstevel@tonic-gate
720Sstevel@tonic-gate rsm_node_id_t rsm_local_nodeid = 0;
730Sstevel@tonic-gate
740Sstevel@tonic-gate static rsm_controller_t *controller_list = NULL;
750Sstevel@tonic-gate
760Sstevel@tonic-gate static rsm_segops_t loopback_ops;
770Sstevel@tonic-gate
780Sstevel@tonic-gate #define MAX_STRLEN 80
790Sstevel@tonic-gate
800Sstevel@tonic-gate #define RSM_IOTYPE_PUTGET 1
810Sstevel@tonic-gate #define RSM_IOTYPE_SCATGATH 2
820Sstevel@tonic-gate
830Sstevel@tonic-gate #define RSMFILE_BUFSIZE 256
840Sstevel@tonic-gate
850Sstevel@tonic-gate #pragma init(_rsm_librsm_init)
860Sstevel@tonic-gate
870Sstevel@tonic-gate static mutex_t _rsm_lock;
880Sstevel@tonic-gate
890Sstevel@tonic-gate static int _rsm_fd = -1;
900Sstevel@tonic-gate static rsm_gnum_t *bar_va, bar_fixed = 0;
910Sstevel@tonic-gate static rsm_pollfd_table_t pollfd_table;
920Sstevel@tonic-gate
930Sstevel@tonic-gate static int _rsm_get_hwaddr(rsmapi_controller_handle_t handle,
940Sstevel@tonic-gate rsm_node_id_t, rsm_addr_t *hwaddrp);
950Sstevel@tonic-gate static int _rsm_get_nodeid(rsmapi_controller_handle_t,
960Sstevel@tonic-gate rsm_addr_t, rsm_node_id_t *);
970Sstevel@tonic-gate static int __rsm_import_implicit_map(rsmseg_handle_t *, int);
980Sstevel@tonic-gate static int __rsm_intr_signal_wait_common(struct pollfd [], minor_t [],
990Sstevel@tonic-gate nfds_t, int, int *);
1000Sstevel@tonic-gate
1010Sstevel@tonic-gate static rsm_lib_funcs_t lib_functions = {
1020Sstevel@tonic-gate RSM_LIB_FUNCS_VERSION,
1030Sstevel@tonic-gate _rsm_get_hwaddr,
1040Sstevel@tonic-gate _rsm_get_nodeid
1050Sstevel@tonic-gate };
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate rsm_topology_t *tp;
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate
1100Sstevel@tonic-gate /*
1110Sstevel@tonic-gate * service module function templates:
1120Sstevel@tonic-gate */
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate /*
1150Sstevel@tonic-gate * The _rsm_librsm_init function is called the first time an application
1160Sstevel@tonic-gate * references the RSMAPI library
1170Sstevel@tonic-gate */
1180Sstevel@tonic-gate int
_rsm_librsm_init()1190Sstevel@tonic-gate _rsm_librsm_init()
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate rsm_ioctlmsg_t msg;
1220Sstevel@tonic-gate int e, tmpfd;
1230Sstevel@tonic-gate int i;
1240Sstevel@tonic-gate char logname[MAXNAMELEN];
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate mutex_init(&_rsm_lock, USYNC_THREAD, NULL);
1270Sstevel@tonic-gate
1280Sstevel@tonic-gate #ifdef DEBUG
1290Sstevel@tonic-gate mutex_init(&rsmlog_lock, USYNC_THREAD, NULL);
1300Sstevel@tonic-gate sprintf(logname, "%s.%d", TRACELOG, getpid());
1311914Scasper rsmlog_fd = fopen(logname, "w+F");
1320Sstevel@tonic-gate if (rsmlog_fd == NULL) {
1330Sstevel@tonic-gate fprintf(stderr, "Log file open failed\n");
1340Sstevel@tonic-gate return (errno);
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate #endif /* DEBUG */
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1400Sstevel@tonic-gate "_rsm_librsm_init: enter\n"));
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate /* initialize the pollfd_table */
1430Sstevel@tonic-gate mutex_init(&pollfd_table.lock, USYNC_THREAD, NULL);
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate for (i = 0; i < RSM_MAX_BUCKETS; i++) {
1460Sstevel@tonic-gate pollfd_table.buckets[i] = NULL;
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate /* open /dev/rsm and mmap barrier generation pages */
1500Sstevel@tonic-gate mutex_lock(&_rsm_lock);
1510Sstevel@tonic-gate _rsm_fd = open(DEVRSM, O_RDONLY);
1520Sstevel@tonic-gate if (_rsm_fd < 0) {
1530Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1540Sstevel@tonic-gate "unable to open /dev/rsm\n"));
1550Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
1560Sstevel@tonic-gate return (errno);
1570Sstevel@tonic-gate }
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate * DUP the opened file descriptor to something greater than
1610Sstevel@tonic-gate * STDERR_FILENO so that we never use the STDIN_FILENO,
1620Sstevel@tonic-gate * STDOUT_FILENO or STDERR_FILENO.
1630Sstevel@tonic-gate */
1640Sstevel@tonic-gate tmpfd = fcntl(_rsm_fd, F_DUPFD, 3);
1650Sstevel@tonic-gate if (tmpfd < 0) {
1660Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1670Sstevel@tonic-gate "F_DUPFD failed\n"));
1680Sstevel@tonic-gate } else {
1690Sstevel@tonic-gate (void) close(_rsm_fd);
1700Sstevel@tonic-gate _rsm_fd = tmpfd;
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1740Sstevel@tonic-gate "_rsm_fd is %d\n", _rsm_fd));
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate if (fcntl(_rsm_fd, F_SETFD, FD_CLOEXEC) < 0) {
177*6812Sraf DBPRINTF((RSM_LIBRARY, RSM_ERR,
1780Sstevel@tonic-gate "F_SETFD failed\n"));
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate /* get mapping generation number page info */
1820Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_BAR_INFO, &msg) < 0) {
1830Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1840Sstevel@tonic-gate "RSM_IOCTL_BAR_INFO failed\n"));
1850Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
1860Sstevel@tonic-gate return (errno);
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate /*
1900Sstevel@tonic-gate * bar_va is mapped to the mapping generation number page
1910Sstevel@tonic-gate * in order to support close barrier
1920Sstevel@tonic-gate */
1930Sstevel@tonic-gate /* LINTED */
1940Sstevel@tonic-gate bar_va = (rsm_gnum_t *)mmap(NULL, msg.len,
1950Sstevel@tonic-gate PROT_READ, MAP_SHARED, _rsm_fd, msg.off);
1960Sstevel@tonic-gate if (bar_va == (rsm_gnum_t *)MAP_FAILED) {
1970Sstevel@tonic-gate bar_va = NULL;
1980Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
1990Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
2000Sstevel@tonic-gate "unable to map barrier page\n"));
2010Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
2020Sstevel@tonic-gate }
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate /* get local nodeid */
2070Sstevel@tonic-gate e = rsm_get_interconnect_topology(&tp);
2080Sstevel@tonic-gate if (e != RSM_SUCCESS) {
2090Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
2100Sstevel@tonic-gate "unable to obtain topology data\n"));
2110Sstevel@tonic-gate return (e);
2120Sstevel@tonic-gate } else
213*6812Sraf rsm_local_nodeid = tp->topology_hdr.local_nodeid;
2140Sstevel@tonic-gate
2150Sstevel@tonic-gate rsm_free_interconnect_topology(tp);
2160Sstevel@tonic-gate
2170Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2180Sstevel@tonic-gate "_rsm_librsm_init: exit\n"));
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate return (RSM_SUCCESS);
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate static int
_rsm_loopbackload(caddr_t name,int unit,rsm_controller_t ** chdl)2240Sstevel@tonic-gate _rsm_loopbackload(caddr_t name, int unit, rsm_controller_t **chdl)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate rsm_controller_t *p;
2270Sstevel@tonic-gate rsm_ioctlmsg_t msg;
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_DEBUG_VERBOSE,
2300Sstevel@tonic-gate "_rsm_loopbackload: enter\n"));
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate * For now do this, but we should open some file and read the
2330Sstevel@tonic-gate * list of supported controllers and there numbers.
2340Sstevel@tonic-gate */
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate p = (rsm_controller_t *)malloc(sizeof (*p) + strlen(name) + 1);
2370Sstevel@tonic-gate if (!p) {
2380Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_ERR,
2390Sstevel@tonic-gate "not enough memory\n"));
2400Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
2410Sstevel@tonic-gate }
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate msg.cname = name;
2440Sstevel@tonic-gate msg.cname_len = strlen(name) +1;
2450Sstevel@tonic-gate msg.cnum = unit;
2460Sstevel@tonic-gate msg.arg = (caddr_t)&p->cntr_attr;
2470Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_ATTR, &msg) < 0) {
2480Sstevel@tonic-gate int error = errno;
2490Sstevel@tonic-gate free((void *)p);
2500Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_ERR,
2510Sstevel@tonic-gate "RSM_IOCTL_ATTR failed\n"));
2520Sstevel@tonic-gate return (error);
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate __rsmloopback_init_ops(&loopback_ops);
2560Sstevel@tonic-gate __rsmdefault_setops(&loopback_ops);
2570Sstevel@tonic-gate p->cntr_segops = &loopback_ops;
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate /*
2600Sstevel@tonic-gate * Should add this entry into list
2610Sstevel@tonic-gate */
2620Sstevel@tonic-gate p->cntr_fd = _rsm_fd;
2630Sstevel@tonic-gate p->cntr_name = strcpy((char *)(p+1), name);
2640Sstevel@tonic-gate p->cntr_unit = unit;
2650Sstevel@tonic-gate p->cntr_refcnt = 1;
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate mutex_init(&p->cntr_lock, USYNC_THREAD, NULL);
2690Sstevel@tonic-gate cond_init(&p->cntr_cv, USYNC_THREAD, NULL);
2700Sstevel@tonic-gate p->cntr_rqlist = NULL;
2710Sstevel@tonic-gate p->cntr_segops->rsm_get_lib_attr(&p->cntr_lib_attr);
2720Sstevel@tonic-gate p->cntr_next = controller_list;
2730Sstevel@tonic-gate controller_list = p;
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate *chdl = p;
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_DEBUG_VERBOSE,
2780Sstevel@tonic-gate "_rsm_loopbackload: exit\n"));
2790Sstevel@tonic-gate return (RSM_SUCCESS);
2800Sstevel@tonic-gate
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate static int
_rsm_modload(caddr_t name,int unit,rsmapi_controller_handle_t * controller)2840Sstevel@tonic-gate _rsm_modload(caddr_t name, int unit, rsmapi_controller_handle_t *controller)
2850Sstevel@tonic-gate {
2860Sstevel@tonic-gate int error = RSM_SUCCESS;
2870Sstevel@tonic-gate char clib[MAX_STRLEN];
2880Sstevel@tonic-gate rsm_controller_t *p = NULL;
2890Sstevel@tonic-gate void *dlh;
2900Sstevel@tonic-gate rsm_attach_entry_t fptr;
2910Sstevel@tonic-gate rsm_ioctlmsg_t msg;
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2940Sstevel@tonic-gate "_rsm_modload: enter\n"));
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate (void) sprintf(clib, "%s.so", name);
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate /* found entry, try to load library */
2990Sstevel@tonic-gate dlh = dlopen(clib, RTLD_LAZY);
3000Sstevel@tonic-gate if (dlh == NULL) {
3010Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3020Sstevel@tonic-gate "unable to find plugin library\n"));
3030Sstevel@tonic-gate error = RSMERR_CTLR_NOT_PRESENT;
3040Sstevel@tonic-gate goto skiplib;
3050Sstevel@tonic-gate }
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate (void) sprintf(clib, "%s_opendevice", name);
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate fptr = (rsm_attach_entry_t)dlsym(dlh, clib); /* lint !e611 */
3100Sstevel@tonic-gate if (fptr != NULL) {
3110Sstevel@tonic-gate /* allocate new lib structure */
3120Sstevel@tonic-gate /* get ops handler, attr and ops */
3130Sstevel@tonic-gate p = (rsm_controller_t *)malloc(sizeof (*p) + strlen(name) + 1);
3140Sstevel@tonic-gate if (p != NULL) {
3150Sstevel@tonic-gate error = fptr(unit, &p->cntr_segops);
3160Sstevel@tonic-gate } else {
3170Sstevel@tonic-gate error = RSMERR_INSUFFICIENT_MEM;
3180Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3190Sstevel@tonic-gate "not enough memory\n"));
3200Sstevel@tonic-gate }
3210Sstevel@tonic-gate } else {
3220Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3230Sstevel@tonic-gate "can't find symbol %s\n", clib));
3240Sstevel@tonic-gate error = RSMERR_CTLR_NOT_PRESENT;
3250Sstevel@tonic-gate (void) dlclose(dlh);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate
3280Sstevel@tonic-gate skiplib:
3290Sstevel@tonic-gate if ((error != RSM_SUCCESS) || (p == NULL)) {
3300Sstevel@tonic-gate if (p != NULL)
3310Sstevel@tonic-gate free((void *)p);
3320Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3330Sstevel@tonic-gate "_rsm_modload error %d\n", error));
3340Sstevel@tonic-gate return (error);
3350Sstevel@tonic-gate }
3360Sstevel@tonic-gate
3370Sstevel@tonic-gate /* check the version number */
3380Sstevel@tonic-gate if (p->cntr_segops->rsm_version != RSM_LIB_VERSION) {
3390Sstevel@tonic-gate /* bad version number */
3400Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3410Sstevel@tonic-gate "wrong version; "
3420Sstevel@tonic-gate "found %d, expected %d\n",
3430Sstevel@tonic-gate p->cntr_segops->rsm_version, RSM_LIB_VERSION));
3440Sstevel@tonic-gate free(p);
3450Sstevel@tonic-gate return (RSMERR_BAD_LIBRARY_VERSION);
3460Sstevel@tonic-gate } else {
3470Sstevel@tonic-gate /* pass the fuctions to NDI library */
3480Sstevel@tonic-gate if ((p->cntr_segops->rsm_register_lib_funcs == NULL) ||
3490Sstevel@tonic-gate (p->cntr_segops->rsm_register_lib_funcs(
3500Sstevel@tonic-gate &lib_functions) != RSM_SUCCESS)) {
3510Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3520Sstevel@tonic-gate "RSMNDI library not registering lib functions\n"));
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate
3550Sstevel@tonic-gate /* get controller attributes */
3560Sstevel@tonic-gate msg.cnum = unit;
3570Sstevel@tonic-gate msg.cname = name;
3580Sstevel@tonic-gate msg.cname_len = strlen(name) +1;
3590Sstevel@tonic-gate msg.arg = (caddr_t)&p->cntr_attr;
3600Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_ATTR, &msg) < 0) {
3610Sstevel@tonic-gate error = errno;
3620Sstevel@tonic-gate free((void *)p);
3630Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3640Sstevel@tonic-gate "RSM_IOCTL_ATTR failed\n"));
3650Sstevel@tonic-gate return (error);
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate /* set controller access functions */
3690Sstevel@tonic-gate __rsmdefault_setops(p->cntr_segops);
3700Sstevel@tonic-gate
3710Sstevel@tonic-gate mutex_init(&p->cntr_lock, USYNC_THREAD, NULL);
3720Sstevel@tonic-gate cond_init(&p->cntr_cv, USYNC_THREAD, NULL);
3730Sstevel@tonic-gate p->cntr_rqlist = NULL;
3740Sstevel@tonic-gate p->cntr_segops->rsm_get_lib_attr(&p->cntr_lib_attr);
3750Sstevel@tonic-gate /* insert into list of controllers */
3760Sstevel@tonic-gate p->cntr_name = strcpy((char *)(p+1), name);
3770Sstevel@tonic-gate p->cntr_fd = _rsm_fd;
3780Sstevel@tonic-gate p->cntr_unit = unit;
3790Sstevel@tonic-gate p->cntr_refcnt = 1; /* first reference */
3800Sstevel@tonic-gate p->cntr_next = controller_list;
3810Sstevel@tonic-gate controller_list = p;
3820Sstevel@tonic-gate *controller = (rsmapi_controller_handle_t)p;
3830Sstevel@tonic-gate errno = RSM_SUCCESS;
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3870Sstevel@tonic-gate "_rsm_modload: exit\n"));
3880Sstevel@tonic-gate return (error);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate
3910Sstevel@tonic-gate /*
3920Sstevel@tonic-gate * inserts a given segment handle into the pollfd table, this is called
3930Sstevel@tonic-gate * when rsm_memseg_get_pollfd() is called the first time on a segment handle.
3940Sstevel@tonic-gate * Returns RSM_SUCCESS if successful otherwise the error code is returned
3950Sstevel@tonic-gate */
3960Sstevel@tonic-gate static int
_rsm_insert_pollfd_table(int segfd,minor_t segrnum)3970Sstevel@tonic-gate _rsm_insert_pollfd_table(int segfd, minor_t segrnum)
3980Sstevel@tonic-gate {
3990Sstevel@tonic-gate int i;
4000Sstevel@tonic-gate int hash;
4010Sstevel@tonic-gate rsm_pollfd_chunk_t *chunk;
4020Sstevel@tonic-gate
4030Sstevel@tonic-gate hash = RSM_POLLFD_HASH(segfd);
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate mutex_lock(&pollfd_table.lock);
4060Sstevel@tonic-gate
4070Sstevel@tonic-gate chunk = pollfd_table.buckets[hash];
4080Sstevel@tonic-gate while (chunk) {
4090Sstevel@tonic-gate if (chunk->nfree > 0)
4100Sstevel@tonic-gate break;
4110Sstevel@tonic-gate chunk = chunk->next;
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate if (!chunk) { /* couldn't find a free chunk - allocate a new one */
4150Sstevel@tonic-gate chunk = malloc(sizeof (rsm_pollfd_chunk_t));
4160Sstevel@tonic-gate if (!chunk) {
4170Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4180Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
4190Sstevel@tonic-gate }
4200Sstevel@tonic-gate chunk->nfree = RSM_POLLFD_PER_CHUNK - 1;
4210Sstevel@tonic-gate chunk->fdarray[0].fd = segfd;
4220Sstevel@tonic-gate chunk->fdarray[0].segrnum = segrnum;
4230Sstevel@tonic-gate for (i = 1; i < RSM_POLLFD_PER_CHUNK; i++) {
4240Sstevel@tonic-gate chunk->fdarray[i].fd = -1;
4250Sstevel@tonic-gate chunk->fdarray[i].segrnum = 0;
4260Sstevel@tonic-gate }
4270Sstevel@tonic-gate /* insert this into the hash table */
4280Sstevel@tonic-gate chunk->next = pollfd_table.buckets[hash];
4290Sstevel@tonic-gate pollfd_table.buckets[hash] = chunk;
4300Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4310Sstevel@tonic-gate "rsm_insert_pollfd: new chunk(%p) @ %d for %d:%d\n",
4320Sstevel@tonic-gate chunk, hash, segfd, segrnum));
4330Sstevel@tonic-gate } else { /* a chunk with free slot was found */
4340Sstevel@tonic-gate for (i = 0; i < RSM_POLLFD_PER_CHUNK; i++) {
4350Sstevel@tonic-gate if (chunk->fdarray[i].fd == -1) {
4360Sstevel@tonic-gate chunk->fdarray[i].fd = segfd;
4370Sstevel@tonic-gate chunk->fdarray[i].segrnum = segrnum;
4380Sstevel@tonic-gate chunk->nfree--;
4390Sstevel@tonic-gate break;
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate }
4420Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4430Sstevel@tonic-gate "rsm_insert_pollfd: inserted @ %d for %d:%d chunk(%p)\n",
4440Sstevel@tonic-gate hash, segfd, segrnum, chunk));
4450Sstevel@tonic-gate assert(i < RSM_POLLFD_PER_CHUNK);
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4490Sstevel@tonic-gate return (RSM_SUCCESS);
4500Sstevel@tonic-gate }
4510Sstevel@tonic-gate
4520Sstevel@tonic-gate /*
4530Sstevel@tonic-gate * Given a file descriptor returns the corresponding segment handles
4540Sstevel@tonic-gate * resource number, if the fd is not found returns 0. 0 is not a valid
4550Sstevel@tonic-gate * minor number for a rsmapi segment since it is used for the barrier
4560Sstevel@tonic-gate * resource.
4570Sstevel@tonic-gate */
4580Sstevel@tonic-gate static minor_t
_rsm_lookup_pollfd_table(int segfd)4590Sstevel@tonic-gate _rsm_lookup_pollfd_table(int segfd)
4600Sstevel@tonic-gate {
4610Sstevel@tonic-gate int i;
4620Sstevel@tonic-gate rsm_pollfd_chunk_t *chunk;
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate if (segfd < 0)
4650Sstevel@tonic-gate return (0);
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate mutex_lock(&pollfd_table.lock);
4680Sstevel@tonic-gate
4690Sstevel@tonic-gate chunk = pollfd_table.buckets[RSM_POLLFD_HASH(segfd)];
4700Sstevel@tonic-gate while (chunk) {
4710Sstevel@tonic-gate assert(chunk->nfree < RSM_POLLFD_PER_CHUNK);
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate for (i = 0; i < RSM_POLLFD_PER_CHUNK; i++) {
4740Sstevel@tonic-gate if (chunk->fdarray[i].fd == segfd) {
4750Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4760Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4770Sstevel@tonic-gate "rsm_lookup_pollfd: found(%d) rnum(%d)\n",
4780Sstevel@tonic-gate segfd, chunk->fdarray[i].segrnum));
4790Sstevel@tonic-gate return (chunk->fdarray[i].segrnum);
4800Sstevel@tonic-gate }
4810Sstevel@tonic-gate }
4820Sstevel@tonic-gate chunk = chunk->next;
4830Sstevel@tonic-gate }
4840Sstevel@tonic-gate
4850Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4860Sstevel@tonic-gate
4870Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4880Sstevel@tonic-gate "rsm_lookup_pollfd: not found(%d)\n", segfd));
4890Sstevel@tonic-gate
4900Sstevel@tonic-gate return (0);
4910Sstevel@tonic-gate }
4920Sstevel@tonic-gate
4930Sstevel@tonic-gate /*
4940Sstevel@tonic-gate * Remove the entry corresponding to the given file descriptor from the
4950Sstevel@tonic-gate * pollfd table.
4960Sstevel@tonic-gate */
4970Sstevel@tonic-gate static void
_rsm_remove_pollfd_table(int segfd)4980Sstevel@tonic-gate _rsm_remove_pollfd_table(int segfd)
4990Sstevel@tonic-gate {
5000Sstevel@tonic-gate int i;
5010Sstevel@tonic-gate int hash;
5020Sstevel@tonic-gate rsm_pollfd_chunk_t *chunk;
5030Sstevel@tonic-gate rsm_pollfd_chunk_t *prev_chunk;
5040Sstevel@tonic-gate
5050Sstevel@tonic-gate if (segfd < 0)
5060Sstevel@tonic-gate return;
5070Sstevel@tonic-gate
5080Sstevel@tonic-gate hash = RSM_POLLFD_HASH(segfd);
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate mutex_lock(&pollfd_table.lock);
5110Sstevel@tonic-gate
5120Sstevel@tonic-gate prev_chunk = chunk = pollfd_table.buckets[hash];
5130Sstevel@tonic-gate while (chunk) {
5140Sstevel@tonic-gate assert(chunk->nfree < RSM_POLLFD_PER_CHUNK);
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate for (i = 0; i < RSM_POLLFD_PER_CHUNK; i++) {
5170Sstevel@tonic-gate if (chunk->fdarray[i].fd == segfd) {
5180Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5190Sstevel@tonic-gate "rsm_remove_pollfd: %d:%d\n",
5200Sstevel@tonic-gate chunk->fdarray[i].fd,
5210Sstevel@tonic-gate chunk->fdarray[i].segrnum));
5220Sstevel@tonic-gate chunk->fdarray[i].fd = -1;
5230Sstevel@tonic-gate chunk->fdarray[i].segrnum = 0;
5240Sstevel@tonic-gate chunk->nfree++;
5250Sstevel@tonic-gate if (chunk->nfree == RSM_POLLFD_PER_CHUNK) {
5260Sstevel@tonic-gate /* chunk is empty free it */
5270Sstevel@tonic-gate if (prev_chunk == chunk) {
5280Sstevel@tonic-gate pollfd_table.buckets[hash] =
5290Sstevel@tonic-gate chunk->next;
5300Sstevel@tonic-gate } else {
5310Sstevel@tonic-gate prev_chunk->next = chunk->next;
5320Sstevel@tonic-gate }
5330Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY,
5340Sstevel@tonic-gate RSM_DEBUG_VERBOSE,
5350Sstevel@tonic-gate "rsm_remove_pollfd:free(%p)\n",
5360Sstevel@tonic-gate chunk));
5370Sstevel@tonic-gate free(chunk);
5380Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
5390Sstevel@tonic-gate return;
5400Sstevel@tonic-gate }
5410Sstevel@tonic-gate }
5420Sstevel@tonic-gate }
5430Sstevel@tonic-gate prev_chunk = chunk;
5440Sstevel@tonic-gate chunk = chunk->next;
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate
5470Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
5480Sstevel@tonic-gate }
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate int
rsm_get_controller(char * name,rsmapi_controller_handle_t * chdl)551*6812Sraf rsm_get_controller(char *name, rsmapi_controller_handle_t *chdl)
5520Sstevel@tonic-gate {
5530Sstevel@tonic-gate rsm_controller_t *p;
5540Sstevel@tonic-gate char cntr_name[MAXNAMELEN]; /* cntr_name=<cntr_type><unit> */
5550Sstevel@tonic-gate char *cntr_type;
5560Sstevel@tonic-gate int unit = 0;
5570Sstevel@tonic-gate int i, e;
5580Sstevel@tonic-gate
5590Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5600Sstevel@tonic-gate "rsm_get_controller: enter\n"));
5610Sstevel@tonic-gate /*
5620Sstevel@tonic-gate * Lookup controller name and return ops vector and controller
5630Sstevel@tonic-gate * structure
5640Sstevel@tonic-gate */
5650Sstevel@tonic-gate
5660Sstevel@tonic-gate if (!chdl) {
5670Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
5680Sstevel@tonic-gate "Invalid controller handle\n"));
5690Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
5700Sstevel@tonic-gate }
5710Sstevel@tonic-gate if (!name) {
5720Sstevel@tonic-gate /* use loopback if null */
5730Sstevel@tonic-gate cntr_type = LOOPBACK;
5740Sstevel@tonic-gate } else {
5750Sstevel@tonic-gate (void) strcpy(cntr_name, name);
5760Sstevel@tonic-gate /* scan from the end till a non-digit is found */
5770Sstevel@tonic-gate for (i = strlen(cntr_name) - 1; i >= 0; i--) {
5780Sstevel@tonic-gate if (! isdigit((int)cntr_name[i]))
5790Sstevel@tonic-gate break;
5800Sstevel@tonic-gate }
5810Sstevel@tonic-gate i++;
5820Sstevel@tonic-gate unit = atoi((char *)cntr_name+i);
5830Sstevel@tonic-gate cntr_name[i] = '\0'; /* null terminate the cntr_type part */
5840Sstevel@tonic-gate cntr_type = (char *)cntr_name;
5850Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5860Sstevel@tonic-gate "cntr_type=%s, instance=%d\n",
5870Sstevel@tonic-gate cntr_type, unit));
5880Sstevel@tonic-gate }
5890Sstevel@tonic-gate
5900Sstevel@tonic-gate /* protect the controller_list by locking the device/library */
5910Sstevel@tonic-gate mutex_lock(&_rsm_lock);
5920Sstevel@tonic-gate
5930Sstevel@tonic-gate for (p = controller_list; p; p = p->cntr_next) {
5940Sstevel@tonic-gate if (!strcasecmp(p->cntr_name, cntr_type) &&
5950Sstevel@tonic-gate !strcasecmp(cntr_type, LOOPBACK)) {
5960Sstevel@tonic-gate p->cntr_refcnt++;
5970Sstevel@tonic-gate *chdl = (rsmapi_controller_handle_t)p;
5980Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
5990Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6000Sstevel@tonic-gate "rsm_get_controller: exit\n"));
6010Sstevel@tonic-gate return (RSM_SUCCESS);
6020Sstevel@tonic-gate } else if (!strcasecmp(p->cntr_name, cntr_type) &&
6030Sstevel@tonic-gate (p->cntr_unit == unit)) {
6040Sstevel@tonic-gate p->cntr_refcnt++;
6050Sstevel@tonic-gate *chdl = (rsmapi_controller_handle_t)p;
6060Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6070Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6080Sstevel@tonic-gate "rsm_get_controller: exit\n"));
6090Sstevel@tonic-gate return (RSM_SUCCESS);
6100Sstevel@tonic-gate }
6110Sstevel@tonic-gate }
6120Sstevel@tonic-gate
6130Sstevel@tonic-gate
6140Sstevel@tonic-gate if (!strcasecmp(cntr_type, LOOPBACK)) {
6150Sstevel@tonic-gate e = _rsm_loopbackload(cntr_type, unit,
6160Sstevel@tonic-gate (rsm_controller_t **)chdl);
6170Sstevel@tonic-gate } else {
6180Sstevel@tonic-gate e = _rsm_modload(cntr_type, unit, chdl);
6190Sstevel@tonic-gate }
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6240Sstevel@tonic-gate " rsm_get_controller: exit\n"));
6250Sstevel@tonic-gate return (e);
6260Sstevel@tonic-gate }
6270Sstevel@tonic-gate
6280Sstevel@tonic-gate int
rsm_release_controller(rsmapi_controller_handle_t cntr_handle)629*6812Sraf rsm_release_controller(rsmapi_controller_handle_t cntr_handle)
6300Sstevel@tonic-gate {
6310Sstevel@tonic-gate int e = RSM_SUCCESS;
6320Sstevel@tonic-gate rsm_controller_t *chdl = (rsm_controller_t *)cntr_handle;
6330Sstevel@tonic-gate rsm_controller_t *curr, *prev;
6340Sstevel@tonic-gate
6350Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6360Sstevel@tonic-gate "rsm_release_controller: enter\n"));
6370Sstevel@tonic-gate
6380Sstevel@tonic-gate mutex_lock(&_rsm_lock);
6390Sstevel@tonic-gate
6400Sstevel@tonic-gate if (chdl->cntr_refcnt == 0) {
6410Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6420Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6430Sstevel@tonic-gate "controller reference count is zero\n"));
6440Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate
6470Sstevel@tonic-gate chdl->cntr_refcnt--;
6480Sstevel@tonic-gate
6490Sstevel@tonic-gate if (chdl->cntr_refcnt > 0) {
6500Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6510Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6520Sstevel@tonic-gate "rsm_release_controller: exit\n"));
6530Sstevel@tonic-gate return (RSM_SUCCESS);
6540Sstevel@tonic-gate }
6550Sstevel@tonic-gate
6560Sstevel@tonic-gate e = chdl->cntr_segops->rsm_closedevice(cntr_handle);
6570Sstevel@tonic-gate
6580Sstevel@tonic-gate /*
6590Sstevel@tonic-gate * remove the controller in any case from the controller list
6600Sstevel@tonic-gate */
6610Sstevel@tonic-gate
6620Sstevel@tonic-gate prev = curr = controller_list;
6630Sstevel@tonic-gate while (curr != NULL) {
6640Sstevel@tonic-gate if (curr == chdl) {
6650Sstevel@tonic-gate if (curr == prev) {
6660Sstevel@tonic-gate controller_list = curr->cntr_next;
6670Sstevel@tonic-gate } else {
6680Sstevel@tonic-gate prev->cntr_next = curr->cntr_next;
6690Sstevel@tonic-gate }
6700Sstevel@tonic-gate free(curr);
6710Sstevel@tonic-gate break;
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate prev = curr;
6740Sstevel@tonic-gate curr = curr->cntr_next;
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6770Sstevel@tonic-gate
6780Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6790Sstevel@tonic-gate "rsm_release_controller: exit\n"));
6800Sstevel@tonic-gate
6810Sstevel@tonic-gate return (e);
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate
684*6812Sraf int
rsm_get_controller_attr(rsmapi_controller_handle_t chandle,rsmapi_controller_attr_t * attr)685*6812Sraf rsm_get_controller_attr(rsmapi_controller_handle_t chandle,
6860Sstevel@tonic-gate rsmapi_controller_attr_t *attr)
6870Sstevel@tonic-gate {
6880Sstevel@tonic-gate rsm_controller_t *p;
6890Sstevel@tonic-gate
6900Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6910Sstevel@tonic-gate "rsm_get_controller_attr: enter\n"));
6920Sstevel@tonic-gate
6930Sstevel@tonic-gate if (!chandle) {
6940Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6950Sstevel@tonic-gate "invalid controller handle\n"));
6960Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate
6990Sstevel@tonic-gate if (!attr) {
7000Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7010Sstevel@tonic-gate "invalid attribute pointer\n"));
7020Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
7030Sstevel@tonic-gate }
7040Sstevel@tonic-gate
7050Sstevel@tonic-gate p = (rsm_controller_t *)chandle;
7060Sstevel@tonic-gate
7070Sstevel@tonic-gate mutex_lock(&_rsm_lock);
7080Sstevel@tonic-gate if (p->cntr_refcnt == 0) {
7090Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
7100Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7110Sstevel@tonic-gate "cntr refcnt is 0\n"));
7120Sstevel@tonic-gate return (RSMERR_CTLR_NOT_PRESENT);
7130Sstevel@tonic-gate }
7140Sstevel@tonic-gate
7150Sstevel@tonic-gate /* copy only the user part of the attr structure */
7160Sstevel@tonic-gate attr->attr_direct_access_sizes =
7170Sstevel@tonic-gate p->cntr_attr.attr_direct_access_sizes;
7180Sstevel@tonic-gate attr->attr_atomic_sizes =
7190Sstevel@tonic-gate p->cntr_attr.attr_atomic_sizes;
7200Sstevel@tonic-gate attr->attr_page_size =
7210Sstevel@tonic-gate p->cntr_attr.attr_page_size;
7220Sstevel@tonic-gate attr->attr_max_export_segment_size =
7230Sstevel@tonic-gate p->cntr_attr.attr_max_export_segment_size;
7240Sstevel@tonic-gate attr->attr_tot_export_segment_size =
7250Sstevel@tonic-gate p->cntr_attr.attr_tot_export_segment_size;
7260Sstevel@tonic-gate attr->attr_max_export_segments =
7270Sstevel@tonic-gate p->cntr_attr.attr_max_export_segments;
7280Sstevel@tonic-gate attr->attr_max_import_map_size =
7290Sstevel@tonic-gate p->cntr_attr.attr_max_import_map_size;
7300Sstevel@tonic-gate attr->attr_tot_import_map_size =
7310Sstevel@tonic-gate p->cntr_attr.attr_tot_import_map_size;
7320Sstevel@tonic-gate attr->attr_max_import_segments =
7330Sstevel@tonic-gate p->cntr_attr.attr_max_import_segments;
7340Sstevel@tonic-gate
7350Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
7360Sstevel@tonic-gate
7370Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7380Sstevel@tonic-gate "rsm_get_controller_attr: exit\n"));
7390Sstevel@tonic-gate
7400Sstevel@tonic-gate return (RSM_SUCCESS);
7410Sstevel@tonic-gate }
7420Sstevel@tonic-gate
7430Sstevel@tonic-gate
7440Sstevel@tonic-gate
7450Sstevel@tonic-gate /*
7460Sstevel@tonic-gate * Create a segment handle for the virtual address range specified
7470Sstevel@tonic-gate * by vaddr and size
7480Sstevel@tonic-gate */
7490Sstevel@tonic-gate int
rsm_memseg_export_create(rsmapi_controller_handle_t controller,rsm_memseg_export_handle_t * memseg,void * vaddr,size_t length,uint_t flags)750*6812Sraf rsm_memseg_export_create(rsmapi_controller_handle_t controller,
7510Sstevel@tonic-gate rsm_memseg_export_handle_t *memseg,
7520Sstevel@tonic-gate void *vaddr,
7530Sstevel@tonic-gate size_t length,
7540Sstevel@tonic-gate uint_t flags)
7550Sstevel@tonic-gate {
7560Sstevel@tonic-gate
7570Sstevel@tonic-gate rsm_controller_t *chdl = (rsm_controller_t *)controller;
7580Sstevel@tonic-gate rsmseg_handle_t *p;
7590Sstevel@tonic-gate rsm_ioctlmsg_t msg;
7600Sstevel@tonic-gate int e;
7610Sstevel@tonic-gate #ifndef _LP64
7620Sstevel@tonic-gate int tmpfd;
7630Sstevel@tonic-gate #endif
7640Sstevel@tonic-gate
7650Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
7660Sstevel@tonic-gate "rsm_memseg_export_create: enter\n"));
7670Sstevel@tonic-gate
7680Sstevel@tonic-gate if (!controller) {
7690Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7700Sstevel@tonic-gate "invalid controller handle\n"));
7710Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
7720Sstevel@tonic-gate }
7730Sstevel@tonic-gate if (!memseg) {
7740Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7750Sstevel@tonic-gate "invalid segment handle\n"));
7760Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
7770Sstevel@tonic-gate }
7780Sstevel@tonic-gate
7790Sstevel@tonic-gate *memseg = 0;
7800Sstevel@tonic-gate
7810Sstevel@tonic-gate /*
7820Sstevel@tonic-gate * Check vaddr and size alignment, both must be mmu page size
7830Sstevel@tonic-gate * aligned
7840Sstevel@tonic-gate */
7850Sstevel@tonic-gate if (!vaddr) {
7860Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7870Sstevel@tonic-gate "invalid arguments\n"));
7880Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
7890Sstevel@tonic-gate }
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate if (!length) {
7920Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7930Sstevel@tonic-gate "invalid arguments\n"));
7940Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
7950Sstevel@tonic-gate }
7960Sstevel@tonic-gate
7970Sstevel@tonic-gate if (((size_t)vaddr & (PAGESIZE - 1)) ||
798*6812Sraf (length & (PAGESIZE - 1))) {
7990Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8000Sstevel@tonic-gate "invalid mem alignment for vaddr or length\n"));
8010Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
8020Sstevel@tonic-gate }
8030Sstevel@tonic-gate
8040Sstevel@tonic-gate /*
8050Sstevel@tonic-gate * The following check does not apply for loopback controller
8060Sstevel@tonic-gate * since for the loopback adapter, the attr_max_export_segment_size
8070Sstevel@tonic-gate * is always 0.
8080Sstevel@tonic-gate */
8090Sstevel@tonic-gate if (strcasecmp(chdl->cntr_name, LOOPBACK)) {
8100Sstevel@tonic-gate if (length > chdl->cntr_attr.attr_max_export_segment_size) {
8110Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8120Sstevel@tonic-gate "length exceeds controller limits\n"));
8130Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8140Sstevel@tonic-gate "controller limits %d\n",
8150Sstevel@tonic-gate chdl->cntr_attr.attr_max_export_segment_size));
8160Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
8170Sstevel@tonic-gate }
8180Sstevel@tonic-gate }
8190Sstevel@tonic-gate
8200Sstevel@tonic-gate p = (rsmseg_handle_t *)malloc(sizeof (*p));
8210Sstevel@tonic-gate if (p == NULL) {
8220Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8230Sstevel@tonic-gate "not enough memory\n"));
8240Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
8250Sstevel@tonic-gate }
8260Sstevel@tonic-gate
8270Sstevel@tonic-gate p->rsmseg_fd = open(DEVRSM, O_RDWR);
8280Sstevel@tonic-gate if (p->rsmseg_fd < 0) {
8290Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8300Sstevel@tonic-gate "unable to open device /dev/rsm\n"));
8310Sstevel@tonic-gate free((void *)p);
8320Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
8330Sstevel@tonic-gate }
8340Sstevel@tonic-gate
8350Sstevel@tonic-gate #ifndef _LP64
8360Sstevel@tonic-gate /*
8370Sstevel@tonic-gate * libc can't handle fd's greater than 255, in order to
8380Sstevel@tonic-gate * insure that these values remain available make /dev/rsm
8390Sstevel@tonic-gate * fd > 255. Note: not needed for LP64
8400Sstevel@tonic-gate */
8410Sstevel@tonic-gate tmpfd = fcntl(p->rsmseg_fd, F_DUPFD, 256);
8420Sstevel@tonic-gate e = errno;
8430Sstevel@tonic-gate if (tmpfd < 0) {
8440Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8450Sstevel@tonic-gate "F_DUPFD failed\n"));
8460Sstevel@tonic-gate } else {
8470Sstevel@tonic-gate (void) close(p->rsmseg_fd);
8480Sstevel@tonic-gate p->rsmseg_fd = tmpfd;
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate #endif /* _LP64 */
8510Sstevel@tonic-gate
8520Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE, ""
8530Sstevel@tonic-gate "rsmseg_fd is %d\n", p->rsmseg_fd));
8540Sstevel@tonic-gate
8550Sstevel@tonic-gate if (fcntl(p->rsmseg_fd, F_SETFD, FD_CLOEXEC) < 0) {
8560Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8570Sstevel@tonic-gate "F_SETFD failed\n"));
8580Sstevel@tonic-gate }
8590Sstevel@tonic-gate
8600Sstevel@tonic-gate p->rsmseg_state = EXPORT_CREATE;
8610Sstevel@tonic-gate p->rsmseg_size = length;
8620Sstevel@tonic-gate /* increment controller handle */
8630Sstevel@tonic-gate p->rsmseg_controller = chdl;
8640Sstevel@tonic-gate
8650Sstevel@tonic-gate /* try to bind user address range */
8660Sstevel@tonic-gate msg.cnum = chdl->cntr_unit;
8670Sstevel@tonic-gate msg.cname = chdl->cntr_name;
8680Sstevel@tonic-gate msg.cname_len = strlen(chdl->cntr_name) +1;
8690Sstevel@tonic-gate msg.vaddr = vaddr;
8700Sstevel@tonic-gate msg.len = length;
8710Sstevel@tonic-gate msg.perm = flags;
8720Sstevel@tonic-gate msg.off = 0;
8730Sstevel@tonic-gate e = RSM_IOCTL_BIND;
8740Sstevel@tonic-gate
8750Sstevel@tonic-gate /* Try to bind */
8760Sstevel@tonic-gate if (ioctl(p->rsmseg_fd, e, &msg) < 0) {
8770Sstevel@tonic-gate e = errno;
8780Sstevel@tonic-gate (void) close(p->rsmseg_fd);
8790Sstevel@tonic-gate free((void *)p);
8800Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8810Sstevel@tonic-gate "RSM_IOCTL_BIND failed\n"));
8820Sstevel@tonic-gate return (e);
8830Sstevel@tonic-gate }
8840Sstevel@tonic-gate /* OK */
8850Sstevel@tonic-gate p->rsmseg_type = RSM_EXPORT_SEG;
8860Sstevel@tonic-gate p->rsmseg_vaddr = vaddr;
8870Sstevel@tonic-gate p->rsmseg_size = length;
8880Sstevel@tonic-gate p->rsmseg_state = EXPORT_BIND;
8890Sstevel@tonic-gate p->rsmseg_pollfd_refcnt = 0;
8900Sstevel@tonic-gate p->rsmseg_rnum = msg.rnum;
8910Sstevel@tonic-gate
8920Sstevel@tonic-gate mutex_init(&p->rsmseg_lock, USYNC_THREAD, NULL);
8930Sstevel@tonic-gate
8940Sstevel@tonic-gate *memseg = (rsm_memseg_export_handle_t)p;
8950Sstevel@tonic-gate
8960Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
8970Sstevel@tonic-gate "rsm_memseg_export_create: exit\n"));
8980Sstevel@tonic-gate
8990Sstevel@tonic-gate return (RSM_SUCCESS);
9000Sstevel@tonic-gate }
9010Sstevel@tonic-gate
9020Sstevel@tonic-gate int
rsm_memseg_export_destroy(rsm_memseg_export_handle_t memseg)903*6812Sraf rsm_memseg_export_destroy(rsm_memseg_export_handle_t memseg)
9040Sstevel@tonic-gate {
9050Sstevel@tonic-gate rsmseg_handle_t *seg;
9060Sstevel@tonic-gate
9070Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9080Sstevel@tonic-gate "rsm_memseg_export_destroy: enter\n"));
9090Sstevel@tonic-gate
9100Sstevel@tonic-gate if (!memseg) {
9110Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9120Sstevel@tonic-gate "invalid segment handle\n"));
9130Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
9140Sstevel@tonic-gate }
9150Sstevel@tonic-gate
9160Sstevel@tonic-gate seg = (rsmseg_handle_t *)memseg;
9170Sstevel@tonic-gate
9180Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
9190Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt) {
9200Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9210Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9220Sstevel@tonic-gate "segment reference count not zero\n"));
9230Sstevel@tonic-gate return (RSMERR_POLLFD_IN_USE);
9240Sstevel@tonic-gate }
9250Sstevel@tonic-gate else
9260Sstevel@tonic-gate seg->rsmseg_state = EXPORT_BIND;
9270Sstevel@tonic-gate
9280Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9290Sstevel@tonic-gate
9300Sstevel@tonic-gate (void) close(seg->rsmseg_fd);
9310Sstevel@tonic-gate mutex_destroy(&seg->rsmseg_lock);
9320Sstevel@tonic-gate free((void *)seg);
9330Sstevel@tonic-gate
9340Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9350Sstevel@tonic-gate "rsm_memseg_export_destroy: exit\n"));
9360Sstevel@tonic-gate
9370Sstevel@tonic-gate return (RSM_SUCCESS);
9380Sstevel@tonic-gate }
9390Sstevel@tonic-gate
9400Sstevel@tonic-gate int
rsm_memseg_export_rebind(rsm_memseg_export_handle_t memseg,void * vaddr,offset_t off,size_t length)941*6812Sraf rsm_memseg_export_rebind(rsm_memseg_export_handle_t memseg, void *vaddr,
9420Sstevel@tonic-gate offset_t off, size_t length)
9430Sstevel@tonic-gate {
9440Sstevel@tonic-gate rsm_ioctlmsg_t msg;
9450Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
9460Sstevel@tonic-gate
9470Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9480Sstevel@tonic-gate "rsm_memseg_export_rebind: enter\n"));
9490Sstevel@tonic-gate
9500Sstevel@tonic-gate off = off;
9510Sstevel@tonic-gate
9520Sstevel@tonic-gate if (!seg) {
9530Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9540Sstevel@tonic-gate "invalid segment handle\n"));
9550Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
9560Sstevel@tonic-gate }
9570Sstevel@tonic-gate if (!vaddr) {
9580Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9590Sstevel@tonic-gate "invalid vaddr\n"));
9600Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
9610Sstevel@tonic-gate }
9620Sstevel@tonic-gate
9630Sstevel@tonic-gate /*
9640Sstevel@tonic-gate * Same as bind except it's ok to have elimint in list.
9650Sstevel@tonic-gate * Call into driver to remove any existing mappings.
9660Sstevel@tonic-gate */
9670Sstevel@tonic-gate msg.vaddr = vaddr;
9680Sstevel@tonic-gate msg.len = length;
9690Sstevel@tonic-gate msg.off = 0;
9700Sstevel@tonic-gate
9710Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
9720Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_REBIND, &msg) < 0) {
9730Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9740Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9750Sstevel@tonic-gate "RSM_IOCTL_REBIND failed\n"));
9760Sstevel@tonic-gate return (errno);
9770Sstevel@tonic-gate }
9780Sstevel@tonic-gate
9790Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9800Sstevel@tonic-gate
9810Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9820Sstevel@tonic-gate "rsm_memseg_export_rebind: exit\n"));
9830Sstevel@tonic-gate
9840Sstevel@tonic-gate return (RSM_SUCCESS);
9850Sstevel@tonic-gate }
9860Sstevel@tonic-gate
9870Sstevel@tonic-gate int
rsm_memseg_export_publish(rsm_memseg_export_handle_t memseg,rsm_memseg_id_t * seg_id,rsmapi_access_entry_t access_list[],uint_t access_list_length)988*6812Sraf rsm_memseg_export_publish(rsm_memseg_export_handle_t memseg,
9890Sstevel@tonic-gate rsm_memseg_id_t *seg_id,
9900Sstevel@tonic-gate rsmapi_access_entry_t access_list[],
9910Sstevel@tonic-gate uint_t access_list_length)
9920Sstevel@tonic-gate
9930Sstevel@tonic-gate {
9940Sstevel@tonic-gate rsm_ioctlmsg_t msg;
9950Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
9960Sstevel@tonic-gate
9970Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9980Sstevel@tonic-gate "rsm_memseg_export_publish: enter\n"));
9990Sstevel@tonic-gate
10000Sstevel@tonic-gate if (seg_id == NULL) {
10010Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10020Sstevel@tonic-gate "invalid segment id\n"));
10030Sstevel@tonic-gate return (RSMERR_BAD_SEGID);
10040Sstevel@tonic-gate }
10050Sstevel@tonic-gate
10060Sstevel@tonic-gate if (!seg) {
10070Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10080Sstevel@tonic-gate "invalid segment handle\n"));
10090Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
10100Sstevel@tonic-gate }
10110Sstevel@tonic-gate
10120Sstevel@tonic-gate if (access_list_length > 0 && !access_list) {
10130Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10140Sstevel@tonic-gate "invalid access control list\n"));
10150Sstevel@tonic-gate return (RSMERR_BAD_ACL);
10160Sstevel@tonic-gate }
10170Sstevel@tonic-gate
10180Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
10190Sstevel@tonic-gate if (seg->rsmseg_state != EXPORT_BIND) {
10200Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10210Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10220Sstevel@tonic-gate "invalid segment state\n"));
10230Sstevel@tonic-gate return (RSMERR_SEG_ALREADY_PUBLISHED);
10240Sstevel@tonic-gate }
10250Sstevel@tonic-gate
10260Sstevel@tonic-gate /*
10270Sstevel@tonic-gate * seg id < RSM_DLPI_END and in the RSM_USER_APP_ID range
10280Sstevel@tonic-gate * are reserved for internal use.
10290Sstevel@tonic-gate */
10300Sstevel@tonic-gate if ((*seg_id > 0) &&
10310Sstevel@tonic-gate ((*seg_id <= RSM_DLPI_ID_END) ||
10320Sstevel@tonic-gate BETWEEN (*seg_id, RSM_USER_APP_ID_BASE, RSM_USER_APP_ID_END))) {
10330Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10340Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10350Sstevel@tonic-gate "invalid segment id\n"));
10360Sstevel@tonic-gate return (RSMERR_RESERVED_SEGID);
10370Sstevel@tonic-gate }
10380Sstevel@tonic-gate
10390Sstevel@tonic-gate msg.key = *seg_id;
10400Sstevel@tonic-gate msg.acl = access_list;
10410Sstevel@tonic-gate msg.acl_len = access_list_length;
10420Sstevel@tonic-gate
10430Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_PUBLISH, &msg) < 0) {
10440Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10450Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10460Sstevel@tonic-gate "RSM_IOCTL_PUBLISH failed\n"));
10470Sstevel@tonic-gate return (errno);
10480Sstevel@tonic-gate }
10490Sstevel@tonic-gate
10500Sstevel@tonic-gate seg->rsmseg_keyid = msg.key;
10510Sstevel@tonic-gate seg->rsmseg_state = EXPORT_PUBLISH;
10520Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10530Sstevel@tonic-gate
10540Sstevel@tonic-gate if (*seg_id == 0)
10550Sstevel@tonic-gate *seg_id = msg.key;
10560Sstevel@tonic-gate
10570Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
10580Sstevel@tonic-gate "rsm_memseg_export_publish: exit\n"));
10590Sstevel@tonic-gate
10600Sstevel@tonic-gate return (RSM_SUCCESS);
10610Sstevel@tonic-gate
10620Sstevel@tonic-gate }
10630Sstevel@tonic-gate
10640Sstevel@tonic-gate int
rsm_memseg_export_unpublish(rsm_memseg_export_handle_t memseg)1065*6812Sraf rsm_memseg_export_unpublish(rsm_memseg_export_handle_t memseg)
10660Sstevel@tonic-gate {
10670Sstevel@tonic-gate rsm_ioctlmsg_t msg;
10680Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
10690Sstevel@tonic-gate
10700Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
10710Sstevel@tonic-gate "rsm_memseg_export_unpublish: enter\n"));
10720Sstevel@tonic-gate
10730Sstevel@tonic-gate if (!seg) {
10740Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10750Sstevel@tonic-gate "invalid arguments\n"));
10760Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
10770Sstevel@tonic-gate }
10780Sstevel@tonic-gate
10790Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
10800Sstevel@tonic-gate if (seg->rsmseg_state != EXPORT_PUBLISH) {
10810Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10820Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10830Sstevel@tonic-gate "segment not published %d\n",
1084*6812Sraf seg->rsmseg_keyid));
10850Sstevel@tonic-gate return (RSMERR_SEG_NOT_PUBLISHED);
10860Sstevel@tonic-gate }
10870Sstevel@tonic-gate
10880Sstevel@tonic-gate msg.key = seg->rsmseg_keyid;
10890Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_UNPUBLISH, &msg) < 0) {
10900Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10910Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10920Sstevel@tonic-gate "RSM_IOCTL_UNPUBLISH failed\n"));
10930Sstevel@tonic-gate return (errno);
10940Sstevel@tonic-gate }
10950Sstevel@tonic-gate
10960Sstevel@tonic-gate seg->rsmseg_state = EXPORT_BIND;
10970Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10980Sstevel@tonic-gate
10990Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
11000Sstevel@tonic-gate "rsm_memseg_export_unpublish: exit\n"));
11010Sstevel@tonic-gate
11020Sstevel@tonic-gate return (RSM_SUCCESS);
11030Sstevel@tonic-gate }
11040Sstevel@tonic-gate
11050Sstevel@tonic-gate
11060Sstevel@tonic-gate int
rsm_memseg_export_republish(rsm_memseg_export_handle_t memseg,rsmapi_access_entry_t access_list[],uint_t access_list_length)1107*6812Sraf rsm_memseg_export_republish(rsm_memseg_export_handle_t memseg,
11080Sstevel@tonic-gate rsmapi_access_entry_t access_list[],
11090Sstevel@tonic-gate uint_t access_list_length)
11100Sstevel@tonic-gate {
11110Sstevel@tonic-gate rsm_ioctlmsg_t msg;
11120Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
11130Sstevel@tonic-gate
11140Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
11150Sstevel@tonic-gate "rsm_memseg_export_republish: enter\n"));
11160Sstevel@tonic-gate
11170Sstevel@tonic-gate if (!seg) {
11180Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11190Sstevel@tonic-gate "invalid segment or segment state\n"));
11200Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
11210Sstevel@tonic-gate }
11220Sstevel@tonic-gate
11230Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
11240Sstevel@tonic-gate if (seg->rsmseg_state != EXPORT_PUBLISH) {
11250Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11260Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11270Sstevel@tonic-gate "segment not published\n"));
11280Sstevel@tonic-gate return (RSMERR_SEG_NOT_PUBLISHED);
11290Sstevel@tonic-gate }
11300Sstevel@tonic-gate
11310Sstevel@tonic-gate if (access_list_length > 0 && !access_list) {
11320Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11330Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11340Sstevel@tonic-gate "invalid access control list\n"));
11350Sstevel@tonic-gate return (RSMERR_BAD_ACL);
11360Sstevel@tonic-gate }
11370Sstevel@tonic-gate
11380Sstevel@tonic-gate msg.key = seg->rsmseg_keyid;
11390Sstevel@tonic-gate msg.acl = access_list;
11400Sstevel@tonic-gate msg.acl_len = access_list_length;
11410Sstevel@tonic-gate
11420Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_REPUBLISH, &msg) < 0) {
11430Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11440Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11450Sstevel@tonic-gate "RSM_IOCTL_REPUBLISH failed\n"));
11460Sstevel@tonic-gate return (errno);
11470Sstevel@tonic-gate }
11480Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11490Sstevel@tonic-gate
11500Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
11510Sstevel@tonic-gate "rsm_memseg_export_republish: exit\n"));
11520Sstevel@tonic-gate
11530Sstevel@tonic-gate return (RSM_SUCCESS);
11540Sstevel@tonic-gate }
11550Sstevel@tonic-gate
11560Sstevel@tonic-gate
11570Sstevel@tonic-gate /*
11580Sstevel@tonic-gate * import side memory segment operations:
11590Sstevel@tonic-gate */
11600Sstevel@tonic-gate int
rsm_memseg_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)1161*6812Sraf rsm_memseg_import_connect(rsmapi_controller_handle_t controller,
11620Sstevel@tonic-gate rsm_node_id_t node_id,
11630Sstevel@tonic-gate rsm_memseg_id_t segment_id,
11640Sstevel@tonic-gate rsm_permission_t perm,
11650Sstevel@tonic-gate rsm_memseg_import_handle_t *im_memseg)
11660Sstevel@tonic-gate {
11670Sstevel@tonic-gate rsm_ioctlmsg_t msg;
11680Sstevel@tonic-gate rsmseg_handle_t *p;
11690Sstevel@tonic-gate rsm_controller_t *cntr = (rsm_controller_t *)controller;
11700Sstevel@tonic-gate #ifndef _LP64 /* added for fd > 255 fix */
11710Sstevel@tonic-gate int tmpfd;
11720Sstevel@tonic-gate #endif
11730Sstevel@tonic-gate int e;
11740Sstevel@tonic-gate
11750Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
11760Sstevel@tonic-gate "rsm_memseg_import_connect: enter\n"));
11770Sstevel@tonic-gate
11780Sstevel@tonic-gate if (!cntr) {
11790Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
11800Sstevel@tonic-gate "invalid controller handle\n"));
11810Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
11820Sstevel@tonic-gate }
11830Sstevel@tonic-gate
11840Sstevel@tonic-gate *im_memseg = 0;
11850Sstevel@tonic-gate
11860Sstevel@tonic-gate p = (rsmseg_handle_t *)malloc(sizeof (*p));
11870Sstevel@tonic-gate if (!p) {
11880Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
11890Sstevel@tonic-gate "not enough memory\n"));
11900Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
11910Sstevel@tonic-gate }
11920Sstevel@tonic-gate
11930Sstevel@tonic-gate if (perm & ~RSM_PERM_RDWR) {
11940Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
11950Sstevel@tonic-gate "invalid permissions\n"));
11960Sstevel@tonic-gate return (RSMERR_PERM_DENIED);
11970Sstevel@tonic-gate }
11980Sstevel@tonic-gate
11990Sstevel@tonic-gate /*
12000Sstevel@tonic-gate * Get size, va from driver
12010Sstevel@tonic-gate */
12020Sstevel@tonic-gate msg.cnum = cntr->cntr_unit;
12030Sstevel@tonic-gate msg.cname = cntr->cntr_name;
12040Sstevel@tonic-gate msg.cname_len = strlen(cntr->cntr_name) +1;
12050Sstevel@tonic-gate msg.nodeid = node_id;
12060Sstevel@tonic-gate msg.key = segment_id;
12070Sstevel@tonic-gate msg.perm = perm;
12080Sstevel@tonic-gate
12090Sstevel@tonic-gate p->rsmseg_fd = open(DEVRSM, O_RDWR);
12100Sstevel@tonic-gate if (p->rsmseg_fd < 0) {
1211*6812Sraf DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
1212*6812Sraf "unable to open /dev/rsm"));
12130Sstevel@tonic-gate free((void *)p);
12140Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
12150Sstevel@tonic-gate }
12160Sstevel@tonic-gate
12170Sstevel@tonic-gate #ifndef _LP64
12180Sstevel@tonic-gate /*
12190Sstevel@tonic-gate * libc can't handle fd's greater than 255, in order to
12200Sstevel@tonic-gate * insure that these values remain available make /dev/rsm
12210Sstevel@tonic-gate * fd > 255. Note: not needed for LP64
12220Sstevel@tonic-gate */
12230Sstevel@tonic-gate tmpfd = fcntl(p->rsmseg_fd, F_DUPFD, 256); /* make fd > 255 */
12240Sstevel@tonic-gate e = errno;
12250Sstevel@tonic-gate if (tmpfd < 0) {
12260Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12270Sstevel@tonic-gate "F_DUPFD failed\n"));
12280Sstevel@tonic-gate } else {
12290Sstevel@tonic-gate (void) close(p->rsmseg_fd);
12300Sstevel@tonic-gate p->rsmseg_fd = tmpfd;
12310Sstevel@tonic-gate }
12320Sstevel@tonic-gate #endif /* _LP64 */
12330Sstevel@tonic-gate
12340Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
12350Sstevel@tonic-gate "rsmseg_fd is %d\n", p->rsmseg_fd));
12360Sstevel@tonic-gate
12370Sstevel@tonic-gate if (fcntl(p->rsmseg_fd, F_SETFD, FD_CLOEXEC) < 0) {
12380Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12390Sstevel@tonic-gate "F_SETFD failed\n"));
12400Sstevel@tonic-gate }
12410Sstevel@tonic-gate if (ioctl(p->rsmseg_fd, RSM_IOCTL_CONNECT, &msg) < 0) {
12420Sstevel@tonic-gate e = errno;
12430Sstevel@tonic-gate (void) close(p->rsmseg_fd);
12440Sstevel@tonic-gate free((void *)p);
12450Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12460Sstevel@tonic-gate "RSM_IOCTL_CONNECT failed\n"));
12470Sstevel@tonic-gate return (e);
12480Sstevel@tonic-gate }
12490Sstevel@tonic-gate
12500Sstevel@tonic-gate /*
12510Sstevel@tonic-gate * We connected ok.
12520Sstevel@tonic-gate */
12530Sstevel@tonic-gate p->rsmseg_type = RSM_IMPORT_SEG;
12540Sstevel@tonic-gate p->rsmseg_state = IMPORT_CONNECT;
12550Sstevel@tonic-gate p->rsmseg_keyid = segment_id;
12560Sstevel@tonic-gate p->rsmseg_nodeid = node_id;
12570Sstevel@tonic-gate p->rsmseg_size = msg.len;
12580Sstevel@tonic-gate p->rsmseg_perm = perm;
12590Sstevel@tonic-gate p->rsmseg_controller = cntr;
12600Sstevel@tonic-gate p->rsmseg_barrier = NULL;
12610Sstevel@tonic-gate p->rsmseg_barmode = RSM_BARRIER_MODE_IMPLICIT;
12620Sstevel@tonic-gate p->rsmseg_bar = (bar_va ? bar_va + msg.off : &bar_fixed);
12630Sstevel@tonic-gate p->rsmseg_gnum = msg.gnum;
12640Sstevel@tonic-gate p->rsmseg_pollfd_refcnt = 0;
12650Sstevel@tonic-gate p->rsmseg_maplen = 0; /* initialized, set in import_map */
12660Sstevel@tonic-gate p->rsmseg_mapoffset = 0;
12670Sstevel@tonic-gate p->rsmseg_flags = 0;
12680Sstevel@tonic-gate p->rsmseg_rnum = msg.rnum;
12690Sstevel@tonic-gate mutex_init(&p->rsmseg_lock, USYNC_THREAD, NULL);
12700Sstevel@tonic-gate
12710Sstevel@tonic-gate p->rsmseg_ops = cntr->cntr_segops;
12720Sstevel@tonic-gate
12730Sstevel@tonic-gate /*
12740Sstevel@tonic-gate * XXX: Based on permission and controller direct_access attribute
12750Sstevel@tonic-gate * we fix the segment ops vector
12760Sstevel@tonic-gate */
12770Sstevel@tonic-gate
12780Sstevel@tonic-gate p->rsmseg_vaddr = 0; /* defer mapping till using maps or trys to rw */
12790Sstevel@tonic-gate
12800Sstevel@tonic-gate *im_memseg = (rsm_memseg_import_handle_t)p;
12810Sstevel@tonic-gate
12820Sstevel@tonic-gate e = p->rsmseg_ops->rsm_memseg_import_connect(controller,
12830Sstevel@tonic-gate node_id, segment_id, perm, im_memseg);
12840Sstevel@tonic-gate
12850Sstevel@tonic-gate if (e != RSM_SUCCESS) {
12860Sstevel@tonic-gate (void) close(p->rsmseg_fd);
12870Sstevel@tonic-gate mutex_destroy(&p->rsmseg_lock);
12880Sstevel@tonic-gate free((void *)p);
12890Sstevel@tonic-gate }
12900Sstevel@tonic-gate
12910Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
12920Sstevel@tonic-gate "rsm_memseg_import_connect: exit\n"));
12930Sstevel@tonic-gate
12940Sstevel@tonic-gate return (e);
12950Sstevel@tonic-gate }
12960Sstevel@tonic-gate
12970Sstevel@tonic-gate
12980Sstevel@tonic-gate int
rsm_memseg_import_disconnect(rsm_memseg_import_handle_t im_memseg)1299*6812Sraf rsm_memseg_import_disconnect(rsm_memseg_import_handle_t im_memseg)
13000Sstevel@tonic-gate {
13010Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
13020Sstevel@tonic-gate int e;
13030Sstevel@tonic-gate
13040Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
13050Sstevel@tonic-gate "rsm_memseg_import_disconnect: enter\n"));
13060Sstevel@tonic-gate
13070Sstevel@tonic-gate if (!seg) {
13080Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13090Sstevel@tonic-gate "invalid segment handle\n"));
13100Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
13110Sstevel@tonic-gate }
13120Sstevel@tonic-gate
13130Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_CONNECT) {
13140Sstevel@tonic-gate if (seg->rsmseg_flags & RSM_IMPLICIT_MAP) {
13150Sstevel@tonic-gate e = rsm_memseg_import_unmap(im_memseg);
13160Sstevel@tonic-gate if (e != RSM_SUCCESS) {
13170Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13180Sstevel@tonic-gate "unmap failure\n"));
13190Sstevel@tonic-gate return (e);
13200Sstevel@tonic-gate }
13210Sstevel@tonic-gate } else {
13220Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13230Sstevel@tonic-gate "segment busy\n"));
13240Sstevel@tonic-gate return (RSMERR_SEG_STILL_MAPPED);
13250Sstevel@tonic-gate }
13260Sstevel@tonic-gate }
13270Sstevel@tonic-gate
13280Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
13290Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt) {
13300Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
13310Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
13320Sstevel@tonic-gate "segment reference count not zero\n"));
13330Sstevel@tonic-gate return (RSMERR_POLLFD_IN_USE);
13340Sstevel@tonic-gate }
13350Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
13360Sstevel@tonic-gate
13370Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_disconnect(im_memseg);
13380Sstevel@tonic-gate
13390Sstevel@tonic-gate if (e == RSM_SUCCESS) {
13400Sstevel@tonic-gate (void) close(seg->rsmseg_fd);
13410Sstevel@tonic-gate mutex_destroy(&seg->rsmseg_lock);
13420Sstevel@tonic-gate free((void *)seg);
13430Sstevel@tonic-gate }
13440Sstevel@tonic-gate
13450Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
13460Sstevel@tonic-gate "rsm_memseg_import_disconnect: exit\n"));
13470Sstevel@tonic-gate
13480Sstevel@tonic-gate return (e);
13490Sstevel@tonic-gate }
13500Sstevel@tonic-gate
13510Sstevel@tonic-gate /*
13520Sstevel@tonic-gate * import side memory segment operations (read access functions):
13530Sstevel@tonic-gate */
13540Sstevel@tonic-gate
13550Sstevel@tonic-gate static int
__rsm_import_verify_access(rsmseg_handle_t * seg,off_t offset,caddr_t datap,size_t len,rsm_permission_t perm,rsm_access_size_t das)13560Sstevel@tonic-gate __rsm_import_verify_access(rsmseg_handle_t *seg,
13570Sstevel@tonic-gate off_t offset,
13580Sstevel@tonic-gate caddr_t datap,
13590Sstevel@tonic-gate size_t len,
13600Sstevel@tonic-gate rsm_permission_t perm,
13610Sstevel@tonic-gate rsm_access_size_t das)
13620Sstevel@tonic-gate {
13630Sstevel@tonic-gate int error;
13640Sstevel@tonic-gate
13650Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
13660Sstevel@tonic-gate " __rsm_import_verify_access: enter\n"));
13670Sstevel@tonic-gate
13680Sstevel@tonic-gate if (!seg) {
13690Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13700Sstevel@tonic-gate "invalid segment handle\n"));
13710Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
13720Sstevel@tonic-gate }
13730Sstevel@tonic-gate if (!datap) {
13740Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13750Sstevel@tonic-gate "invalid data pointer\n"));
13760Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
13770Sstevel@tonic-gate }
13780Sstevel@tonic-gate
13790Sstevel@tonic-gate /*
13800Sstevel@tonic-gate * Check alignment of pointer
13810Sstevel@tonic-gate */
13820Sstevel@tonic-gate if ((uintptr_t)datap & (das - 1)) {
13830Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13840Sstevel@tonic-gate "invalid alignment of data pointer\n"));
13850Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
13860Sstevel@tonic-gate }
13870Sstevel@tonic-gate
13880Sstevel@tonic-gate if (offset & (das - 1)) {
13890Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13900Sstevel@tonic-gate "invalid offset\n"));
13910Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
13920Sstevel@tonic-gate }
13930Sstevel@tonic-gate
13940Sstevel@tonic-gate /* make sure that the import seg is connected */
13950Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_CONNECT &&
13960Sstevel@tonic-gate seg->rsmseg_state != IMPORT_MAP) {
13970Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13980Sstevel@tonic-gate "incorrect segment state\n"));
13990Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
14000Sstevel@tonic-gate }
14010Sstevel@tonic-gate
14020Sstevel@tonic-gate /* do an implicit map if required */
14030Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_CONNECT) {
14040Sstevel@tonic-gate error = __rsm_import_implicit_map(seg, RSM_IOTYPE_PUTGET);
14050Sstevel@tonic-gate if (error != RSM_SUCCESS) {
14060Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14070Sstevel@tonic-gate "implicit map failure\n"));
14080Sstevel@tonic-gate return (error);
14090Sstevel@tonic-gate }
14100Sstevel@tonic-gate }
14110Sstevel@tonic-gate
14120Sstevel@tonic-gate if ((seg->rsmseg_perm & perm) != perm) {
14130Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14140Sstevel@tonic-gate "invalid permissions\n"));
14150Sstevel@tonic-gate return (RSMERR_PERM_DENIED);
14160Sstevel@tonic-gate }
14170Sstevel@tonic-gate
14180Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_MAP) {
14190Sstevel@tonic-gate if ((offset < seg->rsmseg_mapoffset) ||
14200Sstevel@tonic-gate (offset + len > seg->rsmseg_mapoffset +
14210Sstevel@tonic-gate seg->rsmseg_maplen)) {
14220Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14230Sstevel@tonic-gate "incorrect offset+length\n"));
14240Sstevel@tonic-gate return (RSMERR_BAD_OFFSET);
14250Sstevel@tonic-gate }
14260Sstevel@tonic-gate } else { /* IMPORT_CONNECT */
14270Sstevel@tonic-gate if ((len + offset) > seg->rsmseg_size) {
14280Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14290Sstevel@tonic-gate "incorrect offset+length\n"));
14300Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
14310Sstevel@tonic-gate }
14320Sstevel@tonic-gate }
14330Sstevel@tonic-gate
14340Sstevel@tonic-gate if ((seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) &&
14350Sstevel@tonic-gate (seg->rsmseg_barrier == NULL)) {
14360Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14370Sstevel@tonic-gate "invalid barrier\n"));
14380Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
14390Sstevel@tonic-gate }
14400Sstevel@tonic-gate
14410Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
14420Sstevel@tonic-gate " __rsm_import_verify_access: exit\n"));
14430Sstevel@tonic-gate
14440Sstevel@tonic-gate return (RSM_SUCCESS);
14450Sstevel@tonic-gate }
14460Sstevel@tonic-gate
14470Sstevel@tonic-gate static int
__rsm_import_implicit_map(rsmseg_handle_t * seg,int iotype)14480Sstevel@tonic-gate __rsm_import_implicit_map(rsmseg_handle_t *seg, int iotype)
14490Sstevel@tonic-gate {
14500Sstevel@tonic-gate caddr_t va;
14510Sstevel@tonic-gate int flag = MAP_SHARED;
14520Sstevel@tonic-gate int prot = PROT_READ|PROT_WRITE;
14530Sstevel@tonic-gate int mapping_reqd = 0;
14540Sstevel@tonic-gate
14550Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
14560Sstevel@tonic-gate " __rsm_import_implicit_map: enter\n"));
14570Sstevel@tonic-gate
14580Sstevel@tonic-gate if (iotype == RSM_IOTYPE_PUTGET)
14590Sstevel@tonic-gate mapping_reqd = seg->rsmseg_controller->cntr_lib_attr->
14600Sstevel@tonic-gate rsm_putget_map_reqd;
14610Sstevel@tonic-gate else if (iotype == RSM_IOTYPE_SCATGATH)
14620Sstevel@tonic-gate mapping_reqd = seg->rsmseg_controller->cntr_lib_attr->
14630Sstevel@tonic-gate rsm_scatgath_map_reqd;
14640Sstevel@tonic-gate
14650Sstevel@tonic-gate
14660Sstevel@tonic-gate if (mapping_reqd) {
14670Sstevel@tonic-gate va = mmap(NULL, seg->rsmseg_size, prot,
14680Sstevel@tonic-gate flag, seg->rsmseg_fd, 0);
14690Sstevel@tonic-gate
14700Sstevel@tonic-gate if (va == MAP_FAILED) {
14710Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14720Sstevel@tonic-gate "implicit map failed\n"));
14730Sstevel@tonic-gate if (errno == ENOMEM || errno == ENXIO ||
14740Sstevel@tonic-gate errno == EOVERFLOW)
14750Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
14760Sstevel@tonic-gate else if (errno == ENODEV)
14770Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
14780Sstevel@tonic-gate else if (errno == EAGAIN)
14790Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
14800Sstevel@tonic-gate else if (errno == ENOTSUP)
14810Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
14820Sstevel@tonic-gate else if (errno == EACCES)
14830Sstevel@tonic-gate return (RSMERR_BAD_PERMS);
14840Sstevel@tonic-gate else
14850Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
14860Sstevel@tonic-gate }
14870Sstevel@tonic-gate seg->rsmseg_vaddr = va;
14880Sstevel@tonic-gate seg->rsmseg_maplen = seg->rsmseg_size;
14890Sstevel@tonic-gate seg->rsmseg_mapoffset = 0;
14900Sstevel@tonic-gate seg->rsmseg_state = IMPORT_MAP;
14910Sstevel@tonic-gate seg->rsmseg_flags |= RSM_IMPLICIT_MAP;
14920Sstevel@tonic-gate }
14930Sstevel@tonic-gate
14940Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
14950Sstevel@tonic-gate " __rsm_import_implicit_map: exit\n"));
14960Sstevel@tonic-gate
14970Sstevel@tonic-gate return (RSM_SUCCESS);
14980Sstevel@tonic-gate }
14990Sstevel@tonic-gate
15000Sstevel@tonic-gate int
rsm_memseg_import_get8(rsm_memseg_import_handle_t im_memseg,off_t offset,uint8_t * datap,ulong_t rep_cnt)1501*6812Sraf rsm_memseg_import_get8(rsm_memseg_import_handle_t im_memseg,
15020Sstevel@tonic-gate off_t offset,
15030Sstevel@tonic-gate uint8_t *datap,
15040Sstevel@tonic-gate ulong_t rep_cnt)
15050Sstevel@tonic-gate {
15060Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
15070Sstevel@tonic-gate int e;
15080Sstevel@tonic-gate
15090Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15100Sstevel@tonic-gate "rsm_memseg_import_get8: enter\n"));
15110Sstevel@tonic-gate
15120Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt,
15130Sstevel@tonic-gate RSM_PERM_READ,
15140Sstevel@tonic-gate RSM_DAS8);
15150Sstevel@tonic-gate if (e == RSM_SUCCESS) {
15160Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
15170Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
15180Sstevel@tonic-gate
15190Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15200Sstevel@tonic-gate /* generation number snapshot */
15210Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
15220Sstevel@tonic-gate }
15230Sstevel@tonic-gate
15240Sstevel@tonic-gate e = ops->rsm_memseg_import_get8(im_memseg, offset, datap,
15250Sstevel@tonic-gate rep_cnt, 0);
15260Sstevel@tonic-gate
15270Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15280Sstevel@tonic-gate /* check the generation number for force disconnects */
15290Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
15300Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
15310Sstevel@tonic-gate }
15320Sstevel@tonic-gate }
15330Sstevel@tonic-gate }
15340Sstevel@tonic-gate
15350Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15360Sstevel@tonic-gate "rsm_memseg_import_get8: exit\n"));
15370Sstevel@tonic-gate
15380Sstevel@tonic-gate return (e);
15390Sstevel@tonic-gate }
15400Sstevel@tonic-gate
15410Sstevel@tonic-gate int
rsm_memseg_import_get16(rsm_memseg_import_handle_t im_memseg,off_t offset,uint16_t * datap,ulong_t rep_cnt)1542*6812Sraf rsm_memseg_import_get16(rsm_memseg_import_handle_t im_memseg,
15430Sstevel@tonic-gate off_t offset,
15440Sstevel@tonic-gate uint16_t *datap,
15450Sstevel@tonic-gate ulong_t rep_cnt)
15460Sstevel@tonic-gate {
15470Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
15480Sstevel@tonic-gate int e;
15490Sstevel@tonic-gate
15500Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15510Sstevel@tonic-gate "rsm_memseg_import_get16: enter\n"));
15520Sstevel@tonic-gate
15530Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*2,
15540Sstevel@tonic-gate RSM_PERM_READ,
15550Sstevel@tonic-gate RSM_DAS16);
15560Sstevel@tonic-gate if (e == RSM_SUCCESS) {
15570Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
15580Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
15590Sstevel@tonic-gate
15600Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15610Sstevel@tonic-gate /* generation number snapshot */
15620Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
15630Sstevel@tonic-gate }
15640Sstevel@tonic-gate
15650Sstevel@tonic-gate e = ops->rsm_memseg_import_get16(im_memseg, offset, datap,
15660Sstevel@tonic-gate rep_cnt, 0);
15670Sstevel@tonic-gate
15680Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15690Sstevel@tonic-gate /* check the generation number for force disconnects */
15700Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
15710Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
15720Sstevel@tonic-gate }
15730Sstevel@tonic-gate }
15740Sstevel@tonic-gate
15750Sstevel@tonic-gate }
15760Sstevel@tonic-gate
15770Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15780Sstevel@tonic-gate "rsm_memseg_import_get16: exit\n"));
15790Sstevel@tonic-gate
15800Sstevel@tonic-gate return (e);
15810Sstevel@tonic-gate }
15820Sstevel@tonic-gate
15830Sstevel@tonic-gate int
rsm_memseg_import_get32(rsm_memseg_import_handle_t im_memseg,off_t offset,uint32_t * datap,ulong_t rep_cnt)1584*6812Sraf rsm_memseg_import_get32(rsm_memseg_import_handle_t im_memseg,
15850Sstevel@tonic-gate off_t offset,
15860Sstevel@tonic-gate uint32_t *datap,
15870Sstevel@tonic-gate ulong_t rep_cnt)
15880Sstevel@tonic-gate {
15890Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
15900Sstevel@tonic-gate int e;
15910Sstevel@tonic-gate
15920Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15930Sstevel@tonic-gate "rsm_memseg_import_get32: enter\n"));
15940Sstevel@tonic-gate
15950Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*4,
15960Sstevel@tonic-gate RSM_PERM_READ,
15970Sstevel@tonic-gate RSM_DAS32);
15980Sstevel@tonic-gate if (e == RSM_SUCCESS) {
15990Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
16000Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
16010Sstevel@tonic-gate
16020Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16030Sstevel@tonic-gate /* generation number snapshot */
16040Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
16050Sstevel@tonic-gate }
16060Sstevel@tonic-gate
16070Sstevel@tonic-gate e = ops->rsm_memseg_import_get32(im_memseg, offset, datap,
16080Sstevel@tonic-gate rep_cnt, 0);
16090Sstevel@tonic-gate
16100Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16110Sstevel@tonic-gate /* check the generation number for force disconnects */
16120Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
16130Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
16140Sstevel@tonic-gate }
16150Sstevel@tonic-gate }
16160Sstevel@tonic-gate }
16170Sstevel@tonic-gate
16180Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16190Sstevel@tonic-gate "rsm_memseg_import_get32: exit\n"));
16200Sstevel@tonic-gate
16210Sstevel@tonic-gate return (e);
16220Sstevel@tonic-gate }
16230Sstevel@tonic-gate
16240Sstevel@tonic-gate int
rsm_memseg_import_get64(rsm_memseg_import_handle_t im_memseg,off_t offset,uint64_t * datap,ulong_t rep_cnt)1625*6812Sraf rsm_memseg_import_get64(rsm_memseg_import_handle_t im_memseg,
16260Sstevel@tonic-gate off_t offset,
16270Sstevel@tonic-gate uint64_t *datap,
16280Sstevel@tonic-gate ulong_t rep_cnt)
16290Sstevel@tonic-gate {
16300Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
16310Sstevel@tonic-gate int e;
16320Sstevel@tonic-gate
16330Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16340Sstevel@tonic-gate "rsm_memseg_import_get64: enter\n"));
16350Sstevel@tonic-gate
16360Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*8,
16370Sstevel@tonic-gate RSM_PERM_READ,
16380Sstevel@tonic-gate RSM_DAS64);
16390Sstevel@tonic-gate if (e == RSM_SUCCESS) {
16400Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
16410Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
16420Sstevel@tonic-gate
16430Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16440Sstevel@tonic-gate /* generation number snapshot */
16450Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
16460Sstevel@tonic-gate }
16470Sstevel@tonic-gate
16480Sstevel@tonic-gate e = ops->rsm_memseg_import_get64(im_memseg, offset, datap,
16490Sstevel@tonic-gate rep_cnt, 0);
16500Sstevel@tonic-gate
16510Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16520Sstevel@tonic-gate /* check the generation number for force disconnects */
16530Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
16540Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
16550Sstevel@tonic-gate }
16560Sstevel@tonic-gate }
16570Sstevel@tonic-gate }
16580Sstevel@tonic-gate
16590Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16600Sstevel@tonic-gate "rsm_memseg_import_get64: exit\n"));
16610Sstevel@tonic-gate
16620Sstevel@tonic-gate return (e);
16630Sstevel@tonic-gate }
16640Sstevel@tonic-gate
16650Sstevel@tonic-gate int
rsm_memseg_import_get(rsm_memseg_import_handle_t im_memseg,off_t offset,void * dst_addr,size_t length)1666*6812Sraf rsm_memseg_import_get(rsm_memseg_import_handle_t im_memseg,
16670Sstevel@tonic-gate off_t offset,
16680Sstevel@tonic-gate void *dst_addr,
16690Sstevel@tonic-gate size_t length)
16700Sstevel@tonic-gate {
16710Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
16720Sstevel@tonic-gate int e;
16730Sstevel@tonic-gate
16740Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16750Sstevel@tonic-gate "rsm_memseg_import_get: enter\n"));
16760Sstevel@tonic-gate
16770Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)dst_addr, length,
16780Sstevel@tonic-gate RSM_PERM_READ,
16790Sstevel@tonic-gate RSM_DAS8);
16800Sstevel@tonic-gate if (e == RSM_SUCCESS) {
16810Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
16820Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
16830Sstevel@tonic-gate
16840Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16850Sstevel@tonic-gate /* generation number snapshot */
16860Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
16870Sstevel@tonic-gate }
16880Sstevel@tonic-gate
16890Sstevel@tonic-gate e = ops->rsm_memseg_import_get(im_memseg, offset, dst_addr,
16900Sstevel@tonic-gate length);
16910Sstevel@tonic-gate
16920Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16930Sstevel@tonic-gate /* check the generation number for force disconnects */
16940Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
16950Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
16960Sstevel@tonic-gate }
16970Sstevel@tonic-gate }
16980Sstevel@tonic-gate }
16990Sstevel@tonic-gate
17000Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
17010Sstevel@tonic-gate "rsm_memseg_import_get: exit\n"));
17020Sstevel@tonic-gate
17030Sstevel@tonic-gate return (e);
17040Sstevel@tonic-gate }
17050Sstevel@tonic-gate
17060Sstevel@tonic-gate
17070Sstevel@tonic-gate int
rsm_memseg_import_getv(rsm_scat_gath_t * sg_io)1708*6812Sraf rsm_memseg_import_getv(rsm_scat_gath_t *sg_io)
17090Sstevel@tonic-gate {
17100Sstevel@tonic-gate rsm_controller_t *cntrl;
17110Sstevel@tonic-gate rsmseg_handle_t *seg;
17120Sstevel@tonic-gate uint_t save_sg_io_flags;
17130Sstevel@tonic-gate
17140Sstevel@tonic-gate int e;
17150Sstevel@tonic-gate
17160Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
17170Sstevel@tonic-gate "rsm_memseg_import_getv: enter\n"));
17180Sstevel@tonic-gate
17190Sstevel@tonic-gate if (sg_io == NULL) {
17200Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17210Sstevel@tonic-gate "invalid sg_io structure\n"));
17220Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
17230Sstevel@tonic-gate }
17240Sstevel@tonic-gate
17250Sstevel@tonic-gate seg = (rsmseg_handle_t *)sg_io->remote_handle;
17260Sstevel@tonic-gate if (seg == NULL) {
17270Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17280Sstevel@tonic-gate "invalid remote segment handle in sg_io\n"));
17290Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
17300Sstevel@tonic-gate }
17310Sstevel@tonic-gate
17320Sstevel@tonic-gate cntrl = (rsm_controller_t *)seg->rsmseg_controller;
17330Sstevel@tonic-gate if (cntrl == NULL) {
17340Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17350Sstevel@tonic-gate "invalid controller handle\n"));
17360Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
17370Sstevel@tonic-gate }
17380Sstevel@tonic-gate
17390Sstevel@tonic-gate if ((sg_io->io_request_count > RSM_MAX_SGIOREQS) ||
17400Sstevel@tonic-gate (sg_io->io_request_count == 0)) {
17410Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17420Sstevel@tonic-gate "io_request_count value incorrect\n"));
17430Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
17440Sstevel@tonic-gate }
17450Sstevel@tonic-gate
17460Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_CONNECT) {
17470Sstevel@tonic-gate e = __rsm_import_implicit_map(seg, RSM_IOTYPE_SCATGATH);
17480Sstevel@tonic-gate if (e != RSM_SUCCESS) {
17490Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17500Sstevel@tonic-gate "implicit map failure\n"));
17510Sstevel@tonic-gate return (e);
17520Sstevel@tonic-gate }
17530Sstevel@tonic-gate }
17540Sstevel@tonic-gate
17550Sstevel@tonic-gate /*
17560Sstevel@tonic-gate * Copy the flags field of the sg_io structure in a local
17570Sstevel@tonic-gate * variable.
17580Sstevel@tonic-gate * This is required since the flags field can be
17590Sstevel@tonic-gate * changed by the plugin library routine to indicate that
17600Sstevel@tonic-gate * the signal post was done.
17610Sstevel@tonic-gate * This change in the flags field of the sg_io structure
17620Sstevel@tonic-gate * should not be reflected to the user. Hence once the flags
17630Sstevel@tonic-gate * field has been used for the purpose of determining whether
17640Sstevel@tonic-gate * the plugin executed a signal post, it must be restored to
17650Sstevel@tonic-gate * its original value which is stored in the local variable.
17660Sstevel@tonic-gate */
17670Sstevel@tonic-gate save_sg_io_flags = sg_io->flags;
17680Sstevel@tonic-gate
17690Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_memseg_import_getv(sg_io);
17700Sstevel@tonic-gate
17710Sstevel@tonic-gate /*
17720Sstevel@tonic-gate * At this point, if an implicit signal post was requested by
17730Sstevel@tonic-gate * the user, there could be two possibilities that arise:
17740Sstevel@tonic-gate * 1. the plugin routine has already executed the implicit
17750Sstevel@tonic-gate * signal post either successfully or unsuccessfully
17760Sstevel@tonic-gate * 2. the plugin does not have the capability of doing an
17770Sstevel@tonic-gate * implicit signal post and hence the signal post needs
17780Sstevel@tonic-gate * to be done here.
17790Sstevel@tonic-gate * The above two cases can be idenfied by the flags
17800Sstevel@tonic-gate * field within the sg_io structure as follows:
17810Sstevel@tonic-gate * In case 1, the RSM_IMPLICIT_SIGPOST bit is reset to 0 by the
17820Sstevel@tonic-gate * plugin, indicating that the signal post was done.
17830Sstevel@tonic-gate * In case 2, the bit remains set to a 1 as originally given
17840Sstevel@tonic-gate * by the user, and hence a signal post needs to be done here.
17850Sstevel@tonic-gate */
17860Sstevel@tonic-gate if (sg_io->flags & RSM_IMPLICIT_SIGPOST &&
17870Sstevel@tonic-gate e == RSM_SUCCESS) {
17880Sstevel@tonic-gate /* Do the implicit signal post */
17890Sstevel@tonic-gate
17900Sstevel@tonic-gate /*
17910Sstevel@tonic-gate * The value of the second argument to this call
17920Sstevel@tonic-gate * depends on the value of the sg_io->flags field.
17930Sstevel@tonic-gate * If the RSM_SIGPOST_NO_ACCUMULATE flag has been
17940Sstevel@tonic-gate * ored into the sg_io->flags field, this indicates
17950Sstevel@tonic-gate * that the rsm_intr_signal_post is to be done with
17960Sstevel@tonic-gate * the flags argument set to RSM_SIGPOST_NO_ACCUMULATE
17970Sstevel@tonic-gate * Else, the flags argument is set to 0. These
17980Sstevel@tonic-gate * semantics can be achieved simply by masking off
17990Sstevel@tonic-gate * all other bits in the sg_io->flags field except the
18000Sstevel@tonic-gate * RSM_SIGPOST_NO_ACCUMULATE bit and using the result
18010Sstevel@tonic-gate * as the flags argument for the rsm_intr_signal_post.
18020Sstevel@tonic-gate */
18030Sstevel@tonic-gate
18040Sstevel@tonic-gate int sigpost_flags = sg_io->flags & RSM_SIGPOST_NO_ACCUMULATE;
18050Sstevel@tonic-gate e = rsm_intr_signal_post(seg, sigpost_flags);
18060Sstevel@tonic-gate }
18070Sstevel@tonic-gate
18080Sstevel@tonic-gate /* Restore the flags field within the users scatter gather structure */
18090Sstevel@tonic-gate sg_io->flags = save_sg_io_flags;
18100Sstevel@tonic-gate
18110Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18120Sstevel@tonic-gate "rsm_memseg_import_getv: exit\n"));
18130Sstevel@tonic-gate
18140Sstevel@tonic-gate return (e);
18150Sstevel@tonic-gate
18160Sstevel@tonic-gate }
18170Sstevel@tonic-gate
18180Sstevel@tonic-gate /*
18190Sstevel@tonic-gate * import side memory segment operations (write access functions):
18200Sstevel@tonic-gate */
18210Sstevel@tonic-gate
18220Sstevel@tonic-gate int
rsm_memseg_import_put8(rsm_memseg_import_handle_t im_memseg,off_t offset,uint8_t * datap,ulong_t rep_cnt)1823*6812Sraf rsm_memseg_import_put8(rsm_memseg_import_handle_t im_memseg,
18240Sstevel@tonic-gate off_t offset,
18250Sstevel@tonic-gate uint8_t *datap,
18260Sstevel@tonic-gate ulong_t rep_cnt)
18270Sstevel@tonic-gate {
18280Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
18290Sstevel@tonic-gate int e;
18300Sstevel@tonic-gate
18310Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18320Sstevel@tonic-gate "rsm_memseg_import_put8: enter\n"));
18330Sstevel@tonic-gate
18340Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
18350Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
18360Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt,
18370Sstevel@tonic-gate RSM_PERM_WRITE,
18380Sstevel@tonic-gate RSM_DAS8);
18390Sstevel@tonic-gate if (e == RSM_SUCCESS) {
18400Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
18410Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
18420Sstevel@tonic-gate
18430Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18440Sstevel@tonic-gate /* generation number snapshot */
18450Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
18460Sstevel@tonic-gate }
18470Sstevel@tonic-gate
18480Sstevel@tonic-gate e = ops->rsm_memseg_import_put8(im_memseg, offset, datap,
18490Sstevel@tonic-gate rep_cnt, 0);
18500Sstevel@tonic-gate
18510Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18520Sstevel@tonic-gate /* check the generation number for force disconnects */
18530Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
18540Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
18550Sstevel@tonic-gate }
18560Sstevel@tonic-gate }
18570Sstevel@tonic-gate }
18580Sstevel@tonic-gate
18590Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18600Sstevel@tonic-gate "rsm_memseg_import_put8: exit\n"));
18610Sstevel@tonic-gate
18620Sstevel@tonic-gate return (e);
18630Sstevel@tonic-gate }
18640Sstevel@tonic-gate
18650Sstevel@tonic-gate int
rsm_memseg_import_put16(rsm_memseg_import_handle_t im_memseg,off_t offset,uint16_t * datap,ulong_t rep_cnt)1866*6812Sraf rsm_memseg_import_put16(rsm_memseg_import_handle_t im_memseg,
18670Sstevel@tonic-gate off_t offset,
18680Sstevel@tonic-gate uint16_t *datap,
18690Sstevel@tonic-gate ulong_t rep_cnt)
18700Sstevel@tonic-gate {
18710Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
18720Sstevel@tonic-gate int e;
18730Sstevel@tonic-gate
18740Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18750Sstevel@tonic-gate "rsm_memseg_import_put16: enter\n"));
18760Sstevel@tonic-gate
18770Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
18780Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
18790Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*2,
18800Sstevel@tonic-gate RSM_PERM_WRITE,
18810Sstevel@tonic-gate RSM_DAS16);
18820Sstevel@tonic-gate if (e == RSM_SUCCESS) {
18830Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
18840Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
18850Sstevel@tonic-gate
18860Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18870Sstevel@tonic-gate /* generation number snapshot */
18880Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
18890Sstevel@tonic-gate }
18900Sstevel@tonic-gate
18910Sstevel@tonic-gate e = ops->rsm_memseg_import_put16(im_memseg, offset, datap,
18920Sstevel@tonic-gate rep_cnt, 0);
18930Sstevel@tonic-gate
18940Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18950Sstevel@tonic-gate /* check the generation number for force disconnects */
18960Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
18970Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
18980Sstevel@tonic-gate }
18990Sstevel@tonic-gate }
19000Sstevel@tonic-gate
19010Sstevel@tonic-gate }
19020Sstevel@tonic-gate
19030Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19040Sstevel@tonic-gate "rsm_memseg_import_put16: exit\n"));
19050Sstevel@tonic-gate
19060Sstevel@tonic-gate return (e);
19070Sstevel@tonic-gate }
19080Sstevel@tonic-gate
19090Sstevel@tonic-gate int
rsm_memseg_import_put32(rsm_memseg_import_handle_t im_memseg,off_t offset,uint32_t * datap,ulong_t rep_cnt)1910*6812Sraf rsm_memseg_import_put32(rsm_memseg_import_handle_t im_memseg,
19110Sstevel@tonic-gate off_t offset,
19120Sstevel@tonic-gate uint32_t *datap,
19130Sstevel@tonic-gate ulong_t rep_cnt)
19140Sstevel@tonic-gate {
19150Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
19160Sstevel@tonic-gate int e;
19170Sstevel@tonic-gate
19180Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19190Sstevel@tonic-gate "rsm_memseg_import_put32: enter\n"));
19200Sstevel@tonic-gate
19210Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
19220Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
19230Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*4,
19240Sstevel@tonic-gate RSM_PERM_WRITE,
19250Sstevel@tonic-gate RSM_DAS32);
19260Sstevel@tonic-gate if (e == RSM_SUCCESS) {
19270Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
19280Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
19290Sstevel@tonic-gate
19300Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19310Sstevel@tonic-gate /* generation number snapshot */
19320Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
19330Sstevel@tonic-gate }
19340Sstevel@tonic-gate
19350Sstevel@tonic-gate e = ops->rsm_memseg_import_put32(im_memseg, offset, datap,
19360Sstevel@tonic-gate rep_cnt, 0);
19370Sstevel@tonic-gate
19380Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19390Sstevel@tonic-gate /* check the generation number for force disconnects */
19400Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
19410Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
19420Sstevel@tonic-gate }
19430Sstevel@tonic-gate }
19440Sstevel@tonic-gate }
19450Sstevel@tonic-gate
19460Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19470Sstevel@tonic-gate "rsm_memseg_import_put32: exit\n"));
19480Sstevel@tonic-gate
19490Sstevel@tonic-gate return (e);
19500Sstevel@tonic-gate }
19510Sstevel@tonic-gate
19520Sstevel@tonic-gate int
rsm_memseg_import_put64(rsm_memseg_import_handle_t im_memseg,off_t offset,uint64_t * datap,ulong_t rep_cnt)1953*6812Sraf rsm_memseg_import_put64(rsm_memseg_import_handle_t im_memseg,
19540Sstevel@tonic-gate off_t offset,
19550Sstevel@tonic-gate uint64_t *datap,
19560Sstevel@tonic-gate ulong_t rep_cnt)
19570Sstevel@tonic-gate {
19580Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
19590Sstevel@tonic-gate int e;
19600Sstevel@tonic-gate
19610Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19620Sstevel@tonic-gate "rsm_memseg_import_put64: enter\n"));
19630Sstevel@tonic-gate
19640Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
19650Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
19660Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*8,
19670Sstevel@tonic-gate RSM_PERM_WRITE,
19680Sstevel@tonic-gate RSM_DAS64);
19690Sstevel@tonic-gate if (e == RSM_SUCCESS) {
19700Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
19710Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
19720Sstevel@tonic-gate
19730Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19740Sstevel@tonic-gate /* generation number snapshot */
19750Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
19760Sstevel@tonic-gate }
19770Sstevel@tonic-gate
19780Sstevel@tonic-gate e = ops->rsm_memseg_import_put64(im_memseg, offset, datap,
19790Sstevel@tonic-gate rep_cnt, 0);
19800Sstevel@tonic-gate
19810Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19820Sstevel@tonic-gate /* check the generation number for force disconnects */
19830Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
19840Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
19850Sstevel@tonic-gate }
19860Sstevel@tonic-gate }
19870Sstevel@tonic-gate }
19880Sstevel@tonic-gate
19890Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19900Sstevel@tonic-gate "rsm_memseg_import_put64: exit\n"));
19910Sstevel@tonic-gate
19920Sstevel@tonic-gate return (e);
19930Sstevel@tonic-gate }
19940Sstevel@tonic-gate
19950Sstevel@tonic-gate int
rsm_memseg_import_put(rsm_memseg_import_handle_t im_memseg,off_t offset,void * src_addr,size_t length)1996*6812Sraf rsm_memseg_import_put(rsm_memseg_import_handle_t im_memseg,
19970Sstevel@tonic-gate off_t offset,
19980Sstevel@tonic-gate void *src_addr,
19990Sstevel@tonic-gate size_t length)
20000Sstevel@tonic-gate {
20010Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
20020Sstevel@tonic-gate int e;
20030Sstevel@tonic-gate
20040Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
20050Sstevel@tonic-gate "rsm_memseg_import_put: enter\n"));
20060Sstevel@tonic-gate
20070Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)src_addr, length,
20080Sstevel@tonic-gate RSM_PERM_WRITE,
20090Sstevel@tonic-gate RSM_DAS8);
20100Sstevel@tonic-gate if (e == RSM_SUCCESS) {
20110Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
20120Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
20130Sstevel@tonic-gate
20140Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
20150Sstevel@tonic-gate /* generation number snapshot */
20160Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
20170Sstevel@tonic-gate }
20180Sstevel@tonic-gate
20190Sstevel@tonic-gate e = ops->rsm_memseg_import_put(im_memseg, offset, src_addr,
20200Sstevel@tonic-gate length);
20210Sstevel@tonic-gate
20220Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
20230Sstevel@tonic-gate /* check the generation number for force disconnects */
20240Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
20250Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
20260Sstevel@tonic-gate }
20270Sstevel@tonic-gate }
20280Sstevel@tonic-gate
20290Sstevel@tonic-gate }
20300Sstevel@tonic-gate
20310Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
20320Sstevel@tonic-gate "rsm_memseg_import_put: exit\n"));
20330Sstevel@tonic-gate return (e);
20340Sstevel@tonic-gate }
20350Sstevel@tonic-gate
20360Sstevel@tonic-gate
20370Sstevel@tonic-gate int
rsm_memseg_import_putv(rsm_scat_gath_t * sg_io)2038*6812Sraf rsm_memseg_import_putv(rsm_scat_gath_t *sg_io)
20390Sstevel@tonic-gate {
20400Sstevel@tonic-gate rsm_controller_t *cntrl;
20410Sstevel@tonic-gate rsmseg_handle_t *seg;
20420Sstevel@tonic-gate uint_t save_sg_io_flags;
20430Sstevel@tonic-gate
20440Sstevel@tonic-gate int e;
20450Sstevel@tonic-gate
20460Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
20470Sstevel@tonic-gate "rsm_memseg_import_putv: enter\n"));
20480Sstevel@tonic-gate
20490Sstevel@tonic-gate
20500Sstevel@tonic-gate if (sg_io == NULL) {
20510Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20520Sstevel@tonic-gate "invalid sg_io structure\n"));
20530Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
20540Sstevel@tonic-gate }
20550Sstevel@tonic-gate
20560Sstevel@tonic-gate seg = (rsmseg_handle_t *)sg_io->remote_handle;
20570Sstevel@tonic-gate if (seg == NULL) {
20580Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20590Sstevel@tonic-gate "invalid remote segment handle in sg_io\n"));
20600Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
20610Sstevel@tonic-gate }
20620Sstevel@tonic-gate
20630Sstevel@tonic-gate cntrl = (rsm_controller_t *)seg->rsmseg_controller;
20640Sstevel@tonic-gate if (cntrl == NULL) {
20650Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20660Sstevel@tonic-gate "invalid controller handle\n"));
20670Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
20680Sstevel@tonic-gate }
20690Sstevel@tonic-gate
20700Sstevel@tonic-gate if ((sg_io->io_request_count > RSM_MAX_SGIOREQS) ||
20710Sstevel@tonic-gate (sg_io->io_request_count == 0)) {
20720Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20730Sstevel@tonic-gate "io_request_count value incorrect\n"));
20740Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
20750Sstevel@tonic-gate }
20760Sstevel@tonic-gate
20770Sstevel@tonic-gate /* do an implicit map if required */
20780Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_CONNECT) {
20790Sstevel@tonic-gate e = __rsm_import_implicit_map(seg, RSM_IOTYPE_SCATGATH);
20800Sstevel@tonic-gate if (e != RSM_SUCCESS) {
20810Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20820Sstevel@tonic-gate "implicit map failed\n"));
20830Sstevel@tonic-gate return (e);
20840Sstevel@tonic-gate }
20850Sstevel@tonic-gate }
20860Sstevel@tonic-gate
20870Sstevel@tonic-gate /*
20880Sstevel@tonic-gate * Copy the flags field of the sg_io structure in a local
20890Sstevel@tonic-gate * variable.
20900Sstevel@tonic-gate * This is required since the flags field can be
20910Sstevel@tonic-gate * changed by the plugin library routine to indicate that
20920Sstevel@tonic-gate * the signal post was done.
20930Sstevel@tonic-gate * This change in the flags field of the sg_io structure
20940Sstevel@tonic-gate * should not be reflected to the user. Hence once the flags
20950Sstevel@tonic-gate * field has been used for the purpose of determining whether
20960Sstevel@tonic-gate * the plugin executed a signal post, it must be restored to
20970Sstevel@tonic-gate * its original value which is stored in the local variable.
20980Sstevel@tonic-gate */
20990Sstevel@tonic-gate save_sg_io_flags = sg_io->flags;
21000Sstevel@tonic-gate
21010Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_memseg_import_putv(sg_io);
21020Sstevel@tonic-gate
21030Sstevel@tonic-gate /*
21040Sstevel@tonic-gate * At this point, if an implicit signal post was requested by
21050Sstevel@tonic-gate * the user, there could be two possibilities that arise:
21060Sstevel@tonic-gate * 1. the plugin routine has already executed the implicit
21070Sstevel@tonic-gate * signal post either successfully or unsuccessfully
21080Sstevel@tonic-gate * 2. the plugin does not have the capability of doing an
21090Sstevel@tonic-gate * implicit signal post and hence the signal post needs
21100Sstevel@tonic-gate * to be done here.
21110Sstevel@tonic-gate * The above two cases can be idenfied by the flags
21120Sstevel@tonic-gate * field within the sg_io structure as follows:
21130Sstevel@tonic-gate * In case 1, the RSM_IMPLICIT_SIGPOST bit is reset to 0 by the
21140Sstevel@tonic-gate * plugin, indicating that the signal post was done.
21150Sstevel@tonic-gate * In case 2, the bit remains set to a 1 as originally given
21160Sstevel@tonic-gate * by the user, and hence a signal post needs to be done here.
21170Sstevel@tonic-gate */
21180Sstevel@tonic-gate if (sg_io->flags & RSM_IMPLICIT_SIGPOST &&
2119*6812Sraf e == RSM_SUCCESS) {
21200Sstevel@tonic-gate /* Do the implicit signal post */
21210Sstevel@tonic-gate
21220Sstevel@tonic-gate /*
21230Sstevel@tonic-gate * The value of the second argument to this call
21240Sstevel@tonic-gate * depends on the value of the sg_io->flags field.
21250Sstevel@tonic-gate * If the RSM_SIGPOST_NO_ACCUMULATE flag has been
21260Sstevel@tonic-gate * ored into the sg_io->flags field, this indicates
21270Sstevel@tonic-gate * that the rsm_intr_signal_post is to be done with
21280Sstevel@tonic-gate * the flags argument set to RSM_SIGPOST_NO_ACCUMULATE
21290Sstevel@tonic-gate * Else, the flags argument is set to 0. These
21300Sstevel@tonic-gate * semantics can be achieved simply by masking off
21310Sstevel@tonic-gate * all other bits in the sg_io->flags field except the
21320Sstevel@tonic-gate * RSM_SIGPOST_NO_ACCUMULATE bit and using the result
21330Sstevel@tonic-gate * as the flags argument for the rsm_intr_signal_post.
21340Sstevel@tonic-gate */
21350Sstevel@tonic-gate
21360Sstevel@tonic-gate int sigpost_flags = sg_io->flags & RSM_SIGPOST_NO_ACCUMULATE;
21370Sstevel@tonic-gate e = rsm_intr_signal_post(seg, sigpost_flags);
21380Sstevel@tonic-gate
21390Sstevel@tonic-gate }
21400Sstevel@tonic-gate
21410Sstevel@tonic-gate /* Restore the flags field within the users scatter gather structure */
21420Sstevel@tonic-gate sg_io->flags = save_sg_io_flags;
21430Sstevel@tonic-gate
21440Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
21450Sstevel@tonic-gate "rsm_memseg_import_putv: exit\n"));
21460Sstevel@tonic-gate
21470Sstevel@tonic-gate return (e);
21480Sstevel@tonic-gate }
21490Sstevel@tonic-gate
21500Sstevel@tonic-gate
21510Sstevel@tonic-gate /*
21520Sstevel@tonic-gate * import side memory segment operations (mapping):
21530Sstevel@tonic-gate */
21540Sstevel@tonic-gate int
rsm_memseg_import_map(rsm_memseg_import_handle_t im_memseg,void ** address,rsm_attribute_t attr,rsm_permission_t perm,off_t offset,size_t length)2155*6812Sraf rsm_memseg_import_map(rsm_memseg_import_handle_t im_memseg,
21560Sstevel@tonic-gate void **address,
21570Sstevel@tonic-gate rsm_attribute_t attr,
21580Sstevel@tonic-gate rsm_permission_t perm,
21590Sstevel@tonic-gate off_t offset,
21600Sstevel@tonic-gate size_t length)
21610Sstevel@tonic-gate {
21620Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
21630Sstevel@tonic-gate int flag = MAP_SHARED;
21640Sstevel@tonic-gate int prot;
21650Sstevel@tonic-gate caddr_t va;
21660Sstevel@tonic-gate
21670Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
21680Sstevel@tonic-gate "rsm_memseg_import_map: enter\n"));
21690Sstevel@tonic-gate
21700Sstevel@tonic-gate if (!seg) {
21710Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
21720Sstevel@tonic-gate "invalid segment\n"));
21730Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
21740Sstevel@tonic-gate }
21750Sstevel@tonic-gate if (!address) {
21760Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
21770Sstevel@tonic-gate "invalid address\n"));
21780Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
21790Sstevel@tonic-gate }
21800Sstevel@tonic-gate
21810Sstevel@tonic-gate /*
21820Sstevel@tonic-gate * Only one map per segment handle!
21830Sstevel@tonic-gate * XXX need to take a lock here
21840Sstevel@tonic-gate */
21850Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
21860Sstevel@tonic-gate
21870Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_MAP) {
21880Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
21890Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
21900Sstevel@tonic-gate "segment already mapped\n"));
21910Sstevel@tonic-gate return (RSMERR_SEG_ALREADY_MAPPED);
21920Sstevel@tonic-gate }
21930Sstevel@tonic-gate
21940Sstevel@tonic-gate /* Only import segments allowed to map */
21950Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_CONNECT) {
21960Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
21970Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
21980Sstevel@tonic-gate }
21990Sstevel@tonic-gate
22000Sstevel@tonic-gate /* check for permissions */
22010Sstevel@tonic-gate if (perm > RSM_PERM_RDWR) {
22020Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22030Sstevel@tonic-gate "bad permissions when mapping\n"));
22040Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22050Sstevel@tonic-gate return (RSMERR_BAD_PERMS);
22060Sstevel@tonic-gate }
22070Sstevel@tonic-gate
22080Sstevel@tonic-gate if (length == 0) {
22090Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22100Sstevel@tonic-gate "mapping with length 0\n"));
22110Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22120Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
22130Sstevel@tonic-gate }
22140Sstevel@tonic-gate
22150Sstevel@tonic-gate if (offset + length > seg->rsmseg_size) {
22160Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22170Sstevel@tonic-gate "map length + offset exceed segment size\n"));
22180Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22190Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
22200Sstevel@tonic-gate }
22210Sstevel@tonic-gate
22220Sstevel@tonic-gate if ((size_t)offset & (PAGESIZE - 1)) {
22230Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
22240Sstevel@tonic-gate "bad mem alignment\n"));
22250Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
22260Sstevel@tonic-gate }
22270Sstevel@tonic-gate
22280Sstevel@tonic-gate if (attr & RSM_MAP_FIXED) {
22290Sstevel@tonic-gate if ((uintptr_t)(*address) & (PAGESIZE - 1)) {
22300Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
22310Sstevel@tonic-gate "bad mem alignment\n"));
22320Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
22330Sstevel@tonic-gate }
22340Sstevel@tonic-gate flag |= MAP_FIXED;
22350Sstevel@tonic-gate }
22360Sstevel@tonic-gate
22370Sstevel@tonic-gate prot = PROT_NONE;
22380Sstevel@tonic-gate if (perm & RSM_PERM_READ)
22390Sstevel@tonic-gate prot |= PROT_READ;
22400Sstevel@tonic-gate if (perm & RSM_PERM_WRITE)
22410Sstevel@tonic-gate prot |= PROT_WRITE;
22420Sstevel@tonic-gate
22430Sstevel@tonic-gate va = mmap(*address, length, prot, flag, seg->rsmseg_fd, offset);
22440Sstevel@tonic-gate if (va == MAP_FAILED) {
22450Sstevel@tonic-gate int e = errno;
22460Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22470Sstevel@tonic-gate "error %d during map\n", e));
22480Sstevel@tonic-gate
22490Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22500Sstevel@tonic-gate if (e == ENXIO || e == EOVERFLOW ||
22510Sstevel@tonic-gate e == ENOMEM)
22520Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
22530Sstevel@tonic-gate else if (e == ENODEV)
22540Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
22550Sstevel@tonic-gate else if (e == EAGAIN)
22560Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
22570Sstevel@tonic-gate else if (e == ENOTSUP)
22580Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
22590Sstevel@tonic-gate else if (e == EACCES)
22600Sstevel@tonic-gate return (RSMERR_BAD_PERMS);
22610Sstevel@tonic-gate else
22620Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
22630Sstevel@tonic-gate }
22640Sstevel@tonic-gate *address = va;
22650Sstevel@tonic-gate
22660Sstevel@tonic-gate /*
22670Sstevel@tonic-gate * Fix segment ops vector to handle direct access.
22680Sstevel@tonic-gate */
22690Sstevel@tonic-gate /*
22700Sstevel@tonic-gate * XXX: Set this only for full segment mapping. Keep a list
22710Sstevel@tonic-gate * of mappings to use for access functions
22720Sstevel@tonic-gate */
22730Sstevel@tonic-gate seg->rsmseg_vaddr = va;
22740Sstevel@tonic-gate seg->rsmseg_maplen = length;
22750Sstevel@tonic-gate seg->rsmseg_mapoffset = offset;
22760Sstevel@tonic-gate seg->rsmseg_state = IMPORT_MAP;
22770Sstevel@tonic-gate
22780Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22790Sstevel@tonic-gate
22800Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
22810Sstevel@tonic-gate "rsm_memseg_import_map: exit\n"));
22820Sstevel@tonic-gate
22830Sstevel@tonic-gate return (RSM_SUCCESS);
22840Sstevel@tonic-gate }
22850Sstevel@tonic-gate
22860Sstevel@tonic-gate int
rsm_memseg_import_unmap(rsm_memseg_import_handle_t im_memseg)2287*6812Sraf rsm_memseg_import_unmap(rsm_memseg_import_handle_t im_memseg)
22880Sstevel@tonic-gate {
22890Sstevel@tonic-gate /*
22900Sstevel@tonic-gate * Until we fix the rsm driver to catch unload, we unload
22910Sstevel@tonic-gate * the whole segment.
22920Sstevel@tonic-gate */
22930Sstevel@tonic-gate
22940Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
22950Sstevel@tonic-gate
22960Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
22970Sstevel@tonic-gate "rsm_memseg_import_unmap: enter\n"));
22980Sstevel@tonic-gate
22990Sstevel@tonic-gate if (!seg) {
23000Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23010Sstevel@tonic-gate "invalid segment or segment state\n"));
23020Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
23030Sstevel@tonic-gate }
23040Sstevel@tonic-gate
23050Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
23060Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_MAP) {
23070Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
23080Sstevel@tonic-gate return (RSMERR_SEG_NOT_MAPPED);
23090Sstevel@tonic-gate }
23100Sstevel@tonic-gate
23110Sstevel@tonic-gate seg->rsmseg_mapoffset = 0; /* reset the offset */
23120Sstevel@tonic-gate seg->rsmseg_state = IMPORT_CONNECT;
23130Sstevel@tonic-gate seg->rsmseg_flags &= ~RSM_IMPLICIT_MAP;
23140Sstevel@tonic-gate (void) munmap(seg->rsmseg_vaddr, seg->rsmseg_maplen);
23150Sstevel@tonic-gate
23160Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
23170Sstevel@tonic-gate
23180Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23190Sstevel@tonic-gate "rsm_memseg_import_unmap: exit\n"));
23200Sstevel@tonic-gate
23210Sstevel@tonic-gate return (RSM_SUCCESS);
23220Sstevel@tonic-gate }
23230Sstevel@tonic-gate
23240Sstevel@tonic-gate
23250Sstevel@tonic-gate /*
23260Sstevel@tonic-gate * import side memory segment operations (barriers):
23270Sstevel@tonic-gate */
23280Sstevel@tonic-gate int
rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,rsm_barrier_type_t type,rsmapi_barrier_t * barrier)2329*6812Sraf rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,
23300Sstevel@tonic-gate rsm_barrier_type_t type,
23310Sstevel@tonic-gate rsmapi_barrier_t *barrier)
23320Sstevel@tonic-gate {
23330Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
23340Sstevel@tonic-gate rsmbar_handle_t *bar;
23350Sstevel@tonic-gate
23360Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23370Sstevel@tonic-gate "rsm_memseg_import_init_barrier: enter\n"));
23380Sstevel@tonic-gate
23390Sstevel@tonic-gate if (!seg) {
23400Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23410Sstevel@tonic-gate "invalid segment or barrier\n"));
23420Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
23430Sstevel@tonic-gate }
23440Sstevel@tonic-gate if (!barrier) {
23450Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23460Sstevel@tonic-gate "invalid barrier pointer\n"));
23470Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
23480Sstevel@tonic-gate }
23490Sstevel@tonic-gate
23500Sstevel@tonic-gate bar = (rsmbar_handle_t *)barrier;
23510Sstevel@tonic-gate bar->rsmbar_seg = seg;
23520Sstevel@tonic-gate
23530Sstevel@tonic-gate seg->rsmseg_barrier = barrier; /* used in put/get fns */
23540Sstevel@tonic-gate
23550Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23560Sstevel@tonic-gate "rsm_memseg_import_init_barrier: exit\n"));
23570Sstevel@tonic-gate
23580Sstevel@tonic-gate return (seg->rsmseg_ops->rsm_memseg_import_init_barrier(im_memseg,
23590Sstevel@tonic-gate type, (rsm_barrier_handle_t)barrier));
23600Sstevel@tonic-gate }
23610Sstevel@tonic-gate
23620Sstevel@tonic-gate int
rsm_memseg_import_open_barrier(rsmapi_barrier_t * barrier)2363*6812Sraf rsm_memseg_import_open_barrier(rsmapi_barrier_t *barrier)
23640Sstevel@tonic-gate {
23650Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
23660Sstevel@tonic-gate rsm_segops_t *ops;
23670Sstevel@tonic-gate
23680Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23690Sstevel@tonic-gate "rsm_memseg_import_open_barrier: enter\n"));
23700Sstevel@tonic-gate
23710Sstevel@tonic-gate if (!bar) {
23720Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23730Sstevel@tonic-gate "invalid barrier\n"));
23740Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
23750Sstevel@tonic-gate }
23760Sstevel@tonic-gate if (!bar->rsmbar_seg) {
23770Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23780Sstevel@tonic-gate "uninitialized barrier\n"));
23790Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
23800Sstevel@tonic-gate }
23810Sstevel@tonic-gate
23820Sstevel@tonic-gate /* generation number snapshot */
23830Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum; /* bar[0] */
23840Sstevel@tonic-gate
23850Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
23860Sstevel@tonic-gate
23870Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23880Sstevel@tonic-gate "rsm_memseg_import_open_barrier: exit\n"));
23890Sstevel@tonic-gate
23900Sstevel@tonic-gate return (ops->rsm_memseg_import_open_barrier(
23910Sstevel@tonic-gate (rsm_barrier_handle_t)barrier));
23920Sstevel@tonic-gate }
23930Sstevel@tonic-gate
23940Sstevel@tonic-gate int
rsm_memseg_import_order_barrier(rsmapi_barrier_t * barrier)2395*6812Sraf rsm_memseg_import_order_barrier(rsmapi_barrier_t *barrier)
23960Sstevel@tonic-gate {
23970Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
23980Sstevel@tonic-gate rsm_segops_t *ops;
23990Sstevel@tonic-gate
24000Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24010Sstevel@tonic-gate "rsm_memseg_import_order_barrier: enter\n"));
24020Sstevel@tonic-gate
24030Sstevel@tonic-gate if (!bar) {
24040Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24050Sstevel@tonic-gate "invalid barrier\n"));
24060Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
24070Sstevel@tonic-gate }
24080Sstevel@tonic-gate if (!bar->rsmbar_seg) {
24090Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24100Sstevel@tonic-gate "uninitialized barrier\n"));
24110Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
24120Sstevel@tonic-gate }
24130Sstevel@tonic-gate
24140Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
24150Sstevel@tonic-gate
24160Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24170Sstevel@tonic-gate "rsm_memseg_import_order_barrier: exit\n"));
24180Sstevel@tonic-gate
24190Sstevel@tonic-gate return (ops->rsm_memseg_import_order_barrier(
24200Sstevel@tonic-gate (rsm_barrier_handle_t)barrier));
24210Sstevel@tonic-gate }
24220Sstevel@tonic-gate
24230Sstevel@tonic-gate int
rsm_memseg_import_close_barrier(rsmapi_barrier_t * barrier)2424*6812Sraf rsm_memseg_import_close_barrier(rsmapi_barrier_t *barrier)
24250Sstevel@tonic-gate {
24260Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
24270Sstevel@tonic-gate rsm_segops_t *ops;
24280Sstevel@tonic-gate
24290Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24300Sstevel@tonic-gate "rsm_memseg_import_close_barrier: enter\n"));
24310Sstevel@tonic-gate
24320Sstevel@tonic-gate if (!bar) {
24330Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24340Sstevel@tonic-gate "invalid barrier\n"));
24350Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
24360Sstevel@tonic-gate }
24370Sstevel@tonic-gate if (!bar->rsmbar_seg) {
24380Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24390Sstevel@tonic-gate "uninitialized barrier\n"));
24400Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
24410Sstevel@tonic-gate }
24420Sstevel@tonic-gate
24430Sstevel@tonic-gate /* generation number snapshot */
24440Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
24450Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
24460Sstevel@tonic-gate }
24470Sstevel@tonic-gate
24480Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
24490Sstevel@tonic-gate
24500Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24510Sstevel@tonic-gate "rsm_memseg_import_close_barrier: exit\n"));
24520Sstevel@tonic-gate
24530Sstevel@tonic-gate return (ops->rsm_memseg_import_close_barrier(
24540Sstevel@tonic-gate (rsm_barrier_handle_t)barrier));
24550Sstevel@tonic-gate }
24560Sstevel@tonic-gate
24570Sstevel@tonic-gate int
rsm_memseg_import_destroy_barrier(rsmapi_barrier_t * barrier)2458*6812Sraf rsm_memseg_import_destroy_barrier(rsmapi_barrier_t *barrier)
24590Sstevel@tonic-gate {
24600Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
24610Sstevel@tonic-gate rsm_segops_t *ops;
24620Sstevel@tonic-gate
24630Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24640Sstevel@tonic-gate "rsm_memseg_import_destroy_barrier: enter\n"));
24650Sstevel@tonic-gate
24660Sstevel@tonic-gate if (!bar) {
24670Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24680Sstevel@tonic-gate "invalid barrier\n"));
24690Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
24700Sstevel@tonic-gate }
24710Sstevel@tonic-gate if (!bar->rsmbar_seg) {
24720Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24730Sstevel@tonic-gate "uninitialized barrier\n"));
24740Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
24750Sstevel@tonic-gate }
24760Sstevel@tonic-gate
24770Sstevel@tonic-gate bar->rsmbar_seg->rsmseg_barrier = NULL;
24780Sstevel@tonic-gate
24790Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
24800Sstevel@tonic-gate
24810Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24820Sstevel@tonic-gate "rsm_memseg_import_destroy_barrier: exit\n"));
24830Sstevel@tonic-gate
24840Sstevel@tonic-gate return (ops->rsm_memseg_import_destroy_barrier
24850Sstevel@tonic-gate ((rsm_barrier_handle_t)barrier));
24860Sstevel@tonic-gate }
24870Sstevel@tonic-gate
24880Sstevel@tonic-gate int
rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t * mode)2489*6812Sraf rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,
24900Sstevel@tonic-gate rsm_barrier_mode_t *mode)
24910Sstevel@tonic-gate {
24920Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
24930Sstevel@tonic-gate
24940Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24950Sstevel@tonic-gate "rsm_memseg_import_get_mode: enter\n"));
24960Sstevel@tonic-gate
24970Sstevel@tonic-gate if (seg) {
24980Sstevel@tonic-gate *mode = seg->rsmseg_barmode;
24990Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25000Sstevel@tonic-gate "rsm_memseg_import_get_mode: exit\n"));
25010Sstevel@tonic-gate
25020Sstevel@tonic-gate return (seg->rsmseg_ops->rsm_memseg_import_get_mode(im_memseg,
25030Sstevel@tonic-gate mode));
25040Sstevel@tonic-gate }
25050Sstevel@tonic-gate
25060Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
25070Sstevel@tonic-gate "invalid arguments \n"));
25080Sstevel@tonic-gate
25090Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25100Sstevel@tonic-gate
25110Sstevel@tonic-gate }
25120Sstevel@tonic-gate
25130Sstevel@tonic-gate int
rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t mode)2514*6812Sraf rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,
25150Sstevel@tonic-gate rsm_barrier_mode_t mode)
25160Sstevel@tonic-gate {
25170Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
25180Sstevel@tonic-gate
25190Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25200Sstevel@tonic-gate "rsm_memseg_import_set_mode: enter\n"));
25210Sstevel@tonic-gate if (seg) {
25220Sstevel@tonic-gate if ((mode == RSM_BARRIER_MODE_IMPLICIT ||
25230Sstevel@tonic-gate mode == RSM_BARRIER_MODE_EXPLICIT)) {
25240Sstevel@tonic-gate seg->rsmseg_barmode = mode;
25250Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25260Sstevel@tonic-gate "rsm_memseg_import_set_mode: exit\n"));
25270Sstevel@tonic-gate
25280Sstevel@tonic-gate return (seg->rsmseg_ops->rsm_memseg_import_set_mode(
25290Sstevel@tonic-gate im_memseg,
25300Sstevel@tonic-gate mode));
25310Sstevel@tonic-gate } else {
25320Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25330Sstevel@tonic-gate "bad barrier mode\n"));
25340Sstevel@tonic-gate return (RSMERR_BAD_MODE);
25350Sstevel@tonic-gate }
25360Sstevel@tonic-gate }
25370Sstevel@tonic-gate
25380Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
25390Sstevel@tonic-gate "invalid arguments\n"));
25400Sstevel@tonic-gate
25410Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25420Sstevel@tonic-gate }
25430Sstevel@tonic-gate
25440Sstevel@tonic-gate int
rsm_intr_signal_post(void * memseg,uint_t flags)2545*6812Sraf rsm_intr_signal_post(void *memseg, uint_t flags)
25460Sstevel@tonic-gate {
25470Sstevel@tonic-gate rsm_ioctlmsg_t msg;
25480Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
25490Sstevel@tonic-gate
25500Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
25510Sstevel@tonic-gate "rsm_intr_signal_post: enter\n"));
25520Sstevel@tonic-gate
25530Sstevel@tonic-gate flags = flags;
25540Sstevel@tonic-gate
25550Sstevel@tonic-gate if (!seg) {
25560Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
25570Sstevel@tonic-gate "invalid segment handle\n"));
25580Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25590Sstevel@tonic-gate }
25600Sstevel@tonic-gate
25610Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_RING_BELL, &msg) < 0) {
25620Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
25630Sstevel@tonic-gate "RSM_IOCTL_RING_BELL failed\n"));
25640Sstevel@tonic-gate return (errno);
25650Sstevel@tonic-gate }
25660Sstevel@tonic-gate
25670Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
25680Sstevel@tonic-gate "rsm_intr_signal_post: exit\n"));
25690Sstevel@tonic-gate
25700Sstevel@tonic-gate return (RSM_SUCCESS);
25710Sstevel@tonic-gate }
25720Sstevel@tonic-gate
25730Sstevel@tonic-gate int
rsm_intr_signal_wait(void * memseg,int timeout)2574*6812Sraf rsm_intr_signal_wait(void *memseg, int timeout)
25750Sstevel@tonic-gate {
25760Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
25770Sstevel@tonic-gate struct pollfd fds;
25780Sstevel@tonic-gate minor_t rnum;
25790Sstevel@tonic-gate
25800Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
25810Sstevel@tonic-gate "rsm_intr_signal_wait: enter\n"));
25820Sstevel@tonic-gate
25830Sstevel@tonic-gate if (!seg) {
25840Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
25850Sstevel@tonic-gate "invalid segment\n"));
25860Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25870Sstevel@tonic-gate }
25880Sstevel@tonic-gate
25890Sstevel@tonic-gate fds.fd = seg->rsmseg_fd;
25900Sstevel@tonic-gate fds.events = POLLRDNORM;
25910Sstevel@tonic-gate
25920Sstevel@tonic-gate rnum = seg->rsmseg_rnum;
25930Sstevel@tonic-gate
25940Sstevel@tonic-gate return (__rsm_intr_signal_wait_common(&fds, &rnum, 1, timeout, NULL));
25950Sstevel@tonic-gate }
25960Sstevel@tonic-gate
25970Sstevel@tonic-gate int
rsm_intr_signal_wait_pollfd(struct pollfd fds[],nfds_t nfds,int timeout,int * numfdsp)2598*6812Sraf rsm_intr_signal_wait_pollfd(struct pollfd fds[], nfds_t nfds, int timeout,
25990Sstevel@tonic-gate int *numfdsp)
26000Sstevel@tonic-gate {
26010Sstevel@tonic-gate return (__rsm_intr_signal_wait_common(fds, NULL, nfds, timeout,
26020Sstevel@tonic-gate numfdsp));
26030Sstevel@tonic-gate }
26040Sstevel@tonic-gate
26050Sstevel@tonic-gate /*
26060Sstevel@tonic-gate * This is the generic wait routine, it takes the following arguments
26070Sstevel@tonic-gate * - pollfd array
26080Sstevel@tonic-gate * - rnums array corresponding to the pollfd if known, if this is
26090Sstevel@tonic-gate * NULL then the fds are looked up from the pollfd_table.
26100Sstevel@tonic-gate * - number of fds in pollfd array,
26110Sstevel@tonic-gate * - timeout
26120Sstevel@tonic-gate * - pointer to a location where the number of fds with successful
26130Sstevel@tonic-gate * events is returned.
26140Sstevel@tonic-gate */
26150Sstevel@tonic-gate static int
__rsm_intr_signal_wait_common(struct pollfd fds[],minor_t rnums[],nfds_t nfds,int timeout,int * numfdsp)26160Sstevel@tonic-gate __rsm_intr_signal_wait_common(struct pollfd fds[], minor_t rnums[],
26170Sstevel@tonic-gate nfds_t nfds, int timeout, int *numfdsp)
26180Sstevel@tonic-gate {
26190Sstevel@tonic-gate int i;
26200Sstevel@tonic-gate int numsegs = 0;
26210Sstevel@tonic-gate int numfd;
26220Sstevel@tonic-gate int fds_processed = 0;
26230Sstevel@tonic-gate minor_t segrnum;
26240Sstevel@tonic-gate rsm_poll_event_t event_arr[RSM_MAX_POLLFDS];
26250Sstevel@tonic-gate rsm_poll_event_t *event_list = NULL;
26260Sstevel@tonic-gate rsm_poll_event_t *events;
26270Sstevel@tonic-gate rsm_consume_event_msg_t msg;
26280Sstevel@tonic-gate
26290Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE, "wait_common enter\n"));
26300Sstevel@tonic-gate
26310Sstevel@tonic-gate if (numfdsp) {
26320Sstevel@tonic-gate *numfdsp = 0;
26330Sstevel@tonic-gate }
26340Sstevel@tonic-gate
26350Sstevel@tonic-gate numfd = poll(fds, nfds, timeout);
26360Sstevel@tonic-gate
26370Sstevel@tonic-gate switch (numfd) {
26380Sstevel@tonic-gate case -1: /* poll returned error - map to RSMERR_... */
26390Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR, "signal wait pollfd err\n"));
26400Sstevel@tonic-gate switch (errno) {
26410Sstevel@tonic-gate case EAGAIN:
26420Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
26430Sstevel@tonic-gate case EFAULT:
26440Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
26450Sstevel@tonic-gate case EINTR:
26460Sstevel@tonic-gate return (RSMERR_INTERRUPTED);
26470Sstevel@tonic-gate case EINVAL:
26480Sstevel@tonic-gate default:
26490Sstevel@tonic-gate return (RSMERR_BAD_ARGS_ERRORS);
26500Sstevel@tonic-gate }
26510Sstevel@tonic-gate case 0: /* timedout - return from here */
26520Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
26530Sstevel@tonic-gate "signal wait timed out\n"));
26540Sstevel@tonic-gate return (RSMERR_TIMEOUT);
26550Sstevel@tonic-gate default:
26560Sstevel@tonic-gate break;
26570Sstevel@tonic-gate }
26580Sstevel@tonic-gate
26590Sstevel@tonic-gate if (numfd <= RSM_MAX_POLLFDS) {
26600Sstevel@tonic-gate /* use the event array on the stack */
26610Sstevel@tonic-gate events = (rsm_poll_event_t *)event_arr;
26620Sstevel@tonic-gate } else {
26630Sstevel@tonic-gate /*
26640Sstevel@tonic-gate * actual number of fds corresponding to rsmapi segments might
26650Sstevel@tonic-gate * be < numfd, don't want to scan the list to figure that out
26660Sstevel@tonic-gate * lets just allocate on the heap
26670Sstevel@tonic-gate */
26680Sstevel@tonic-gate event_list = (rsm_poll_event_t *)malloc(
2669*6812Sraf sizeof (rsm_poll_event_t)*numfd);
26700Sstevel@tonic-gate if (!event_list) {
26710Sstevel@tonic-gate /*
26720Sstevel@tonic-gate * return with error even if poll might have succeeded
26730Sstevel@tonic-gate * since the application can retry and the events will
26740Sstevel@tonic-gate * still be available.
26750Sstevel@tonic-gate */
26760Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
26770Sstevel@tonic-gate }
26780Sstevel@tonic-gate events = event_list;
26790Sstevel@tonic-gate }
26800Sstevel@tonic-gate
26810Sstevel@tonic-gate /*
26820Sstevel@tonic-gate * process the fds for events and if it corresponds to an rsmapi
26830Sstevel@tonic-gate * segment consume the event
26840Sstevel@tonic-gate */
26850Sstevel@tonic-gate for (i = 0; i < nfds; i++) {
26860Sstevel@tonic-gate if (fds[i].revents == POLLRDNORM) {
26870Sstevel@tonic-gate /*
26880Sstevel@tonic-gate * poll returned an event and if its POLLRDNORM, it
26890Sstevel@tonic-gate * might correspond to an rsmapi segment
26900Sstevel@tonic-gate */
26910Sstevel@tonic-gate if (rnums) { /* resource num is passed in */
26920Sstevel@tonic-gate segrnum = rnums[i];
26930Sstevel@tonic-gate } else { /* lookup pollfd table to get resource num */
26940Sstevel@tonic-gate segrnum = _rsm_lookup_pollfd_table(fds[i].fd);
26950Sstevel@tonic-gate }
26960Sstevel@tonic-gate if (segrnum) {
26970Sstevel@tonic-gate events[numsegs].rnum = segrnum;
26980Sstevel@tonic-gate events[numsegs].revent = 0;
26990Sstevel@tonic-gate events[numsegs].fdsidx = i; /* fdlist index */
27000Sstevel@tonic-gate numsegs++;
27010Sstevel@tonic-gate }
27020Sstevel@tonic-gate }
27030Sstevel@tonic-gate
27040Sstevel@tonic-gate if ((fds[i].revents) && (++fds_processed == numfd)) {
27050Sstevel@tonic-gate /*
27060Sstevel@tonic-gate * only "numfd" events have revents field set, once we
27070Sstevel@tonic-gate * process that many break out of the loop
27080Sstevel@tonic-gate */
27090Sstevel@tonic-gate break;
27100Sstevel@tonic-gate }
27110Sstevel@tonic-gate }
27120Sstevel@tonic-gate
27130Sstevel@tonic-gate if (numsegs == 0) { /* No events for rsmapi segs in the fdlist */
27140Sstevel@tonic-gate if (event_list) {
27150Sstevel@tonic-gate free(event_list);
27160Sstevel@tonic-gate }
27170Sstevel@tonic-gate if (numfdsp) {
27180Sstevel@tonic-gate *numfdsp = numfd;
27190Sstevel@tonic-gate }
27200Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27210Sstevel@tonic-gate "wait_common exit: no rsmapi segs\n"));
27220Sstevel@tonic-gate return (RSM_SUCCESS);
27230Sstevel@tonic-gate }
27240Sstevel@tonic-gate
27250Sstevel@tonic-gate msg.seglist = (caddr_t)events;
27260Sstevel@tonic-gate msg.numents = numsegs;
27270Sstevel@tonic-gate
27280Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_CONSUMEEVENT, &msg) < 0) {
27290Sstevel@tonic-gate int error = errno;
27300Sstevel@tonic-gate if (event_list) {
27310Sstevel@tonic-gate free(event_list);
27320Sstevel@tonic-gate }
27330Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_ERR,
27340Sstevel@tonic-gate "RSM_IOCTL_CONSUMEEVENT failed(%d)\n", error));
27350Sstevel@tonic-gate return (error);
27360Sstevel@tonic-gate }
27370Sstevel@tonic-gate
27380Sstevel@tonic-gate /* count the number of segs for which consumeevent was successful */
27390Sstevel@tonic-gate numfd -= numsegs;
27400Sstevel@tonic-gate
27410Sstevel@tonic-gate for (i = 0; i < numsegs; i++) {
27420Sstevel@tonic-gate if (events[i].revent != 0) {
27430Sstevel@tonic-gate fds[events[i].fdsidx].revents = POLLRDNORM;
27440Sstevel@tonic-gate numfd++;
27450Sstevel@tonic-gate } else { /* failed to consume event so set revents to 0 */
27460Sstevel@tonic-gate fds[events[i].fdsidx].revents = 0;
27470Sstevel@tonic-gate }
27480Sstevel@tonic-gate }
27490Sstevel@tonic-gate
27500Sstevel@tonic-gate if (event_list) {
27510Sstevel@tonic-gate free(event_list);
27520Sstevel@tonic-gate }
27530Sstevel@tonic-gate
27540Sstevel@tonic-gate if (numfd > 0) {
27550Sstevel@tonic-gate if (numfdsp) {
27560Sstevel@tonic-gate *numfdsp = numfd;
27570Sstevel@tonic-gate }
27580Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27590Sstevel@tonic-gate "wait_common exit\n"));
27600Sstevel@tonic-gate return (RSM_SUCCESS);
27610Sstevel@tonic-gate } else {
27620Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27630Sstevel@tonic-gate "wait_common exit\n"));
27640Sstevel@tonic-gate return (RSMERR_TIMEOUT);
27650Sstevel@tonic-gate }
27660Sstevel@tonic-gate }
27670Sstevel@tonic-gate
27680Sstevel@tonic-gate /*
27690Sstevel@tonic-gate * This function provides the data (file descriptor and event) for
27700Sstevel@tonic-gate * the specified pollfd struct. The pollfd struct may then be
27710Sstevel@tonic-gate * subsequently used with the poll system call to wait for an event
27720Sstevel@tonic-gate * signalled by rsm_intr_signal_post. The memory segment must be
27730Sstevel@tonic-gate * currently published for a successful return with a valid pollfd.
27740Sstevel@tonic-gate * A reference count for the descriptor is incremented.
27750Sstevel@tonic-gate */
27760Sstevel@tonic-gate int
rsm_memseg_get_pollfd(void * memseg,struct pollfd * poll_fd)2777*6812Sraf rsm_memseg_get_pollfd(void *memseg,
27780Sstevel@tonic-gate struct pollfd *poll_fd)
27790Sstevel@tonic-gate {
27800Sstevel@tonic-gate int i;
27810Sstevel@tonic-gate int err = RSM_SUCCESS;
27820Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
27830Sstevel@tonic-gate
27840Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27850Sstevel@tonic-gate "rsm_memseg_get_pollfd: enter\n"));
27860Sstevel@tonic-gate
27870Sstevel@tonic-gate if (!seg) {
27880Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
27890Sstevel@tonic-gate "invalid segment\n"));
27900Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
27910Sstevel@tonic-gate }
27920Sstevel@tonic-gate
27930Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
27940Sstevel@tonic-gate
27950Sstevel@tonic-gate poll_fd->fd = seg->rsmseg_fd;
27960Sstevel@tonic-gate poll_fd->events = POLLRDNORM;
27970Sstevel@tonic-gate seg->rsmseg_pollfd_refcnt++;
27980Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt == 1) {
27990Sstevel@tonic-gate /* insert the segment into the pollfd table */
28000Sstevel@tonic-gate err = _rsm_insert_pollfd_table(seg->rsmseg_fd,
28010Sstevel@tonic-gate seg->rsmseg_rnum);
28020Sstevel@tonic-gate }
28030Sstevel@tonic-gate
28040Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
28050Sstevel@tonic-gate
28060Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28070Sstevel@tonic-gate "rsm_memseg_get_pollfd: exit(%d)\n", err));
28080Sstevel@tonic-gate
28090Sstevel@tonic-gate return (err);
28100Sstevel@tonic-gate }
28110Sstevel@tonic-gate
28120Sstevel@tonic-gate /*
28130Sstevel@tonic-gate * This function decrements the segment pollfd reference count.
28140Sstevel@tonic-gate * A segment unpublish or destroy operation will fail if the reference count is
28150Sstevel@tonic-gate * non zero.
28160Sstevel@tonic-gate */
28170Sstevel@tonic-gate int
rsm_memseg_release_pollfd(void * memseg)2818*6812Sraf rsm_memseg_release_pollfd(void * memseg)
28190Sstevel@tonic-gate {
28200Sstevel@tonic-gate int i;
28210Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
28220Sstevel@tonic-gate
28230Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28240Sstevel@tonic-gate "rsm_memseg_release_pollfd: enter\n"));
28250Sstevel@tonic-gate
28260Sstevel@tonic-gate if (!seg) {
28270Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
28280Sstevel@tonic-gate "invalid segment handle\n"));
28290Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
28300Sstevel@tonic-gate }
28310Sstevel@tonic-gate
28320Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
28330Sstevel@tonic-gate
28340Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt) {
28350Sstevel@tonic-gate seg->rsmseg_pollfd_refcnt--;
28360Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt == 0) {
28370Sstevel@tonic-gate /* last reference removed - update the pollfd_table */
28380Sstevel@tonic-gate _rsm_remove_pollfd_table(seg->rsmseg_fd);
28390Sstevel@tonic-gate }
28400Sstevel@tonic-gate }
28410Sstevel@tonic-gate
28420Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
28430Sstevel@tonic-gate
28440Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28450Sstevel@tonic-gate "rsm_memseg_release_pollfd: exit\n"));
28460Sstevel@tonic-gate
28470Sstevel@tonic-gate return (RSM_SUCCESS);
28480Sstevel@tonic-gate }
28490Sstevel@tonic-gate
28500Sstevel@tonic-gate /*
28510Sstevel@tonic-gate * The interconnect topology data is obtained from the Kernel Agent
28520Sstevel@tonic-gate * and stored in a memory buffer allocated by this function. A pointer
28530Sstevel@tonic-gate * to the buffer is stored in the location specified by the caller in
28540Sstevel@tonic-gate * the function argument. It is the callers responsibility to
28550Sstevel@tonic-gate * call rsm_free_interconnect_topolgy() to free the allocated memory.
28560Sstevel@tonic-gate */
28570Sstevel@tonic-gate int
rsm_get_interconnect_topology(rsm_topology_t ** topology_data)2858*6812Sraf rsm_get_interconnect_topology(rsm_topology_t **topology_data)
28590Sstevel@tonic-gate {
28600Sstevel@tonic-gate uint32_t topology_data_size;
28610Sstevel@tonic-gate rsm_topology_t *topology_ptr;
28620Sstevel@tonic-gate int error;
28630Sstevel@tonic-gate
28640Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28650Sstevel@tonic-gate "rsm_get_interconnect_topology: enter\n"));
28660Sstevel@tonic-gate
28670Sstevel@tonic-gate if (topology_data == NULL)
28680Sstevel@tonic-gate return (RSMERR_BAD_TOPOLOGY_PTR);
28690Sstevel@tonic-gate
28700Sstevel@tonic-gate *topology_data = NULL;
28710Sstevel@tonic-gate
28720Sstevel@tonic-gate again:
28730Sstevel@tonic-gate /* obtain the size of the topology data */
28740Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_TOPOLOGY_SIZE, &topology_data_size) < 0) {
28750Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
28760Sstevel@tonic-gate "RSM_IOCTL_TOPOLOGY_SIZE failed\n"));
28770Sstevel@tonic-gate return (errno);
28780Sstevel@tonic-gate }
28790Sstevel@tonic-gate
28800Sstevel@tonic-gate /* allocate double-word aligned memory to hold the topology data */
28810Sstevel@tonic-gate topology_ptr = (rsm_topology_t *)memalign(8, topology_data_size);
28820Sstevel@tonic-gate if (topology_ptr == NULL) {
28830Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
28840Sstevel@tonic-gate "not enough memory\n"));
28850Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
28860Sstevel@tonic-gate }
28870Sstevel@tonic-gate
28880Sstevel@tonic-gate /*
28890Sstevel@tonic-gate * Request the topology data.
28900Sstevel@tonic-gate * Pass in the size to be used as a check in case
28910Sstevel@tonic-gate * the data has grown since the size was obtained - if
28920Sstevel@tonic-gate * it has, the errno value will be E2BIG.
28930Sstevel@tonic-gate */
28940Sstevel@tonic-gate topology_ptr->topology_hdr.local_nodeid =
28950Sstevel@tonic-gate (rsm_node_id_t)topology_data_size;
28960Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_TOPOLOGY_DATA, topology_ptr) < 0) {
28970Sstevel@tonic-gate error = errno;
28980Sstevel@tonic-gate free((void *)topology_ptr);
28990Sstevel@tonic-gate if (error == E2BIG)
29000Sstevel@tonic-gate goto again;
29010Sstevel@tonic-gate else {
29020Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29030Sstevel@tonic-gate "RSM_IOCTL_TOPOLOGY_DATA failed\n"));
29040Sstevel@tonic-gate return (error);
29050Sstevel@tonic-gate }
29060Sstevel@tonic-gate } else
29070Sstevel@tonic-gate *topology_data = topology_ptr;
29080Sstevel@tonic-gate
29090Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29100Sstevel@tonic-gate " rsm_get_interconnect_topology: exit\n"));
29110Sstevel@tonic-gate
29120Sstevel@tonic-gate return (RSM_SUCCESS);
29130Sstevel@tonic-gate }
29140Sstevel@tonic-gate
29150Sstevel@tonic-gate
29160Sstevel@tonic-gate void
rsm_free_interconnect_topology(rsm_topology_t * topology_ptr)2917*6812Sraf rsm_free_interconnect_topology(rsm_topology_t *topology_ptr)
29180Sstevel@tonic-gate {
29190Sstevel@tonic-gate
29200Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29210Sstevel@tonic-gate "rsm_free_interconnect_topology: enter\n"));
29220Sstevel@tonic-gate
29230Sstevel@tonic-gate if (topology_ptr) {
29240Sstevel@tonic-gate free((void *)topology_ptr);
29250Sstevel@tonic-gate }
29260Sstevel@tonic-gate
29270Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29280Sstevel@tonic-gate "rsm_free_interconnect_topology: exit\n"));
29290Sstevel@tonic-gate }
29300Sstevel@tonic-gate
29310Sstevel@tonic-gate int
rsm_create_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,rsm_localmemory_handle_t * local_hndl_p,caddr_t local_vaddr,size_t len)2932*6812Sraf rsm_create_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,
29330Sstevel@tonic-gate rsm_localmemory_handle_t *local_hndl_p,
29340Sstevel@tonic-gate caddr_t local_vaddr, size_t len)
29350Sstevel@tonic-gate {
29360Sstevel@tonic-gate int e;
29370Sstevel@tonic-gate rsm_controller_t *cntrl = (rsm_controller_t *)cntrl_handle;
29380Sstevel@tonic-gate
29390Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29400Sstevel@tonic-gate "rsm_create_localmemory_handle: enter\n"));
29410Sstevel@tonic-gate
29420Sstevel@tonic-gate if ((size_t)local_vaddr & (PAGESIZE - 1)) {
29430Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29440Sstevel@tonic-gate "invalid arguments\n"));
29450Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
29460Sstevel@tonic-gate }
29470Sstevel@tonic-gate
29480Sstevel@tonic-gate if (!cntrl_handle) {
29490Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29500Sstevel@tonic-gate "invalid controller handle\n"));
29510Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
29520Sstevel@tonic-gate }
29530Sstevel@tonic-gate if (!local_hndl_p) {
29540Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29550Sstevel@tonic-gate "invalid local memory handle pointer\n"));
29560Sstevel@tonic-gate return (RSMERR_BAD_LOCALMEM_HNDL);
29570Sstevel@tonic-gate }
29580Sstevel@tonic-gate if (len == 0) {
29590Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29600Sstevel@tonic-gate "invalid length\n"));
29610Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
29620Sstevel@tonic-gate }
29630Sstevel@tonic-gate
29640Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_create_localmemory_handle(
29650Sstevel@tonic-gate cntrl_handle,
29660Sstevel@tonic-gate local_hndl_p,
29670Sstevel@tonic-gate local_vaddr,
29680Sstevel@tonic-gate len);
29690Sstevel@tonic-gate
29700Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29710Sstevel@tonic-gate "rsm_create_localmemory_handle: exit\n"));
29720Sstevel@tonic-gate
29730Sstevel@tonic-gate return (e);
29740Sstevel@tonic-gate }
29750Sstevel@tonic-gate
29760Sstevel@tonic-gate int
rsm_free_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,rsm_localmemory_handle_t local_handle)2977*6812Sraf rsm_free_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,
29780Sstevel@tonic-gate rsm_localmemory_handle_t local_handle)
29790Sstevel@tonic-gate {
29800Sstevel@tonic-gate int e;
29810Sstevel@tonic-gate
29820Sstevel@tonic-gate rsm_controller_t *cntrl = (rsm_controller_t *)cntrl_handle;
29830Sstevel@tonic-gate
29840Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29850Sstevel@tonic-gate "rsm_free_localmemory_handle: enter\n"));
29860Sstevel@tonic-gate
29870Sstevel@tonic-gate
29880Sstevel@tonic-gate if (!cntrl_handle) {
29890Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29900Sstevel@tonic-gate "invalid controller handle\n"));
29910Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
29920Sstevel@tonic-gate }
29930Sstevel@tonic-gate
29940Sstevel@tonic-gate if (!local_handle) {
29950Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29960Sstevel@tonic-gate "invalid localmemory handle\n"));
29970Sstevel@tonic-gate return (RSMERR_BAD_LOCALMEM_HNDL);
29980Sstevel@tonic-gate }
29990Sstevel@tonic-gate
30000Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_free_localmemory_handle(local_handle);
30010Sstevel@tonic-gate
30020Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
30030Sstevel@tonic-gate "rsm_free_localmemory_handle: exit\n"));
30040Sstevel@tonic-gate
30050Sstevel@tonic-gate return (e);
30060Sstevel@tonic-gate }
30070Sstevel@tonic-gate
30080Sstevel@tonic-gate int
rsm_get_segmentid_range(const char * appid,rsm_memseg_id_t * baseid,uint32_t * length)3009*6812Sraf rsm_get_segmentid_range(const char *appid, rsm_memseg_id_t *baseid,
30100Sstevel@tonic-gate uint32_t *length)
30110Sstevel@tonic-gate {
30120Sstevel@tonic-gate char buf[RSMFILE_BUFSIZE];
30130Sstevel@tonic-gate char *s;
30140Sstevel@tonic-gate char *fieldv[4];
30150Sstevel@tonic-gate int fieldc = 0;
30160Sstevel@tonic-gate int found = 0;
30170Sstevel@tonic-gate int err = RSMERR_BAD_APPID;
30180Sstevel@tonic-gate FILE *fp;
30190Sstevel@tonic-gate
30200Sstevel@tonic-gate if (appid == NULL || baseid == NULL || length == NULL)
30210Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
30220Sstevel@tonic-gate
30231914Scasper if ((fp = fopen(RSMSEGIDFILE, "rF")) == NULL) {
30240Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
30250Sstevel@tonic-gate "cannot open <%s>\n", RSMSEGIDFILE));
30260Sstevel@tonic-gate return (RSMERR_BAD_CONF);
30270Sstevel@tonic-gate }
30280Sstevel@tonic-gate
30290Sstevel@tonic-gate while (s = fgets(buf, RSMFILE_BUFSIZE, fp)) {
30300Sstevel@tonic-gate fieldc = 0;
30310Sstevel@tonic-gate while (isspace(*s)) /* skip the leading spaces */
30320Sstevel@tonic-gate s++;
30330Sstevel@tonic-gate
30340Sstevel@tonic-gate if (*s == '#') { /* comment line - skip it */
30350Sstevel@tonic-gate continue;
30360Sstevel@tonic-gate }
30370Sstevel@tonic-gate
30380Sstevel@tonic-gate /*
30390Sstevel@tonic-gate * parse the reserved segid file and
30400Sstevel@tonic-gate * set the pointers appropriately.
30410Sstevel@tonic-gate * fieldv[0] : keyword
30420Sstevel@tonic-gate * fieldv[1] : application identifier
30430Sstevel@tonic-gate * fieldv[2] : baseid
30440Sstevel@tonic-gate * fieldv[3] : length
30450Sstevel@tonic-gate */
30460Sstevel@tonic-gate while ((*s != '\n') && (*s != '\0') && (fieldc < 4)) {
30470Sstevel@tonic-gate
30480Sstevel@tonic-gate while (isspace(*s)) /* skip the leading spaces */
30490Sstevel@tonic-gate s++;
30500Sstevel@tonic-gate
30510Sstevel@tonic-gate fieldv[fieldc++] = s;
30520Sstevel@tonic-gate
30530Sstevel@tonic-gate if (fieldc == 4) {
30540Sstevel@tonic-gate if (fieldv[3][strlen(fieldv[3])-1] == '\n')
30550Sstevel@tonic-gate fieldv[3][strlen(fieldv[3])-1] = '\0';
30560Sstevel@tonic-gate break;
30570Sstevel@tonic-gate }
30580Sstevel@tonic-gate
30590Sstevel@tonic-gate while (*s && !isspace(*s))
30600Sstevel@tonic-gate ++s; /* move to the next white space */
30610Sstevel@tonic-gate
30620Sstevel@tonic-gate if (*s)
30630Sstevel@tonic-gate *s++ = '\0';
30640Sstevel@tonic-gate }
30650Sstevel@tonic-gate
30660Sstevel@tonic-gate if (fieldc < 4) { /* some fields are missing */
30670Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30680Sstevel@tonic-gate break;
30690Sstevel@tonic-gate }
30700Sstevel@tonic-gate
30710Sstevel@tonic-gate if (strcasecmp(fieldv[1], appid) == 0) { /* found a match */
30720Sstevel@tonic-gate if (strcasecmp(fieldv[0], RSMSEG_RESERVED) == 0) {
30730Sstevel@tonic-gate errno = 0;
30740Sstevel@tonic-gate *baseid = strtol(fieldv[2], (char **)NULL, 16);
30750Sstevel@tonic-gate if (errno != 0) {
30760Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30770Sstevel@tonic-gate break;
30780Sstevel@tonic-gate }
30790Sstevel@tonic-gate
30800Sstevel@tonic-gate errno = 0;
30810Sstevel@tonic-gate *length = (int)strtol(fieldv[3],
30820Sstevel@tonic-gate (char **)NULL, 10);
30830Sstevel@tonic-gate if (errno != 0) {
30840Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30850Sstevel@tonic-gate break;
30860Sstevel@tonic-gate }
30870Sstevel@tonic-gate
30880Sstevel@tonic-gate found = 1;
30890Sstevel@tonic-gate } else { /* error in format */
30900Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30910Sstevel@tonic-gate }
30920Sstevel@tonic-gate break;
30930Sstevel@tonic-gate }
30940Sstevel@tonic-gate }
30950Sstevel@tonic-gate
30960Sstevel@tonic-gate (void) fclose(fp);
30970Sstevel@tonic-gate
30980Sstevel@tonic-gate if (found)
30990Sstevel@tonic-gate return (RSM_SUCCESS);
31000Sstevel@tonic-gate
31010Sstevel@tonic-gate return (err);
31020Sstevel@tonic-gate }
31030Sstevel@tonic-gate
31040Sstevel@tonic-gate static int
_rsm_get_hwaddr(rsmapi_controller_handle_t handle,rsm_node_id_t nodeid,rsm_addr_t * hwaddrp)31050Sstevel@tonic-gate _rsm_get_hwaddr(rsmapi_controller_handle_t handle, rsm_node_id_t nodeid,
31060Sstevel@tonic-gate rsm_addr_t *hwaddrp)
31070Sstevel@tonic-gate {
31080Sstevel@tonic-gate rsm_ioctlmsg_t msg = {0};
31090Sstevel@tonic-gate rsm_controller_t *ctrlp;
31100Sstevel@tonic-gate
31110Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31120Sstevel@tonic-gate "_rsm_get_hwaddr: enter\n"));
31130Sstevel@tonic-gate
31140Sstevel@tonic-gate ctrlp = (rsm_controller_t *)handle;
31150Sstevel@tonic-gate
31160Sstevel@tonic-gate if (ctrlp == NULL) {
31170Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31180Sstevel@tonic-gate "invalid controller handle\n"));
31190Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
31200Sstevel@tonic-gate }
31210Sstevel@tonic-gate
31220Sstevel@tonic-gate msg.cname = ctrlp->cntr_name;
31230Sstevel@tonic-gate msg.cname_len = strlen(ctrlp->cntr_name) +1;
31240Sstevel@tonic-gate msg.cnum = ctrlp->cntr_unit;
31250Sstevel@tonic-gate msg.nodeid = nodeid;
31260Sstevel@tonic-gate
31270Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_MAP_TO_ADDR, &msg) < 0) {
31280Sstevel@tonic-gate int error = errno;
31290Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31300Sstevel@tonic-gate "RSM_IOCTL_MAP_TO_ADDR failed\n"));
31310Sstevel@tonic-gate return (error);
31320Sstevel@tonic-gate }
31330Sstevel@tonic-gate
31340Sstevel@tonic-gate *hwaddrp = msg.hwaddr;
31350Sstevel@tonic-gate
31360Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31370Sstevel@tonic-gate "_rsm_get_hwaddr: exit\n"));
31380Sstevel@tonic-gate
31390Sstevel@tonic-gate return (RSM_SUCCESS);
31400Sstevel@tonic-gate
31410Sstevel@tonic-gate }
31420Sstevel@tonic-gate
31430Sstevel@tonic-gate static int
_rsm_get_nodeid(rsmapi_controller_handle_t handle,rsm_addr_t hwaddr,rsm_node_id_t * nodeidp)31440Sstevel@tonic-gate _rsm_get_nodeid(rsmapi_controller_handle_t handle, rsm_addr_t hwaddr,
31450Sstevel@tonic-gate rsm_node_id_t *nodeidp)
31460Sstevel@tonic-gate {
31470Sstevel@tonic-gate
31480Sstevel@tonic-gate rsm_ioctlmsg_t msg = {0};
31490Sstevel@tonic-gate rsm_controller_t *ctrlp;
31500Sstevel@tonic-gate
31510Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31520Sstevel@tonic-gate "_rsm_get_nodeid: enter\n"));
31530Sstevel@tonic-gate
31540Sstevel@tonic-gate ctrlp = (rsm_controller_t *)handle;
31550Sstevel@tonic-gate
31560Sstevel@tonic-gate if (ctrlp == NULL) {
31570Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31580Sstevel@tonic-gate "invalid arguments\n"));
31590Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
31600Sstevel@tonic-gate }
31610Sstevel@tonic-gate
31620Sstevel@tonic-gate msg.cname = ctrlp->cntr_name;
31630Sstevel@tonic-gate msg.cname_len = strlen(ctrlp->cntr_name) +1;
31640Sstevel@tonic-gate msg.cnum = ctrlp->cntr_unit;
31650Sstevel@tonic-gate msg.hwaddr = hwaddr;
31660Sstevel@tonic-gate
31670Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_MAP_TO_NODEID, &msg) < 0) {
31680Sstevel@tonic-gate int error = errno;
31690Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31700Sstevel@tonic-gate "RSM_IOCTL_MAP_TO_NODEID failed\n"));
31710Sstevel@tonic-gate return (error);
31720Sstevel@tonic-gate }
31730Sstevel@tonic-gate
31740Sstevel@tonic-gate *nodeidp = msg.nodeid;
31750Sstevel@tonic-gate
31760Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31770Sstevel@tonic-gate "_rsm_get_nodeid: exit\n"));
31780Sstevel@tonic-gate
31790Sstevel@tonic-gate return (RSM_SUCCESS);
31800Sstevel@tonic-gate
31810Sstevel@tonic-gate }
31820Sstevel@tonic-gate
31830Sstevel@tonic-gate #ifdef DEBUG
31840Sstevel@tonic-gate void
dbg_printf(int msg_category,int msg_level,char * fmt,...)31850Sstevel@tonic-gate dbg_printf(int msg_category, int msg_level, char *fmt, ...)
31860Sstevel@tonic-gate {
31870Sstevel@tonic-gate if ((msg_category & rsmlibdbg_category) &&
31880Sstevel@tonic-gate (msg_level <= rsmlibdbg_level)) {
31890Sstevel@tonic-gate va_list arg_list;
31900Sstevel@tonic-gate va_start(arg_list, fmt);
31910Sstevel@tonic-gate mutex_lock(&rsmlog_lock);
3192*6812Sraf fprintf(rsmlog_fd, "Thread %d ", thr_self());
31930Sstevel@tonic-gate vfprintf(rsmlog_fd, fmt, arg_list);
31940Sstevel@tonic-gate fflush(rsmlog_fd);
31950Sstevel@tonic-gate mutex_unlock(&rsmlog_lock);
31960Sstevel@tonic-gate va_end(arg_list);
31970Sstevel@tonic-gate }
31980Sstevel@tonic-gate }
31990Sstevel@tonic-gate #endif /* DEBUG */
3200