17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate * Copyright 1999-2003 Sun Microsystems, Inc.  All rights reserved.
247c478bdstevel@tonic-gate * Use is subject to license terms.
257c478bdstevel@tonic-gate */
267c478bdstevel@tonic-gate
277c478bdstevel@tonic-gate#ifndef _RSM_IN_H
287c478bdstevel@tonic-gate#define	_RSM_IN_H
297c478bdstevel@tonic-gate
307c478bdstevel@tonic-gate#pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#ifdef	__cplusplus
337c478bdstevel@tonic-gateextern "C" {
347c478bdstevel@tonic-gate#endif
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#include <sys/ddi.h>
377c478bdstevel@tonic-gate#include <sys/sunddi.h>
387c478bdstevel@tonic-gate#include <sys/rsm/rsm.h>
397c478bdstevel@tonic-gate#include <sys/rsm/rsmpi.h>
407c478bdstevel@tonic-gate
417c478bdstevel@tonic-gate#define	DRIVER_NAME	"rsm"
427c478bdstevel@tonic-gate
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate#define	RSM_DRIVER_MINOR	0
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate#define	RSM_CNUM	8
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate#define	RSMIPC_SZ	10	/* number of outstanding requests, max: 256 */
497c478bdstevel@tonic-gate
507c478bdstevel@tonic-gate#define	RSMIPC_MAX_MESSAGES	64 /* max msgs that receiver can buffer */
517c478bdstevel@tonic-gate#define	RSMIPC_LOTSFREE_MSGBUFS	16 /* chunks of credits sent to sender  */
527c478bdstevel@tonic-gate
537c478bdstevel@tonic-gate/*
547c478bdstevel@tonic-gate * The base for Sun RSMAPI Kernel Agent service idenitifiers is RSM_INTR_T_KA
557c478bdstevel@tonic-gate * as defined below. This is as per the RSMPI specification. Thus,
567c478bdstevel@tonic-gate * in the kernel agent, we need to use this value as the service identifier
577c478bdstevel@tonic-gate * while registering the service handlers.
587c478bdstevel@tonic-gate */
597c478bdstevel@tonic-gate#define	RSM_INTR_T_KA	0x88
607c478bdstevel@tonic-gate#define	RSM_SERVICE	RSM_INTR_T_KA
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate#define	RSM_PRI		2
637c478bdstevel@tonic-gate#define	RSM_QUEUE_SZ	256
647c478bdstevel@tonic-gate
657c478bdstevel@tonic-gate#define	RSM_LOCK	0
667c478bdstevel@tonic-gate#define	RSM_NOLOCK	1
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate#define	RSM_MAX_NUM_SEG	4095	/* default value for max imp and exp segs */
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gate#define	RSM_MAX_NODE	64	/* maximum number of nodes in the cluster */
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#define	RSM_MAX_CTRL	32	/* maximum number of controllers per node */
737c478bdstevel@tonic-gate
747c478bdstevel@tonic-gate/*
757c478bdstevel@tonic-gate * The following defines UINT_MAX rounded down to a page aligned value.
767c478bdstevel@tonic-gate */
777c478bdstevel@tonic-gate#define	RSM_MAXSZ_PAGE_ALIGNED (UINT_MAX & PAGEMASK)
787c478bdstevel@tonic-gate/*
797c478bdstevel@tonic-gate * Define TRASHSIZE as the maximum possible size which is page aligned
807c478bdstevel@tonic-gate * This value cannot be 0xffffffffffffe000 since this is taken as a
817c478bdstevel@tonic-gate * negative value in the devmap_umem_remap call, thus causing the call
827c478bdstevel@tonic-gate * to fail.
837c478bdstevel@tonic-gate */
847c478bdstevel@tonic-gate#define	TRASHSIZE 0x7fffffffffffe000
857c478bdstevel@tonic-gate
867c478bdstevel@tonic-gate#define	RSM_ACCESS_READ				0444
877c478bdstevel@tonic-gate#define	RSM_ACCESS_WRITE			0222
887c478bdstevel@tonic-gate#define	RSM_ACCESS_TRUSTED			0666
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gate/* flag values for rsmseg_unload */
917c478bdstevel@tonic-gate#define	DISCONNECT	1
927c478bdstevel@tonic-gate#define	NO_DISCONNECT	0
937c478bdstevel@tonic-gate
947c478bdstevel@tonic-gatestruct rsm_driver_data {
957c478bdstevel@tonic-gate	kmutex_t	drv_lock;
967c478bdstevel@tonic-gate	kcondvar_t	drv_cv;
977c478bdstevel@tonic-gate	int		drv_state;	/* RSM_DRV_YYYY states */
987c478bdstevel@tonic-gate	int		drv_memdel_cnt; /* number of memdel callbacks */
997c478bdstevel@tonic-gate};
1007c478bdstevel@tonic-gate
1017c478bdstevel@tonic-gate/* rsm driver state */
1027c478bdstevel@tonic-gate#define	RSM_DRV_NEW			0
1037c478bdstevel@tonic-gate#define	RSM_DRV_OK			1
1047c478bdstevel@tonic-gate#define	RSM_DRV_PREDEL_STARTED		2
1057c478bdstevel@tonic-gate#define	RSM_DRV_PREDEL_COMPLETED	3
1067c478bdstevel@tonic-gate#define	RSM_DRV_POSTDEL_IN_PROGRESS	4
1077c478bdstevel@tonic-gate#define	RSM_DRV_DR_IN_PROGRESS		5
1087c478bdstevel@tonic-gate#define	RSM_DRV_REG_PROCESSING		6
1097c478bdstevel@tonic-gate#define	RSM_DRV_UNREG_PROCESSING	7
1107c478bdstevel@tonic-gate
1117c478bdstevel@tonic-gate/* internal flags */
1127c478bdstevel@tonic-gate#define	RSM_DR_QUIESCE		0
1137c478bdstevel@tonic-gate#define	RSM_DR_UNQUIESCE	1
1147c478bdstevel@tonic-gate
1157c478bdstevel@tonic-gatetypedef enum {
1167c478bdstevel@tonic-gate	RSM_STATE_NEW = 0,
1177c478bdstevel@tonic-gate	RSM_STATE_NEW_QUIESCED,
1187c478bdstevel@tonic-gate	RSM_STATE_BIND,
1197c478bdstevel@tonic-gate	RSM_STATE_BIND_QUIESCED,
1207c478bdstevel@tonic-gate	RSM_STATE_EXPORT,
1217c478bdstevel@tonic-gate	RSM_STATE_EXPORT_QUIESCING,
1227c478bdstevel@tonic-gate	RSM_STATE_EXPORT_QUIESCED,
1237c478bdstevel@tonic-gate	RSM_STATE_ZOMBIE,
1247c478bdstevel@tonic-gate	RSM_STATE_CONNECTING,
1257c478bdstevel@tonic-gate	RSM_STATE_ABORT_CONNECT,
1267c478bdstevel@tonic-gate	RSM_STATE_CONNECT,
1277c478bdstevel@tonic-gate	RSM_STATE_CONN_QUIESCE,
1287c478bdstevel@tonic-gate	RSM_STATE_MAPPING,
1297c478bdstevel@tonic-gate	RSM_STATE_ACTIVE,
1307c478bdstevel@tonic-gate	RSM_STATE_MAP_QUIESCE,
1317c478bdstevel@tonic-gate	RSM_STATE_DISCONNECT,
1327c478bdstevel@tonic-gate	RSM_STATE_END
1337c478bdstevel@tonic-gate} rsm_resource_state_t;
1347c478bdstevel@tonic-gate
1357c478bdstevel@tonic-gatetypedef enum {
1367c478bdstevel@tonic-gate	RSM_RESOURCE_EXPORT_SEGMENT,
1377c478bdstevel@tonic-gate	RSM_RESOURCE_IMPORT_SEGMENT,
1387c478bdstevel@tonic-gate	RSM_RESOURCE_BAR
1397c478bdstevel@tonic-gate}rsm_resource_type_t;
1407c478bdstevel@tonic-gate
1417c478bdstevel@tonic-gate/*
1427c478bdstevel@tonic-gate * All resources have the only common info. whether it is a segment or
1437c478bdstevel@tonic-gate * a notification queue.
1447c478bdstevel@tonic-gate */
1457c478bdstevel@tonic-gatetypedef struct rsm_resource {
1467c478bdstevel@tonic-gate	kmutex_t		rsmrc_lock;	/* sync on resource */
1477c478bdstevel@tonic-gate	minor_t			rsmrc_num;	/* (minor) number */
1487c478bdstevel@tonic-gate	rsm_memseg_id_t		rsmrc_key;	/* user key */
1497c478bdstevel@tonic-gate	mode_t			rsmrc_mode;	/* access permission */
1507c478bdstevel@tonic-gate	struct adapter		*rsmrc_adapter;	/* controller number */
1517c478bdstevel@tonic-gate	rsm_node_id_t		rsmrc_node;	/*  nodeid */
1527c478bdstevel@tonic-gate	rsm_resource_type_t	rsmrc_type;	/* type of this resource */
1537c478bdstevel@tonic-gate	rsm_resource_state_t	rsmrc_state;	/* segment state */
1547c478bdstevel@tonic-gate	struct rsm_resource	*rsmrc_next;
1557c478bdstevel@tonic-gate} rsmresource_t;
1567c478bdstevel@tonic-gate
1577c478bdstevel@tonic-gate#define	RSMRC_BLKSZ	16
1587c478bdstevel@tonic-gate#define	RSMRC_RESERVED	((rsmresource_t *)0x1)
1597c478bdstevel@tonic-gate
1607c478bdstevel@tonic-gate#define	RSM_HASHSZ	128
1617c478bdstevel@tonic-gate
1627c478bdstevel@tonic-gate#define	RSM_USER_MEMORY		0x1
1637c478bdstevel@tonic-gate#define	RSM_KERNEL_MEMORY	0x2
1647c478bdstevel@tonic-gate#define	RSM_EXPORT_WAIT		0x4
1657c478bdstevel@tonic-gate#define	RSM_SEGMENT_POLL	0x8
1667c478bdstevel@tonic-gate#define	RSM_FORCE_DISCONNECT	0x10
1677c478bdstevel@tonic-gate#define	RSM_IMPORT_DUMMY	0x20
1687c478bdstevel@tonic-gate/*
1697c478bdstevel@tonic-gate * The following macro is used within the kernel agent to indicate that
1707c478bdstevel@tonic-gate * rebind/unbind is allowed for an exported segment. It is a part of the
1717c478bdstevel@tonic-gate * segment's s_flags field.
1727c478bdstevel@tonic-gate */
1737c478bdstevel@tonic-gate#define	RSMKA_ALLOW_UNBIND_REBIND	0x40
1747c478bdstevel@tonic-gate#define	RSM_REPUBLISH_WAIT	0x80
1757c478bdstevel@tonic-gate#define	RSM_DR_INPROGRESS	0x100
1767c478bdstevel@tonic-gate#define	RSM_FORCE_DESTROY_WAIT	0x200
1777c478bdstevel@tonic-gate#define	RSMKA_SET_RESOURCE_DONTWAIT	0x400
1787c478bdstevel@tonic-gate
1797c478bdstevel@tonic-gate#define	RSMRC_LOCK(p)	mutex_enter(&(p)->rsmrc_lock)
1807c478bdstevel@tonic-gate#define	RSMRC_UNLOCK(p)	mutex_exit(&(p)->rsmrc_lock)
1817c478bdstevel@tonic-gate#define	RSMRC_HELD(p)	MUTEX_HELD(&(p)->rsmrc_lock)
1827c478bdstevel@tonic-gate#define	RSMRC_TRY(p)	mutex_tryenter(&(p)->rsmrc_lock)
1837c478bdstevel@tonic-gate
1847c478bdstevel@tonic-gatetypedef struct rsm_region {
1857c478bdstevel@tonic-gate	caddr_t		r_vaddr;	/* exported virtual address */
1867c478bdstevel@tonic-gate	size_t		r_len;		/* length of export region */
1877c478bdstevel@tonic-gate	offset_t	r_off;		/* offset of this region in segment */
1887c478bdstevel@tonic-gate	struct as	*r_asp;
1897c478bdstevel@tonic-gate	struct rsm_region *r_next;	/* next region of segment */
1907c478bdstevel@tonic-gate}rsm_region;
1917c478bdstevel@tonic-gate
1927c478bdstevel@tonic-gatetypedef struct rsm_cookie {
1937c478bdstevel@tonic-gate	devmap_cookie_t		c_dhp;		/* devmap cookie handle */
1947c478bdstevel@tonic-gate	offset_t		c_off;		/* offset of mapping	*/
1957c478bdstevel@tonic-gate	size_t			c_len;		/* len of mapping	*/
1967c478bdstevel@tonic-gate	struct rsm_cookie	*c_next;	/* next handle		*/
1977c478bdstevel@tonic-gate}rsmcookie_t;
1987c478bdstevel@tonic-gate
1997c478bdstevel@tonic-gatetypedef struct rsm_mapinfo {
2007c478bdstevel@tonic-gate	dev_info_t	*dip;
2017c478bdstevel@tonic-gate	uint_t		dev_register;
2027c478bdstevel@tonic-gate	off_t		dev_offset;
2037c478bdstevel@tonic-gate	off_t		start_offset;
2047c478bdstevel@tonic-gate	size_t		individual_len;
2057c478bdstevel@tonic-gate	struct rsm_mapinfo *next;
2067c478bdstevel@tonic-gate} rsm_mapinfo_t;
2077c478bdstevel@tonic-gate
2087c478bdstevel@tonic-gate
2097c478bdstevel@tonic-gate
2107c478bdstevel@tonic-gate/*
2117c478bdstevel@tonic-gate * Shared Importer data structure
2127c478bdstevel@tonic-gate *
2137c478bdstevel@tonic-gate */
2147c478bdstevel@tonic-gatetypedef struct rsm_import_share {
2157c478bdstevel@tonic-gate	kmutex_t	rsmsi_lock;	/* lock for shared importers	*/
2167c478bdstevel@tonic-gate	kcondvar_t	rsmsi_cv;	/* condvar to wait at		*/
2177c478bdstevel@tonic-gate	rsm_node_id_t	rsmsi_node;
2187c478bdstevel@tonic-gate	rsm_memseg_id_t	rsmsi_segid;
2197c478bdstevel@tonic-gate	size_t		rsmsi_seglen;
2207c478bdstevel@tonic-gate	rsm_memseg_import_handle_t	rsmsi_handle; /* RSMPI handle */
2217c478bdstevel@tonic-gate	uint_t		rsmsi_state;
2227c478bdstevel@tonic-gate#define	RSMSI_STATE_NEW			0x0001
2237c478bdstevel@tonic-gate#define	RSMSI_STATE_CONNECTING		0x0002
2247c478bdstevel@tonic-gate#define	RSMSI_STATE_ABORT_CONNECT	0x0004
2257c478bdstevel@tonic-gate#define	RSMSI_STATE_CONNECTED		0x0008
2267c478bdstevel@tonic-gate#define	RSMSI_STATE_CONN_QUIESCE	0x0010
2277c478bdstevel@tonic-gate#define	RSMSI_STATE_MAPPED		0x0020
2287c478bdstevel@tonic-gate#define	RSMSI_STATE_MAP_QUIESCE		0x0040
2297c478bdstevel@tonic-gate#define	RSMSI_STATE_DISCONNECTED	0x0080
2307c478bdstevel@tonic-gate
2317c478bdstevel@tonic-gate	uint_t		rsmsi_refcnt;	/* ref count of importers	*/
2327c478bdstevel@tonic-gate	uint_t		rsmsi_mapcnt;	/* count of mapped importers	*/
2337c478bdstevel@tonic-gate	mode_t		rsmsi_mode;	/* mode of last (re)publish	*/
2347c478bdstevel@tonic-gate	uid_t		rsmsi_uid;
2357c478bdstevel@tonic-gate	gid_t		rsmsi_gid;
2367c478bdstevel@tonic-gate	rsm_mapinfo_t	*rsmsi_mapinfo;	/* register, offset, len values */
2377c478bdstevel@tonic-gate	uint_t		rsmsi_flags;	/* flags			*/
2387c478bdstevel@tonic-gate#define	RSMSI_FLAGS_ABORTDONE	0x0001	/* NOT_IMPORTING msg for abort conn */
2397c478bdstevel@tonic-gate					/* has been sent		    */
2407c478bdstevel@tonic-gate	void		*rsmsi_cookie;	/* cookie of the first seg connect */
2417c478bdstevel@tonic-gate} rsm_import_share_t;
2427c478bdstevel@tonic-gate
2437c478bdstevel@tonic-gate#define	RSMSI_LOCK(sharep)	mutex_enter(&(sharep)->rsmsi_lock)
2447c478bdstevel@tonic-gate#define	RSMSI_UNLOCK(sharep)	mutex_exit(&(sharep)->rsmsi_lock)
2457c478bdstevel@tonic-gate#define	RSMSI_HELD(sharep)	MUTEX_HELD(&(sharep)->rsmsi_lock)
2467c478bdstevel@tonic-gate#define	RSMSI_TRY(sharep)	mutex_tryenter(&(sharep)->rsmsi_lock)
2477c478bdstevel@tonic-gate
2487c478bdstevel@tonic-gatetypedef struct rsm_seginfo {
2497c478bdstevel@tonic-gate	rsmresource_t		s_hdr;		/* resource hdr */
2507c478bdstevel@tonic-gate#define	s_state	s_hdr.rsmrc_state	/* segment state */
2517c478bdstevel@tonic-gate#define	s_adapter s_hdr.rsmrc_adapter
2527c478bdstevel@tonic-gate#define	s_node	s_hdr.rsmrc_node
2537c478bdstevel@tonic-gate#define	s_lock	s_hdr.rsmrc_lock
2547c478bdstevel@tonic-gate#define	s_minor	s_hdr.rsmrc_num		/* minor # of segment */
2557c478bdstevel@tonic-gate#define	s_key	s_hdr.rsmrc_key		/* user segment key */
2567c478bdstevel@tonic-gate#define	s_mode	s_hdr.rsmrc_mode	/* user segment mode */
2577c478bdstevel@tonic-gate#define	s_type	s_hdr.rsmrc_type	/* segment type */
2587c478bdstevel@tonic-gate	uid_t			s_uid;		/* owner id */
2597c478bdstevel@tonic-gate	gid_t			s_gid;		/* owner id */
2607c478bdstevel@tonic-gate
2617c478bdstevel@tonic-gate	size_t			s_len;		/* total segment size */
2627c478bdstevel@tonic-gate	rsm_region		s_region;	/* regions of segment */
2637c478bdstevel@tonic-gate
2647c478bdstevel@tonic-gate	int			s_flags;
2657c478bdstevel@tonic-gate	int			s_pollflag;	/* indicates poll status */
2667c478bdstevel@tonic-gate
2677c478bdstevel@tonic-gate	kcondvar_t		s_cv;		/* condition to wait on */
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate	rsm_memseg_id_t		s_segid;	/* NIC segment id */
2707c478bdstevel@tonic-gate
2717c478bdstevel@tonic-gate	int		s_acl_len;		/* length of access list */
2727c478bdstevel@tonic-gate	rsmapi_access_entry_t *s_acl;		/* access list */
2737c478bdstevel@tonic-gate	rsm_access_entry_t *s_acl_in;		/* access list with hwaddr */
2747c478bdstevel@tonic-gate
2757c478bdstevel@tonic-gate	struct pollhead	s_poll;
2767c478bdstevel@tonic-gate	uint32_t	s_pollevent;
2777c478bdstevel@tonic-gate	pid_t 		s_pid;
2787c478bdstevel@tonic-gate
2797c478bdstevel@tonic-gate	rsmcookie_t	*s_ckl;		/* list of devmap cookie */
2807c478bdstevel@tonic-gate
2817c478bdstevel@tonic-gate	size_t		s_total_maplen;
2827c478bdstevel@tonic-gate	rsm_mapinfo_t	*s_mapinfo;	/* register, offset, len  */
2837c478bdstevel@tonic-gate
2847c478bdstevel@tonic-gate	union {
2857c478bdstevel@tonic-gate		rsm_memseg_import_handle_t	in;
2867c478bdstevel@tonic-gate		rsm_memseg_export_handle_t	out;
2877c478bdstevel@tonic-gate	} s_handle;			/* NIC handle for segment */
2887c478bdstevel@tonic-gate
2897c478bdstevel@tonic-gate	/*
2907c478bdstevel@tonic-gate	 * This field is used to indicate the cookie returned by the
2917c478bdstevel@tonic-gate	 * ddi_umem_lock when binding pages for an export segment.
2927c478bdstevel@tonic-gate	 * Also, for importers on the same node as the export segment,
2937c478bdstevel@tonic-gate	 * this field indicates the cookie used during import mapping.
2947c478bdstevel@tonic-gate	 */
2957c478bdstevel@tonic-gate	ddi_umem_cookie_t	s_cookie;
2967c478bdstevel@tonic-gate	rsm_import_share_t	*s_share;	/* shared importer data	    */
2977c478bdstevel@tonic-gate	/*
2987c478bdstevel@tonic-gate	 * This field in an import segments indicates the number of
2997c478bdstevel@tonic-gate	 * putv/getv operations in progress and in an export segment
3007c478bdstevel@tonic-gate	 * it is the number of putv/getv ops currently using it as
3017c478bdstevel@tonic-gate	 * a handle in the iovec.
3027c478bdstevel@tonic-gate	 */
3037c478bdstevel@tonic-gate	uint_t			s_rdmacnt;
3047c478bdstevel@tonic-gate	struct proc		*s_proc;
3057c478bdstevel@tonic-gate} rsmseg_t;
3067c478bdstevel@tonic-gate
3077c478bdstevel@tonic-gate#define	rsmseglock_acquire(p)	RSMRC_LOCK((rsmresource_t *)(p))
3087c478bdstevel@tonic-gate#define	rsmseglock_release(p)	RSMRC_UNLOCK((rsmresource_t *)(p))
3097c478bdstevel@tonic-gate#define	rsmseglock_held(p)	RSMRC_HELD((rsmresource_t *)(p))
3107c478bdstevel@tonic-gate#define	rsmseglock_try(p)	RSMRC_TRY((rsmresource_t *)(p))
3117c478bdstevel@tonic-gate
3127c478bdstevel@tonic-gate#define	rsmsharelock_acquire(p)	RSMSI_LOCK(p->s_share)
3137c478bdstevel@tonic-gate#define	rsmsharelock_release(p)	RSMSI_UNLOCK(p->s_share)
3147c478bdstevel@tonic-gate#define	rsmsharelock_held(p)	RSMSI_HELD(p->s_share)
3157c478bdstevel@tonic-gate#define	rsmsharelock_try(p)	RSMSI_TRY(p->s_share)
3167c478bdstevel@tonic-gate
3177c478bdstevel@tonic-gate/*
3187c478bdstevel@tonic-gate * Resource elements structure
3197c478bdstevel@tonic-gate */
3207c478bdstevel@tonic-gatetypedef struct {
3217c478bdstevel@tonic-gate	int		rsmrcblk_avail;
3227c478bdstevel@tonic-gate	rsmresource_t	*rsmrcblk_blks[RSMRC_BLKSZ];
3237c478bdstevel@tonic-gate}rsmresource_blk_t;
3247c478bdstevel@tonic-gate
3257c478bdstevel@tonic-gatestruct rsmresource_table {
3267c478bdstevel@tonic-gate	krwlock_t	rsmrc_lock;
3277c478bdstevel@tonic-gate	int		rsmrc_len;
3287c478bdstevel@tonic-gate	int		rsmrc_sz;
3297c478bdstevel@tonic-gate	rsmresource_blk_t **rsmrc_root;
3307c478bdstevel@tonic-gate};
3317c478bdstevel@tonic-gate
3327c478bdstevel@tonic-gate/*
3337c478bdstevel@tonic-gate * Struct for advertised resource list
3347c478bdstevel@tonic-gate */
3357c478bdstevel@tonic-gate/*
3367c478bdstevel@tonic-gate * Hashtable structs
3377c478bdstevel@tonic-gate * bucket points to an array of pointers, each entry in the bucket array
3387c478bdstevel@tonic-gate * points to a linked list of resource items.
3397c478bdstevel@tonic-gate * bucket index = bucket_address%RSM_HASHSZ
3407c478bdstevel@tonic-gate */
3417c478bdstevel@tonic-gatetypedef struct rsmhash_table {
3427c478bdstevel@tonic-gate	krwlock_t		rsmhash_rw;
3437c478bdstevel@tonic-gate	rsmresource_t		**bucket;
3447c478bdstevel@tonic-gate} rsmhash_table_t;
3457c478bdstevel@tonic-gate
3467c478bdstevel@tonic-gate/*
3477c478bdstevel@tonic-gate * Remote messaging related structure
3487c478bdstevel@tonic-gate */
3497c478bdstevel@tonic-gate
3507c478bdstevel@tonic-gate/*
3517c478bdstevel@tonic-gate * Flags for ipc slot
3527c478bdstevel@tonic-gate */
3537c478bdstevel@tonic-gate#define	RSMIPC_FREE	0x1			/* slot is free */
3547c478bdstevel@tonic-gate#define	RSMIPC_PENDING	0x2			/* slot has pending request */
3557c478bdstevel@tonic-gate
3567c478bdstevel@tonic-gate#define	RSMIPC_SET(x, v)	((x)->rsmipc_flags |= (v))
3577c478bdstevel@tonic-gate#define	RSMIPC_GET(x, v)	((x)->rsmipc_flags & (v))
3587c478bdstevel@tonic-gate#define	RSMIPC_CLEAR(x, v)	((x)->rsmipc_flags &= ~(v))
3597c478bdstevel@tonic-gate
3607c478bdstevel@tonic-gatetypedef struct rsmipc_slot {
3617c478bdstevel@tonic-gate	kmutex_t 	rsmipc_lock;		/* lock for remote msgs */
3627c478bdstevel@tonic-gate	kcondvar_t	rsmipc_cv;		/* condition var to wait on */
3637c478bdstevel@tonic-gate	int		rsmipc_flags;
3647c478bdstevel@tonic-gate	rsmipc_cookie_t	rsmipc_cookie;		/* cookie of request in wire */
3657c478bdstevel@tonic-gate	void 		*rsmipc_data;		/* ptr to data to copy */
3667c478bdstevel@tonic-gate}rsmipc_slot_t;
3677c478bdstevel@tonic-gate
3687c478bdstevel@tonic-gate/*
3697c478bdstevel@tonic-gate * Messaging struc
3707c478bdstevel@tonic-gate */
3717c478bdstevel@tonic-gatetypedef struct {
3727c478bdstevel@tonic-gate	kmutex_t	lock;
3737c478bdstevel@tonic-gate	kcondvar_t	cv;
3747c478bdstevel@tonic-gate	int		count;
3757c478bdstevel@tonic-gate	int		wanted;
3767c478bdstevel@tonic-gate	int		sequence;
3777c478bdstevel@tonic-gate	rsmipc_slot_t	slots[RSMIPC_SZ];
3787c478bdstevel@tonic-gate}rsm_ipc_t;
3797c478bdstevel@tonic-gate
3807c478bdstevel@tonic-gate/*
3817c478bdstevel@tonic-gate * These tokens are used for building the list of remote node importers
3827c478bdstevel@tonic-gate * of a segment exported from the local node
3837c478bdstevel@tonic-gate */
3847c478bdstevel@tonic-gatetypedef struct importing_token {
3857c478bdstevel@tonic-gate	struct importing_token	*next;
3867c478bdstevel@tonic-gate	rsm_memseg_id_t		key;
3877c478bdstevel@tonic-gate	rsm_node_id_t		importing_node;
3887c478bdstevel@tonic-gate	void			*import_segment_cookie;
3897c478bdstevel@tonic-gate	rsm_addr_t		importing_adapter_hwaddr;
3907c478bdstevel@tonic-gate} importing_token_t;
3917c478bdstevel@tonic-gate
3927c478bdstevel@tonic-gatetypedef struct {
3937c478bdstevel@tonic-gate	kmutex_t		lock;
3947c478bdstevel@tonic-gate	importing_token_t	**bucket;
3957c478bdstevel@tonic-gate} importers_table_t;
3967c478bdstevel@tonic-gate
3977c478bdstevel@tonic-gate/*
3987c478bdstevel@tonic-gate * Used by the rsm_send_republish() fn
3997c478bdstevel@tonic-gate */
4007c478bdstevel@tonic-gatetypedef struct republish_token {
4017c478bdstevel@tonic-gate	struct republish_token	*next;
4027c478bdstevel@tonic-gate	rsm_memseg_id_t		key;
4037c478bdstevel@tonic-gate	rsm_node_id_t		importing_node;
4047c478bdstevel@tonic-gate	rsm_permission_t	permission;
4057c478bdstevel@tonic-gate} republish_token_t;
4067c478bdstevel@tonic-gate
4077c478bdstevel@tonic-gate/*
4087c478bdstevel@tonic-gate * data strucuture for list manipulation
4097c478bdstevel@tonic-gate */
4107c478bdstevel@tonic-gatetypedef struct list_element {
4117c478bdstevel@tonic-gate	struct list_element	*next;
4127c478bdstevel@tonic-gate	rsm_node_id_t		nodeid;
4137c478bdstevel@tonic-gate	uint32_t		flags;
4147c478bdstevel@tonic-gate#define	RSM_SUSPEND_ACKPENDING	0x01
4157c478bdstevel@tonic-gate#define	RSM_SUSPEND_NODEDEAD	0x02
4167c478bdstevel@tonic-gate} list_element_t;
4177c478bdstevel@tonic-gate
4187c478bdstevel@tonic-gatetypedef struct list_head {
4197c478bdstevel@tonic-gate	struct list_element	*list_head;
4207c478bdstevel@tonic-gate	kmutex_t		list_lock;
4217c478bdstevel@tonic-gate} list_head_t;
4227c478bdstevel@tonic-gate
4237c478bdstevel@tonic-gate#ifdef	__cplusplus
4247c478bdstevel@tonic-gate}
4257c478bdstevel@tonic-gate#endif
4267c478bdstevel@tonic-gate
4277c478bdstevel@tonic-gate#endif	/* _RSM_IN_H */
428