17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5004388ebScasper * Common Development and Distribution License (the "License").
6004388ebScasper * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21e8031f0aSraf
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <stdlib.h>
297c478bd9Sstevel@tonic-gate #include <unistd.h>
307c478bd9Sstevel@tonic-gate #include <stdarg.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include <strings.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/mman.h>
377c478bd9Sstevel@tonic-gate #include <sys/uio.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <sys/resource.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <assert.h>
427c478bd9Sstevel@tonic-gate #include <fcntl.h>
437c478bd9Sstevel@tonic-gate #include <dlfcn.h>
447c478bd9Sstevel@tonic-gate #include <sched.h>
457c478bd9Sstevel@tonic-gate #include <stropts.h>
467c478bd9Sstevel@tonic-gate #include <poll.h>
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate #include <rsmapi.h>
497c478bd9Sstevel@tonic-gate #include <sys/rsm/rsmndi.h>
507c478bd9Sstevel@tonic-gate #include <rsmlib_in.h>
517c478bd9Sstevel@tonic-gate #include <sys/rsm/rsm.h>
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate /* lint -w2 */
547c478bd9Sstevel@tonic-gate extern void __rsmloopback_init_ops(rsm_segops_t *);
557c478bd9Sstevel@tonic-gate extern void __rsmdefault_setops(rsm_segops_t *);
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate typedef void (*rsm_access_func_t)(void *, void *, rsm_access_size_t);
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate #ifdef DEBUG
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate #define RSMLOG_BUF_SIZE 256
627c478bd9Sstevel@tonic-gate FILE *rsmlog_fd = NULL;
637c478bd9Sstevel@tonic-gate static mutex_t rsmlog_lock;
647c478bd9Sstevel@tonic-gate int rsmlibdbg_category = RSM_LIBRARY;
657c478bd9Sstevel@tonic-gate int rsmlibdbg_level = RSM_ERR;
667c478bd9Sstevel@tonic-gate void dbg_printf(int category, int level, char *fmt, ...);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate #endif /* DEBUG */
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate rsm_node_id_t rsm_local_nodeid = 0;
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate static rsm_controller_t *controller_list = NULL;
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate static rsm_segops_t loopback_ops;
757c478bd9Sstevel@tonic-gate
767c478bd9Sstevel@tonic-gate #define MAX_STRLEN 80
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate #define RSM_IOTYPE_PUTGET 1
797c478bd9Sstevel@tonic-gate #define RSM_IOTYPE_SCATGATH 2
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate #define RSMFILE_BUFSIZE 256
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate #pragma init(_rsm_librsm_init)
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate static mutex_t _rsm_lock;
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate static int _rsm_fd = -1;
887c478bd9Sstevel@tonic-gate static rsm_gnum_t *bar_va, bar_fixed = 0;
897c478bd9Sstevel@tonic-gate static rsm_pollfd_table_t pollfd_table;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate static int _rsm_get_hwaddr(rsmapi_controller_handle_t handle,
927c478bd9Sstevel@tonic-gate rsm_node_id_t, rsm_addr_t *hwaddrp);
937c478bd9Sstevel@tonic-gate static int _rsm_get_nodeid(rsmapi_controller_handle_t,
947c478bd9Sstevel@tonic-gate rsm_addr_t, rsm_node_id_t *);
957c478bd9Sstevel@tonic-gate static int __rsm_import_implicit_map(rsmseg_handle_t *, int);
967c478bd9Sstevel@tonic-gate static int __rsm_intr_signal_wait_common(struct pollfd [], minor_t [],
977c478bd9Sstevel@tonic-gate nfds_t, int, int *);
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate static rsm_lib_funcs_t lib_functions = {
1007c478bd9Sstevel@tonic-gate RSM_LIB_FUNCS_VERSION,
1017c478bd9Sstevel@tonic-gate _rsm_get_hwaddr,
1027c478bd9Sstevel@tonic-gate _rsm_get_nodeid
1037c478bd9Sstevel@tonic-gate };
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate rsm_topology_t *tp;
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate /*
1097c478bd9Sstevel@tonic-gate * service module function templates:
1107c478bd9Sstevel@tonic-gate */
1117c478bd9Sstevel@tonic-gate
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate * The _rsm_librsm_init function is called the first time an application
1147c478bd9Sstevel@tonic-gate * references the RSMAPI library
1157c478bd9Sstevel@tonic-gate */
1167c478bd9Sstevel@tonic-gate int
_rsm_librsm_init()1177c478bd9Sstevel@tonic-gate _rsm_librsm_init()
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
1207c478bd9Sstevel@tonic-gate int e, tmpfd;
1217c478bd9Sstevel@tonic-gate int i;
1227c478bd9Sstevel@tonic-gate char logname[MAXNAMELEN];
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate mutex_init(&_rsm_lock, USYNC_THREAD, NULL);
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate #ifdef DEBUG
1277c478bd9Sstevel@tonic-gate mutex_init(&rsmlog_lock, USYNC_THREAD, NULL);
1287c478bd9Sstevel@tonic-gate sprintf(logname, "%s.%d", TRACELOG, getpid());
129004388ebScasper rsmlog_fd = fopen(logname, "w+F");
1307c478bd9Sstevel@tonic-gate if (rsmlog_fd == NULL) {
1317c478bd9Sstevel@tonic-gate fprintf(stderr, "Log file open failed\n");
1327c478bd9Sstevel@tonic-gate return (errno);
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate #endif /* DEBUG */
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1387c478bd9Sstevel@tonic-gate "_rsm_librsm_init: enter\n"));
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /* initialize the pollfd_table */
1417c478bd9Sstevel@tonic-gate mutex_init(&pollfd_table.lock, USYNC_THREAD, NULL);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate for (i = 0; i < RSM_MAX_BUCKETS; i++) {
1447c478bd9Sstevel@tonic-gate pollfd_table.buckets[i] = NULL;
1457c478bd9Sstevel@tonic-gate }
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate /* open /dev/rsm and mmap barrier generation pages */
1487c478bd9Sstevel@tonic-gate mutex_lock(&_rsm_lock);
1497c478bd9Sstevel@tonic-gate _rsm_fd = open(DEVRSM, O_RDONLY);
1507c478bd9Sstevel@tonic-gate if (_rsm_fd < 0) {
1517c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1527c478bd9Sstevel@tonic-gate "unable to open /dev/rsm\n"));
1537c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
1547c478bd9Sstevel@tonic-gate return (errno);
1557c478bd9Sstevel@tonic-gate }
1567c478bd9Sstevel@tonic-gate
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate * DUP the opened file descriptor to something greater than
1597c478bd9Sstevel@tonic-gate * STDERR_FILENO so that we never use the STDIN_FILENO,
1607c478bd9Sstevel@tonic-gate * STDOUT_FILENO or STDERR_FILENO.
1617c478bd9Sstevel@tonic-gate */
1627c478bd9Sstevel@tonic-gate tmpfd = fcntl(_rsm_fd, F_DUPFD, 3);
1637c478bd9Sstevel@tonic-gate if (tmpfd < 0) {
1647c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1657c478bd9Sstevel@tonic-gate "F_DUPFD failed\n"));
1667c478bd9Sstevel@tonic-gate } else {
1677c478bd9Sstevel@tonic-gate (void) close(_rsm_fd);
1687c478bd9Sstevel@tonic-gate _rsm_fd = tmpfd;
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate
1717c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
1727c478bd9Sstevel@tonic-gate "_rsm_fd is %d\n", _rsm_fd));
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate if (fcntl(_rsm_fd, F_SETFD, FD_CLOEXEC) < 0) {
1757c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1767c478bd9Sstevel@tonic-gate "F_SETFD failed\n"));
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate
1797c478bd9Sstevel@tonic-gate /* get mapping generation number page info */
1807c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_BAR_INFO, &msg) < 0) {
1817c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1827c478bd9Sstevel@tonic-gate "RSM_IOCTL_BAR_INFO failed\n"));
1837c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
1847c478bd9Sstevel@tonic-gate return (errno);
1857c478bd9Sstevel@tonic-gate }
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * bar_va is mapped to the mapping generation number page
1897c478bd9Sstevel@tonic-gate * in order to support close barrier
1907c478bd9Sstevel@tonic-gate */
1917c478bd9Sstevel@tonic-gate /* LINTED */
1927c478bd9Sstevel@tonic-gate bar_va = (rsm_gnum_t *)mmap(NULL, msg.len,
1937c478bd9Sstevel@tonic-gate PROT_READ, MAP_SHARED, _rsm_fd, msg.off);
1947c478bd9Sstevel@tonic-gate if (bar_va == (rsm_gnum_t *)MAP_FAILED) {
1957c478bd9Sstevel@tonic-gate bar_va = NULL;
1967c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
1977c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
1987c478bd9Sstevel@tonic-gate "unable to map barrier page\n"));
1997c478bd9Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate
2027c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /* get local nodeid */
2057c478bd9Sstevel@tonic-gate e = rsm_get_interconnect_topology(&tp);
2067c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
2077c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
2087c478bd9Sstevel@tonic-gate "unable to obtain topology data\n"));
2097c478bd9Sstevel@tonic-gate return (e);
2107c478bd9Sstevel@tonic-gate } else
2117c478bd9Sstevel@tonic-gate rsm_local_nodeid = tp->topology_hdr.local_nodeid;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate rsm_free_interconnect_topology(tp);
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2167c478bd9Sstevel@tonic-gate "_rsm_librsm_init: exit\n"));
2177c478bd9Sstevel@tonic-gate
2187c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate static int
_rsm_loopbackload(caddr_t name,int unit,rsm_controller_t ** chdl)2227c478bd9Sstevel@tonic-gate _rsm_loopbackload(caddr_t name, int unit, rsm_controller_t **chdl)
2237c478bd9Sstevel@tonic-gate {
2247c478bd9Sstevel@tonic-gate rsm_controller_t *p;
2257c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_DEBUG_VERBOSE,
2287c478bd9Sstevel@tonic-gate "_rsm_loopbackload: enter\n"));
2297c478bd9Sstevel@tonic-gate /*
2307c478bd9Sstevel@tonic-gate * For now do this, but we should open some file and read the
2317c478bd9Sstevel@tonic-gate * list of supported controllers and there numbers.
2327c478bd9Sstevel@tonic-gate */
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate p = (rsm_controller_t *)malloc(sizeof (*p) + strlen(name) + 1);
2357c478bd9Sstevel@tonic-gate if (!p) {
2367c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_ERR,
2377c478bd9Sstevel@tonic-gate "not enough memory\n"));
2387c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate msg.cname = name;
2427c478bd9Sstevel@tonic-gate msg.cname_len = strlen(name) +1;
2437c478bd9Sstevel@tonic-gate msg.cnum = unit;
2447c478bd9Sstevel@tonic-gate msg.arg = (caddr_t)&p->cntr_attr;
2457c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_ATTR, &msg) < 0) {
2467c478bd9Sstevel@tonic-gate int error = errno;
2477c478bd9Sstevel@tonic-gate free((void *)p);
2487c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_ERR,
2497c478bd9Sstevel@tonic-gate "RSM_IOCTL_ATTR failed\n"));
2507c478bd9Sstevel@tonic-gate return (error);
2517c478bd9Sstevel@tonic-gate }
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate __rsmloopback_init_ops(&loopback_ops);
2547c478bd9Sstevel@tonic-gate __rsmdefault_setops(&loopback_ops);
2557c478bd9Sstevel@tonic-gate p->cntr_segops = &loopback_ops;
2567c478bd9Sstevel@tonic-gate
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate * Should add this entry into list
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate p->cntr_fd = _rsm_fd;
2617c478bd9Sstevel@tonic-gate p->cntr_name = strcpy((char *)(p+1), name);
2627c478bd9Sstevel@tonic-gate p->cntr_unit = unit;
2637c478bd9Sstevel@tonic-gate p->cntr_refcnt = 1;
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate
2667c478bd9Sstevel@tonic-gate mutex_init(&p->cntr_lock, USYNC_THREAD, NULL);
2677c478bd9Sstevel@tonic-gate cond_init(&p->cntr_cv, USYNC_THREAD, NULL);
2687c478bd9Sstevel@tonic-gate p->cntr_rqlist = NULL;
2697c478bd9Sstevel@tonic-gate p->cntr_segops->rsm_get_lib_attr(&p->cntr_lib_attr);
2707c478bd9Sstevel@tonic-gate p->cntr_next = controller_list;
2717c478bd9Sstevel@tonic-gate controller_list = p;
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate *chdl = p;
2747c478bd9Sstevel@tonic-gate
2757c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_DEBUG_VERBOSE,
2767c478bd9Sstevel@tonic-gate "_rsm_loopbackload: exit\n"));
2777c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate
2817c478bd9Sstevel@tonic-gate static int
_rsm_modload(caddr_t name,int unit,rsmapi_controller_handle_t * controller)2827c478bd9Sstevel@tonic-gate _rsm_modload(caddr_t name, int unit, rsmapi_controller_handle_t *controller)
2837c478bd9Sstevel@tonic-gate {
2847c478bd9Sstevel@tonic-gate int error = RSM_SUCCESS;
2857c478bd9Sstevel@tonic-gate char clib[MAX_STRLEN];
2867c478bd9Sstevel@tonic-gate rsm_controller_t *p = NULL;
2877c478bd9Sstevel@tonic-gate void *dlh;
2887c478bd9Sstevel@tonic-gate rsm_attach_entry_t fptr;
2897c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
2927c478bd9Sstevel@tonic-gate "_rsm_modload: enter\n"));
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate (void) sprintf(clib, "%s.so", name);
2957c478bd9Sstevel@tonic-gate
2967c478bd9Sstevel@tonic-gate /* found entry, try to load library */
2977c478bd9Sstevel@tonic-gate dlh = dlopen(clib, RTLD_LAZY);
2987c478bd9Sstevel@tonic-gate if (dlh == NULL) {
2997c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3007c478bd9Sstevel@tonic-gate "unable to find plugin library\n"));
3017c478bd9Sstevel@tonic-gate error = RSMERR_CTLR_NOT_PRESENT;
3027c478bd9Sstevel@tonic-gate goto skiplib;
3037c478bd9Sstevel@tonic-gate }
3047c478bd9Sstevel@tonic-gate
3057c478bd9Sstevel@tonic-gate (void) sprintf(clib, "%s_opendevice", name);
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate fptr = (rsm_attach_entry_t)dlsym(dlh, clib); /* lint !e611 */
3087c478bd9Sstevel@tonic-gate if (fptr != NULL) {
3097c478bd9Sstevel@tonic-gate /* allocate new lib structure */
3107c478bd9Sstevel@tonic-gate /* get ops handler, attr and ops */
3117c478bd9Sstevel@tonic-gate p = (rsm_controller_t *)malloc(sizeof (*p) + strlen(name) + 1);
3127c478bd9Sstevel@tonic-gate if (p != NULL) {
3137c478bd9Sstevel@tonic-gate error = fptr(unit, &p->cntr_segops);
3147c478bd9Sstevel@tonic-gate } else {
3157c478bd9Sstevel@tonic-gate error = RSMERR_INSUFFICIENT_MEM;
3167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3177c478bd9Sstevel@tonic-gate "not enough memory\n"));
3187c478bd9Sstevel@tonic-gate }
3197c478bd9Sstevel@tonic-gate } else {
3207c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3217c478bd9Sstevel@tonic-gate "can't find symbol %s\n", clib));
3227c478bd9Sstevel@tonic-gate error = RSMERR_CTLR_NOT_PRESENT;
3237c478bd9Sstevel@tonic-gate (void) dlclose(dlh);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate
3267c478bd9Sstevel@tonic-gate skiplib:
3277c478bd9Sstevel@tonic-gate if ((error != RSM_SUCCESS) || (p == NULL)) {
3287c478bd9Sstevel@tonic-gate if (p != NULL)
3297c478bd9Sstevel@tonic-gate free((void *)p);
3307c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3317c478bd9Sstevel@tonic-gate "_rsm_modload error %d\n", error));
3327c478bd9Sstevel@tonic-gate return (error);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate /* check the version number */
3367c478bd9Sstevel@tonic-gate if (p->cntr_segops->rsm_version != RSM_LIB_VERSION) {
3377c478bd9Sstevel@tonic-gate /* bad version number */
3387c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3397c478bd9Sstevel@tonic-gate "wrong version; "
3407c478bd9Sstevel@tonic-gate "found %d, expected %d\n",
3417c478bd9Sstevel@tonic-gate p->cntr_segops->rsm_version, RSM_LIB_VERSION));
3427c478bd9Sstevel@tonic-gate free(p);
3437c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LIBRARY_VERSION);
3447c478bd9Sstevel@tonic-gate } else {
3457c478bd9Sstevel@tonic-gate /* pass the fuctions to NDI library */
3467c478bd9Sstevel@tonic-gate if ((p->cntr_segops->rsm_register_lib_funcs == NULL) ||
3477c478bd9Sstevel@tonic-gate (p->cntr_segops->rsm_register_lib_funcs(
3487c478bd9Sstevel@tonic-gate &lib_functions) != RSM_SUCCESS)) {
3497c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3507c478bd9Sstevel@tonic-gate "RSMNDI library not registering lib functions\n"));
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate /* get controller attributes */
3547c478bd9Sstevel@tonic-gate msg.cnum = unit;
3557c478bd9Sstevel@tonic-gate msg.cname = name;
3567c478bd9Sstevel@tonic-gate msg.cname_len = strlen(name) +1;
3577c478bd9Sstevel@tonic-gate msg.arg = (caddr_t)&p->cntr_attr;
3587c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_ATTR, &msg) < 0) {
3597c478bd9Sstevel@tonic-gate error = errno;
3607c478bd9Sstevel@tonic-gate free((void *)p);
3617c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
3627c478bd9Sstevel@tonic-gate "RSM_IOCTL_ATTR failed\n"));
3637c478bd9Sstevel@tonic-gate return (error);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate
3667c478bd9Sstevel@tonic-gate /* set controller access functions */
3677c478bd9Sstevel@tonic-gate __rsmdefault_setops(p->cntr_segops);
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate mutex_init(&p->cntr_lock, USYNC_THREAD, NULL);
3707c478bd9Sstevel@tonic-gate cond_init(&p->cntr_cv, USYNC_THREAD, NULL);
3717c478bd9Sstevel@tonic-gate p->cntr_rqlist = NULL;
3727c478bd9Sstevel@tonic-gate p->cntr_segops->rsm_get_lib_attr(&p->cntr_lib_attr);
3737c478bd9Sstevel@tonic-gate /* insert into list of controllers */
3747c478bd9Sstevel@tonic-gate p->cntr_name = strcpy((char *)(p+1), name);
3757c478bd9Sstevel@tonic-gate p->cntr_fd = _rsm_fd;
3767c478bd9Sstevel@tonic-gate p->cntr_unit = unit;
3777c478bd9Sstevel@tonic-gate p->cntr_refcnt = 1; /* first reference */
3787c478bd9Sstevel@tonic-gate p->cntr_next = controller_list;
3797c478bd9Sstevel@tonic-gate controller_list = p;
3807c478bd9Sstevel@tonic-gate *controller = (rsmapi_controller_handle_t)p;
3817c478bd9Sstevel@tonic-gate errno = RSM_SUCCESS;
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate
3847c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
3857c478bd9Sstevel@tonic-gate "_rsm_modload: exit\n"));
3867c478bd9Sstevel@tonic-gate return (error);
3877c478bd9Sstevel@tonic-gate }
3887c478bd9Sstevel@tonic-gate
3897c478bd9Sstevel@tonic-gate /*
3907c478bd9Sstevel@tonic-gate * inserts a given segment handle into the pollfd table, this is called
3917c478bd9Sstevel@tonic-gate * when rsm_memseg_get_pollfd() is called the first time on a segment handle.
3927c478bd9Sstevel@tonic-gate * Returns RSM_SUCCESS if successful otherwise the error code is returned
3937c478bd9Sstevel@tonic-gate */
3947c478bd9Sstevel@tonic-gate static int
_rsm_insert_pollfd_table(int segfd,minor_t segrnum)3957c478bd9Sstevel@tonic-gate _rsm_insert_pollfd_table(int segfd, minor_t segrnum)
3967c478bd9Sstevel@tonic-gate {
3977c478bd9Sstevel@tonic-gate int i;
3987c478bd9Sstevel@tonic-gate int hash;
3997c478bd9Sstevel@tonic-gate rsm_pollfd_chunk_t *chunk;
4007c478bd9Sstevel@tonic-gate
4017c478bd9Sstevel@tonic-gate hash = RSM_POLLFD_HASH(segfd);
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate mutex_lock(&pollfd_table.lock);
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate chunk = pollfd_table.buckets[hash];
4067c478bd9Sstevel@tonic-gate while (chunk) {
4077c478bd9Sstevel@tonic-gate if (chunk->nfree > 0)
4087c478bd9Sstevel@tonic-gate break;
4097c478bd9Sstevel@tonic-gate chunk = chunk->next;
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate
4127c478bd9Sstevel@tonic-gate if (!chunk) { /* couldn't find a free chunk - allocate a new one */
4137c478bd9Sstevel@tonic-gate chunk = malloc(sizeof (rsm_pollfd_chunk_t));
4147c478bd9Sstevel@tonic-gate if (!chunk) {
4157c478bd9Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4167c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate chunk->nfree = RSM_POLLFD_PER_CHUNK - 1;
4197c478bd9Sstevel@tonic-gate chunk->fdarray[0].fd = segfd;
4207c478bd9Sstevel@tonic-gate chunk->fdarray[0].segrnum = segrnum;
4217c478bd9Sstevel@tonic-gate for (i = 1; i < RSM_POLLFD_PER_CHUNK; i++) {
4227c478bd9Sstevel@tonic-gate chunk->fdarray[i].fd = -1;
4237c478bd9Sstevel@tonic-gate chunk->fdarray[i].segrnum = 0;
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate /* insert this into the hash table */
4267c478bd9Sstevel@tonic-gate chunk->next = pollfd_table.buckets[hash];
4277c478bd9Sstevel@tonic-gate pollfd_table.buckets[hash] = chunk;
4287c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4297c478bd9Sstevel@tonic-gate "rsm_insert_pollfd: new chunk(%p) @ %d for %d:%d\n",
4307c478bd9Sstevel@tonic-gate chunk, hash, segfd, segrnum));
4317c478bd9Sstevel@tonic-gate } else { /* a chunk with free slot was found */
4327c478bd9Sstevel@tonic-gate for (i = 0; i < RSM_POLLFD_PER_CHUNK; i++) {
4337c478bd9Sstevel@tonic-gate if (chunk->fdarray[i].fd == -1) {
4347c478bd9Sstevel@tonic-gate chunk->fdarray[i].fd = segfd;
4357c478bd9Sstevel@tonic-gate chunk->fdarray[i].segrnum = segrnum;
4367c478bd9Sstevel@tonic-gate chunk->nfree--;
4377c478bd9Sstevel@tonic-gate break;
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4417c478bd9Sstevel@tonic-gate "rsm_insert_pollfd: inserted @ %d for %d:%d chunk(%p)\n",
4427c478bd9Sstevel@tonic-gate hash, segfd, segrnum, chunk));
4437c478bd9Sstevel@tonic-gate assert(i < RSM_POLLFD_PER_CHUNK);
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate
4467c478bd9Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4477c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate /*
4517c478bd9Sstevel@tonic-gate * Given a file descriptor returns the corresponding segment handles
4527c478bd9Sstevel@tonic-gate * resource number, if the fd is not found returns 0. 0 is not a valid
4537c478bd9Sstevel@tonic-gate * minor number for a rsmapi segment since it is used for the barrier
4547c478bd9Sstevel@tonic-gate * resource.
4557c478bd9Sstevel@tonic-gate */
4567c478bd9Sstevel@tonic-gate static minor_t
_rsm_lookup_pollfd_table(int segfd)4577c478bd9Sstevel@tonic-gate _rsm_lookup_pollfd_table(int segfd)
4587c478bd9Sstevel@tonic-gate {
4597c478bd9Sstevel@tonic-gate int i;
4607c478bd9Sstevel@tonic-gate rsm_pollfd_chunk_t *chunk;
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate if (segfd < 0)
4637c478bd9Sstevel@tonic-gate return (0);
4647c478bd9Sstevel@tonic-gate
4657c478bd9Sstevel@tonic-gate mutex_lock(&pollfd_table.lock);
4667c478bd9Sstevel@tonic-gate
4677c478bd9Sstevel@tonic-gate chunk = pollfd_table.buckets[RSM_POLLFD_HASH(segfd)];
4687c478bd9Sstevel@tonic-gate while (chunk) {
4697c478bd9Sstevel@tonic-gate assert(chunk->nfree < RSM_POLLFD_PER_CHUNK);
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate for (i = 0; i < RSM_POLLFD_PER_CHUNK; i++) {
4727c478bd9Sstevel@tonic-gate if (chunk->fdarray[i].fd == segfd) {
4737c478bd9Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4747c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4757c478bd9Sstevel@tonic-gate "rsm_lookup_pollfd: found(%d) rnum(%d)\n",
4767c478bd9Sstevel@tonic-gate segfd, chunk->fdarray[i].segrnum));
4777c478bd9Sstevel@tonic-gate return (chunk->fdarray[i].segrnum);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate chunk = chunk->next;
4817c478bd9Sstevel@tonic-gate }
4827c478bd9Sstevel@tonic-gate
4837c478bd9Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
4847c478bd9Sstevel@tonic-gate
4857c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
4867c478bd9Sstevel@tonic-gate "rsm_lookup_pollfd: not found(%d)\n", segfd));
4877c478bd9Sstevel@tonic-gate
4887c478bd9Sstevel@tonic-gate return (0);
4897c478bd9Sstevel@tonic-gate }
4907c478bd9Sstevel@tonic-gate
4917c478bd9Sstevel@tonic-gate /*
4927c478bd9Sstevel@tonic-gate * Remove the entry corresponding to the given file descriptor from the
4937c478bd9Sstevel@tonic-gate * pollfd table.
4947c478bd9Sstevel@tonic-gate */
4957c478bd9Sstevel@tonic-gate static void
_rsm_remove_pollfd_table(int segfd)4967c478bd9Sstevel@tonic-gate _rsm_remove_pollfd_table(int segfd)
4977c478bd9Sstevel@tonic-gate {
4987c478bd9Sstevel@tonic-gate int i;
4997c478bd9Sstevel@tonic-gate int hash;
5007c478bd9Sstevel@tonic-gate rsm_pollfd_chunk_t *chunk;
5017c478bd9Sstevel@tonic-gate rsm_pollfd_chunk_t *prev_chunk;
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate if (segfd < 0)
5047c478bd9Sstevel@tonic-gate return;
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate hash = RSM_POLLFD_HASH(segfd);
5077c478bd9Sstevel@tonic-gate
5087c478bd9Sstevel@tonic-gate mutex_lock(&pollfd_table.lock);
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate prev_chunk = chunk = pollfd_table.buckets[hash];
5117c478bd9Sstevel@tonic-gate while (chunk) {
5127c478bd9Sstevel@tonic-gate assert(chunk->nfree < RSM_POLLFD_PER_CHUNK);
5137c478bd9Sstevel@tonic-gate
5147c478bd9Sstevel@tonic-gate for (i = 0; i < RSM_POLLFD_PER_CHUNK; i++) {
5157c478bd9Sstevel@tonic-gate if (chunk->fdarray[i].fd == segfd) {
5167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5177c478bd9Sstevel@tonic-gate "rsm_remove_pollfd: %d:%d\n",
5187c478bd9Sstevel@tonic-gate chunk->fdarray[i].fd,
5197c478bd9Sstevel@tonic-gate chunk->fdarray[i].segrnum));
5207c478bd9Sstevel@tonic-gate chunk->fdarray[i].fd = -1;
5217c478bd9Sstevel@tonic-gate chunk->fdarray[i].segrnum = 0;
5227c478bd9Sstevel@tonic-gate chunk->nfree++;
5237c478bd9Sstevel@tonic-gate if (chunk->nfree == RSM_POLLFD_PER_CHUNK) {
5247c478bd9Sstevel@tonic-gate /* chunk is empty free it */
5257c478bd9Sstevel@tonic-gate if (prev_chunk == chunk) {
5267c478bd9Sstevel@tonic-gate pollfd_table.buckets[hash] =
5277c478bd9Sstevel@tonic-gate chunk->next;
5287c478bd9Sstevel@tonic-gate } else {
5297c478bd9Sstevel@tonic-gate prev_chunk->next = chunk->next;
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY,
5327c478bd9Sstevel@tonic-gate RSM_DEBUG_VERBOSE,
5337c478bd9Sstevel@tonic-gate "rsm_remove_pollfd:free(%p)\n",
5347c478bd9Sstevel@tonic-gate chunk));
5357c478bd9Sstevel@tonic-gate free(chunk);
5367c478bd9Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
5377c478bd9Sstevel@tonic-gate return;
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate }
5417c478bd9Sstevel@tonic-gate prev_chunk = chunk;
5427c478bd9Sstevel@tonic-gate chunk = chunk->next;
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate
5457c478bd9Sstevel@tonic-gate mutex_unlock(&pollfd_table.lock);
5467c478bd9Sstevel@tonic-gate }
5477c478bd9Sstevel@tonic-gate
5487c478bd9Sstevel@tonic-gate int
rsm_get_controller(char * name,rsmapi_controller_handle_t * chdl)549*7257d1b4Sraf rsm_get_controller(char *name, rsmapi_controller_handle_t *chdl)
5507c478bd9Sstevel@tonic-gate {
5517c478bd9Sstevel@tonic-gate rsm_controller_t *p;
5527c478bd9Sstevel@tonic-gate char cntr_name[MAXNAMELEN]; /* cntr_name=<cntr_type><unit> */
5537c478bd9Sstevel@tonic-gate char *cntr_type;
5547c478bd9Sstevel@tonic-gate int unit = 0;
5557c478bd9Sstevel@tonic-gate int i, e;
5567c478bd9Sstevel@tonic-gate
5577c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5587c478bd9Sstevel@tonic-gate "rsm_get_controller: enter\n"));
5597c478bd9Sstevel@tonic-gate /*
5607c478bd9Sstevel@tonic-gate * Lookup controller name and return ops vector and controller
5617c478bd9Sstevel@tonic-gate * structure
5627c478bd9Sstevel@tonic-gate */
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate if (!chdl) {
5657c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
5667c478bd9Sstevel@tonic-gate "Invalid controller handle\n"));
5677c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
5687c478bd9Sstevel@tonic-gate }
5697c478bd9Sstevel@tonic-gate if (!name) {
5707c478bd9Sstevel@tonic-gate /* use loopback if null */
5717c478bd9Sstevel@tonic-gate cntr_type = LOOPBACK;
5727c478bd9Sstevel@tonic-gate } else {
5737c478bd9Sstevel@tonic-gate (void) strcpy(cntr_name, name);
5747c478bd9Sstevel@tonic-gate /* scan from the end till a non-digit is found */
5757c478bd9Sstevel@tonic-gate for (i = strlen(cntr_name) - 1; i >= 0; i--) {
5767c478bd9Sstevel@tonic-gate if (! isdigit((int)cntr_name[i]))
5777c478bd9Sstevel@tonic-gate break;
5787c478bd9Sstevel@tonic-gate }
5797c478bd9Sstevel@tonic-gate i++;
5807c478bd9Sstevel@tonic-gate unit = atoi((char *)cntr_name+i);
5817c478bd9Sstevel@tonic-gate cntr_name[i] = '\0'; /* null terminate the cntr_type part */
5827c478bd9Sstevel@tonic-gate cntr_type = (char *)cntr_name;
5837c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5847c478bd9Sstevel@tonic-gate "cntr_type=%s, instance=%d\n",
5857c478bd9Sstevel@tonic-gate cntr_type, unit));
5867c478bd9Sstevel@tonic-gate }
5877c478bd9Sstevel@tonic-gate
5887c478bd9Sstevel@tonic-gate /* protect the controller_list by locking the device/library */
5897c478bd9Sstevel@tonic-gate mutex_lock(&_rsm_lock);
5907c478bd9Sstevel@tonic-gate
5917c478bd9Sstevel@tonic-gate for (p = controller_list; p; p = p->cntr_next) {
5927c478bd9Sstevel@tonic-gate if (!strcasecmp(p->cntr_name, cntr_type) &&
5937c478bd9Sstevel@tonic-gate !strcasecmp(cntr_type, LOOPBACK)) {
5947c478bd9Sstevel@tonic-gate p->cntr_refcnt++;
5957c478bd9Sstevel@tonic-gate *chdl = (rsmapi_controller_handle_t)p;
5967c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
5977c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
5987c478bd9Sstevel@tonic-gate "rsm_get_controller: exit\n"));
5997c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
6007c478bd9Sstevel@tonic-gate } else if (!strcasecmp(p->cntr_name, cntr_type) &&
6017c478bd9Sstevel@tonic-gate (p->cntr_unit == unit)) {
6027c478bd9Sstevel@tonic-gate p->cntr_refcnt++;
6037c478bd9Sstevel@tonic-gate *chdl = (rsmapi_controller_handle_t)p;
6047c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6057c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6067c478bd9Sstevel@tonic-gate "rsm_get_controller: exit\n"));
6077c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
6087c478bd9Sstevel@tonic-gate }
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate
6127c478bd9Sstevel@tonic-gate if (!strcasecmp(cntr_type, LOOPBACK)) {
6137c478bd9Sstevel@tonic-gate e = _rsm_loopbackload(cntr_type, unit,
6147c478bd9Sstevel@tonic-gate (rsm_controller_t **)chdl);
6157c478bd9Sstevel@tonic-gate } else {
6167c478bd9Sstevel@tonic-gate e = _rsm_modload(cntr_type, unit, chdl);
6177c478bd9Sstevel@tonic-gate }
6187c478bd9Sstevel@tonic-gate
6197c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6207c478bd9Sstevel@tonic-gate
6217c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6227c478bd9Sstevel@tonic-gate " rsm_get_controller: exit\n"));
6237c478bd9Sstevel@tonic-gate return (e);
6247c478bd9Sstevel@tonic-gate }
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate int
rsm_release_controller(rsmapi_controller_handle_t cntr_handle)627*7257d1b4Sraf rsm_release_controller(rsmapi_controller_handle_t cntr_handle)
6287c478bd9Sstevel@tonic-gate {
6297c478bd9Sstevel@tonic-gate int e = RSM_SUCCESS;
6307c478bd9Sstevel@tonic-gate rsm_controller_t *chdl = (rsm_controller_t *)cntr_handle;
6317c478bd9Sstevel@tonic-gate rsm_controller_t *curr, *prev;
6327c478bd9Sstevel@tonic-gate
6337c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6347c478bd9Sstevel@tonic-gate "rsm_release_controller: enter\n"));
6357c478bd9Sstevel@tonic-gate
6367c478bd9Sstevel@tonic-gate mutex_lock(&_rsm_lock);
6377c478bd9Sstevel@tonic-gate
6387c478bd9Sstevel@tonic-gate if (chdl->cntr_refcnt == 0) {
6397c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6407c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6417c478bd9Sstevel@tonic-gate "controller reference count is zero\n"));
6427c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
6437c478bd9Sstevel@tonic-gate }
6447c478bd9Sstevel@tonic-gate
6457c478bd9Sstevel@tonic-gate chdl->cntr_refcnt--;
6467c478bd9Sstevel@tonic-gate
6477c478bd9Sstevel@tonic-gate if (chdl->cntr_refcnt > 0) {
6487c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6497c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6507c478bd9Sstevel@tonic-gate "rsm_release_controller: exit\n"));
6517c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate
6547c478bd9Sstevel@tonic-gate e = chdl->cntr_segops->rsm_closedevice(cntr_handle);
6557c478bd9Sstevel@tonic-gate
6567c478bd9Sstevel@tonic-gate /*
6577c478bd9Sstevel@tonic-gate * remove the controller in any case from the controller list
6587c478bd9Sstevel@tonic-gate */
6597c478bd9Sstevel@tonic-gate
6607c478bd9Sstevel@tonic-gate prev = curr = controller_list;
6617c478bd9Sstevel@tonic-gate while (curr != NULL) {
6627c478bd9Sstevel@tonic-gate if (curr == chdl) {
6637c478bd9Sstevel@tonic-gate if (curr == prev) {
6647c478bd9Sstevel@tonic-gate controller_list = curr->cntr_next;
6657c478bd9Sstevel@tonic-gate } else {
6667c478bd9Sstevel@tonic-gate prev->cntr_next = curr->cntr_next;
6677c478bd9Sstevel@tonic-gate }
6687c478bd9Sstevel@tonic-gate free(curr);
6697c478bd9Sstevel@tonic-gate break;
6707c478bd9Sstevel@tonic-gate }
6717c478bd9Sstevel@tonic-gate prev = curr;
6727c478bd9Sstevel@tonic-gate curr = curr->cntr_next;
6737c478bd9Sstevel@tonic-gate }
6747c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
6757c478bd9Sstevel@tonic-gate
6767c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6777c478bd9Sstevel@tonic-gate "rsm_release_controller: exit\n"));
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate return (e);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate
682*7257d1b4Sraf int
rsm_get_controller_attr(rsmapi_controller_handle_t chandle,rsmapi_controller_attr_t * attr)683*7257d1b4Sraf rsm_get_controller_attr(rsmapi_controller_handle_t chandle,
6847c478bd9Sstevel@tonic-gate rsmapi_controller_attr_t *attr)
6857c478bd9Sstevel@tonic-gate {
6867c478bd9Sstevel@tonic-gate rsm_controller_t *p;
6877c478bd9Sstevel@tonic-gate
6887c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
6897c478bd9Sstevel@tonic-gate "rsm_get_controller_attr: enter\n"));
6907c478bd9Sstevel@tonic-gate
6917c478bd9Sstevel@tonic-gate if (!chandle) {
6927c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6937c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
6947c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
6957c478bd9Sstevel@tonic-gate }
6967c478bd9Sstevel@tonic-gate
6977c478bd9Sstevel@tonic-gate if (!attr) {
6987c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
6997c478bd9Sstevel@tonic-gate "invalid attribute pointer\n"));
7007c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
7017c478bd9Sstevel@tonic-gate }
7027c478bd9Sstevel@tonic-gate
7037c478bd9Sstevel@tonic-gate p = (rsm_controller_t *)chandle;
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate mutex_lock(&_rsm_lock);
7067c478bd9Sstevel@tonic-gate if (p->cntr_refcnt == 0) {
7077c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
7087c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7097c478bd9Sstevel@tonic-gate "cntr refcnt is 0\n"));
7107c478bd9Sstevel@tonic-gate return (RSMERR_CTLR_NOT_PRESENT);
7117c478bd9Sstevel@tonic-gate }
7127c478bd9Sstevel@tonic-gate
7137c478bd9Sstevel@tonic-gate /* copy only the user part of the attr structure */
7147c478bd9Sstevel@tonic-gate attr->attr_direct_access_sizes =
7157c478bd9Sstevel@tonic-gate p->cntr_attr.attr_direct_access_sizes;
7167c478bd9Sstevel@tonic-gate attr->attr_atomic_sizes =
7177c478bd9Sstevel@tonic-gate p->cntr_attr.attr_atomic_sizes;
7187c478bd9Sstevel@tonic-gate attr->attr_page_size =
7197c478bd9Sstevel@tonic-gate p->cntr_attr.attr_page_size;
7207c478bd9Sstevel@tonic-gate attr->attr_max_export_segment_size =
7217c478bd9Sstevel@tonic-gate p->cntr_attr.attr_max_export_segment_size;
7227c478bd9Sstevel@tonic-gate attr->attr_tot_export_segment_size =
7237c478bd9Sstevel@tonic-gate p->cntr_attr.attr_tot_export_segment_size;
7247c478bd9Sstevel@tonic-gate attr->attr_max_export_segments =
7257c478bd9Sstevel@tonic-gate p->cntr_attr.attr_max_export_segments;
7267c478bd9Sstevel@tonic-gate attr->attr_max_import_map_size =
7277c478bd9Sstevel@tonic-gate p->cntr_attr.attr_max_import_map_size;
7287c478bd9Sstevel@tonic-gate attr->attr_tot_import_map_size =
7297c478bd9Sstevel@tonic-gate p->cntr_attr.attr_tot_import_map_size;
7307c478bd9Sstevel@tonic-gate attr->attr_max_import_segments =
7317c478bd9Sstevel@tonic-gate p->cntr_attr.attr_max_import_segments;
7327c478bd9Sstevel@tonic-gate
7337c478bd9Sstevel@tonic-gate mutex_unlock(&_rsm_lock);
7347c478bd9Sstevel@tonic-gate
7357c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
7367c478bd9Sstevel@tonic-gate "rsm_get_controller_attr: exit\n"));
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate
7427c478bd9Sstevel@tonic-gate
7437c478bd9Sstevel@tonic-gate /*
7447c478bd9Sstevel@tonic-gate * Create a segment handle for the virtual address range specified
7457c478bd9Sstevel@tonic-gate * by vaddr and size
7467c478bd9Sstevel@tonic-gate */
7477c478bd9Sstevel@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)748*7257d1b4Sraf rsm_memseg_export_create(rsmapi_controller_handle_t controller,
7497c478bd9Sstevel@tonic-gate rsm_memseg_export_handle_t *memseg,
7507c478bd9Sstevel@tonic-gate void *vaddr,
7517c478bd9Sstevel@tonic-gate size_t length,
7527c478bd9Sstevel@tonic-gate uint_t flags)
7537c478bd9Sstevel@tonic-gate {
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate rsm_controller_t *chdl = (rsm_controller_t *)controller;
7567c478bd9Sstevel@tonic-gate rsmseg_handle_t *p;
7577c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
7587c478bd9Sstevel@tonic-gate int e;
7597c478bd9Sstevel@tonic-gate #ifndef _LP64
7607c478bd9Sstevel@tonic-gate int tmpfd;
7617c478bd9Sstevel@tonic-gate #endif
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
7647c478bd9Sstevel@tonic-gate "rsm_memseg_export_create: enter\n"));
7657c478bd9Sstevel@tonic-gate
7667c478bd9Sstevel@tonic-gate if (!controller) {
7677c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7687c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
7697c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
7707c478bd9Sstevel@tonic-gate }
7717c478bd9Sstevel@tonic-gate if (!memseg) {
7727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7737c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
7747c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
7757c478bd9Sstevel@tonic-gate }
7767c478bd9Sstevel@tonic-gate
7777c478bd9Sstevel@tonic-gate *memseg = 0;
7787c478bd9Sstevel@tonic-gate
7797c478bd9Sstevel@tonic-gate /*
7807c478bd9Sstevel@tonic-gate * Check vaddr and size alignment, both must be mmu page size
7817c478bd9Sstevel@tonic-gate * aligned
7827c478bd9Sstevel@tonic-gate */
7837c478bd9Sstevel@tonic-gate if (!vaddr) {
7847c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7857c478bd9Sstevel@tonic-gate "invalid arguments\n"));
7867c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
7877c478bd9Sstevel@tonic-gate }
7887c478bd9Sstevel@tonic-gate
7897c478bd9Sstevel@tonic-gate if (!length) {
7907c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7917c478bd9Sstevel@tonic-gate "invalid arguments\n"));
7927c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
7937c478bd9Sstevel@tonic-gate }
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate if (((size_t)vaddr & (PAGESIZE - 1)) ||
7967c478bd9Sstevel@tonic-gate (length & (PAGESIZE - 1))) {
7977c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
7987c478bd9Sstevel@tonic-gate "invalid mem alignment for vaddr or length\n"));
7997c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
8007c478bd9Sstevel@tonic-gate }
8017c478bd9Sstevel@tonic-gate
8027c478bd9Sstevel@tonic-gate /*
8037c478bd9Sstevel@tonic-gate * The following check does not apply for loopback controller
8047c478bd9Sstevel@tonic-gate * since for the loopback adapter, the attr_max_export_segment_size
8057c478bd9Sstevel@tonic-gate * is always 0.
8067c478bd9Sstevel@tonic-gate */
8077c478bd9Sstevel@tonic-gate if (strcasecmp(chdl->cntr_name, LOOPBACK)) {
8087c478bd9Sstevel@tonic-gate if (length > chdl->cntr_attr.attr_max_export_segment_size) {
8097c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8107c478bd9Sstevel@tonic-gate "length exceeds controller limits\n"));
8117c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8127c478bd9Sstevel@tonic-gate "controller limits %d\n",
8137c478bd9Sstevel@tonic-gate chdl->cntr_attr.attr_max_export_segment_size));
8147c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
8157c478bd9Sstevel@tonic-gate }
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate p = (rsmseg_handle_t *)malloc(sizeof (*p));
8197c478bd9Sstevel@tonic-gate if (p == NULL) {
8207c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
8217c478bd9Sstevel@tonic-gate "not enough memory\n"));
8227c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
8237c478bd9Sstevel@tonic-gate }
8247c478bd9Sstevel@tonic-gate
8257c478bd9Sstevel@tonic-gate p->rsmseg_fd = open(DEVRSM, O_RDWR);
8267c478bd9Sstevel@tonic-gate if (p->rsmseg_fd < 0) {
8277c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8287c478bd9Sstevel@tonic-gate "unable to open device /dev/rsm\n"));
8297c478bd9Sstevel@tonic-gate free((void *)p);
8307c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
8317c478bd9Sstevel@tonic-gate }
8327c478bd9Sstevel@tonic-gate
8337c478bd9Sstevel@tonic-gate #ifndef _LP64
8347c478bd9Sstevel@tonic-gate /*
8357c478bd9Sstevel@tonic-gate * libc can't handle fd's greater than 255, in order to
8367c478bd9Sstevel@tonic-gate * insure that these values remain available make /dev/rsm
8377c478bd9Sstevel@tonic-gate * fd > 255. Note: not needed for LP64
8387c478bd9Sstevel@tonic-gate */
8397c478bd9Sstevel@tonic-gate tmpfd = fcntl(p->rsmseg_fd, F_DUPFD, 256);
8407c478bd9Sstevel@tonic-gate e = errno;
8417c478bd9Sstevel@tonic-gate if (tmpfd < 0) {
8427c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8437c478bd9Sstevel@tonic-gate "F_DUPFD failed\n"));
8447c478bd9Sstevel@tonic-gate } else {
8457c478bd9Sstevel@tonic-gate (void) close(p->rsmseg_fd);
8467c478bd9Sstevel@tonic-gate p->rsmseg_fd = tmpfd;
8477c478bd9Sstevel@tonic-gate }
8487c478bd9Sstevel@tonic-gate #endif /* _LP64 */
8497c478bd9Sstevel@tonic-gate
8507c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE, ""
8517c478bd9Sstevel@tonic-gate "rsmseg_fd is %d\n", p->rsmseg_fd));
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate if (fcntl(p->rsmseg_fd, F_SETFD, FD_CLOEXEC) < 0) {
8547c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8557c478bd9Sstevel@tonic-gate "F_SETFD failed\n"));
8567c478bd9Sstevel@tonic-gate }
8577c478bd9Sstevel@tonic-gate
8587c478bd9Sstevel@tonic-gate p->rsmseg_state = EXPORT_CREATE;
8597c478bd9Sstevel@tonic-gate p->rsmseg_size = length;
8607c478bd9Sstevel@tonic-gate /* increment controller handle */
8617c478bd9Sstevel@tonic-gate p->rsmseg_controller = chdl;
8627c478bd9Sstevel@tonic-gate
8637c478bd9Sstevel@tonic-gate /* try to bind user address range */
8647c478bd9Sstevel@tonic-gate msg.cnum = chdl->cntr_unit;
8657c478bd9Sstevel@tonic-gate msg.cname = chdl->cntr_name;
8667c478bd9Sstevel@tonic-gate msg.cname_len = strlen(chdl->cntr_name) +1;
8677c478bd9Sstevel@tonic-gate msg.vaddr = vaddr;
8687c478bd9Sstevel@tonic-gate msg.len = length;
8697c478bd9Sstevel@tonic-gate msg.perm = flags;
8707c478bd9Sstevel@tonic-gate msg.off = 0;
8717c478bd9Sstevel@tonic-gate e = RSM_IOCTL_BIND;
8727c478bd9Sstevel@tonic-gate
8737c478bd9Sstevel@tonic-gate /* Try to bind */
8747c478bd9Sstevel@tonic-gate if (ioctl(p->rsmseg_fd, e, &msg) < 0) {
8757c478bd9Sstevel@tonic-gate e = errno;
8767c478bd9Sstevel@tonic-gate (void) close(p->rsmseg_fd);
8777c478bd9Sstevel@tonic-gate free((void *)p);
8787c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
8797c478bd9Sstevel@tonic-gate "RSM_IOCTL_BIND failed\n"));
8807c478bd9Sstevel@tonic-gate return (e);
8817c478bd9Sstevel@tonic-gate }
8827c478bd9Sstevel@tonic-gate /* OK */
8837c478bd9Sstevel@tonic-gate p->rsmseg_type = RSM_EXPORT_SEG;
8847c478bd9Sstevel@tonic-gate p->rsmseg_vaddr = vaddr;
8857c478bd9Sstevel@tonic-gate p->rsmseg_size = length;
8867c478bd9Sstevel@tonic-gate p->rsmseg_state = EXPORT_BIND;
8877c478bd9Sstevel@tonic-gate p->rsmseg_pollfd_refcnt = 0;
8887c478bd9Sstevel@tonic-gate p->rsmseg_rnum = msg.rnum;
8897c478bd9Sstevel@tonic-gate
8907c478bd9Sstevel@tonic-gate mutex_init(&p->rsmseg_lock, USYNC_THREAD, NULL);
8917c478bd9Sstevel@tonic-gate
8927c478bd9Sstevel@tonic-gate *memseg = (rsm_memseg_export_handle_t)p;
8937c478bd9Sstevel@tonic-gate
8947c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
8957c478bd9Sstevel@tonic-gate "rsm_memseg_export_create: exit\n"));
8967c478bd9Sstevel@tonic-gate
8977c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
8987c478bd9Sstevel@tonic-gate }
8997c478bd9Sstevel@tonic-gate
9007c478bd9Sstevel@tonic-gate int
rsm_memseg_export_destroy(rsm_memseg_export_handle_t memseg)901*7257d1b4Sraf rsm_memseg_export_destroy(rsm_memseg_export_handle_t memseg)
9027c478bd9Sstevel@tonic-gate {
9037c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg;
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9067c478bd9Sstevel@tonic-gate "rsm_memseg_export_destroy: enter\n"));
9077c478bd9Sstevel@tonic-gate
9087c478bd9Sstevel@tonic-gate if (!memseg) {
9097c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9107c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
9117c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
9127c478bd9Sstevel@tonic-gate }
9137c478bd9Sstevel@tonic-gate
9147c478bd9Sstevel@tonic-gate seg = (rsmseg_handle_t *)memseg;
9157c478bd9Sstevel@tonic-gate
9167c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
9177c478bd9Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt) {
9187c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9197c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9207c478bd9Sstevel@tonic-gate "segment reference count not zero\n"));
9217c478bd9Sstevel@tonic-gate return (RSMERR_POLLFD_IN_USE);
9227c478bd9Sstevel@tonic-gate }
9237c478bd9Sstevel@tonic-gate else
9247c478bd9Sstevel@tonic-gate seg->rsmseg_state = EXPORT_BIND;
9257c478bd9Sstevel@tonic-gate
9267c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate (void) close(seg->rsmseg_fd);
9297c478bd9Sstevel@tonic-gate mutex_destroy(&seg->rsmseg_lock);
9307c478bd9Sstevel@tonic-gate free((void *)seg);
9317c478bd9Sstevel@tonic-gate
9327c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9337c478bd9Sstevel@tonic-gate "rsm_memseg_export_destroy: exit\n"));
9347c478bd9Sstevel@tonic-gate
9357c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
9367c478bd9Sstevel@tonic-gate }
9377c478bd9Sstevel@tonic-gate
9387c478bd9Sstevel@tonic-gate int
rsm_memseg_export_rebind(rsm_memseg_export_handle_t memseg,void * vaddr,offset_t off,size_t length)939*7257d1b4Sraf rsm_memseg_export_rebind(rsm_memseg_export_handle_t memseg, void *vaddr,
9407c478bd9Sstevel@tonic-gate offset_t off, size_t length)
9417c478bd9Sstevel@tonic-gate {
9427c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
9437c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9467c478bd9Sstevel@tonic-gate "rsm_memseg_export_rebind: enter\n"));
9477c478bd9Sstevel@tonic-gate
9487c478bd9Sstevel@tonic-gate off = off;
9497c478bd9Sstevel@tonic-gate
9507c478bd9Sstevel@tonic-gate if (!seg) {
9517c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9527c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
9537c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
9547c478bd9Sstevel@tonic-gate }
9557c478bd9Sstevel@tonic-gate if (!vaddr) {
9567c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9577c478bd9Sstevel@tonic-gate "invalid vaddr\n"));
9587c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
9597c478bd9Sstevel@tonic-gate }
9607c478bd9Sstevel@tonic-gate
9617c478bd9Sstevel@tonic-gate /*
9627c478bd9Sstevel@tonic-gate * Same as bind except it's ok to have elimint in list.
9637c478bd9Sstevel@tonic-gate * Call into driver to remove any existing mappings.
9647c478bd9Sstevel@tonic-gate */
9657c478bd9Sstevel@tonic-gate msg.vaddr = vaddr;
9667c478bd9Sstevel@tonic-gate msg.len = length;
9677c478bd9Sstevel@tonic-gate msg.off = 0;
9687c478bd9Sstevel@tonic-gate
9697c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
9707c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_REBIND, &msg) < 0) {
9717c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
9737c478bd9Sstevel@tonic-gate "RSM_IOCTL_REBIND failed\n"));
9747c478bd9Sstevel@tonic-gate return (errno);
9757c478bd9Sstevel@tonic-gate }
9767c478bd9Sstevel@tonic-gate
9777c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
9787c478bd9Sstevel@tonic-gate
9797c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9807c478bd9Sstevel@tonic-gate "rsm_memseg_export_rebind: exit\n"));
9817c478bd9Sstevel@tonic-gate
9827c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@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)986*7257d1b4Sraf rsm_memseg_export_publish(rsm_memseg_export_handle_t memseg,
9877c478bd9Sstevel@tonic-gate rsm_memseg_id_t *seg_id,
9887c478bd9Sstevel@tonic-gate rsmapi_access_entry_t access_list[],
9897c478bd9Sstevel@tonic-gate uint_t access_list_length)
9907c478bd9Sstevel@tonic-gate
9917c478bd9Sstevel@tonic-gate {
9927c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
9937c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
9947c478bd9Sstevel@tonic-gate
9957c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
9967c478bd9Sstevel@tonic-gate "rsm_memseg_export_publish: enter\n"));
9977c478bd9Sstevel@tonic-gate
9987c478bd9Sstevel@tonic-gate if (seg_id == NULL) {
9997c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10007c478bd9Sstevel@tonic-gate "invalid segment id\n"));
10017c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEGID);
10027c478bd9Sstevel@tonic-gate }
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate if (!seg) {
10057c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10067c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
10077c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
10087c478bd9Sstevel@tonic-gate }
10097c478bd9Sstevel@tonic-gate
10107c478bd9Sstevel@tonic-gate if (access_list_length > 0 && !access_list) {
10117c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10127c478bd9Sstevel@tonic-gate "invalid access control list\n"));
10137c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ACL);
10147c478bd9Sstevel@tonic-gate }
10157c478bd9Sstevel@tonic-gate
10167c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
10177c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != EXPORT_BIND) {
10187c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10197c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10207c478bd9Sstevel@tonic-gate "invalid segment state\n"));
10217c478bd9Sstevel@tonic-gate return (RSMERR_SEG_ALREADY_PUBLISHED);
10227c478bd9Sstevel@tonic-gate }
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate /*
10257c478bd9Sstevel@tonic-gate * seg id < RSM_DLPI_END and in the RSM_USER_APP_ID range
10267c478bd9Sstevel@tonic-gate * are reserved for internal use.
10277c478bd9Sstevel@tonic-gate */
10287c478bd9Sstevel@tonic-gate if ((*seg_id > 0) &&
10297c478bd9Sstevel@tonic-gate ((*seg_id <= RSM_DLPI_ID_END) ||
10307c478bd9Sstevel@tonic-gate BETWEEN (*seg_id, RSM_USER_APP_ID_BASE, RSM_USER_APP_ID_END))) {
10317c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10327c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10337c478bd9Sstevel@tonic-gate "invalid segment id\n"));
10347c478bd9Sstevel@tonic-gate return (RSMERR_RESERVED_SEGID);
10357c478bd9Sstevel@tonic-gate }
10367c478bd9Sstevel@tonic-gate
10377c478bd9Sstevel@tonic-gate msg.key = *seg_id;
10387c478bd9Sstevel@tonic-gate msg.acl = access_list;
10397c478bd9Sstevel@tonic-gate msg.acl_len = access_list_length;
10407c478bd9Sstevel@tonic-gate
10417c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_PUBLISH, &msg) < 0) {
10427c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10437c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10447c478bd9Sstevel@tonic-gate "RSM_IOCTL_PUBLISH failed\n"));
10457c478bd9Sstevel@tonic-gate return (errno);
10467c478bd9Sstevel@tonic-gate }
10477c478bd9Sstevel@tonic-gate
10487c478bd9Sstevel@tonic-gate seg->rsmseg_keyid = msg.key;
10497c478bd9Sstevel@tonic-gate seg->rsmseg_state = EXPORT_PUBLISH;
10507c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10517c478bd9Sstevel@tonic-gate
10527c478bd9Sstevel@tonic-gate if (*seg_id == 0)
10537c478bd9Sstevel@tonic-gate *seg_id = msg.key;
10547c478bd9Sstevel@tonic-gate
10557c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
10567c478bd9Sstevel@tonic-gate "rsm_memseg_export_publish: exit\n"));
10577c478bd9Sstevel@tonic-gate
10587c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate }
10617c478bd9Sstevel@tonic-gate
10627c478bd9Sstevel@tonic-gate int
rsm_memseg_export_unpublish(rsm_memseg_export_handle_t memseg)1063*7257d1b4Sraf rsm_memseg_export_unpublish(rsm_memseg_export_handle_t memseg)
10647c478bd9Sstevel@tonic-gate {
10657c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
10667c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
10677c478bd9Sstevel@tonic-gate
10687c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
10697c478bd9Sstevel@tonic-gate "rsm_memseg_export_unpublish: enter\n"));
10707c478bd9Sstevel@tonic-gate
10717c478bd9Sstevel@tonic-gate if (!seg) {
10727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10737c478bd9Sstevel@tonic-gate "invalid arguments\n"));
10747c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
10757c478bd9Sstevel@tonic-gate }
10767c478bd9Sstevel@tonic-gate
10777c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
10787c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != EXPORT_PUBLISH) {
10797c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10807c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10817c478bd9Sstevel@tonic-gate "segment not published %d\n",
10827c478bd9Sstevel@tonic-gate seg->rsmseg_keyid));
10837c478bd9Sstevel@tonic-gate return (RSMERR_SEG_NOT_PUBLISHED);
10847c478bd9Sstevel@tonic-gate }
10857c478bd9Sstevel@tonic-gate
10867c478bd9Sstevel@tonic-gate msg.key = seg->rsmseg_keyid;
10877c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_UNPUBLISH, &msg) < 0) {
10887c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10897c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
10907c478bd9Sstevel@tonic-gate "RSM_IOCTL_UNPUBLISH failed\n"));
10917c478bd9Sstevel@tonic-gate return (errno);
10927c478bd9Sstevel@tonic-gate }
10937c478bd9Sstevel@tonic-gate
10947c478bd9Sstevel@tonic-gate seg->rsmseg_state = EXPORT_BIND;
10957c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
10967c478bd9Sstevel@tonic-gate
10977c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
10987c478bd9Sstevel@tonic-gate "rsm_memseg_export_unpublish: exit\n"));
10997c478bd9Sstevel@tonic-gate
11007c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
11017c478bd9Sstevel@tonic-gate }
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate
11047c478bd9Sstevel@tonic-gate int
rsm_memseg_export_republish(rsm_memseg_export_handle_t memseg,rsmapi_access_entry_t access_list[],uint_t access_list_length)1105*7257d1b4Sraf rsm_memseg_export_republish(rsm_memseg_export_handle_t memseg,
11067c478bd9Sstevel@tonic-gate rsmapi_access_entry_t access_list[],
11077c478bd9Sstevel@tonic-gate uint_t access_list_length)
11087c478bd9Sstevel@tonic-gate {
11097c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
11107c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
11117c478bd9Sstevel@tonic-gate
11127c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
11137c478bd9Sstevel@tonic-gate "rsm_memseg_export_republish: enter\n"));
11147c478bd9Sstevel@tonic-gate
11157c478bd9Sstevel@tonic-gate if (!seg) {
11167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11177c478bd9Sstevel@tonic-gate "invalid segment or segment state\n"));
11187c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
11197c478bd9Sstevel@tonic-gate }
11207c478bd9Sstevel@tonic-gate
11217c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
11227c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != EXPORT_PUBLISH) {
11237c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11247c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11257c478bd9Sstevel@tonic-gate "segment not published\n"));
11267c478bd9Sstevel@tonic-gate return (RSMERR_SEG_NOT_PUBLISHED);
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate
11297c478bd9Sstevel@tonic-gate if (access_list_length > 0 && !access_list) {
11307c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11317c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11327c478bd9Sstevel@tonic-gate "invalid access control list\n"));
11337c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ACL);
11347c478bd9Sstevel@tonic-gate }
11357c478bd9Sstevel@tonic-gate
11367c478bd9Sstevel@tonic-gate msg.key = seg->rsmseg_keyid;
11377c478bd9Sstevel@tonic-gate msg.acl = access_list;
11387c478bd9Sstevel@tonic-gate msg.acl_len = access_list_length;
11397c478bd9Sstevel@tonic-gate
11407c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_REPUBLISH, &msg) < 0) {
11417c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11427c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
11437c478bd9Sstevel@tonic-gate "RSM_IOCTL_REPUBLISH failed\n"));
11447c478bd9Sstevel@tonic-gate return (errno);
11457c478bd9Sstevel@tonic-gate }
11467c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
11477c478bd9Sstevel@tonic-gate
11487c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_DEBUG_VERBOSE,
11497c478bd9Sstevel@tonic-gate "rsm_memseg_export_republish: exit\n"));
11507c478bd9Sstevel@tonic-gate
11517c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
11527c478bd9Sstevel@tonic-gate }
11537c478bd9Sstevel@tonic-gate
11547c478bd9Sstevel@tonic-gate
11557c478bd9Sstevel@tonic-gate /*
11567c478bd9Sstevel@tonic-gate * import side memory segment operations:
11577c478bd9Sstevel@tonic-gate */
11587c478bd9Sstevel@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)1159*7257d1b4Sraf rsm_memseg_import_connect(rsmapi_controller_handle_t controller,
11607c478bd9Sstevel@tonic-gate rsm_node_id_t node_id,
11617c478bd9Sstevel@tonic-gate rsm_memseg_id_t segment_id,
11627c478bd9Sstevel@tonic-gate rsm_permission_t perm,
11637c478bd9Sstevel@tonic-gate rsm_memseg_import_handle_t *im_memseg)
11647c478bd9Sstevel@tonic-gate {
11657c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
11667c478bd9Sstevel@tonic-gate rsmseg_handle_t *p;
11677c478bd9Sstevel@tonic-gate rsm_controller_t *cntr = (rsm_controller_t *)controller;
11687c478bd9Sstevel@tonic-gate #ifndef _LP64 /* added for fd > 255 fix */
11697c478bd9Sstevel@tonic-gate int tmpfd;
11707c478bd9Sstevel@tonic-gate #endif
11717c478bd9Sstevel@tonic-gate int e;
11727c478bd9Sstevel@tonic-gate
11737c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
11747c478bd9Sstevel@tonic-gate "rsm_memseg_import_connect: enter\n"));
11757c478bd9Sstevel@tonic-gate
11767c478bd9Sstevel@tonic-gate if (!cntr) {
11777c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
11787c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
11797c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
11807c478bd9Sstevel@tonic-gate }
11817c478bd9Sstevel@tonic-gate
11827c478bd9Sstevel@tonic-gate *im_memseg = 0;
11837c478bd9Sstevel@tonic-gate
11847c478bd9Sstevel@tonic-gate p = (rsmseg_handle_t *)malloc(sizeof (*p));
11857c478bd9Sstevel@tonic-gate if (!p) {
11867c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
11877c478bd9Sstevel@tonic-gate "not enough memory\n"));
11887c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
11897c478bd9Sstevel@tonic-gate }
11907c478bd9Sstevel@tonic-gate
11917c478bd9Sstevel@tonic-gate if (perm & ~RSM_PERM_RDWR) {
11927c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
11937c478bd9Sstevel@tonic-gate "invalid permissions\n"));
11947c478bd9Sstevel@tonic-gate return (RSMERR_PERM_DENIED);
11957c478bd9Sstevel@tonic-gate }
11967c478bd9Sstevel@tonic-gate
11977c478bd9Sstevel@tonic-gate /*
11987c478bd9Sstevel@tonic-gate * Get size, va from driver
11997c478bd9Sstevel@tonic-gate */
12007c478bd9Sstevel@tonic-gate msg.cnum = cntr->cntr_unit;
12017c478bd9Sstevel@tonic-gate msg.cname = cntr->cntr_name;
12027c478bd9Sstevel@tonic-gate msg.cname_len = strlen(cntr->cntr_name) +1;
12037c478bd9Sstevel@tonic-gate msg.nodeid = node_id;
12047c478bd9Sstevel@tonic-gate msg.key = segment_id;
12057c478bd9Sstevel@tonic-gate msg.perm = perm;
12067c478bd9Sstevel@tonic-gate
12077c478bd9Sstevel@tonic-gate p->rsmseg_fd = open(DEVRSM, O_RDWR);
12087c478bd9Sstevel@tonic-gate if (p->rsmseg_fd < 0) {
12097c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12107c478bd9Sstevel@tonic-gate "unable to open /dev/rsm"));
12117c478bd9Sstevel@tonic-gate free((void *)p);
12127c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
12137c478bd9Sstevel@tonic-gate }
12147c478bd9Sstevel@tonic-gate
12157c478bd9Sstevel@tonic-gate #ifndef _LP64
12167c478bd9Sstevel@tonic-gate /*
12177c478bd9Sstevel@tonic-gate * libc can't handle fd's greater than 255, in order to
12187c478bd9Sstevel@tonic-gate * insure that these values remain available make /dev/rsm
12197c478bd9Sstevel@tonic-gate * fd > 255. Note: not needed for LP64
12207c478bd9Sstevel@tonic-gate */
12217c478bd9Sstevel@tonic-gate tmpfd = fcntl(p->rsmseg_fd, F_DUPFD, 256); /* make fd > 255 */
12227c478bd9Sstevel@tonic-gate e = errno;
12237c478bd9Sstevel@tonic-gate if (tmpfd < 0) {
12247c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12257c478bd9Sstevel@tonic-gate "F_DUPFD failed\n"));
12267c478bd9Sstevel@tonic-gate } else {
12277c478bd9Sstevel@tonic-gate (void) close(p->rsmseg_fd);
12287c478bd9Sstevel@tonic-gate p->rsmseg_fd = tmpfd;
12297c478bd9Sstevel@tonic-gate }
12307c478bd9Sstevel@tonic-gate #endif /* _LP64 */
12317c478bd9Sstevel@tonic-gate
12327c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
12337c478bd9Sstevel@tonic-gate "rsmseg_fd is %d\n", p->rsmseg_fd));
12347c478bd9Sstevel@tonic-gate
12357c478bd9Sstevel@tonic-gate if (fcntl(p->rsmseg_fd, F_SETFD, FD_CLOEXEC) < 0) {
12367c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12377c478bd9Sstevel@tonic-gate "F_SETFD failed\n"));
12387c478bd9Sstevel@tonic-gate }
12397c478bd9Sstevel@tonic-gate if (ioctl(p->rsmseg_fd, RSM_IOCTL_CONNECT, &msg) < 0) {
12407c478bd9Sstevel@tonic-gate e = errno;
12417c478bd9Sstevel@tonic-gate (void) close(p->rsmseg_fd);
12427c478bd9Sstevel@tonic-gate free((void *)p);
12437c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
12447c478bd9Sstevel@tonic-gate "RSM_IOCTL_CONNECT failed\n"));
12457c478bd9Sstevel@tonic-gate return (e);
12467c478bd9Sstevel@tonic-gate }
12477c478bd9Sstevel@tonic-gate
12487c478bd9Sstevel@tonic-gate /*
12497c478bd9Sstevel@tonic-gate * We connected ok.
12507c478bd9Sstevel@tonic-gate */
12517c478bd9Sstevel@tonic-gate p->rsmseg_type = RSM_IMPORT_SEG;
12527c478bd9Sstevel@tonic-gate p->rsmseg_state = IMPORT_CONNECT;
12537c478bd9Sstevel@tonic-gate p->rsmseg_keyid = segment_id;
12547c478bd9Sstevel@tonic-gate p->rsmseg_nodeid = node_id;
12557c478bd9Sstevel@tonic-gate p->rsmseg_size = msg.len;
12567c478bd9Sstevel@tonic-gate p->rsmseg_perm = perm;
12577c478bd9Sstevel@tonic-gate p->rsmseg_controller = cntr;
12587c478bd9Sstevel@tonic-gate p->rsmseg_barrier = NULL;
12597c478bd9Sstevel@tonic-gate p->rsmseg_barmode = RSM_BARRIER_MODE_IMPLICIT;
12607c478bd9Sstevel@tonic-gate p->rsmseg_bar = (bar_va ? bar_va + msg.off : &bar_fixed);
12617c478bd9Sstevel@tonic-gate p->rsmseg_gnum = msg.gnum;
12627c478bd9Sstevel@tonic-gate p->rsmseg_pollfd_refcnt = 0;
12637c478bd9Sstevel@tonic-gate p->rsmseg_maplen = 0; /* initialized, set in import_map */
12647c478bd9Sstevel@tonic-gate p->rsmseg_mapoffset = 0;
12657c478bd9Sstevel@tonic-gate p->rsmseg_flags = 0;
12667c478bd9Sstevel@tonic-gate p->rsmseg_rnum = msg.rnum;
12677c478bd9Sstevel@tonic-gate mutex_init(&p->rsmseg_lock, USYNC_THREAD, NULL);
12687c478bd9Sstevel@tonic-gate
12697c478bd9Sstevel@tonic-gate p->rsmseg_ops = cntr->cntr_segops;
12707c478bd9Sstevel@tonic-gate
12717c478bd9Sstevel@tonic-gate /*
12727c478bd9Sstevel@tonic-gate * XXX: Based on permission and controller direct_access attribute
12737c478bd9Sstevel@tonic-gate * we fix the segment ops vector
12747c478bd9Sstevel@tonic-gate */
12757c478bd9Sstevel@tonic-gate
12767c478bd9Sstevel@tonic-gate p->rsmseg_vaddr = 0; /* defer mapping till using maps or trys to rw */
12777c478bd9Sstevel@tonic-gate
12787c478bd9Sstevel@tonic-gate *im_memseg = (rsm_memseg_import_handle_t)p;
12797c478bd9Sstevel@tonic-gate
12807c478bd9Sstevel@tonic-gate e = p->rsmseg_ops->rsm_memseg_import_connect(controller,
12817c478bd9Sstevel@tonic-gate node_id, segment_id, perm, im_memseg);
12827c478bd9Sstevel@tonic-gate
12837c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
12847c478bd9Sstevel@tonic-gate (void) close(p->rsmseg_fd);
12857c478bd9Sstevel@tonic-gate mutex_destroy(&p->rsmseg_lock);
12867c478bd9Sstevel@tonic-gate free((void *)p);
12877c478bd9Sstevel@tonic-gate }
12887c478bd9Sstevel@tonic-gate
12897c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
12907c478bd9Sstevel@tonic-gate "rsm_memseg_import_connect: exit\n"));
12917c478bd9Sstevel@tonic-gate
12927c478bd9Sstevel@tonic-gate return (e);
12937c478bd9Sstevel@tonic-gate }
12947c478bd9Sstevel@tonic-gate
12957c478bd9Sstevel@tonic-gate
12967c478bd9Sstevel@tonic-gate int
rsm_memseg_import_disconnect(rsm_memseg_import_handle_t im_memseg)1297*7257d1b4Sraf rsm_memseg_import_disconnect(rsm_memseg_import_handle_t im_memseg)
12987c478bd9Sstevel@tonic-gate {
12997c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
13007c478bd9Sstevel@tonic-gate int e;
13017c478bd9Sstevel@tonic-gate
13027c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
13037c478bd9Sstevel@tonic-gate "rsm_memseg_import_disconnect: enter\n"));
13047c478bd9Sstevel@tonic-gate
13057c478bd9Sstevel@tonic-gate if (!seg) {
13067c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13077c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
13087c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
13097c478bd9Sstevel@tonic-gate }
13107c478bd9Sstevel@tonic-gate
13117c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_CONNECT) {
13127c478bd9Sstevel@tonic-gate if (seg->rsmseg_flags & RSM_IMPLICIT_MAP) {
13137c478bd9Sstevel@tonic-gate e = rsm_memseg_import_unmap(im_memseg);
13147c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
13157c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13167c478bd9Sstevel@tonic-gate "unmap failure\n"));
13177c478bd9Sstevel@tonic-gate return (e);
13187c478bd9Sstevel@tonic-gate }
13197c478bd9Sstevel@tonic-gate } else {
13207c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13217c478bd9Sstevel@tonic-gate "segment busy\n"));
13227c478bd9Sstevel@tonic-gate return (RSMERR_SEG_STILL_MAPPED);
13237c478bd9Sstevel@tonic-gate }
13247c478bd9Sstevel@tonic-gate }
13257c478bd9Sstevel@tonic-gate
13267c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
13277c478bd9Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt) {
13287c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
13297c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_EXPORT, RSM_ERR,
13307c478bd9Sstevel@tonic-gate "segment reference count not zero\n"));
13317c478bd9Sstevel@tonic-gate return (RSMERR_POLLFD_IN_USE);
13327c478bd9Sstevel@tonic-gate }
13337c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate e = seg->rsmseg_ops->rsm_memseg_import_disconnect(im_memseg);
13367c478bd9Sstevel@tonic-gate
13377c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
13387c478bd9Sstevel@tonic-gate (void) close(seg->rsmseg_fd);
13397c478bd9Sstevel@tonic-gate mutex_destroy(&seg->rsmseg_lock);
13407c478bd9Sstevel@tonic-gate free((void *)seg);
13417c478bd9Sstevel@tonic-gate }
13427c478bd9Sstevel@tonic-gate
13437c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
13447c478bd9Sstevel@tonic-gate "rsm_memseg_import_disconnect: exit\n"));
13457c478bd9Sstevel@tonic-gate
13467c478bd9Sstevel@tonic-gate return (e);
13477c478bd9Sstevel@tonic-gate }
13487c478bd9Sstevel@tonic-gate
13497c478bd9Sstevel@tonic-gate /*
13507c478bd9Sstevel@tonic-gate * import side memory segment operations (read access functions):
13517c478bd9Sstevel@tonic-gate */
13527c478bd9Sstevel@tonic-gate
13537c478bd9Sstevel@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)13547c478bd9Sstevel@tonic-gate __rsm_import_verify_access(rsmseg_handle_t *seg,
13557c478bd9Sstevel@tonic-gate off_t offset,
13567c478bd9Sstevel@tonic-gate caddr_t datap,
13577c478bd9Sstevel@tonic-gate size_t len,
13587c478bd9Sstevel@tonic-gate rsm_permission_t perm,
13597c478bd9Sstevel@tonic-gate rsm_access_size_t das)
13607c478bd9Sstevel@tonic-gate {
13617c478bd9Sstevel@tonic-gate int error;
13627c478bd9Sstevel@tonic-gate
13637c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
13647c478bd9Sstevel@tonic-gate " __rsm_import_verify_access: enter\n"));
13657c478bd9Sstevel@tonic-gate
13667c478bd9Sstevel@tonic-gate if (!seg) {
13677c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13687c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
13697c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
13707c478bd9Sstevel@tonic-gate }
13717c478bd9Sstevel@tonic-gate if (!datap) {
13727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13737c478bd9Sstevel@tonic-gate "invalid data pointer\n"));
13747c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
13757c478bd9Sstevel@tonic-gate }
13767c478bd9Sstevel@tonic-gate
13777c478bd9Sstevel@tonic-gate /*
13787c478bd9Sstevel@tonic-gate * Check alignment of pointer
13797c478bd9Sstevel@tonic-gate */
13807c478bd9Sstevel@tonic-gate if ((uintptr_t)datap & (das - 1)) {
13817c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13827c478bd9Sstevel@tonic-gate "invalid alignment of data pointer\n"));
13837c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
13847c478bd9Sstevel@tonic-gate }
13857c478bd9Sstevel@tonic-gate
13867c478bd9Sstevel@tonic-gate if (offset & (das - 1)) {
13877c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13887c478bd9Sstevel@tonic-gate "invalid offset\n"));
13897c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
13907c478bd9Sstevel@tonic-gate }
13917c478bd9Sstevel@tonic-gate
13927c478bd9Sstevel@tonic-gate /* make sure that the import seg is connected */
13937c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_CONNECT &&
13947c478bd9Sstevel@tonic-gate seg->rsmseg_state != IMPORT_MAP) {
13957c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
13967c478bd9Sstevel@tonic-gate "incorrect segment state\n"));
13977c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
13987c478bd9Sstevel@tonic-gate }
13997c478bd9Sstevel@tonic-gate
14007c478bd9Sstevel@tonic-gate /* do an implicit map if required */
14017c478bd9Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_CONNECT) {
14027c478bd9Sstevel@tonic-gate error = __rsm_import_implicit_map(seg, RSM_IOTYPE_PUTGET);
14037c478bd9Sstevel@tonic-gate if (error != RSM_SUCCESS) {
14047c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14057c478bd9Sstevel@tonic-gate "implicit map failure\n"));
14067c478bd9Sstevel@tonic-gate return (error);
14077c478bd9Sstevel@tonic-gate }
14087c478bd9Sstevel@tonic-gate }
14097c478bd9Sstevel@tonic-gate
14107c478bd9Sstevel@tonic-gate if ((seg->rsmseg_perm & perm) != perm) {
14117c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14127c478bd9Sstevel@tonic-gate "invalid permissions\n"));
14137c478bd9Sstevel@tonic-gate return (RSMERR_PERM_DENIED);
14147c478bd9Sstevel@tonic-gate }
14157c478bd9Sstevel@tonic-gate
14167c478bd9Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_MAP) {
14177c478bd9Sstevel@tonic-gate if ((offset < seg->rsmseg_mapoffset) ||
14187c478bd9Sstevel@tonic-gate (offset + len > seg->rsmseg_mapoffset +
14197c478bd9Sstevel@tonic-gate seg->rsmseg_maplen)) {
14207c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14217c478bd9Sstevel@tonic-gate "incorrect offset+length\n"));
14227c478bd9Sstevel@tonic-gate return (RSMERR_BAD_OFFSET);
14237c478bd9Sstevel@tonic-gate }
14247c478bd9Sstevel@tonic-gate } else { /* IMPORT_CONNECT */
14257c478bd9Sstevel@tonic-gate if ((len + offset) > seg->rsmseg_size) {
14267c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14277c478bd9Sstevel@tonic-gate "incorrect offset+length\n"));
14287c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
14297c478bd9Sstevel@tonic-gate }
14307c478bd9Sstevel@tonic-gate }
14317c478bd9Sstevel@tonic-gate
14327c478bd9Sstevel@tonic-gate if ((seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) &&
14337c478bd9Sstevel@tonic-gate (seg->rsmseg_barrier == NULL)) {
14347c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14357c478bd9Sstevel@tonic-gate "invalid barrier\n"));
14367c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
14377c478bd9Sstevel@tonic-gate }
14387c478bd9Sstevel@tonic-gate
14397c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
14407c478bd9Sstevel@tonic-gate " __rsm_import_verify_access: exit\n"));
14417c478bd9Sstevel@tonic-gate
14427c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
14437c478bd9Sstevel@tonic-gate }
14447c478bd9Sstevel@tonic-gate
14457c478bd9Sstevel@tonic-gate static int
__rsm_import_implicit_map(rsmseg_handle_t * seg,int iotype)14467c478bd9Sstevel@tonic-gate __rsm_import_implicit_map(rsmseg_handle_t *seg, int iotype)
14477c478bd9Sstevel@tonic-gate {
14487c478bd9Sstevel@tonic-gate caddr_t va;
14497c478bd9Sstevel@tonic-gate int flag = MAP_SHARED;
14507c478bd9Sstevel@tonic-gate int prot = PROT_READ|PROT_WRITE;
14517c478bd9Sstevel@tonic-gate int mapping_reqd = 0;
14527c478bd9Sstevel@tonic-gate
14537c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
14547c478bd9Sstevel@tonic-gate " __rsm_import_implicit_map: enter\n"));
14557c478bd9Sstevel@tonic-gate
14567c478bd9Sstevel@tonic-gate if (iotype == RSM_IOTYPE_PUTGET)
14577c478bd9Sstevel@tonic-gate mapping_reqd = seg->rsmseg_controller->cntr_lib_attr->
14587c478bd9Sstevel@tonic-gate rsm_putget_map_reqd;
14597c478bd9Sstevel@tonic-gate else if (iotype == RSM_IOTYPE_SCATGATH)
14607c478bd9Sstevel@tonic-gate mapping_reqd = seg->rsmseg_controller->cntr_lib_attr->
14617c478bd9Sstevel@tonic-gate rsm_scatgath_map_reqd;
14627c478bd9Sstevel@tonic-gate
14637c478bd9Sstevel@tonic-gate
14647c478bd9Sstevel@tonic-gate if (mapping_reqd) {
14657c478bd9Sstevel@tonic-gate va = mmap(NULL, seg->rsmseg_size, prot,
14667c478bd9Sstevel@tonic-gate flag, seg->rsmseg_fd, 0);
14677c478bd9Sstevel@tonic-gate
14687c478bd9Sstevel@tonic-gate if (va == MAP_FAILED) {
14697c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
14707c478bd9Sstevel@tonic-gate "implicit map failed\n"));
14717c478bd9Sstevel@tonic-gate if (errno == ENOMEM || errno == ENXIO ||
14727c478bd9Sstevel@tonic-gate errno == EOVERFLOW)
14737c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
14747c478bd9Sstevel@tonic-gate else if (errno == ENODEV)
14757c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
14767c478bd9Sstevel@tonic-gate else if (errno == EAGAIN)
14777c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
14787c478bd9Sstevel@tonic-gate else if (errno == ENOTSUP)
14797c478bd9Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
14807c478bd9Sstevel@tonic-gate else if (errno == EACCES)
14817c478bd9Sstevel@tonic-gate return (RSMERR_BAD_PERMS);
14827c478bd9Sstevel@tonic-gate else
14837c478bd9Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
14847c478bd9Sstevel@tonic-gate }
14857c478bd9Sstevel@tonic-gate seg->rsmseg_vaddr = va;
14867c478bd9Sstevel@tonic-gate seg->rsmseg_maplen = seg->rsmseg_size;
14877c478bd9Sstevel@tonic-gate seg->rsmseg_mapoffset = 0;
14887c478bd9Sstevel@tonic-gate seg->rsmseg_state = IMPORT_MAP;
14897c478bd9Sstevel@tonic-gate seg->rsmseg_flags |= RSM_IMPLICIT_MAP;
14907c478bd9Sstevel@tonic-gate }
14917c478bd9Sstevel@tonic-gate
14927c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
14937c478bd9Sstevel@tonic-gate " __rsm_import_implicit_map: exit\n"));
14947c478bd9Sstevel@tonic-gate
14957c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
14967c478bd9Sstevel@tonic-gate }
14977c478bd9Sstevel@tonic-gate
14987c478bd9Sstevel@tonic-gate int
rsm_memseg_import_get8(rsm_memseg_import_handle_t im_memseg,off_t offset,uint8_t * datap,ulong_t rep_cnt)1499*7257d1b4Sraf rsm_memseg_import_get8(rsm_memseg_import_handle_t im_memseg,
15007c478bd9Sstevel@tonic-gate off_t offset,
15017c478bd9Sstevel@tonic-gate uint8_t *datap,
15027c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
15037c478bd9Sstevel@tonic-gate {
15047c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
15057c478bd9Sstevel@tonic-gate int e;
15067c478bd9Sstevel@tonic-gate
15077c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15087c478bd9Sstevel@tonic-gate "rsm_memseg_import_get8: enter\n"));
15097c478bd9Sstevel@tonic-gate
15107c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt,
15117c478bd9Sstevel@tonic-gate RSM_PERM_READ,
15127c478bd9Sstevel@tonic-gate RSM_DAS8);
15137c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
15147c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
15157c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
15167c478bd9Sstevel@tonic-gate
15177c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15187c478bd9Sstevel@tonic-gate /* generation number snapshot */
15197c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
15207c478bd9Sstevel@tonic-gate }
15217c478bd9Sstevel@tonic-gate
15227c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_get8(im_memseg, offset, datap,
15237c478bd9Sstevel@tonic-gate rep_cnt, 0);
15247c478bd9Sstevel@tonic-gate
15257c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15267c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
15277c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
15287c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
15297c478bd9Sstevel@tonic-gate }
15307c478bd9Sstevel@tonic-gate }
15317c478bd9Sstevel@tonic-gate }
15327c478bd9Sstevel@tonic-gate
15337c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15347c478bd9Sstevel@tonic-gate "rsm_memseg_import_get8: exit\n"));
15357c478bd9Sstevel@tonic-gate
15367c478bd9Sstevel@tonic-gate return (e);
15377c478bd9Sstevel@tonic-gate }
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gate int
rsm_memseg_import_get16(rsm_memseg_import_handle_t im_memseg,off_t offset,uint16_t * datap,ulong_t rep_cnt)1540*7257d1b4Sraf rsm_memseg_import_get16(rsm_memseg_import_handle_t im_memseg,
15417c478bd9Sstevel@tonic-gate off_t offset,
15427c478bd9Sstevel@tonic-gate uint16_t *datap,
15437c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
15447c478bd9Sstevel@tonic-gate {
15457c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
15467c478bd9Sstevel@tonic-gate int e;
15477c478bd9Sstevel@tonic-gate
15487c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15497c478bd9Sstevel@tonic-gate "rsm_memseg_import_get16: enter\n"));
15507c478bd9Sstevel@tonic-gate
15517c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*2,
15527c478bd9Sstevel@tonic-gate RSM_PERM_READ,
15537c478bd9Sstevel@tonic-gate RSM_DAS16);
15547c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
15557c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
15567c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
15577c478bd9Sstevel@tonic-gate
15587c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15597c478bd9Sstevel@tonic-gate /* generation number snapshot */
15607c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
15617c478bd9Sstevel@tonic-gate }
15627c478bd9Sstevel@tonic-gate
15637c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_get16(im_memseg, offset, datap,
15647c478bd9Sstevel@tonic-gate rep_cnt, 0);
15657c478bd9Sstevel@tonic-gate
15667c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
15677c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
15687c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
15697c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
15707c478bd9Sstevel@tonic-gate }
15717c478bd9Sstevel@tonic-gate }
15727c478bd9Sstevel@tonic-gate
15737c478bd9Sstevel@tonic-gate }
15747c478bd9Sstevel@tonic-gate
15757c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15767c478bd9Sstevel@tonic-gate "rsm_memseg_import_get16: exit\n"));
15777c478bd9Sstevel@tonic-gate
15787c478bd9Sstevel@tonic-gate return (e);
15797c478bd9Sstevel@tonic-gate }
15807c478bd9Sstevel@tonic-gate
15817c478bd9Sstevel@tonic-gate int
rsm_memseg_import_get32(rsm_memseg_import_handle_t im_memseg,off_t offset,uint32_t * datap,ulong_t rep_cnt)1582*7257d1b4Sraf rsm_memseg_import_get32(rsm_memseg_import_handle_t im_memseg,
15837c478bd9Sstevel@tonic-gate off_t offset,
15847c478bd9Sstevel@tonic-gate uint32_t *datap,
15857c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
15867c478bd9Sstevel@tonic-gate {
15877c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
15887c478bd9Sstevel@tonic-gate int e;
15897c478bd9Sstevel@tonic-gate
15907c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
15917c478bd9Sstevel@tonic-gate "rsm_memseg_import_get32: enter\n"));
15927c478bd9Sstevel@tonic-gate
15937c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*4,
15947c478bd9Sstevel@tonic-gate RSM_PERM_READ,
15957c478bd9Sstevel@tonic-gate RSM_DAS32);
15967c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
15977c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
15987c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
15997c478bd9Sstevel@tonic-gate
16007c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16017c478bd9Sstevel@tonic-gate /* generation number snapshot */
16027c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
16037c478bd9Sstevel@tonic-gate }
16047c478bd9Sstevel@tonic-gate
16057c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_get32(im_memseg, offset, datap,
16067c478bd9Sstevel@tonic-gate rep_cnt, 0);
16077c478bd9Sstevel@tonic-gate
16087c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16097c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
16107c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
16117c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
16127c478bd9Sstevel@tonic-gate }
16137c478bd9Sstevel@tonic-gate }
16147c478bd9Sstevel@tonic-gate }
16157c478bd9Sstevel@tonic-gate
16167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16177c478bd9Sstevel@tonic-gate "rsm_memseg_import_get32: exit\n"));
16187c478bd9Sstevel@tonic-gate
16197c478bd9Sstevel@tonic-gate return (e);
16207c478bd9Sstevel@tonic-gate }
16217c478bd9Sstevel@tonic-gate
16227c478bd9Sstevel@tonic-gate int
rsm_memseg_import_get64(rsm_memseg_import_handle_t im_memseg,off_t offset,uint64_t * datap,ulong_t rep_cnt)1623*7257d1b4Sraf rsm_memseg_import_get64(rsm_memseg_import_handle_t im_memseg,
16247c478bd9Sstevel@tonic-gate off_t offset,
16257c478bd9Sstevel@tonic-gate uint64_t *datap,
16267c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
16277c478bd9Sstevel@tonic-gate {
16287c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
16297c478bd9Sstevel@tonic-gate int e;
16307c478bd9Sstevel@tonic-gate
16317c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16327c478bd9Sstevel@tonic-gate "rsm_memseg_import_get64: enter\n"));
16337c478bd9Sstevel@tonic-gate
16347c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*8,
16357c478bd9Sstevel@tonic-gate RSM_PERM_READ,
16367c478bd9Sstevel@tonic-gate RSM_DAS64);
16377c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
16387c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
16397c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
16407c478bd9Sstevel@tonic-gate
16417c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16427c478bd9Sstevel@tonic-gate /* generation number snapshot */
16437c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
16447c478bd9Sstevel@tonic-gate }
16457c478bd9Sstevel@tonic-gate
16467c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_get64(im_memseg, offset, datap,
16477c478bd9Sstevel@tonic-gate rep_cnt, 0);
16487c478bd9Sstevel@tonic-gate
16497c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16507c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
16517c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
16527c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
16537c478bd9Sstevel@tonic-gate }
16547c478bd9Sstevel@tonic-gate }
16557c478bd9Sstevel@tonic-gate }
16567c478bd9Sstevel@tonic-gate
16577c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16587c478bd9Sstevel@tonic-gate "rsm_memseg_import_get64: exit\n"));
16597c478bd9Sstevel@tonic-gate
16607c478bd9Sstevel@tonic-gate return (e);
16617c478bd9Sstevel@tonic-gate }
16627c478bd9Sstevel@tonic-gate
16637c478bd9Sstevel@tonic-gate int
rsm_memseg_import_get(rsm_memseg_import_handle_t im_memseg,off_t offset,void * dst_addr,size_t length)1664*7257d1b4Sraf rsm_memseg_import_get(rsm_memseg_import_handle_t im_memseg,
16657c478bd9Sstevel@tonic-gate off_t offset,
16667c478bd9Sstevel@tonic-gate void *dst_addr,
16677c478bd9Sstevel@tonic-gate size_t length)
16687c478bd9Sstevel@tonic-gate {
16697c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
16707c478bd9Sstevel@tonic-gate int e;
16717c478bd9Sstevel@tonic-gate
16727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16737c478bd9Sstevel@tonic-gate "rsm_memseg_import_get: enter\n"));
16747c478bd9Sstevel@tonic-gate
16757c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)dst_addr, length,
16767c478bd9Sstevel@tonic-gate RSM_PERM_READ,
16777c478bd9Sstevel@tonic-gate RSM_DAS8);
16787c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
16797c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
16807c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
16817c478bd9Sstevel@tonic-gate
16827c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16837c478bd9Sstevel@tonic-gate /* generation number snapshot */
16847c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
16857c478bd9Sstevel@tonic-gate }
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_get(im_memseg, offset, dst_addr,
16887c478bd9Sstevel@tonic-gate length);
16897c478bd9Sstevel@tonic-gate
16907c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
16917c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
16927c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
16937c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
16947c478bd9Sstevel@tonic-gate }
16957c478bd9Sstevel@tonic-gate }
16967c478bd9Sstevel@tonic-gate }
16977c478bd9Sstevel@tonic-gate
16987c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
16997c478bd9Sstevel@tonic-gate "rsm_memseg_import_get: exit\n"));
17007c478bd9Sstevel@tonic-gate
17017c478bd9Sstevel@tonic-gate return (e);
17027c478bd9Sstevel@tonic-gate }
17037c478bd9Sstevel@tonic-gate
17047c478bd9Sstevel@tonic-gate
17057c478bd9Sstevel@tonic-gate int
rsm_memseg_import_getv(rsm_scat_gath_t * sg_io)1706*7257d1b4Sraf rsm_memseg_import_getv(rsm_scat_gath_t *sg_io)
17077c478bd9Sstevel@tonic-gate {
17087c478bd9Sstevel@tonic-gate rsm_controller_t *cntrl;
17097c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg;
17107c478bd9Sstevel@tonic-gate uint_t save_sg_io_flags;
17117c478bd9Sstevel@tonic-gate
17127c478bd9Sstevel@tonic-gate int e;
17137c478bd9Sstevel@tonic-gate
17147c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
17157c478bd9Sstevel@tonic-gate "rsm_memseg_import_getv: enter\n"));
17167c478bd9Sstevel@tonic-gate
17177c478bd9Sstevel@tonic-gate if (sg_io == NULL) {
17187c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17197c478bd9Sstevel@tonic-gate "invalid sg_io structure\n"));
17207c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
17217c478bd9Sstevel@tonic-gate }
17227c478bd9Sstevel@tonic-gate
17237c478bd9Sstevel@tonic-gate seg = (rsmseg_handle_t *)sg_io->remote_handle;
17247c478bd9Sstevel@tonic-gate if (seg == NULL) {
17257c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17267c478bd9Sstevel@tonic-gate "invalid remote segment handle in sg_io\n"));
17277c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
17287c478bd9Sstevel@tonic-gate }
17297c478bd9Sstevel@tonic-gate
17307c478bd9Sstevel@tonic-gate cntrl = (rsm_controller_t *)seg->rsmseg_controller;
17317c478bd9Sstevel@tonic-gate if (cntrl == NULL) {
17327c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17337c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
17347c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
17357c478bd9Sstevel@tonic-gate }
17367c478bd9Sstevel@tonic-gate
17377c478bd9Sstevel@tonic-gate if ((sg_io->io_request_count > RSM_MAX_SGIOREQS) ||
17387c478bd9Sstevel@tonic-gate (sg_io->io_request_count == 0)) {
17397c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17407c478bd9Sstevel@tonic-gate "io_request_count value incorrect\n"));
17417c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
17427c478bd9Sstevel@tonic-gate }
17437c478bd9Sstevel@tonic-gate
17447c478bd9Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_CONNECT) {
17457c478bd9Sstevel@tonic-gate e = __rsm_import_implicit_map(seg, RSM_IOTYPE_SCATGATH);
17467c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
17477c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
17487c478bd9Sstevel@tonic-gate "implicit map failure\n"));
17497c478bd9Sstevel@tonic-gate return (e);
17507c478bd9Sstevel@tonic-gate }
17517c478bd9Sstevel@tonic-gate }
17527c478bd9Sstevel@tonic-gate
17537c478bd9Sstevel@tonic-gate /*
17547c478bd9Sstevel@tonic-gate * Copy the flags field of the sg_io structure in a local
17557c478bd9Sstevel@tonic-gate * variable.
17567c478bd9Sstevel@tonic-gate * This is required since the flags field can be
17577c478bd9Sstevel@tonic-gate * changed by the plugin library routine to indicate that
17587c478bd9Sstevel@tonic-gate * the signal post was done.
17597c478bd9Sstevel@tonic-gate * This change in the flags field of the sg_io structure
17607c478bd9Sstevel@tonic-gate * should not be reflected to the user. Hence once the flags
17617c478bd9Sstevel@tonic-gate * field has been used for the purpose of determining whether
17627c478bd9Sstevel@tonic-gate * the plugin executed a signal post, it must be restored to
17637c478bd9Sstevel@tonic-gate * its original value which is stored in the local variable.
17647c478bd9Sstevel@tonic-gate */
17657c478bd9Sstevel@tonic-gate save_sg_io_flags = sg_io->flags;
17667c478bd9Sstevel@tonic-gate
17677c478bd9Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_memseg_import_getv(sg_io);
17687c478bd9Sstevel@tonic-gate
17697c478bd9Sstevel@tonic-gate /*
17707c478bd9Sstevel@tonic-gate * At this point, if an implicit signal post was requested by
17717c478bd9Sstevel@tonic-gate * the user, there could be two possibilities that arise:
17727c478bd9Sstevel@tonic-gate * 1. the plugin routine has already executed the implicit
17737c478bd9Sstevel@tonic-gate * signal post either successfully or unsuccessfully
17747c478bd9Sstevel@tonic-gate * 2. the plugin does not have the capability of doing an
17757c478bd9Sstevel@tonic-gate * implicit signal post and hence the signal post needs
17767c478bd9Sstevel@tonic-gate * to be done here.
17777c478bd9Sstevel@tonic-gate * The above two cases can be idenfied by the flags
17787c478bd9Sstevel@tonic-gate * field within the sg_io structure as follows:
17797c478bd9Sstevel@tonic-gate * In case 1, the RSM_IMPLICIT_SIGPOST bit is reset to 0 by the
17807c478bd9Sstevel@tonic-gate * plugin, indicating that the signal post was done.
17817c478bd9Sstevel@tonic-gate * In case 2, the bit remains set to a 1 as originally given
17827c478bd9Sstevel@tonic-gate * by the user, and hence a signal post needs to be done here.
17837c478bd9Sstevel@tonic-gate */
17847c478bd9Sstevel@tonic-gate if (sg_io->flags & RSM_IMPLICIT_SIGPOST &&
17857c478bd9Sstevel@tonic-gate e == RSM_SUCCESS) {
17867c478bd9Sstevel@tonic-gate /* Do the implicit signal post */
17877c478bd9Sstevel@tonic-gate
17887c478bd9Sstevel@tonic-gate /*
17897c478bd9Sstevel@tonic-gate * The value of the second argument to this call
17907c478bd9Sstevel@tonic-gate * depends on the value of the sg_io->flags field.
17917c478bd9Sstevel@tonic-gate * If the RSM_SIGPOST_NO_ACCUMULATE flag has been
17927c478bd9Sstevel@tonic-gate * ored into the sg_io->flags field, this indicates
17937c478bd9Sstevel@tonic-gate * that the rsm_intr_signal_post is to be done with
17947c478bd9Sstevel@tonic-gate * the flags argument set to RSM_SIGPOST_NO_ACCUMULATE
17957c478bd9Sstevel@tonic-gate * Else, the flags argument is set to 0. These
17967c478bd9Sstevel@tonic-gate * semantics can be achieved simply by masking off
17977c478bd9Sstevel@tonic-gate * all other bits in the sg_io->flags field except the
17987c478bd9Sstevel@tonic-gate * RSM_SIGPOST_NO_ACCUMULATE bit and using the result
17997c478bd9Sstevel@tonic-gate * as the flags argument for the rsm_intr_signal_post.
18007c478bd9Sstevel@tonic-gate */
18017c478bd9Sstevel@tonic-gate
18027c478bd9Sstevel@tonic-gate int sigpost_flags = sg_io->flags & RSM_SIGPOST_NO_ACCUMULATE;
18037c478bd9Sstevel@tonic-gate e = rsm_intr_signal_post(seg, sigpost_flags);
18047c478bd9Sstevel@tonic-gate }
18057c478bd9Sstevel@tonic-gate
18067c478bd9Sstevel@tonic-gate /* Restore the flags field within the users scatter gather structure */
18077c478bd9Sstevel@tonic-gate sg_io->flags = save_sg_io_flags;
18087c478bd9Sstevel@tonic-gate
18097c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18107c478bd9Sstevel@tonic-gate "rsm_memseg_import_getv: exit\n"));
18117c478bd9Sstevel@tonic-gate
18127c478bd9Sstevel@tonic-gate return (e);
18137c478bd9Sstevel@tonic-gate
18147c478bd9Sstevel@tonic-gate }
18157c478bd9Sstevel@tonic-gate
18167c478bd9Sstevel@tonic-gate /*
18177c478bd9Sstevel@tonic-gate * import side memory segment operations (write access functions):
18187c478bd9Sstevel@tonic-gate */
18197c478bd9Sstevel@tonic-gate
18207c478bd9Sstevel@tonic-gate int
rsm_memseg_import_put8(rsm_memseg_import_handle_t im_memseg,off_t offset,uint8_t * datap,ulong_t rep_cnt)1821*7257d1b4Sraf rsm_memseg_import_put8(rsm_memseg_import_handle_t im_memseg,
18227c478bd9Sstevel@tonic-gate off_t offset,
18237c478bd9Sstevel@tonic-gate uint8_t *datap,
18247c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
18257c478bd9Sstevel@tonic-gate {
18267c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
18277c478bd9Sstevel@tonic-gate int e;
18287c478bd9Sstevel@tonic-gate
18297c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18307c478bd9Sstevel@tonic-gate "rsm_memseg_import_put8: enter\n"));
18317c478bd9Sstevel@tonic-gate
18327c478bd9Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
18337c478bd9Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
18347c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt,
18357c478bd9Sstevel@tonic-gate RSM_PERM_WRITE,
18367c478bd9Sstevel@tonic-gate RSM_DAS8);
18377c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
18387c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
18397c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
18407c478bd9Sstevel@tonic-gate
18417c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18427c478bd9Sstevel@tonic-gate /* generation number snapshot */
18437c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
18447c478bd9Sstevel@tonic-gate }
18457c478bd9Sstevel@tonic-gate
18467c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_put8(im_memseg, offset, datap,
18477c478bd9Sstevel@tonic-gate rep_cnt, 0);
18487c478bd9Sstevel@tonic-gate
18497c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18507c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
18517c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
18527c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
18537c478bd9Sstevel@tonic-gate }
18547c478bd9Sstevel@tonic-gate }
18557c478bd9Sstevel@tonic-gate }
18567c478bd9Sstevel@tonic-gate
18577c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18587c478bd9Sstevel@tonic-gate "rsm_memseg_import_put8: exit\n"));
18597c478bd9Sstevel@tonic-gate
18607c478bd9Sstevel@tonic-gate return (e);
18617c478bd9Sstevel@tonic-gate }
18627c478bd9Sstevel@tonic-gate
18637c478bd9Sstevel@tonic-gate int
rsm_memseg_import_put16(rsm_memseg_import_handle_t im_memseg,off_t offset,uint16_t * datap,ulong_t rep_cnt)1864*7257d1b4Sraf rsm_memseg_import_put16(rsm_memseg_import_handle_t im_memseg,
18657c478bd9Sstevel@tonic-gate off_t offset,
18667c478bd9Sstevel@tonic-gate uint16_t *datap,
18677c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
18687c478bd9Sstevel@tonic-gate {
18697c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
18707c478bd9Sstevel@tonic-gate int e;
18717c478bd9Sstevel@tonic-gate
18727c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
18737c478bd9Sstevel@tonic-gate "rsm_memseg_import_put16: enter\n"));
18747c478bd9Sstevel@tonic-gate
18757c478bd9Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
18767c478bd9Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
18777c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*2,
18787c478bd9Sstevel@tonic-gate RSM_PERM_WRITE,
18797c478bd9Sstevel@tonic-gate RSM_DAS16);
18807c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
18817c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
18827c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
18837c478bd9Sstevel@tonic-gate
18847c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18857c478bd9Sstevel@tonic-gate /* generation number snapshot */
18867c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
18877c478bd9Sstevel@tonic-gate }
18887c478bd9Sstevel@tonic-gate
18897c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_put16(im_memseg, offset, datap,
18907c478bd9Sstevel@tonic-gate rep_cnt, 0);
18917c478bd9Sstevel@tonic-gate
18927c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
18937c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
18947c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
18957c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
18967c478bd9Sstevel@tonic-gate }
18977c478bd9Sstevel@tonic-gate }
18987c478bd9Sstevel@tonic-gate
18997c478bd9Sstevel@tonic-gate }
19007c478bd9Sstevel@tonic-gate
19017c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19027c478bd9Sstevel@tonic-gate "rsm_memseg_import_put16: exit\n"));
19037c478bd9Sstevel@tonic-gate
19047c478bd9Sstevel@tonic-gate return (e);
19057c478bd9Sstevel@tonic-gate }
19067c478bd9Sstevel@tonic-gate
19077c478bd9Sstevel@tonic-gate int
rsm_memseg_import_put32(rsm_memseg_import_handle_t im_memseg,off_t offset,uint32_t * datap,ulong_t rep_cnt)1908*7257d1b4Sraf rsm_memseg_import_put32(rsm_memseg_import_handle_t im_memseg,
19097c478bd9Sstevel@tonic-gate off_t offset,
19107c478bd9Sstevel@tonic-gate uint32_t *datap,
19117c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
19127c478bd9Sstevel@tonic-gate {
19137c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
19147c478bd9Sstevel@tonic-gate int e;
19157c478bd9Sstevel@tonic-gate
19167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19177c478bd9Sstevel@tonic-gate "rsm_memseg_import_put32: enter\n"));
19187c478bd9Sstevel@tonic-gate
19197c478bd9Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
19207c478bd9Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
19217c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*4,
19227c478bd9Sstevel@tonic-gate RSM_PERM_WRITE,
19237c478bd9Sstevel@tonic-gate RSM_DAS32);
19247c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
19257c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
19267c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
19277c478bd9Sstevel@tonic-gate
19287c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19297c478bd9Sstevel@tonic-gate /* generation number snapshot */
19307c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
19317c478bd9Sstevel@tonic-gate }
19327c478bd9Sstevel@tonic-gate
19337c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_put32(im_memseg, offset, datap,
19347c478bd9Sstevel@tonic-gate rep_cnt, 0);
19357c478bd9Sstevel@tonic-gate
19367c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19377c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
19387c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
19397c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
19407c478bd9Sstevel@tonic-gate }
19417c478bd9Sstevel@tonic-gate }
19427c478bd9Sstevel@tonic-gate }
19437c478bd9Sstevel@tonic-gate
19447c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19457c478bd9Sstevel@tonic-gate "rsm_memseg_import_put32: exit\n"));
19467c478bd9Sstevel@tonic-gate
19477c478bd9Sstevel@tonic-gate return (e);
19487c478bd9Sstevel@tonic-gate }
19497c478bd9Sstevel@tonic-gate
19507c478bd9Sstevel@tonic-gate int
rsm_memseg_import_put64(rsm_memseg_import_handle_t im_memseg,off_t offset,uint64_t * datap,ulong_t rep_cnt)1951*7257d1b4Sraf rsm_memseg_import_put64(rsm_memseg_import_handle_t im_memseg,
19527c478bd9Sstevel@tonic-gate off_t offset,
19537c478bd9Sstevel@tonic-gate uint64_t *datap,
19547c478bd9Sstevel@tonic-gate ulong_t rep_cnt)
19557c478bd9Sstevel@tonic-gate {
19567c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
19577c478bd9Sstevel@tonic-gate int e;
19587c478bd9Sstevel@tonic-gate
19597c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19607c478bd9Sstevel@tonic-gate "rsm_memseg_import_put64: enter\n"));
19617c478bd9Sstevel@tonic-gate
19627c478bd9Sstevel@tonic-gate /* addr of data will always pass the alignment check, avoids */
19637c478bd9Sstevel@tonic-gate /* need for a special case in verify_access for PUTs */
19647c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)datap, rep_cnt*8,
19657c478bd9Sstevel@tonic-gate RSM_PERM_WRITE,
19667c478bd9Sstevel@tonic-gate RSM_DAS64);
19677c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
19687c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
19697c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
19707c478bd9Sstevel@tonic-gate
19717c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19727c478bd9Sstevel@tonic-gate /* generation number snapshot */
19737c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
19747c478bd9Sstevel@tonic-gate }
19757c478bd9Sstevel@tonic-gate
19767c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_put64(im_memseg, offset, datap,
19777c478bd9Sstevel@tonic-gate rep_cnt, 0);
19787c478bd9Sstevel@tonic-gate
19797c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
19807c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
19817c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
19827c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
19837c478bd9Sstevel@tonic-gate }
19847c478bd9Sstevel@tonic-gate }
19857c478bd9Sstevel@tonic-gate }
19867c478bd9Sstevel@tonic-gate
19877c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
19887c478bd9Sstevel@tonic-gate "rsm_memseg_import_put64: exit\n"));
19897c478bd9Sstevel@tonic-gate
19907c478bd9Sstevel@tonic-gate return (e);
19917c478bd9Sstevel@tonic-gate }
19927c478bd9Sstevel@tonic-gate
19937c478bd9Sstevel@tonic-gate int
rsm_memseg_import_put(rsm_memseg_import_handle_t im_memseg,off_t offset,void * src_addr,size_t length)1994*7257d1b4Sraf rsm_memseg_import_put(rsm_memseg_import_handle_t im_memseg,
19957c478bd9Sstevel@tonic-gate off_t offset,
19967c478bd9Sstevel@tonic-gate void *src_addr,
19977c478bd9Sstevel@tonic-gate size_t length)
19987c478bd9Sstevel@tonic-gate {
19997c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
20007c478bd9Sstevel@tonic-gate int e;
20017c478bd9Sstevel@tonic-gate
20027c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
20037c478bd9Sstevel@tonic-gate "rsm_memseg_import_put: enter\n"));
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gate e = __rsm_import_verify_access(seg, offset, (caddr_t)src_addr, length,
20067c478bd9Sstevel@tonic-gate RSM_PERM_WRITE,
20077c478bd9Sstevel@tonic-gate RSM_DAS8);
20087c478bd9Sstevel@tonic-gate if (e == RSM_SUCCESS) {
20097c478bd9Sstevel@tonic-gate rsm_segops_t *ops = seg->rsmseg_ops;
20107c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)seg->rsmseg_barrier;
20117c478bd9Sstevel@tonic-gate
20127c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
20137c478bd9Sstevel@tonic-gate /* generation number snapshot */
20147c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum;
20157c478bd9Sstevel@tonic-gate }
20167c478bd9Sstevel@tonic-gate
20177c478bd9Sstevel@tonic-gate e = ops->rsm_memseg_import_put(im_memseg, offset, src_addr,
20187c478bd9Sstevel@tonic-gate length);
20197c478bd9Sstevel@tonic-gate
20207c478bd9Sstevel@tonic-gate if (seg->rsmseg_barmode == RSM_BARRIER_MODE_IMPLICIT) {
20217c478bd9Sstevel@tonic-gate /* check the generation number for force disconnects */
20227c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
20237c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
20247c478bd9Sstevel@tonic-gate }
20257c478bd9Sstevel@tonic-gate }
20267c478bd9Sstevel@tonic-gate
20277c478bd9Sstevel@tonic-gate }
20287c478bd9Sstevel@tonic-gate
20297c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
20307c478bd9Sstevel@tonic-gate "rsm_memseg_import_put: exit\n"));
20317c478bd9Sstevel@tonic-gate return (e);
20327c478bd9Sstevel@tonic-gate }
20337c478bd9Sstevel@tonic-gate
20347c478bd9Sstevel@tonic-gate
20357c478bd9Sstevel@tonic-gate int
rsm_memseg_import_putv(rsm_scat_gath_t * sg_io)2036*7257d1b4Sraf rsm_memseg_import_putv(rsm_scat_gath_t *sg_io)
20377c478bd9Sstevel@tonic-gate {
20387c478bd9Sstevel@tonic-gate rsm_controller_t *cntrl;
20397c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg;
20407c478bd9Sstevel@tonic-gate uint_t save_sg_io_flags;
20417c478bd9Sstevel@tonic-gate
20427c478bd9Sstevel@tonic-gate int e;
20437c478bd9Sstevel@tonic-gate
20447c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
20457c478bd9Sstevel@tonic-gate "rsm_memseg_import_putv: enter\n"));
20467c478bd9Sstevel@tonic-gate
20477c478bd9Sstevel@tonic-gate
20487c478bd9Sstevel@tonic-gate if (sg_io == NULL) {
20497c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20507c478bd9Sstevel@tonic-gate "invalid sg_io structure\n"));
20517c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
20527c478bd9Sstevel@tonic-gate }
20537c478bd9Sstevel@tonic-gate
20547c478bd9Sstevel@tonic-gate seg = (rsmseg_handle_t *)sg_io->remote_handle;
20557c478bd9Sstevel@tonic-gate if (seg == NULL) {
20567c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20577c478bd9Sstevel@tonic-gate "invalid remote segment handle in sg_io\n"));
20587c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
20597c478bd9Sstevel@tonic-gate }
20607c478bd9Sstevel@tonic-gate
20617c478bd9Sstevel@tonic-gate cntrl = (rsm_controller_t *)seg->rsmseg_controller;
20627c478bd9Sstevel@tonic-gate if (cntrl == NULL) {
20637c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20647c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
20657c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
20667c478bd9Sstevel@tonic-gate }
20677c478bd9Sstevel@tonic-gate
20687c478bd9Sstevel@tonic-gate if ((sg_io->io_request_count > RSM_MAX_SGIOREQS) ||
20697c478bd9Sstevel@tonic-gate (sg_io->io_request_count == 0)) {
20707c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20717c478bd9Sstevel@tonic-gate "io_request_count value incorrect\n"));
20727c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SGIO);
20737c478bd9Sstevel@tonic-gate }
20747c478bd9Sstevel@tonic-gate
20757c478bd9Sstevel@tonic-gate /* do an implicit map if required */
20767c478bd9Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_CONNECT) {
20777c478bd9Sstevel@tonic-gate e = __rsm_import_implicit_map(seg, RSM_IOTYPE_SCATGATH);
20787c478bd9Sstevel@tonic-gate if (e != RSM_SUCCESS) {
20797c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
20807c478bd9Sstevel@tonic-gate "implicit map failed\n"));
20817c478bd9Sstevel@tonic-gate return (e);
20827c478bd9Sstevel@tonic-gate }
20837c478bd9Sstevel@tonic-gate }
20847c478bd9Sstevel@tonic-gate
20857c478bd9Sstevel@tonic-gate /*
20867c478bd9Sstevel@tonic-gate * Copy the flags field of the sg_io structure in a local
20877c478bd9Sstevel@tonic-gate * variable.
20887c478bd9Sstevel@tonic-gate * This is required since the flags field can be
20897c478bd9Sstevel@tonic-gate * changed by the plugin library routine to indicate that
20907c478bd9Sstevel@tonic-gate * the signal post was done.
20917c478bd9Sstevel@tonic-gate * This change in the flags field of the sg_io structure
20927c478bd9Sstevel@tonic-gate * should not be reflected to the user. Hence once the flags
20937c478bd9Sstevel@tonic-gate * field has been used for the purpose of determining whether
20947c478bd9Sstevel@tonic-gate * the plugin executed a signal post, it must be restored to
20957c478bd9Sstevel@tonic-gate * its original value which is stored in the local variable.
20967c478bd9Sstevel@tonic-gate */
20977c478bd9Sstevel@tonic-gate save_sg_io_flags = sg_io->flags;
20987c478bd9Sstevel@tonic-gate
20997c478bd9Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_memseg_import_putv(sg_io);
21007c478bd9Sstevel@tonic-gate
21017c478bd9Sstevel@tonic-gate /*
21027c478bd9Sstevel@tonic-gate * At this point, if an implicit signal post was requested by
21037c478bd9Sstevel@tonic-gate * the user, there could be two possibilities that arise:
21047c478bd9Sstevel@tonic-gate * 1. the plugin routine has already executed the implicit
21057c478bd9Sstevel@tonic-gate * signal post either successfully or unsuccessfully
21067c478bd9Sstevel@tonic-gate * 2. the plugin does not have the capability of doing an
21077c478bd9Sstevel@tonic-gate * implicit signal post and hence the signal post needs
21087c478bd9Sstevel@tonic-gate * to be done here.
21097c478bd9Sstevel@tonic-gate * The above two cases can be idenfied by the flags
21107c478bd9Sstevel@tonic-gate * field within the sg_io structure as follows:
21117c478bd9Sstevel@tonic-gate * In case 1, the RSM_IMPLICIT_SIGPOST bit is reset to 0 by the
21127c478bd9Sstevel@tonic-gate * plugin, indicating that the signal post was done.
21137c478bd9Sstevel@tonic-gate * In case 2, the bit remains set to a 1 as originally given
21147c478bd9Sstevel@tonic-gate * by the user, and hence a signal post needs to be done here.
21157c478bd9Sstevel@tonic-gate */
21167c478bd9Sstevel@tonic-gate if (sg_io->flags & RSM_IMPLICIT_SIGPOST &&
21177c478bd9Sstevel@tonic-gate e == RSM_SUCCESS) {
21187c478bd9Sstevel@tonic-gate /* Do the implicit signal post */
21197c478bd9Sstevel@tonic-gate
21207c478bd9Sstevel@tonic-gate /*
21217c478bd9Sstevel@tonic-gate * The value of the second argument to this call
21227c478bd9Sstevel@tonic-gate * depends on the value of the sg_io->flags field.
21237c478bd9Sstevel@tonic-gate * If the RSM_SIGPOST_NO_ACCUMULATE flag has been
21247c478bd9Sstevel@tonic-gate * ored into the sg_io->flags field, this indicates
21257c478bd9Sstevel@tonic-gate * that the rsm_intr_signal_post is to be done with
21267c478bd9Sstevel@tonic-gate * the flags argument set to RSM_SIGPOST_NO_ACCUMULATE
21277c478bd9Sstevel@tonic-gate * Else, the flags argument is set to 0. These
21287c478bd9Sstevel@tonic-gate * semantics can be achieved simply by masking off
21297c478bd9Sstevel@tonic-gate * all other bits in the sg_io->flags field except the
21307c478bd9Sstevel@tonic-gate * RSM_SIGPOST_NO_ACCUMULATE bit and using the result
21317c478bd9Sstevel@tonic-gate * as the flags argument for the rsm_intr_signal_post.
21327c478bd9Sstevel@tonic-gate */
21337c478bd9Sstevel@tonic-gate
21347c478bd9Sstevel@tonic-gate int sigpost_flags = sg_io->flags & RSM_SIGPOST_NO_ACCUMULATE;
21357c478bd9Sstevel@tonic-gate e = rsm_intr_signal_post(seg, sigpost_flags);
21367c478bd9Sstevel@tonic-gate
21377c478bd9Sstevel@tonic-gate }
21387c478bd9Sstevel@tonic-gate
21397c478bd9Sstevel@tonic-gate /* Restore the flags field within the users scatter gather structure */
21407c478bd9Sstevel@tonic-gate sg_io->flags = save_sg_io_flags;
21417c478bd9Sstevel@tonic-gate
21427c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
21437c478bd9Sstevel@tonic-gate "rsm_memseg_import_putv: exit\n"));
21447c478bd9Sstevel@tonic-gate
21457c478bd9Sstevel@tonic-gate return (e);
21467c478bd9Sstevel@tonic-gate }
21477c478bd9Sstevel@tonic-gate
21487c478bd9Sstevel@tonic-gate
21497c478bd9Sstevel@tonic-gate /*
21507c478bd9Sstevel@tonic-gate * import side memory segment operations (mapping):
21517c478bd9Sstevel@tonic-gate */
21527c478bd9Sstevel@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)2153*7257d1b4Sraf rsm_memseg_import_map(rsm_memseg_import_handle_t im_memseg,
21547c478bd9Sstevel@tonic-gate void **address,
21557c478bd9Sstevel@tonic-gate rsm_attribute_t attr,
21567c478bd9Sstevel@tonic-gate rsm_permission_t perm,
21577c478bd9Sstevel@tonic-gate off_t offset,
21587c478bd9Sstevel@tonic-gate size_t length)
21597c478bd9Sstevel@tonic-gate {
21607c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
21617c478bd9Sstevel@tonic-gate int flag = MAP_SHARED;
21627c478bd9Sstevel@tonic-gate int prot;
21637c478bd9Sstevel@tonic-gate caddr_t va;
21647c478bd9Sstevel@tonic-gate
21657c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
21667c478bd9Sstevel@tonic-gate "rsm_memseg_import_map: enter\n"));
21677c478bd9Sstevel@tonic-gate
21687c478bd9Sstevel@tonic-gate if (!seg) {
21697c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
21707c478bd9Sstevel@tonic-gate "invalid segment\n"));
21717c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
21727c478bd9Sstevel@tonic-gate }
21737c478bd9Sstevel@tonic-gate if (!address) {
21747c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
21757c478bd9Sstevel@tonic-gate "invalid address\n"));
21767c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
21777c478bd9Sstevel@tonic-gate }
21787c478bd9Sstevel@tonic-gate
21797c478bd9Sstevel@tonic-gate /*
21807c478bd9Sstevel@tonic-gate * Only one map per segment handle!
21817c478bd9Sstevel@tonic-gate * XXX need to take a lock here
21827c478bd9Sstevel@tonic-gate */
21837c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
21847c478bd9Sstevel@tonic-gate
21857c478bd9Sstevel@tonic-gate if (seg->rsmseg_state == IMPORT_MAP) {
21867c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
21877c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
21887c478bd9Sstevel@tonic-gate "segment already mapped\n"));
21897c478bd9Sstevel@tonic-gate return (RSMERR_SEG_ALREADY_MAPPED);
21907c478bd9Sstevel@tonic-gate }
21917c478bd9Sstevel@tonic-gate
21927c478bd9Sstevel@tonic-gate /* Only import segments allowed to map */
21937c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_CONNECT) {
21947c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
21957c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
21967c478bd9Sstevel@tonic-gate }
21977c478bd9Sstevel@tonic-gate
21987c478bd9Sstevel@tonic-gate /* check for permissions */
21997c478bd9Sstevel@tonic-gate if (perm > RSM_PERM_RDWR) {
22007c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22017c478bd9Sstevel@tonic-gate "bad permissions when mapping\n"));
22027c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22037c478bd9Sstevel@tonic-gate return (RSMERR_BAD_PERMS);
22047c478bd9Sstevel@tonic-gate }
22057c478bd9Sstevel@tonic-gate
22067c478bd9Sstevel@tonic-gate if (length == 0) {
22077c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22087c478bd9Sstevel@tonic-gate "mapping with length 0\n"));
22097c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22107c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
22117c478bd9Sstevel@tonic-gate }
22127c478bd9Sstevel@tonic-gate
22137c478bd9Sstevel@tonic-gate if (offset + length > seg->rsmseg_size) {
22147c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22157c478bd9Sstevel@tonic-gate "map length + offset exceed segment size\n"));
22167c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22177c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
22187c478bd9Sstevel@tonic-gate }
22197c478bd9Sstevel@tonic-gate
22207c478bd9Sstevel@tonic-gate if ((size_t)offset & (PAGESIZE - 1)) {
22217c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
22227c478bd9Sstevel@tonic-gate "bad mem alignment\n"));
22237c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
22247c478bd9Sstevel@tonic-gate }
22257c478bd9Sstevel@tonic-gate
22267c478bd9Sstevel@tonic-gate if (attr & RSM_MAP_FIXED) {
22277c478bd9Sstevel@tonic-gate if ((uintptr_t)(*address) & (PAGESIZE - 1)) {
22287c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
22297c478bd9Sstevel@tonic-gate "bad mem alignment\n"));
22307c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MEM_ALIGNMENT);
22317c478bd9Sstevel@tonic-gate }
22327c478bd9Sstevel@tonic-gate flag |= MAP_FIXED;
22337c478bd9Sstevel@tonic-gate }
22347c478bd9Sstevel@tonic-gate
22357c478bd9Sstevel@tonic-gate prot = PROT_NONE;
22367c478bd9Sstevel@tonic-gate if (perm & RSM_PERM_READ)
22377c478bd9Sstevel@tonic-gate prot |= PROT_READ;
22387c478bd9Sstevel@tonic-gate if (perm & RSM_PERM_WRITE)
22397c478bd9Sstevel@tonic-gate prot |= PROT_WRITE;
22407c478bd9Sstevel@tonic-gate
22417c478bd9Sstevel@tonic-gate va = mmap(*address, length, prot, flag, seg->rsmseg_fd, offset);
22427c478bd9Sstevel@tonic-gate if (va == MAP_FAILED) {
22437c478bd9Sstevel@tonic-gate int e = errno;
22447c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22457c478bd9Sstevel@tonic-gate "error %d during map\n", e));
22467c478bd9Sstevel@tonic-gate
22477c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22487c478bd9Sstevel@tonic-gate if (e == ENXIO || e == EOVERFLOW ||
22497c478bd9Sstevel@tonic-gate e == ENOMEM)
22507c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
22517c478bd9Sstevel@tonic-gate else if (e == ENODEV)
22527c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
22537c478bd9Sstevel@tonic-gate else if (e == EAGAIN)
22547c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
22557c478bd9Sstevel@tonic-gate else if (e == ENOTSUP)
22567c478bd9Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
22577c478bd9Sstevel@tonic-gate else if (e == EACCES)
22587c478bd9Sstevel@tonic-gate return (RSMERR_BAD_PERMS);
22597c478bd9Sstevel@tonic-gate else
22607c478bd9Sstevel@tonic-gate return (RSMERR_MAP_FAILED);
22617c478bd9Sstevel@tonic-gate }
22627c478bd9Sstevel@tonic-gate *address = va;
22637c478bd9Sstevel@tonic-gate
22647c478bd9Sstevel@tonic-gate /*
22657c478bd9Sstevel@tonic-gate * Fix segment ops vector to handle direct access.
22667c478bd9Sstevel@tonic-gate */
22677c478bd9Sstevel@tonic-gate /*
22687c478bd9Sstevel@tonic-gate * XXX: Set this only for full segment mapping. Keep a list
22697c478bd9Sstevel@tonic-gate * of mappings to use for access functions
22707c478bd9Sstevel@tonic-gate */
22717c478bd9Sstevel@tonic-gate seg->rsmseg_vaddr = va;
22727c478bd9Sstevel@tonic-gate seg->rsmseg_maplen = length;
22737c478bd9Sstevel@tonic-gate seg->rsmseg_mapoffset = offset;
22747c478bd9Sstevel@tonic-gate seg->rsmseg_state = IMPORT_MAP;
22757c478bd9Sstevel@tonic-gate
22767c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
22777c478bd9Sstevel@tonic-gate
22787c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
22797c478bd9Sstevel@tonic-gate "rsm_memseg_import_map: exit\n"));
22807c478bd9Sstevel@tonic-gate
22817c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
22827c478bd9Sstevel@tonic-gate }
22837c478bd9Sstevel@tonic-gate
22847c478bd9Sstevel@tonic-gate int
rsm_memseg_import_unmap(rsm_memseg_import_handle_t im_memseg)2285*7257d1b4Sraf rsm_memseg_import_unmap(rsm_memseg_import_handle_t im_memseg)
22867c478bd9Sstevel@tonic-gate {
22877c478bd9Sstevel@tonic-gate /*
22887c478bd9Sstevel@tonic-gate * Until we fix the rsm driver to catch unload, we unload
22897c478bd9Sstevel@tonic-gate * the whole segment.
22907c478bd9Sstevel@tonic-gate */
22917c478bd9Sstevel@tonic-gate
22927c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
22937c478bd9Sstevel@tonic-gate
22947c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
22957c478bd9Sstevel@tonic-gate "rsm_memseg_import_unmap: enter\n"));
22967c478bd9Sstevel@tonic-gate
22977c478bd9Sstevel@tonic-gate if (!seg) {
22987c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
22997c478bd9Sstevel@tonic-gate "invalid segment or segment state\n"));
23007c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
23017c478bd9Sstevel@tonic-gate }
23027c478bd9Sstevel@tonic-gate
23037c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
23047c478bd9Sstevel@tonic-gate if (seg->rsmseg_state != IMPORT_MAP) {
23057c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
23067c478bd9Sstevel@tonic-gate return (RSMERR_SEG_NOT_MAPPED);
23077c478bd9Sstevel@tonic-gate }
23087c478bd9Sstevel@tonic-gate
23097c478bd9Sstevel@tonic-gate seg->rsmseg_mapoffset = 0; /* reset the offset */
23107c478bd9Sstevel@tonic-gate seg->rsmseg_state = IMPORT_CONNECT;
23117c478bd9Sstevel@tonic-gate seg->rsmseg_flags &= ~RSM_IMPLICIT_MAP;
23127c478bd9Sstevel@tonic-gate (void) munmap(seg->rsmseg_vaddr, seg->rsmseg_maplen);
23137c478bd9Sstevel@tonic-gate
23147c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
23157c478bd9Sstevel@tonic-gate
23167c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23177c478bd9Sstevel@tonic-gate "rsm_memseg_import_unmap: exit\n"));
23187c478bd9Sstevel@tonic-gate
23197c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
23207c478bd9Sstevel@tonic-gate }
23217c478bd9Sstevel@tonic-gate
23227c478bd9Sstevel@tonic-gate
23237c478bd9Sstevel@tonic-gate /*
23247c478bd9Sstevel@tonic-gate * import side memory segment operations (barriers):
23257c478bd9Sstevel@tonic-gate */
23267c478bd9Sstevel@tonic-gate int
rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,rsm_barrier_type_t type,rsmapi_barrier_t * barrier)2327*7257d1b4Sraf rsm_memseg_import_init_barrier(rsm_memseg_import_handle_t im_memseg,
23287c478bd9Sstevel@tonic-gate rsm_barrier_type_t type,
23297c478bd9Sstevel@tonic-gate rsmapi_barrier_t *barrier)
23307c478bd9Sstevel@tonic-gate {
23317c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
23327c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar;
23337c478bd9Sstevel@tonic-gate
23347c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23357c478bd9Sstevel@tonic-gate "rsm_memseg_import_init_barrier: enter\n"));
23367c478bd9Sstevel@tonic-gate
23377c478bd9Sstevel@tonic-gate if (!seg) {
23387c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23397c478bd9Sstevel@tonic-gate "invalid segment or barrier\n"));
23407c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
23417c478bd9Sstevel@tonic-gate }
23427c478bd9Sstevel@tonic-gate if (!barrier) {
23437c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23447c478bd9Sstevel@tonic-gate "invalid barrier pointer\n"));
23457c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
23467c478bd9Sstevel@tonic-gate }
23477c478bd9Sstevel@tonic-gate
23487c478bd9Sstevel@tonic-gate bar = (rsmbar_handle_t *)barrier;
23497c478bd9Sstevel@tonic-gate bar->rsmbar_seg = seg;
23507c478bd9Sstevel@tonic-gate
23517c478bd9Sstevel@tonic-gate seg->rsmseg_barrier = barrier; /* used in put/get fns */
23527c478bd9Sstevel@tonic-gate
23537c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23547c478bd9Sstevel@tonic-gate "rsm_memseg_import_init_barrier: exit\n"));
23557c478bd9Sstevel@tonic-gate
23567c478bd9Sstevel@tonic-gate return (seg->rsmseg_ops->rsm_memseg_import_init_barrier(im_memseg,
23577c478bd9Sstevel@tonic-gate type, (rsm_barrier_handle_t)barrier));
23587c478bd9Sstevel@tonic-gate }
23597c478bd9Sstevel@tonic-gate
23607c478bd9Sstevel@tonic-gate int
rsm_memseg_import_open_barrier(rsmapi_barrier_t * barrier)2361*7257d1b4Sraf rsm_memseg_import_open_barrier(rsmapi_barrier_t *barrier)
23627c478bd9Sstevel@tonic-gate {
23637c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
23647c478bd9Sstevel@tonic-gate rsm_segops_t *ops;
23657c478bd9Sstevel@tonic-gate
23667c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23677c478bd9Sstevel@tonic-gate "rsm_memseg_import_open_barrier: enter\n"));
23687c478bd9Sstevel@tonic-gate
23697c478bd9Sstevel@tonic-gate if (!bar) {
23707c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23717c478bd9Sstevel@tonic-gate "invalid barrier\n"));
23727c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
23737c478bd9Sstevel@tonic-gate }
23747c478bd9Sstevel@tonic-gate if (!bar->rsmbar_seg) {
23757c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
23767c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
23777c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
23787c478bd9Sstevel@tonic-gate }
23797c478bd9Sstevel@tonic-gate
23807c478bd9Sstevel@tonic-gate /* generation number snapshot */
23817c478bd9Sstevel@tonic-gate bar->rsmbar_gen = bar->rsmbar_seg->rsmseg_gnum; /* bar[0] */
23827c478bd9Sstevel@tonic-gate
23837c478bd9Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
23847c478bd9Sstevel@tonic-gate
23857c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23867c478bd9Sstevel@tonic-gate "rsm_memseg_import_open_barrier: exit\n"));
23877c478bd9Sstevel@tonic-gate
23887c478bd9Sstevel@tonic-gate return (ops->rsm_memseg_import_open_barrier(
23897c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)barrier));
23907c478bd9Sstevel@tonic-gate }
23917c478bd9Sstevel@tonic-gate
23927c478bd9Sstevel@tonic-gate int
rsm_memseg_import_order_barrier(rsmapi_barrier_t * barrier)2393*7257d1b4Sraf rsm_memseg_import_order_barrier(rsmapi_barrier_t *barrier)
23947c478bd9Sstevel@tonic-gate {
23957c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
23967c478bd9Sstevel@tonic-gate rsm_segops_t *ops;
23977c478bd9Sstevel@tonic-gate
23987c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
23997c478bd9Sstevel@tonic-gate "rsm_memseg_import_order_barrier: enter\n"));
24007c478bd9Sstevel@tonic-gate
24017c478bd9Sstevel@tonic-gate if (!bar) {
24027c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24037c478bd9Sstevel@tonic-gate "invalid barrier\n"));
24047c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
24057c478bd9Sstevel@tonic-gate }
24067c478bd9Sstevel@tonic-gate if (!bar->rsmbar_seg) {
24077c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24087c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
24097c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
24107c478bd9Sstevel@tonic-gate }
24117c478bd9Sstevel@tonic-gate
24127c478bd9Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
24137c478bd9Sstevel@tonic-gate
24147c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24157c478bd9Sstevel@tonic-gate "rsm_memseg_import_order_barrier: exit\n"));
24167c478bd9Sstevel@tonic-gate
24177c478bd9Sstevel@tonic-gate return (ops->rsm_memseg_import_order_barrier(
24187c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)barrier));
24197c478bd9Sstevel@tonic-gate }
24207c478bd9Sstevel@tonic-gate
24217c478bd9Sstevel@tonic-gate int
rsm_memseg_import_close_barrier(rsmapi_barrier_t * barrier)2422*7257d1b4Sraf rsm_memseg_import_close_barrier(rsmapi_barrier_t *barrier)
24237c478bd9Sstevel@tonic-gate {
24247c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
24257c478bd9Sstevel@tonic-gate rsm_segops_t *ops;
24267c478bd9Sstevel@tonic-gate
24277c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24287c478bd9Sstevel@tonic-gate "rsm_memseg_import_close_barrier: enter\n"));
24297c478bd9Sstevel@tonic-gate
24307c478bd9Sstevel@tonic-gate if (!bar) {
24317c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24327c478bd9Sstevel@tonic-gate "invalid barrier\n"));
24337c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
24347c478bd9Sstevel@tonic-gate }
24357c478bd9Sstevel@tonic-gate if (!bar->rsmbar_seg) {
24367c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24377c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
24387c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
24397c478bd9Sstevel@tonic-gate }
24407c478bd9Sstevel@tonic-gate
24417c478bd9Sstevel@tonic-gate /* generation number snapshot */
24427c478bd9Sstevel@tonic-gate if (bar->rsmbar_gen != bar->rsmbar_seg->rsmseg_bar[0]) {
24437c478bd9Sstevel@tonic-gate return (RSMERR_CONN_ABORTED);
24447c478bd9Sstevel@tonic-gate }
24457c478bd9Sstevel@tonic-gate
24467c478bd9Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
24477c478bd9Sstevel@tonic-gate
24487c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24497c478bd9Sstevel@tonic-gate "rsm_memseg_import_close_barrier: exit\n"));
24507c478bd9Sstevel@tonic-gate
24517c478bd9Sstevel@tonic-gate return (ops->rsm_memseg_import_close_barrier(
24527c478bd9Sstevel@tonic-gate (rsm_barrier_handle_t)barrier));
24537c478bd9Sstevel@tonic-gate }
24547c478bd9Sstevel@tonic-gate
24557c478bd9Sstevel@tonic-gate int
rsm_memseg_import_destroy_barrier(rsmapi_barrier_t * barrier)2456*7257d1b4Sraf rsm_memseg_import_destroy_barrier(rsmapi_barrier_t *barrier)
24577c478bd9Sstevel@tonic-gate {
24587c478bd9Sstevel@tonic-gate rsmbar_handle_t *bar = (rsmbar_handle_t *)barrier;
24597c478bd9Sstevel@tonic-gate rsm_segops_t *ops;
24607c478bd9Sstevel@tonic-gate
24617c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24627c478bd9Sstevel@tonic-gate "rsm_memseg_import_destroy_barrier: enter\n"));
24637c478bd9Sstevel@tonic-gate
24647c478bd9Sstevel@tonic-gate if (!bar) {
24657c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24667c478bd9Sstevel@tonic-gate "invalid barrier\n"));
24677c478bd9Sstevel@tonic-gate return (RSMERR_BAD_BARRIER_PTR);
24687c478bd9Sstevel@tonic-gate }
24697c478bd9Sstevel@tonic-gate if (!bar->rsmbar_seg) {
24707c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
24717c478bd9Sstevel@tonic-gate "uninitialized barrier\n"));
24727c478bd9Sstevel@tonic-gate return (RSMERR_BARRIER_UNINITIALIZED);
24737c478bd9Sstevel@tonic-gate }
24747c478bd9Sstevel@tonic-gate
24757c478bd9Sstevel@tonic-gate bar->rsmbar_seg->rsmseg_barrier = NULL;
24767c478bd9Sstevel@tonic-gate
24777c478bd9Sstevel@tonic-gate ops = bar->rsmbar_seg->rsmseg_ops;
24787c478bd9Sstevel@tonic-gate
24797c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24807c478bd9Sstevel@tonic-gate "rsm_memseg_import_destroy_barrier: exit\n"));
24817c478bd9Sstevel@tonic-gate
24827c478bd9Sstevel@tonic-gate return (ops->rsm_memseg_import_destroy_barrier
24837c478bd9Sstevel@tonic-gate ((rsm_barrier_handle_t)barrier));
24847c478bd9Sstevel@tonic-gate }
24857c478bd9Sstevel@tonic-gate
24867c478bd9Sstevel@tonic-gate int
rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t * mode)2487*7257d1b4Sraf rsm_memseg_import_get_mode(rsm_memseg_import_handle_t im_memseg,
24887c478bd9Sstevel@tonic-gate rsm_barrier_mode_t *mode)
24897c478bd9Sstevel@tonic-gate {
24907c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
24917c478bd9Sstevel@tonic-gate
24927c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24937c478bd9Sstevel@tonic-gate "rsm_memseg_import_get_mode: enter\n"));
24947c478bd9Sstevel@tonic-gate
24957c478bd9Sstevel@tonic-gate if (seg) {
24967c478bd9Sstevel@tonic-gate *mode = seg->rsmseg_barmode;
24977c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
24987c478bd9Sstevel@tonic-gate "rsm_memseg_import_get_mode: exit\n"));
24997c478bd9Sstevel@tonic-gate
25007c478bd9Sstevel@tonic-gate return (seg->rsmseg_ops->rsm_memseg_import_get_mode(im_memseg,
25017c478bd9Sstevel@tonic-gate mode));
25027c478bd9Sstevel@tonic-gate }
25037c478bd9Sstevel@tonic-gate
25047c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
25057c478bd9Sstevel@tonic-gate "invalid arguments \n"));
25067c478bd9Sstevel@tonic-gate
25077c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25087c478bd9Sstevel@tonic-gate
25097c478bd9Sstevel@tonic-gate }
25107c478bd9Sstevel@tonic-gate
25117c478bd9Sstevel@tonic-gate int
rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,rsm_barrier_mode_t mode)2512*7257d1b4Sraf rsm_memseg_import_set_mode(rsm_memseg_import_handle_t im_memseg,
25137c478bd9Sstevel@tonic-gate rsm_barrier_mode_t mode)
25147c478bd9Sstevel@tonic-gate {
25157c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)im_memseg;
25167c478bd9Sstevel@tonic-gate
25177c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25187c478bd9Sstevel@tonic-gate "rsm_memseg_import_set_mode: enter\n"));
25197c478bd9Sstevel@tonic-gate if (seg) {
25207c478bd9Sstevel@tonic-gate if ((mode == RSM_BARRIER_MODE_IMPLICIT ||
25217c478bd9Sstevel@tonic-gate mode == RSM_BARRIER_MODE_EXPLICIT)) {
25227c478bd9Sstevel@tonic-gate seg->rsmseg_barmode = mode;
25237c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25247c478bd9Sstevel@tonic-gate "rsm_memseg_import_set_mode: exit\n"));
25257c478bd9Sstevel@tonic-gate
25267c478bd9Sstevel@tonic-gate return (seg->rsmseg_ops->rsm_memseg_import_set_mode(
25277c478bd9Sstevel@tonic-gate im_memseg,
25287c478bd9Sstevel@tonic-gate mode));
25297c478bd9Sstevel@tonic-gate } else {
25307c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_DEBUG_VERBOSE,
25317c478bd9Sstevel@tonic-gate "bad barrier mode\n"));
25327c478bd9Sstevel@tonic-gate return (RSMERR_BAD_MODE);
25337c478bd9Sstevel@tonic-gate }
25347c478bd9Sstevel@tonic-gate }
25357c478bd9Sstevel@tonic-gate
25367c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_IMPORT, RSM_ERR,
25377c478bd9Sstevel@tonic-gate "invalid arguments\n"));
25387c478bd9Sstevel@tonic-gate
25397c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25407c478bd9Sstevel@tonic-gate }
25417c478bd9Sstevel@tonic-gate
25427c478bd9Sstevel@tonic-gate int
rsm_intr_signal_post(void * memseg,uint_t flags)2543*7257d1b4Sraf rsm_intr_signal_post(void *memseg, uint_t flags)
25447c478bd9Sstevel@tonic-gate {
25457c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg;
25467c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
25477c478bd9Sstevel@tonic-gate
25487c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
25497c478bd9Sstevel@tonic-gate "rsm_intr_signal_post: enter\n"));
25507c478bd9Sstevel@tonic-gate
25517c478bd9Sstevel@tonic-gate flags = flags;
25527c478bd9Sstevel@tonic-gate
25537c478bd9Sstevel@tonic-gate if (!seg) {
25547c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
25557c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
25567c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25577c478bd9Sstevel@tonic-gate }
25587c478bd9Sstevel@tonic-gate
25597c478bd9Sstevel@tonic-gate if (ioctl(seg->rsmseg_fd, RSM_IOCTL_RING_BELL, &msg) < 0) {
25607c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
25617c478bd9Sstevel@tonic-gate "RSM_IOCTL_RING_BELL failed\n"));
25627c478bd9Sstevel@tonic-gate return (errno);
25637c478bd9Sstevel@tonic-gate }
25647c478bd9Sstevel@tonic-gate
25657c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
25667c478bd9Sstevel@tonic-gate "rsm_intr_signal_post: exit\n"));
25677c478bd9Sstevel@tonic-gate
25687c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
25697c478bd9Sstevel@tonic-gate }
25707c478bd9Sstevel@tonic-gate
25717c478bd9Sstevel@tonic-gate int
rsm_intr_signal_wait(void * memseg,int timeout)2572*7257d1b4Sraf rsm_intr_signal_wait(void *memseg, int timeout)
25737c478bd9Sstevel@tonic-gate {
25747c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
25757c478bd9Sstevel@tonic-gate struct pollfd fds;
25767c478bd9Sstevel@tonic-gate minor_t rnum;
25777c478bd9Sstevel@tonic-gate
25787c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
25797c478bd9Sstevel@tonic-gate "rsm_intr_signal_wait: enter\n"));
25807c478bd9Sstevel@tonic-gate
25817c478bd9Sstevel@tonic-gate if (!seg) {
25827c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
25837c478bd9Sstevel@tonic-gate "invalid segment\n"));
25847c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
25857c478bd9Sstevel@tonic-gate }
25867c478bd9Sstevel@tonic-gate
25877c478bd9Sstevel@tonic-gate fds.fd = seg->rsmseg_fd;
25887c478bd9Sstevel@tonic-gate fds.events = POLLRDNORM;
25897c478bd9Sstevel@tonic-gate
25907c478bd9Sstevel@tonic-gate rnum = seg->rsmseg_rnum;
25917c478bd9Sstevel@tonic-gate
25927c478bd9Sstevel@tonic-gate return (__rsm_intr_signal_wait_common(&fds, &rnum, 1, timeout, NULL));
25937c478bd9Sstevel@tonic-gate }
25947c478bd9Sstevel@tonic-gate
25957c478bd9Sstevel@tonic-gate int
rsm_intr_signal_wait_pollfd(struct pollfd fds[],nfds_t nfds,int timeout,int * numfdsp)2596*7257d1b4Sraf rsm_intr_signal_wait_pollfd(struct pollfd fds[], nfds_t nfds, int timeout,
25977c478bd9Sstevel@tonic-gate int *numfdsp)
25987c478bd9Sstevel@tonic-gate {
25997c478bd9Sstevel@tonic-gate return (__rsm_intr_signal_wait_common(fds, NULL, nfds, timeout,
26007c478bd9Sstevel@tonic-gate numfdsp));
26017c478bd9Sstevel@tonic-gate }
26027c478bd9Sstevel@tonic-gate
26037c478bd9Sstevel@tonic-gate /*
26047c478bd9Sstevel@tonic-gate * This is the generic wait routine, it takes the following arguments
26057c478bd9Sstevel@tonic-gate * - pollfd array
26067c478bd9Sstevel@tonic-gate * - rnums array corresponding to the pollfd if known, if this is
26077c478bd9Sstevel@tonic-gate * NULL then the fds are looked up from the pollfd_table.
26087c478bd9Sstevel@tonic-gate * - number of fds in pollfd array,
26097c478bd9Sstevel@tonic-gate * - timeout
26107c478bd9Sstevel@tonic-gate * - pointer to a location where the number of fds with successful
26117c478bd9Sstevel@tonic-gate * events is returned.
26127c478bd9Sstevel@tonic-gate */
26137c478bd9Sstevel@tonic-gate static int
__rsm_intr_signal_wait_common(struct pollfd fds[],minor_t rnums[],nfds_t nfds,int timeout,int * numfdsp)26147c478bd9Sstevel@tonic-gate __rsm_intr_signal_wait_common(struct pollfd fds[], minor_t rnums[],
26157c478bd9Sstevel@tonic-gate nfds_t nfds, int timeout, int *numfdsp)
26167c478bd9Sstevel@tonic-gate {
26177c478bd9Sstevel@tonic-gate int i;
26187c478bd9Sstevel@tonic-gate int numsegs = 0;
26197c478bd9Sstevel@tonic-gate int numfd;
26207c478bd9Sstevel@tonic-gate int fds_processed = 0;
26217c478bd9Sstevel@tonic-gate minor_t segrnum;
26227c478bd9Sstevel@tonic-gate rsm_poll_event_t event_arr[RSM_MAX_POLLFDS];
26237c478bd9Sstevel@tonic-gate rsm_poll_event_t *event_list = NULL;
26247c478bd9Sstevel@tonic-gate rsm_poll_event_t *events;
26257c478bd9Sstevel@tonic-gate rsm_consume_event_msg_t msg;
26267c478bd9Sstevel@tonic-gate
26277c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE, "wait_common enter\n"));
26287c478bd9Sstevel@tonic-gate
26297c478bd9Sstevel@tonic-gate if (numfdsp) {
26307c478bd9Sstevel@tonic-gate *numfdsp = 0;
26317c478bd9Sstevel@tonic-gate }
26327c478bd9Sstevel@tonic-gate
26337c478bd9Sstevel@tonic-gate numfd = poll(fds, nfds, timeout);
26347c478bd9Sstevel@tonic-gate
26357c478bd9Sstevel@tonic-gate switch (numfd) {
26367c478bd9Sstevel@tonic-gate case -1: /* poll returned error - map to RSMERR_... */
26377c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR, "signal wait pollfd err\n"));
26387c478bd9Sstevel@tonic-gate switch (errno) {
26397c478bd9Sstevel@tonic-gate case EAGAIN:
26407c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_RESOURCES);
26417c478bd9Sstevel@tonic-gate case EFAULT:
26427c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
26437c478bd9Sstevel@tonic-gate case EINTR:
26447c478bd9Sstevel@tonic-gate return (RSMERR_INTERRUPTED);
26457c478bd9Sstevel@tonic-gate case EINVAL:
26467c478bd9Sstevel@tonic-gate default:
26477c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ARGS_ERRORS);
26487c478bd9Sstevel@tonic-gate }
26497c478bd9Sstevel@tonic-gate case 0: /* timedout - return from here */
26507c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
26517c478bd9Sstevel@tonic-gate "signal wait timed out\n"));
26527c478bd9Sstevel@tonic-gate return (RSMERR_TIMEOUT);
26537c478bd9Sstevel@tonic-gate default:
26547c478bd9Sstevel@tonic-gate break;
26557c478bd9Sstevel@tonic-gate }
26567c478bd9Sstevel@tonic-gate
26577c478bd9Sstevel@tonic-gate if (numfd <= RSM_MAX_POLLFDS) {
26587c478bd9Sstevel@tonic-gate /* use the event array on the stack */
26597c478bd9Sstevel@tonic-gate events = (rsm_poll_event_t *)event_arr;
26607c478bd9Sstevel@tonic-gate } else {
26617c478bd9Sstevel@tonic-gate /*
26627c478bd9Sstevel@tonic-gate * actual number of fds corresponding to rsmapi segments might
26637c478bd9Sstevel@tonic-gate * be < numfd, don't want to scan the list to figure that out
26647c478bd9Sstevel@tonic-gate * lets just allocate on the heap
26657c478bd9Sstevel@tonic-gate */
26667c478bd9Sstevel@tonic-gate event_list = (rsm_poll_event_t *)malloc(
26677c478bd9Sstevel@tonic-gate sizeof (rsm_poll_event_t)*numfd);
26687c478bd9Sstevel@tonic-gate if (!event_list) {
26697c478bd9Sstevel@tonic-gate /*
26707c478bd9Sstevel@tonic-gate * return with error even if poll might have succeeded
26717c478bd9Sstevel@tonic-gate * since the application can retry and the events will
26727c478bd9Sstevel@tonic-gate * still be available.
26737c478bd9Sstevel@tonic-gate */
26747c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
26757c478bd9Sstevel@tonic-gate }
26767c478bd9Sstevel@tonic-gate events = event_list;
26777c478bd9Sstevel@tonic-gate }
26787c478bd9Sstevel@tonic-gate
26797c478bd9Sstevel@tonic-gate /*
26807c478bd9Sstevel@tonic-gate * process the fds for events and if it corresponds to an rsmapi
26817c478bd9Sstevel@tonic-gate * segment consume the event
26827c478bd9Sstevel@tonic-gate */
26837c478bd9Sstevel@tonic-gate for (i = 0; i < nfds; i++) {
26847c478bd9Sstevel@tonic-gate if (fds[i].revents == POLLRDNORM) {
26857c478bd9Sstevel@tonic-gate /*
26867c478bd9Sstevel@tonic-gate * poll returned an event and if its POLLRDNORM, it
26877c478bd9Sstevel@tonic-gate * might correspond to an rsmapi segment
26887c478bd9Sstevel@tonic-gate */
26897c478bd9Sstevel@tonic-gate if (rnums) { /* resource num is passed in */
26907c478bd9Sstevel@tonic-gate segrnum = rnums[i];
26917c478bd9Sstevel@tonic-gate } else { /* lookup pollfd table to get resource num */
26927c478bd9Sstevel@tonic-gate segrnum = _rsm_lookup_pollfd_table(fds[i].fd);
26937c478bd9Sstevel@tonic-gate }
26947c478bd9Sstevel@tonic-gate if (segrnum) {
26957c478bd9Sstevel@tonic-gate events[numsegs].rnum = segrnum;
26967c478bd9Sstevel@tonic-gate events[numsegs].revent = 0;
26977c478bd9Sstevel@tonic-gate events[numsegs].fdsidx = i; /* fdlist index */
26987c478bd9Sstevel@tonic-gate numsegs++;
26997c478bd9Sstevel@tonic-gate }
27007c478bd9Sstevel@tonic-gate }
27017c478bd9Sstevel@tonic-gate
27027c478bd9Sstevel@tonic-gate if ((fds[i].revents) && (++fds_processed == numfd)) {
27037c478bd9Sstevel@tonic-gate /*
27047c478bd9Sstevel@tonic-gate * only "numfd" events have revents field set, once we
27057c478bd9Sstevel@tonic-gate * process that many break out of the loop
27067c478bd9Sstevel@tonic-gate */
27077c478bd9Sstevel@tonic-gate break;
27087c478bd9Sstevel@tonic-gate }
27097c478bd9Sstevel@tonic-gate }
27107c478bd9Sstevel@tonic-gate
27117c478bd9Sstevel@tonic-gate if (numsegs == 0) { /* No events for rsmapi segs in the fdlist */
27127c478bd9Sstevel@tonic-gate if (event_list) {
27137c478bd9Sstevel@tonic-gate free(event_list);
27147c478bd9Sstevel@tonic-gate }
27157c478bd9Sstevel@tonic-gate if (numfdsp) {
27167c478bd9Sstevel@tonic-gate *numfdsp = numfd;
27177c478bd9Sstevel@tonic-gate }
27187c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27197c478bd9Sstevel@tonic-gate "wait_common exit: no rsmapi segs\n"));
27207c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
27217c478bd9Sstevel@tonic-gate }
27227c478bd9Sstevel@tonic-gate
27237c478bd9Sstevel@tonic-gate msg.seglist = (caddr_t)events;
27247c478bd9Sstevel@tonic-gate msg.numents = numsegs;
27257c478bd9Sstevel@tonic-gate
27267c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_CONSUMEEVENT, &msg) < 0) {
27277c478bd9Sstevel@tonic-gate int error = errno;
27287c478bd9Sstevel@tonic-gate if (event_list) {
27297c478bd9Sstevel@tonic-gate free(event_list);
27307c478bd9Sstevel@tonic-gate }
27317c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY|RSM_LOOPBACK, RSM_ERR,
27327c478bd9Sstevel@tonic-gate "RSM_IOCTL_CONSUMEEVENT failed(%d)\n", error));
27337c478bd9Sstevel@tonic-gate return (error);
27347c478bd9Sstevel@tonic-gate }
27357c478bd9Sstevel@tonic-gate
27367c478bd9Sstevel@tonic-gate /* count the number of segs for which consumeevent was successful */
27377c478bd9Sstevel@tonic-gate numfd -= numsegs;
27387c478bd9Sstevel@tonic-gate
27397c478bd9Sstevel@tonic-gate for (i = 0; i < numsegs; i++) {
27407c478bd9Sstevel@tonic-gate if (events[i].revent != 0) {
27417c478bd9Sstevel@tonic-gate fds[events[i].fdsidx].revents = POLLRDNORM;
27427c478bd9Sstevel@tonic-gate numfd++;
27437c478bd9Sstevel@tonic-gate } else { /* failed to consume event so set revents to 0 */
27447c478bd9Sstevel@tonic-gate fds[events[i].fdsidx].revents = 0;
27457c478bd9Sstevel@tonic-gate }
27467c478bd9Sstevel@tonic-gate }
27477c478bd9Sstevel@tonic-gate
27487c478bd9Sstevel@tonic-gate if (event_list) {
27497c478bd9Sstevel@tonic-gate free(event_list);
27507c478bd9Sstevel@tonic-gate }
27517c478bd9Sstevel@tonic-gate
27527c478bd9Sstevel@tonic-gate if (numfd > 0) {
27537c478bd9Sstevel@tonic-gate if (numfdsp) {
27547c478bd9Sstevel@tonic-gate *numfdsp = numfd;
27557c478bd9Sstevel@tonic-gate }
27567c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27577c478bd9Sstevel@tonic-gate "wait_common exit\n"));
27587c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
27597c478bd9Sstevel@tonic-gate } else {
27607c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27617c478bd9Sstevel@tonic-gate "wait_common exit\n"));
27627c478bd9Sstevel@tonic-gate return (RSMERR_TIMEOUT);
27637c478bd9Sstevel@tonic-gate }
27647c478bd9Sstevel@tonic-gate }
27657c478bd9Sstevel@tonic-gate
27667c478bd9Sstevel@tonic-gate /*
27677c478bd9Sstevel@tonic-gate * This function provides the data (file descriptor and event) for
27687c478bd9Sstevel@tonic-gate * the specified pollfd struct. The pollfd struct may then be
27697c478bd9Sstevel@tonic-gate * subsequently used with the poll system call to wait for an event
27707c478bd9Sstevel@tonic-gate * signalled by rsm_intr_signal_post. The memory segment must be
27717c478bd9Sstevel@tonic-gate * currently published for a successful return with a valid pollfd.
27727c478bd9Sstevel@tonic-gate * A reference count for the descriptor is incremented.
27737c478bd9Sstevel@tonic-gate */
27747c478bd9Sstevel@tonic-gate int
rsm_memseg_get_pollfd(void * memseg,struct pollfd * poll_fd)2775*7257d1b4Sraf rsm_memseg_get_pollfd(void *memseg,
27767c478bd9Sstevel@tonic-gate struct pollfd *poll_fd)
27777c478bd9Sstevel@tonic-gate {
27787c478bd9Sstevel@tonic-gate int i;
27797c478bd9Sstevel@tonic-gate int err = RSM_SUCCESS;
27807c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
27817c478bd9Sstevel@tonic-gate
27827c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
27837c478bd9Sstevel@tonic-gate "rsm_memseg_get_pollfd: enter\n"));
27847c478bd9Sstevel@tonic-gate
27857c478bd9Sstevel@tonic-gate if (!seg) {
27867c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
27877c478bd9Sstevel@tonic-gate "invalid segment\n"));
27887c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
27897c478bd9Sstevel@tonic-gate }
27907c478bd9Sstevel@tonic-gate
27917c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
27927c478bd9Sstevel@tonic-gate
27937c478bd9Sstevel@tonic-gate poll_fd->fd = seg->rsmseg_fd;
27947c478bd9Sstevel@tonic-gate poll_fd->events = POLLRDNORM;
27957c478bd9Sstevel@tonic-gate seg->rsmseg_pollfd_refcnt++;
27967c478bd9Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt == 1) {
27977c478bd9Sstevel@tonic-gate /* insert the segment into the pollfd table */
27987c478bd9Sstevel@tonic-gate err = _rsm_insert_pollfd_table(seg->rsmseg_fd,
27997c478bd9Sstevel@tonic-gate seg->rsmseg_rnum);
28007c478bd9Sstevel@tonic-gate }
28017c478bd9Sstevel@tonic-gate
28027c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
28037c478bd9Sstevel@tonic-gate
28047c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28057c478bd9Sstevel@tonic-gate "rsm_memseg_get_pollfd: exit(%d)\n", err));
28067c478bd9Sstevel@tonic-gate
28077c478bd9Sstevel@tonic-gate return (err);
28087c478bd9Sstevel@tonic-gate }
28097c478bd9Sstevel@tonic-gate
28107c478bd9Sstevel@tonic-gate /*
28117c478bd9Sstevel@tonic-gate * This function decrements the segment pollfd reference count.
28127c478bd9Sstevel@tonic-gate * A segment unpublish or destroy operation will fail if the reference count is
28137c478bd9Sstevel@tonic-gate * non zero.
28147c478bd9Sstevel@tonic-gate */
28157c478bd9Sstevel@tonic-gate int
rsm_memseg_release_pollfd(void * memseg)2816*7257d1b4Sraf rsm_memseg_release_pollfd(void * memseg)
28177c478bd9Sstevel@tonic-gate {
28187c478bd9Sstevel@tonic-gate int i;
28197c478bd9Sstevel@tonic-gate rsmseg_handle_t *seg = (rsmseg_handle_t *)memseg;
28207c478bd9Sstevel@tonic-gate
28217c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28227c478bd9Sstevel@tonic-gate "rsm_memseg_release_pollfd: enter\n"));
28237c478bd9Sstevel@tonic-gate
28247c478bd9Sstevel@tonic-gate if (!seg) {
28257c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
28267c478bd9Sstevel@tonic-gate "invalid segment handle\n"));
28277c478bd9Sstevel@tonic-gate return (RSMERR_BAD_SEG_HNDL);
28287c478bd9Sstevel@tonic-gate }
28297c478bd9Sstevel@tonic-gate
28307c478bd9Sstevel@tonic-gate mutex_lock(&seg->rsmseg_lock);
28317c478bd9Sstevel@tonic-gate
28327c478bd9Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt) {
28337c478bd9Sstevel@tonic-gate seg->rsmseg_pollfd_refcnt--;
28347c478bd9Sstevel@tonic-gate if (seg->rsmseg_pollfd_refcnt == 0) {
28357c478bd9Sstevel@tonic-gate /* last reference removed - update the pollfd_table */
28367c478bd9Sstevel@tonic-gate _rsm_remove_pollfd_table(seg->rsmseg_fd);
28377c478bd9Sstevel@tonic-gate }
28387c478bd9Sstevel@tonic-gate }
28397c478bd9Sstevel@tonic-gate
28407c478bd9Sstevel@tonic-gate mutex_unlock(&seg->rsmseg_lock);
28417c478bd9Sstevel@tonic-gate
28427c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28437c478bd9Sstevel@tonic-gate "rsm_memseg_release_pollfd: exit\n"));
28447c478bd9Sstevel@tonic-gate
28457c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
28467c478bd9Sstevel@tonic-gate }
28477c478bd9Sstevel@tonic-gate
28487c478bd9Sstevel@tonic-gate /*
28497c478bd9Sstevel@tonic-gate * The interconnect topology data is obtained from the Kernel Agent
28507c478bd9Sstevel@tonic-gate * and stored in a memory buffer allocated by this function. A pointer
28517c478bd9Sstevel@tonic-gate * to the buffer is stored in the location specified by the caller in
28527c478bd9Sstevel@tonic-gate * the function argument. It is the callers responsibility to
28537c478bd9Sstevel@tonic-gate * call rsm_free_interconnect_topolgy() to free the allocated memory.
28547c478bd9Sstevel@tonic-gate */
28557c478bd9Sstevel@tonic-gate int
rsm_get_interconnect_topology(rsm_topology_t ** topology_data)2856*7257d1b4Sraf rsm_get_interconnect_topology(rsm_topology_t **topology_data)
28577c478bd9Sstevel@tonic-gate {
28587c478bd9Sstevel@tonic-gate uint32_t topology_data_size;
28597c478bd9Sstevel@tonic-gate rsm_topology_t *topology_ptr;
28607c478bd9Sstevel@tonic-gate int error;
28617c478bd9Sstevel@tonic-gate
28627c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
28637c478bd9Sstevel@tonic-gate "rsm_get_interconnect_topology: enter\n"));
28647c478bd9Sstevel@tonic-gate
28657c478bd9Sstevel@tonic-gate if (topology_data == NULL)
28667c478bd9Sstevel@tonic-gate return (RSMERR_BAD_TOPOLOGY_PTR);
28677c478bd9Sstevel@tonic-gate
28687c478bd9Sstevel@tonic-gate *topology_data = NULL;
28697c478bd9Sstevel@tonic-gate
28707c478bd9Sstevel@tonic-gate again:
28717c478bd9Sstevel@tonic-gate /* obtain the size of the topology data */
28727c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_TOPOLOGY_SIZE, &topology_data_size) < 0) {
28737c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
28747c478bd9Sstevel@tonic-gate "RSM_IOCTL_TOPOLOGY_SIZE failed\n"));
28757c478bd9Sstevel@tonic-gate return (errno);
28767c478bd9Sstevel@tonic-gate }
28777c478bd9Sstevel@tonic-gate
28787c478bd9Sstevel@tonic-gate /* allocate double-word aligned memory to hold the topology data */
28797c478bd9Sstevel@tonic-gate topology_ptr = (rsm_topology_t *)memalign(8, topology_data_size);
28807c478bd9Sstevel@tonic-gate if (topology_ptr == NULL) {
28817c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
28827c478bd9Sstevel@tonic-gate "not enough memory\n"));
28837c478bd9Sstevel@tonic-gate return (RSMERR_INSUFFICIENT_MEM);
28847c478bd9Sstevel@tonic-gate }
28857c478bd9Sstevel@tonic-gate
28867c478bd9Sstevel@tonic-gate /*
28877c478bd9Sstevel@tonic-gate * Request the topology data.
28887c478bd9Sstevel@tonic-gate * Pass in the size to be used as a check in case
28897c478bd9Sstevel@tonic-gate * the data has grown since the size was obtained - if
28907c478bd9Sstevel@tonic-gate * it has, the errno value will be E2BIG.
28917c478bd9Sstevel@tonic-gate */
28927c478bd9Sstevel@tonic-gate topology_ptr->topology_hdr.local_nodeid =
28937c478bd9Sstevel@tonic-gate (rsm_node_id_t)topology_data_size;
28947c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_TOPOLOGY_DATA, topology_ptr) < 0) {
28957c478bd9Sstevel@tonic-gate error = errno;
28967c478bd9Sstevel@tonic-gate free((void *)topology_ptr);
28977c478bd9Sstevel@tonic-gate if (error == E2BIG)
28987c478bd9Sstevel@tonic-gate goto again;
28997c478bd9Sstevel@tonic-gate else {
29007c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29017c478bd9Sstevel@tonic-gate "RSM_IOCTL_TOPOLOGY_DATA failed\n"));
29027c478bd9Sstevel@tonic-gate return (error);
29037c478bd9Sstevel@tonic-gate }
29047c478bd9Sstevel@tonic-gate } else
29057c478bd9Sstevel@tonic-gate *topology_data = topology_ptr;
29067c478bd9Sstevel@tonic-gate
29077c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29087c478bd9Sstevel@tonic-gate " rsm_get_interconnect_topology: exit\n"));
29097c478bd9Sstevel@tonic-gate
29107c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
29117c478bd9Sstevel@tonic-gate }
29127c478bd9Sstevel@tonic-gate
29137c478bd9Sstevel@tonic-gate
29147c478bd9Sstevel@tonic-gate void
rsm_free_interconnect_topology(rsm_topology_t * topology_ptr)2915*7257d1b4Sraf rsm_free_interconnect_topology(rsm_topology_t *topology_ptr)
29167c478bd9Sstevel@tonic-gate {
29177c478bd9Sstevel@tonic-gate
29187c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29197c478bd9Sstevel@tonic-gate "rsm_free_interconnect_topology: enter\n"));
29207c478bd9Sstevel@tonic-gate
29217c478bd9Sstevel@tonic-gate if (topology_ptr) {
29227c478bd9Sstevel@tonic-gate free((void *)topology_ptr);
29237c478bd9Sstevel@tonic-gate }
29247c478bd9Sstevel@tonic-gate
29257c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29267c478bd9Sstevel@tonic-gate "rsm_free_interconnect_topology: exit\n"));
29277c478bd9Sstevel@tonic-gate }
29287c478bd9Sstevel@tonic-gate
29297c478bd9Sstevel@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)2930*7257d1b4Sraf rsm_create_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,
29317c478bd9Sstevel@tonic-gate rsm_localmemory_handle_t *local_hndl_p,
29327c478bd9Sstevel@tonic-gate caddr_t local_vaddr, size_t len)
29337c478bd9Sstevel@tonic-gate {
29347c478bd9Sstevel@tonic-gate int e;
29357c478bd9Sstevel@tonic-gate rsm_controller_t *cntrl = (rsm_controller_t *)cntrl_handle;
29367c478bd9Sstevel@tonic-gate
29377c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29387c478bd9Sstevel@tonic-gate "rsm_create_localmemory_handle: enter\n"));
29397c478bd9Sstevel@tonic-gate
29407c478bd9Sstevel@tonic-gate if ((size_t)local_vaddr & (PAGESIZE - 1)) {
29417c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29427c478bd9Sstevel@tonic-gate "invalid arguments\n"));
29437c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
29447c478bd9Sstevel@tonic-gate }
29457c478bd9Sstevel@tonic-gate
29467c478bd9Sstevel@tonic-gate if (!cntrl_handle) {
29477c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29487c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
29497c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
29507c478bd9Sstevel@tonic-gate }
29517c478bd9Sstevel@tonic-gate if (!local_hndl_p) {
29527c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29537c478bd9Sstevel@tonic-gate "invalid local memory handle pointer\n"));
29547c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LOCALMEM_HNDL);
29557c478bd9Sstevel@tonic-gate }
29567c478bd9Sstevel@tonic-gate if (len == 0) {
29577c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29587c478bd9Sstevel@tonic-gate "invalid length\n"));
29597c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LENGTH);
29607c478bd9Sstevel@tonic-gate }
29617c478bd9Sstevel@tonic-gate
29627c478bd9Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_create_localmemory_handle(
29637c478bd9Sstevel@tonic-gate cntrl_handle,
29647c478bd9Sstevel@tonic-gate local_hndl_p,
29657c478bd9Sstevel@tonic-gate local_vaddr,
29667c478bd9Sstevel@tonic-gate len);
29677c478bd9Sstevel@tonic-gate
29687c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29697c478bd9Sstevel@tonic-gate "rsm_create_localmemory_handle: exit\n"));
29707c478bd9Sstevel@tonic-gate
29717c478bd9Sstevel@tonic-gate return (e);
29727c478bd9Sstevel@tonic-gate }
29737c478bd9Sstevel@tonic-gate
29747c478bd9Sstevel@tonic-gate int
rsm_free_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,rsm_localmemory_handle_t local_handle)2975*7257d1b4Sraf rsm_free_localmemory_handle(rsmapi_controller_handle_t cntrl_handle,
29767c478bd9Sstevel@tonic-gate rsm_localmemory_handle_t local_handle)
29777c478bd9Sstevel@tonic-gate {
29787c478bd9Sstevel@tonic-gate int e;
29797c478bd9Sstevel@tonic-gate
29807c478bd9Sstevel@tonic-gate rsm_controller_t *cntrl = (rsm_controller_t *)cntrl_handle;
29817c478bd9Sstevel@tonic-gate
29827c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
29837c478bd9Sstevel@tonic-gate "rsm_free_localmemory_handle: enter\n"));
29847c478bd9Sstevel@tonic-gate
29857c478bd9Sstevel@tonic-gate
29867c478bd9Sstevel@tonic-gate if (!cntrl_handle) {
29877c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29887c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
29897c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
29907c478bd9Sstevel@tonic-gate }
29917c478bd9Sstevel@tonic-gate
29927c478bd9Sstevel@tonic-gate if (!local_handle) {
29937c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
29947c478bd9Sstevel@tonic-gate "invalid localmemory handle\n"));
29957c478bd9Sstevel@tonic-gate return (RSMERR_BAD_LOCALMEM_HNDL);
29967c478bd9Sstevel@tonic-gate }
29977c478bd9Sstevel@tonic-gate
29987c478bd9Sstevel@tonic-gate e = cntrl->cntr_segops->rsm_free_localmemory_handle(local_handle);
29997c478bd9Sstevel@tonic-gate
30007c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
30017c478bd9Sstevel@tonic-gate "rsm_free_localmemory_handle: exit\n"));
30027c478bd9Sstevel@tonic-gate
30037c478bd9Sstevel@tonic-gate return (e);
30047c478bd9Sstevel@tonic-gate }
30057c478bd9Sstevel@tonic-gate
30067c478bd9Sstevel@tonic-gate int
rsm_get_segmentid_range(const char * appid,rsm_memseg_id_t * baseid,uint32_t * length)3007*7257d1b4Sraf rsm_get_segmentid_range(const char *appid, rsm_memseg_id_t *baseid,
30087c478bd9Sstevel@tonic-gate uint32_t *length)
30097c478bd9Sstevel@tonic-gate {
30107c478bd9Sstevel@tonic-gate char buf[RSMFILE_BUFSIZE];
30117c478bd9Sstevel@tonic-gate char *s;
30127c478bd9Sstevel@tonic-gate char *fieldv[4];
30137c478bd9Sstevel@tonic-gate int fieldc = 0;
30147c478bd9Sstevel@tonic-gate int found = 0;
30157c478bd9Sstevel@tonic-gate int err = RSMERR_BAD_APPID;
30167c478bd9Sstevel@tonic-gate FILE *fp;
30177c478bd9Sstevel@tonic-gate
30187c478bd9Sstevel@tonic-gate if (appid == NULL || baseid == NULL || length == NULL)
30197c478bd9Sstevel@tonic-gate return (RSMERR_BAD_ADDR);
30207c478bd9Sstevel@tonic-gate
3021004388ebScasper if ((fp = fopen(RSMSEGIDFILE, "rF")) == NULL) {
30227c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
30237c478bd9Sstevel@tonic-gate "cannot open <%s>\n", RSMSEGIDFILE));
30247c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CONF);
30257c478bd9Sstevel@tonic-gate }
30267c478bd9Sstevel@tonic-gate
30277c478bd9Sstevel@tonic-gate while (s = fgets(buf, RSMFILE_BUFSIZE, fp)) {
30287c478bd9Sstevel@tonic-gate fieldc = 0;
30297c478bd9Sstevel@tonic-gate while (isspace(*s)) /* skip the leading spaces */
30307c478bd9Sstevel@tonic-gate s++;
30317c478bd9Sstevel@tonic-gate
30327c478bd9Sstevel@tonic-gate if (*s == '#') { /* comment line - skip it */
30337c478bd9Sstevel@tonic-gate continue;
30347c478bd9Sstevel@tonic-gate }
30357c478bd9Sstevel@tonic-gate
30367c478bd9Sstevel@tonic-gate /*
30377c478bd9Sstevel@tonic-gate * parse the reserved segid file and
30387c478bd9Sstevel@tonic-gate * set the pointers appropriately.
30397c478bd9Sstevel@tonic-gate * fieldv[0] : keyword
30407c478bd9Sstevel@tonic-gate * fieldv[1] : application identifier
30417c478bd9Sstevel@tonic-gate * fieldv[2] : baseid
30427c478bd9Sstevel@tonic-gate * fieldv[3] : length
30437c478bd9Sstevel@tonic-gate */
30447c478bd9Sstevel@tonic-gate while ((*s != '\n') && (*s != '\0') && (fieldc < 4)) {
30457c478bd9Sstevel@tonic-gate
30467c478bd9Sstevel@tonic-gate while (isspace(*s)) /* skip the leading spaces */
30477c478bd9Sstevel@tonic-gate s++;
30487c478bd9Sstevel@tonic-gate
30497c478bd9Sstevel@tonic-gate fieldv[fieldc++] = s;
30507c478bd9Sstevel@tonic-gate
30517c478bd9Sstevel@tonic-gate if (fieldc == 4) {
30527c478bd9Sstevel@tonic-gate if (fieldv[3][strlen(fieldv[3])-1] == '\n')
30537c478bd9Sstevel@tonic-gate fieldv[3][strlen(fieldv[3])-1] = '\0';
30547c478bd9Sstevel@tonic-gate break;
30557c478bd9Sstevel@tonic-gate }
30567c478bd9Sstevel@tonic-gate
30577c478bd9Sstevel@tonic-gate while (*s && !isspace(*s))
30587c478bd9Sstevel@tonic-gate ++s; /* move to the next white space */
30597c478bd9Sstevel@tonic-gate
30607c478bd9Sstevel@tonic-gate if (*s)
30617c478bd9Sstevel@tonic-gate *s++ = '\0';
30627c478bd9Sstevel@tonic-gate }
30637c478bd9Sstevel@tonic-gate
30647c478bd9Sstevel@tonic-gate if (fieldc < 4) { /* some fields are missing */
30657c478bd9Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30667c478bd9Sstevel@tonic-gate break;
30677c478bd9Sstevel@tonic-gate }
30687c478bd9Sstevel@tonic-gate
30697c478bd9Sstevel@tonic-gate if (strcasecmp(fieldv[1], appid) == 0) { /* found a match */
30707c478bd9Sstevel@tonic-gate if (strcasecmp(fieldv[0], RSMSEG_RESERVED) == 0) {
30717c478bd9Sstevel@tonic-gate errno = 0;
30727c478bd9Sstevel@tonic-gate *baseid = strtol(fieldv[2], (char **)NULL, 16);
30737c478bd9Sstevel@tonic-gate if (errno != 0) {
30747c478bd9Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30757c478bd9Sstevel@tonic-gate break;
30767c478bd9Sstevel@tonic-gate }
30777c478bd9Sstevel@tonic-gate
30787c478bd9Sstevel@tonic-gate errno = 0;
30797c478bd9Sstevel@tonic-gate *length = (int)strtol(fieldv[3],
30807c478bd9Sstevel@tonic-gate (char **)NULL, 10);
30817c478bd9Sstevel@tonic-gate if (errno != 0) {
30827c478bd9Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30837c478bd9Sstevel@tonic-gate break;
30847c478bd9Sstevel@tonic-gate }
30857c478bd9Sstevel@tonic-gate
30867c478bd9Sstevel@tonic-gate found = 1;
30877c478bd9Sstevel@tonic-gate } else { /* error in format */
30887c478bd9Sstevel@tonic-gate err = RSMERR_BAD_CONF;
30897c478bd9Sstevel@tonic-gate }
30907c478bd9Sstevel@tonic-gate break;
30917c478bd9Sstevel@tonic-gate }
30927c478bd9Sstevel@tonic-gate }
30937c478bd9Sstevel@tonic-gate
30947c478bd9Sstevel@tonic-gate (void) fclose(fp);
30957c478bd9Sstevel@tonic-gate
30967c478bd9Sstevel@tonic-gate if (found)
30977c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
30987c478bd9Sstevel@tonic-gate
30997c478bd9Sstevel@tonic-gate return (err);
31007c478bd9Sstevel@tonic-gate }
31017c478bd9Sstevel@tonic-gate
31027c478bd9Sstevel@tonic-gate static int
_rsm_get_hwaddr(rsmapi_controller_handle_t handle,rsm_node_id_t nodeid,rsm_addr_t * hwaddrp)31037c478bd9Sstevel@tonic-gate _rsm_get_hwaddr(rsmapi_controller_handle_t handle, rsm_node_id_t nodeid,
31047c478bd9Sstevel@tonic-gate rsm_addr_t *hwaddrp)
31057c478bd9Sstevel@tonic-gate {
31067c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg = {0};
31077c478bd9Sstevel@tonic-gate rsm_controller_t *ctrlp;
31087c478bd9Sstevel@tonic-gate
31097c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31107c478bd9Sstevel@tonic-gate "_rsm_get_hwaddr: enter\n"));
31117c478bd9Sstevel@tonic-gate
31127c478bd9Sstevel@tonic-gate ctrlp = (rsm_controller_t *)handle;
31137c478bd9Sstevel@tonic-gate
31147c478bd9Sstevel@tonic-gate if (ctrlp == NULL) {
31157c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31167c478bd9Sstevel@tonic-gate "invalid controller handle\n"));
31177c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
31187c478bd9Sstevel@tonic-gate }
31197c478bd9Sstevel@tonic-gate
31207c478bd9Sstevel@tonic-gate msg.cname = ctrlp->cntr_name;
31217c478bd9Sstevel@tonic-gate msg.cname_len = strlen(ctrlp->cntr_name) +1;
31227c478bd9Sstevel@tonic-gate msg.cnum = ctrlp->cntr_unit;
31237c478bd9Sstevel@tonic-gate msg.nodeid = nodeid;
31247c478bd9Sstevel@tonic-gate
31257c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_MAP_TO_ADDR, &msg) < 0) {
31267c478bd9Sstevel@tonic-gate int error = errno;
31277c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31287c478bd9Sstevel@tonic-gate "RSM_IOCTL_MAP_TO_ADDR failed\n"));
31297c478bd9Sstevel@tonic-gate return (error);
31307c478bd9Sstevel@tonic-gate }
31317c478bd9Sstevel@tonic-gate
31327c478bd9Sstevel@tonic-gate *hwaddrp = msg.hwaddr;
31337c478bd9Sstevel@tonic-gate
31347c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31357c478bd9Sstevel@tonic-gate "_rsm_get_hwaddr: exit\n"));
31367c478bd9Sstevel@tonic-gate
31377c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
31387c478bd9Sstevel@tonic-gate
31397c478bd9Sstevel@tonic-gate }
31407c478bd9Sstevel@tonic-gate
31417c478bd9Sstevel@tonic-gate static int
_rsm_get_nodeid(rsmapi_controller_handle_t handle,rsm_addr_t hwaddr,rsm_node_id_t * nodeidp)31427c478bd9Sstevel@tonic-gate _rsm_get_nodeid(rsmapi_controller_handle_t handle, rsm_addr_t hwaddr,
31437c478bd9Sstevel@tonic-gate rsm_node_id_t *nodeidp)
31447c478bd9Sstevel@tonic-gate {
31457c478bd9Sstevel@tonic-gate
31467c478bd9Sstevel@tonic-gate rsm_ioctlmsg_t msg = {0};
31477c478bd9Sstevel@tonic-gate rsm_controller_t *ctrlp;
31487c478bd9Sstevel@tonic-gate
31497c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31507c478bd9Sstevel@tonic-gate "_rsm_get_nodeid: enter\n"));
31517c478bd9Sstevel@tonic-gate
31527c478bd9Sstevel@tonic-gate ctrlp = (rsm_controller_t *)handle;
31537c478bd9Sstevel@tonic-gate
31547c478bd9Sstevel@tonic-gate if (ctrlp == NULL) {
31557c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31567c478bd9Sstevel@tonic-gate "invalid arguments\n"));
31577c478bd9Sstevel@tonic-gate return (RSMERR_BAD_CTLR_HNDL);
31587c478bd9Sstevel@tonic-gate }
31597c478bd9Sstevel@tonic-gate
31607c478bd9Sstevel@tonic-gate msg.cname = ctrlp->cntr_name;
31617c478bd9Sstevel@tonic-gate msg.cname_len = strlen(ctrlp->cntr_name) +1;
31627c478bd9Sstevel@tonic-gate msg.cnum = ctrlp->cntr_unit;
31637c478bd9Sstevel@tonic-gate msg.hwaddr = hwaddr;
31647c478bd9Sstevel@tonic-gate
31657c478bd9Sstevel@tonic-gate if (ioctl(_rsm_fd, RSM_IOCTL_MAP_TO_NODEID, &msg) < 0) {
31667c478bd9Sstevel@tonic-gate int error = errno;
31677c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_ERR,
31687c478bd9Sstevel@tonic-gate "RSM_IOCTL_MAP_TO_NODEID failed\n"));
31697c478bd9Sstevel@tonic-gate return (error);
31707c478bd9Sstevel@tonic-gate }
31717c478bd9Sstevel@tonic-gate
31727c478bd9Sstevel@tonic-gate *nodeidp = msg.nodeid;
31737c478bd9Sstevel@tonic-gate
31747c478bd9Sstevel@tonic-gate DBPRINTF((RSM_LIBRARY, RSM_DEBUG_VERBOSE,
31757c478bd9Sstevel@tonic-gate "_rsm_get_nodeid: exit\n"));
31767c478bd9Sstevel@tonic-gate
31777c478bd9Sstevel@tonic-gate return (RSM_SUCCESS);
31787c478bd9Sstevel@tonic-gate
31797c478bd9Sstevel@tonic-gate }
31807c478bd9Sstevel@tonic-gate
31817c478bd9Sstevel@tonic-gate #ifdef DEBUG
31827c478bd9Sstevel@tonic-gate void
dbg_printf(int msg_category,int msg_level,char * fmt,...)31837c478bd9Sstevel@tonic-gate dbg_printf(int msg_category, int msg_level, char *fmt, ...)
31847c478bd9Sstevel@tonic-gate {
31857c478bd9Sstevel@tonic-gate if ((msg_category & rsmlibdbg_category) &&
31867c478bd9Sstevel@tonic-gate (msg_level <= rsmlibdbg_level)) {
31877c478bd9Sstevel@tonic-gate va_list arg_list;
31887c478bd9Sstevel@tonic-gate va_start(arg_list, fmt);
31897c478bd9Sstevel@tonic-gate mutex_lock(&rsmlog_lock);
3190*7257d1b4Sraf fprintf(rsmlog_fd, "Thread %d ", thr_self());
31917c478bd9Sstevel@tonic-gate vfprintf(rsmlog_fd, fmt, arg_list);
31927c478bd9Sstevel@tonic-gate fflush(rsmlog_fd);
31937c478bd9Sstevel@tonic-gate mutex_unlock(&rsmlog_lock);
31947c478bd9Sstevel@tonic-gate va_end(arg_list);
31957c478bd9Sstevel@tonic-gate }
31967c478bd9Sstevel@tonic-gate }
31977c478bd9Sstevel@tonic-gate #endif /* DEBUG */
3198