xref: /titanic_51/usr/src/uts/sun4u/starfire/io/idn.c (revision e0731422366620894c16c1ee6515551c5f00733d)
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
5b0fc0e77Sgovinda  * Common Development and Distribution License (the "License").
6b0fc0e77Sgovinda  * 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  */
217c478bd9Sstevel@tonic-gate /*
22d3d50737SRafael Vanoni  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
287c478bd9Sstevel@tonic-gate #include <sys/open.h>
297c478bd9Sstevel@tonic-gate #include <sys/param.h>
307c478bd9Sstevel@tonic-gate #include <sys/machparam.h>
317c478bd9Sstevel@tonic-gate #include <sys/systm.h>
327c478bd9Sstevel@tonic-gate #include <sys/signal.h>
337c478bd9Sstevel@tonic-gate #include <sys/cred.h>
347c478bd9Sstevel@tonic-gate #include <sys/user.h>
357c478bd9Sstevel@tonic-gate #include <sys/proc.h>
367c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
377c478bd9Sstevel@tonic-gate #include <sys/uio.h>
387c478bd9Sstevel@tonic-gate #include <sys/buf.h>
397c478bd9Sstevel@tonic-gate #include <sys/file.h>
407c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
417c478bd9Sstevel@tonic-gate #include <sys/stat.h>
427c478bd9Sstevel@tonic-gate #include <sys/stream.h>
437c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
447c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
457c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
467c478bd9Sstevel@tonic-gate #include <inet/common.h>
477c478bd9Sstevel@tonic-gate #include <inet/mi.h>
487c478bd9Sstevel@tonic-gate #include <inet/nd.h>
497c478bd9Sstevel@tonic-gate #include <sys/poll.h>
507c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
517c478bd9Sstevel@tonic-gate #include <sys/debug.h>
527c478bd9Sstevel@tonic-gate #include <sys/conf.h>
537c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
547c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
557c478bd9Sstevel@tonic-gate #include <sys/errno.h>
567c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
577c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
587c478bd9Sstevel@tonic-gate #include <sys/promif.h>
597c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h>
607c478bd9Sstevel@tonic-gate #include <sys/obpdefs.h>
617c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
627c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h>
637c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
647c478bd9Sstevel@tonic-gate #include <sys/membar.h>
657c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
667c478bd9Sstevel@tonic-gate #include <sys/vm_machparam.h>
677c478bd9Sstevel@tonic-gate #include <sys/x_call.h>
687c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
697c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
707c478bd9Sstevel@tonic-gate #include <sys/dmv.h>
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate #include <sys/idn.h>
737c478bd9Sstevel@tonic-gate #include <sys/idn_xf.h>
747c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
757c478bd9Sstevel@tonic-gate #include <sys/cpu_sgn.h>
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate struct idn_gkstat	sg_kstat;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	MBXTBL_PART_REPORT	((caddr_t)1)
807c478bd9Sstevel@tonic-gate #define	MBXTBL_FULL_REPORT	((caddr_t)2)
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate idn_domain_t	idn_domain[MAX_DOMAINS];
837c478bd9Sstevel@tonic-gate idn_global_t	idn;
847c478bd9Sstevel@tonic-gate int		idn_debug;
857c478bd9Sstevel@tonic-gate int		idn_snoop;
867c478bd9Sstevel@tonic-gate int		idn_history;
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate typedef enum {
897c478bd9Sstevel@tonic-gate 	IDN_GPROPS_OKAY,
907c478bd9Sstevel@tonic-gate 	IDN_GPROPS_UNCHECKED,
917c478bd9Sstevel@tonic-gate 	IDN_GPROPS_ERROR
927c478bd9Sstevel@tonic-gate } idn_gprops_t;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate struct idn_history	idnhlog;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * IDN "tunables".
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate int		idn_smr_size;
1007c478bd9Sstevel@tonic-gate int		idn_nwr_size;
1017c478bd9Sstevel@tonic-gate int		idn_lowat;
1027c478bd9Sstevel@tonic-gate int		idn_hiwat;
1037c478bd9Sstevel@tonic-gate int		idn_protocol_nservers;
1047c478bd9Sstevel@tonic-gate int		idn_awolmsg_interval;
1057c478bd9Sstevel@tonic-gate int		idn_smr_bufsize;
1067c478bd9Sstevel@tonic-gate int		idn_slab_bufcount;
1077c478bd9Sstevel@tonic-gate int		idn_slab_prealloc;
1087c478bd9Sstevel@tonic-gate int		idn_slab_maxperdomain;
1097c478bd9Sstevel@tonic-gate int		idn_slab_mintotal;
1107c478bd9Sstevel@tonic-gate int		idn_window_max;
1117c478bd9Sstevel@tonic-gate int		idn_window_incr;
1127c478bd9Sstevel@tonic-gate int		idn_window_emax;
1137c478bd9Sstevel@tonic-gate int		idn_reclaim_min;
1147c478bd9Sstevel@tonic-gate int		idn_reclaim_max;
1157c478bd9Sstevel@tonic-gate int		idn_mbox_per_net;
1167c478bd9Sstevel@tonic-gate int		idn_max_nets;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate int		idn_netsvr_spin_count;
1197c478bd9Sstevel@tonic-gate int		idn_netsvr_wait_min;
1207c478bd9Sstevel@tonic-gate int		idn_netsvr_wait_max;
1217c478bd9Sstevel@tonic-gate int		idn_netsvr_wait_shift;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate int		idn_checksum;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate int		idn_msgwait_nego;
1267c478bd9Sstevel@tonic-gate int		idn_msgwait_cfg;
1277c478bd9Sstevel@tonic-gate int		idn_msgwait_con;
1287c478bd9Sstevel@tonic-gate int		idn_msgwait_fin;
1297c478bd9Sstevel@tonic-gate int		idn_msgwait_cmd;
1307c478bd9Sstevel@tonic-gate int		idn_msgwait_data;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate int		idn_retryfreq_nego;
1337c478bd9Sstevel@tonic-gate int		idn_retryfreq_con;
1347c478bd9Sstevel@tonic-gate int		idn_retryfreq_fin;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate int		idn_window_emax;	/* calculated */
1377c478bd9Sstevel@tonic-gate int		idn_slab_maxperdomain;	/* calculated */
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate  * DMV interrupt support.
1417c478bd9Sstevel@tonic-gate  */
1427c478bd9Sstevel@tonic-gate int		idn_pil;
1437c478bd9Sstevel@tonic-gate int		idn_dmv_pending_max;
1447c478bd9Sstevel@tonic-gate idn_dmv_msg_t	*idn_iv_queue[NCPU];
1457c478bd9Sstevel@tonic-gate int		idn_intr_index[NCPU];	/* idn_handler ONLY */
1467c478bd9Sstevel@tonic-gate static idn_dmv_data_t	*idn_dmv_data;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate int		idn_sigbpil;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate idnparam_t	idn_param_arr[] = {
1517c478bd9Sstevel@tonic-gate { 0,		1,		0,		/* 0 */ "idn_modunloadable" },
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate /*
1557c478bd9Sstevel@tonic-gate  * Parameters that are only accessible in a DEBUG driver.
1567c478bd9Sstevel@tonic-gate  */
1577c478bd9Sstevel@tonic-gate static char *idn_param_debug_only[] = {
1587c478bd9Sstevel@tonic-gate #if 0
1597c478bd9Sstevel@tonic-gate 	"idn_checksum",
1607c478bd9Sstevel@tonic-gate #endif /* 0 */
1617c478bd9Sstevel@tonic-gate 	0
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate /*
1657c478bd9Sstevel@tonic-gate  * Parameters that are READ-ONLY.
1667c478bd9Sstevel@tonic-gate  */
1677c478bd9Sstevel@tonic-gate static char *idn_param_read_only[] = {
1687c478bd9Sstevel@tonic-gate #if 0
1697c478bd9Sstevel@tonic-gate 	"idn_window_emax",
1707c478bd9Sstevel@tonic-gate 	"idn_slab_maxperdomain",
1717c478bd9Sstevel@tonic-gate #endif /* 0 */
1727c478bd9Sstevel@tonic-gate 	0
1737c478bd9Sstevel@tonic-gate };
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate static struct idn_global_props {
1767c478bd9Sstevel@tonic-gate 	int		p_min, p_max, p_def;
1777c478bd9Sstevel@tonic-gate 	char		*p_string;
1787c478bd9Sstevel@tonic-gate 	int		*p_var;
1797c478bd9Sstevel@tonic-gate } idn_global_props[] = {
1807c478bd9Sstevel@tonic-gate { 0,	0,	0,	"idn_debug",		&idn_debug		},
1817c478bd9Sstevel@tonic-gate { 0,	1,	0,	"idn_history",		&idn_history		},
1827c478bd9Sstevel@tonic-gate { 0,	IDN_SMR_MAXSIZE,
1837c478bd9Sstevel@tonic-gate 		0,	"idn_smr_size",		&idn_smr_size		},
1847c478bd9Sstevel@tonic-gate { 0,	IDN_SMR_MAXSIZE,
1857c478bd9Sstevel@tonic-gate 		0,	"idn_nwr_size",		&idn_nwr_size		},
1867c478bd9Sstevel@tonic-gate { 1,	512*1024,
1877c478bd9Sstevel@tonic-gate 		1,	"idn_lowat",		&idn_lowat		},
1887c478bd9Sstevel@tonic-gate { 1*1024,
1897c478bd9Sstevel@tonic-gate 	1*1024*1024,
1907c478bd9Sstevel@tonic-gate 		256*1024,
1917c478bd9Sstevel@tonic-gate 			"idn_hiwat",		&idn_hiwat		},
1927c478bd9Sstevel@tonic-gate { IDN_SMR_BUFSIZE_MIN,
1937c478bd9Sstevel@tonic-gate 	IDN_SMR_BUFSIZE_MAX,
1947c478bd9Sstevel@tonic-gate 		IDN_SMR_BUFSIZE_DEF,
1957c478bd9Sstevel@tonic-gate 			"idn_smr_bufsize",	&idn_smr_bufsize	},
1967c478bd9Sstevel@tonic-gate { 4,	1024,	32,	"idn_slab_bufcount",	&idn_slab_bufcount	},
1977c478bd9Sstevel@tonic-gate { 0,	10,	0,	"idn_slab_prealloc",	&idn_slab_prealloc	},
1987c478bd9Sstevel@tonic-gate { 2,	MAX_DOMAINS,
1997c478bd9Sstevel@tonic-gate 		8,	"idn_slab_mintotal",	&idn_slab_mintotal	},
2007c478bd9Sstevel@tonic-gate { 8,	256,	64,	"idn_window_max",	&idn_window_max		},
2017c478bd9Sstevel@tonic-gate { 0,	32,	8,	"idn_window_incr",	&idn_window_incr	},
2027c478bd9Sstevel@tonic-gate { 1,	128,	5,	"idn_reclaim_min",	&idn_reclaim_min	},
2037c478bd9Sstevel@tonic-gate { 0,	128,	0,	"idn_reclaim_max",	&idn_reclaim_max	},
2047c478bd9Sstevel@tonic-gate { 1,	IDN_MAXMAX_NETS,
2057c478bd9Sstevel@tonic-gate 		8,	"idn_max_nets",		&idn_max_nets		},
2067c478bd9Sstevel@tonic-gate { 31,	511,	127,	"idn_mbox_per_net",	&idn_mbox_per_net	},
2077c478bd9Sstevel@tonic-gate { 0,	1,	1,	"idn_checksum",		&idn_checksum		},
2087c478bd9Sstevel@tonic-gate { 0,	10000,	500,	"idn_netsvr_spin_count",
2097c478bd9Sstevel@tonic-gate 						&idn_netsvr_spin_count	},
2107c478bd9Sstevel@tonic-gate { 0,	30*100,	40,	"idn_netsvr_wait_min",	&idn_netsvr_wait_min	},
2117c478bd9Sstevel@tonic-gate { 0,	60*100,	16*100,	"idn_netsvr_wait_max",	&idn_netsvr_wait_max	},
2127c478bd9Sstevel@tonic-gate { 1,	5,	1,	"idn_netsvr_wait_shift",
2137c478bd9Sstevel@tonic-gate 						&idn_netsvr_wait_shift	},
2147c478bd9Sstevel@tonic-gate { 1,	MAX_DOMAINS,
2157c478bd9Sstevel@tonic-gate 		IDN_PROTOCOL_NSERVERS,
2167c478bd9Sstevel@tonic-gate 			"idn_protocol_nservers",
2177c478bd9Sstevel@tonic-gate 						&idn_protocol_nservers	},
2187c478bd9Sstevel@tonic-gate { 0,	3600,	IDN_AWOLMSG_INTERVAL,
2197c478bd9Sstevel@tonic-gate 			"idn_awolmsg_interval",	&idn_awolmsg_interval	},
2207c478bd9Sstevel@tonic-gate { 10,	300,	IDN_MSGWAIT_NEGO,
2217c478bd9Sstevel@tonic-gate 			"idn_msgwait_nego",	&idn_msgwait_nego	},
2227c478bd9Sstevel@tonic-gate { 10,	300,	IDN_MSGWAIT_CFG,
2237c478bd9Sstevel@tonic-gate 			"idn_msgwait_cfg",	&idn_msgwait_cfg	},
2247c478bd9Sstevel@tonic-gate { 10,	300,	IDN_MSGWAIT_CON,
2257c478bd9Sstevel@tonic-gate 			"idn_msgwait_con",	&idn_msgwait_con	},
2267c478bd9Sstevel@tonic-gate { 10,	300,	IDN_MSGWAIT_FIN,
2277c478bd9Sstevel@tonic-gate 			"idn_msgwait_fin",	&idn_msgwait_fin	},
2287c478bd9Sstevel@tonic-gate { 10,	300,	IDN_MSGWAIT_CMD,
2297c478bd9Sstevel@tonic-gate 			"idn_msgwait_cmd",	&idn_msgwait_cmd	},
2307c478bd9Sstevel@tonic-gate { 10,	300,	IDN_MSGWAIT_DATA,
2317c478bd9Sstevel@tonic-gate 			"idn_msgwait_data",	&idn_msgwait_data	},
2327c478bd9Sstevel@tonic-gate { 1,	60,	IDN_RETRYFREQ_NEGO,
2337c478bd9Sstevel@tonic-gate 			"idn_retryfreq_nego",	&idn_retryfreq_nego	},
2347c478bd9Sstevel@tonic-gate { 1,	60,	IDN_RETRYFREQ_CON,
2357c478bd9Sstevel@tonic-gate 			"idn_retryfreq_con",	&idn_retryfreq_con	},
2367c478bd9Sstevel@tonic-gate { 1,	60,	IDN_RETRYFREQ_FIN,
2377c478bd9Sstevel@tonic-gate 			"idn_retryfreq_fin",	&idn_retryfreq_fin	},
2387c478bd9Sstevel@tonic-gate { 1,	9,	IDN_PIL,
2397c478bd9Sstevel@tonic-gate 			"idn_pil",		&idn_pil		},
2407c478bd9Sstevel@tonic-gate { 1,	9,	IDN_SIGBPIL,
2417c478bd9Sstevel@tonic-gate 			"idn_sigbpil",		&idn_sigbpil		},
2427c478bd9Sstevel@tonic-gate { 8,	512,	IDN_DMV_PENDING_MAX,
2437c478bd9Sstevel@tonic-gate 			"idn_dmv_pending_max",	&idn_dmv_pending_max	},
2447c478bd9Sstevel@tonic-gate { 0,	0,	0,	NULL,			NULL			}
2457c478bd9Sstevel@tonic-gate };
2467c478bd9Sstevel@tonic-gate 
2477c478bd9Sstevel@tonic-gate struct idn	*idn_i2s_table[IDN_MAXMAX_NETS << 1];
2487c478bd9Sstevel@tonic-gate clock_t		idn_msg_waittime[IDN_NUM_MSGTYPES];
2497c478bd9Sstevel@tonic-gate clock_t		idn_msg_retrytime[(int)IDN_NUM_RETRYTYPES];
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate static caddr_t	idn_ndlist;	/* head of 'named dispatch' var list */
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate static int	idnattach(dev_info_t *, ddi_attach_cmd_t);
2547c478bd9Sstevel@tonic-gate static int	idndetach(dev_info_t *, ddi_detach_cmd_t);
2557c478bd9Sstevel@tonic-gate static int	idnopen(register queue_t *, dev_t *, int, int, cred_t *);
2567c478bd9Sstevel@tonic-gate static int	idnclose(queue_t *, int, cred_t *);
2577c478bd9Sstevel@tonic-gate static int	idnwput(queue_t *, mblk_t *);
2587c478bd9Sstevel@tonic-gate static int	idnwsrv(queue_t *);
2597c478bd9Sstevel@tonic-gate static int	idnrput(queue_t *, mblk_t *);
2607c478bd9Sstevel@tonic-gate static void	idnioctl(queue_t *, mblk_t *);
2617c478bd9Sstevel@tonic-gate static idn_gprops_t	idn_check_conf(dev_info_t *dip, processorid_t *cpuid);
2627c478bd9Sstevel@tonic-gate static int	idn_size_check();
2637c478bd9Sstevel@tonic-gate static void	idn_xmit_monitor_init();
2647c478bd9Sstevel@tonic-gate static void	idn_xmit_monitor_deinit();
2657c478bd9Sstevel@tonic-gate static void	idn_init_msg_waittime();
2667c478bd9Sstevel@tonic-gate static void	idn_init_msg_retrytime();
2677c478bd9Sstevel@tonic-gate static void	idn_sigb_setup(cpu_sgnblk_t *sigbp, void *arg);
2687c478bd9Sstevel@tonic-gate static int	idn_init(dev_info_t *dip);
2697c478bd9Sstevel@tonic-gate static int	idn_deinit();
2707c478bd9Sstevel@tonic-gate static void	idn_sigbhandler_create();
2717c478bd9Sstevel@tonic-gate static void	idn_sigbhandler_kill();
2727c478bd9Sstevel@tonic-gate static uint_t	idn_sigbhandler_wakeup(caddr_t arg1, caddr_t arg2);
2737c478bd9Sstevel@tonic-gate static void	idn_sigbhandler_thread(struct sigbintr **sbpp);
2747c478bd9Sstevel@tonic-gate static void	idn_sigbhandler(processorid_t cpuid, cpu_sgnblk_t *sgnblkp);
2757c478bd9Sstevel@tonic-gate static int	idn_info(idnsb_info_t *sfp);
2767c478bd9Sstevel@tonic-gate static int	idn_init_smr();
2777c478bd9Sstevel@tonic-gate static void	idn_deinit_smr();
2787c478bd9Sstevel@tonic-gate static int	idn_prom_getsmr(uint_t *smrsz, uint64_t *paddrp,
2797c478bd9Sstevel@tonic-gate 				uint64_t *sizep);
2807c478bd9Sstevel@tonic-gate static int	idn_init_handler();
2817c478bd9Sstevel@tonic-gate static void	idn_deinit_handler();
2827c478bd9Sstevel@tonic-gate static uint_t	idn_handler(caddr_t unused, caddr_t unused2);
2837c478bd9Sstevel@tonic-gate /*
2847c478bd9Sstevel@tonic-gate  * ioctl services
2857c478bd9Sstevel@tonic-gate  */
2867c478bd9Sstevel@tonic-gate static int	idnioc_link(idnop_t *idnop);
2877c478bd9Sstevel@tonic-gate static int	idnioc_unlink(idnop_t *idnop);
2887c478bd9Sstevel@tonic-gate static int	idn_rw_mem(idnop_t *idnop);
2897c478bd9Sstevel@tonic-gate static int	idn_send_ping(idnop_t *idnop);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate static void 	idn_domains_init(struct hwconfig *local_hw);
2927c478bd9Sstevel@tonic-gate static void 	idn_domains_deinit();
2937c478bd9Sstevel@tonic-gate static void	idn_retrytask_init();
2947c478bd9Sstevel@tonic-gate static void	idn_retrytask_deinit();
2957c478bd9Sstevel@tonic-gate static void	idn_gkstat_init();
2967c478bd9Sstevel@tonic-gate static void	idn_gkstat_deinit();
2977c478bd9Sstevel@tonic-gate static int	idn_gkstat_update();
2987c478bd9Sstevel@tonic-gate static void	idn_timercache_init();
2997c478bd9Sstevel@tonic-gate static void	idn_timercache_deinit();
3007c478bd9Sstevel@tonic-gate static void	idn_dopers_init();
3017c478bd9Sstevel@tonic-gate static void	idn_dopers_deinit();
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate static void	idn_param_cleanup();
3047c478bd9Sstevel@tonic-gate static int	idn_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr);
3057c478bd9Sstevel@tonic-gate static int	idn_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp,
3067c478bd9Sstevel@tonic-gate 					cred_t *cr);
3077c478bd9Sstevel@tonic-gate static int	idn_param_register(register idnparam_t *idnpa, int count);
3087c478bd9Sstevel@tonic-gate static int	idn_slabpool_report(queue_t *wq, mblk_t *mp, caddr_t cp,
3097c478bd9Sstevel@tonic-gate 					cred_t *cr);
3107c478bd9Sstevel@tonic-gate static int	idn_buffer_report(queue_t *wq, mblk_t *mp, caddr_t cp,
3117c478bd9Sstevel@tonic-gate 					cred_t *cr);
3127c478bd9Sstevel@tonic-gate static int	idn_mboxtbl_report(queue_t *wq, mblk_t *mp, caddr_t cp,
3137c478bd9Sstevel@tonic-gate 					cred_t *cr);
3147c478bd9Sstevel@tonic-gate static int	idn_mainmbox_report(queue_t *wq, mblk_t *mp, caddr_t cp,
3157c478bd9Sstevel@tonic-gate 					cred_t *cr);
3167c478bd9Sstevel@tonic-gate static void	idn_mainmbox_domain_report(queue_t *wq, mblk_t *mp, int domid,
3177c478bd9Sstevel@tonic-gate 					idn_mainmbox_t *mmp, char *mbxtype);
3187c478bd9Sstevel@tonic-gate static int	idn_global_report(queue_t *wq, mblk_t *mp, caddr_t cp,
3197c478bd9Sstevel@tonic-gate 					cred_t *cr);
3207c478bd9Sstevel@tonic-gate static int	idn_domain_report(queue_t *wq, mblk_t *mp, caddr_t cp,
3217c478bd9Sstevel@tonic-gate 					cred_t *cr);
3227c478bd9Sstevel@tonic-gate static int	idn_get_net_binding(queue_t *wq, mblk_t *mp, caddr_t cp,
3237c478bd9Sstevel@tonic-gate 					cred_t *cr);
3247c478bd9Sstevel@tonic-gate static int	idn_set_net_binding(queue_t *wq, mblk_t *mp, char *value,
3257c478bd9Sstevel@tonic-gate 					caddr_t cp, cred_t *cr);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * String definitions used for DEBUG and non-DEBUG.
3297c478bd9Sstevel@tonic-gate  */
3307c478bd9Sstevel@tonic-gate const char	*idnm_str[] = {
3317c478bd9Sstevel@tonic-gate /*  0 */	"null",
3327c478bd9Sstevel@tonic-gate /*  1 */	"nego",
3337c478bd9Sstevel@tonic-gate /*  2 */	"con",
3347c478bd9Sstevel@tonic-gate /*  3 */	"cfg",
3357c478bd9Sstevel@tonic-gate /*  4 */	"fin",
3367c478bd9Sstevel@tonic-gate /*  5 */	"cmd",
3377c478bd9Sstevel@tonic-gate /*  6 */	"data",
3387c478bd9Sstevel@tonic-gate };
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate const char	*idnds_str[] = {
3417c478bd9Sstevel@tonic-gate /*  0 */	"CLOSED",
3427c478bd9Sstevel@tonic-gate /*  1 */	"NEGO_PEND",
3437c478bd9Sstevel@tonic-gate /*  2 */	"NEGO_SENT",
3447c478bd9Sstevel@tonic-gate /*  3 */	"NEGO_RCVD",
3457c478bd9Sstevel@tonic-gate /*  4 */	"CONFIG",
3467c478bd9Sstevel@tonic-gate /*  5 */	"CON_PEND",
3477c478bd9Sstevel@tonic-gate /*  6 */	"CON_SENT",
3487c478bd9Sstevel@tonic-gate /*  7 */	"CON_RCVD",
3497c478bd9Sstevel@tonic-gate /*  8 */	"CON_READY",
3507c478bd9Sstevel@tonic-gate /*  9 */	"CONNECTED",
3517c478bd9Sstevel@tonic-gate /* 10 */	"FIN_PEND",
3527c478bd9Sstevel@tonic-gate /* 11 */	"FIN_SENT",
3537c478bd9Sstevel@tonic-gate /* 12 */	"FIN_RCVD",
3547c478bd9Sstevel@tonic-gate /* 13 */	"DMAP"
3557c478bd9Sstevel@tonic-gate };
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate const char	*idnxs_str[] = {
3587c478bd9Sstevel@tonic-gate /* 0 */		"PEND",
3597c478bd9Sstevel@tonic-gate /* 1 */		"SENT",
3607c478bd9Sstevel@tonic-gate /* 2 */		"RCVD",
3617c478bd9Sstevel@tonic-gate /* 3 */		"FINAL",
3627c478bd9Sstevel@tonic-gate /* 4 */		"NIL"
3637c478bd9Sstevel@tonic-gate };
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate const char	*idngs_str[] = {
3667c478bd9Sstevel@tonic-gate /*  0 */	"OFFLINE",
3677c478bd9Sstevel@tonic-gate /*  1 */	"CONNECT",
3687c478bd9Sstevel@tonic-gate /*  2 */	"ONLINE",
3697c478bd9Sstevel@tonic-gate /*  3 */	"DISCONNECT",
3707c478bd9Sstevel@tonic-gate /*  4 */	"RECONFIG",
3717c478bd9Sstevel@tonic-gate /*  5 */	"unknown",
3727c478bd9Sstevel@tonic-gate /*  6 */	"unknown",
3737c478bd9Sstevel@tonic-gate /*  7 */	"unknown",
3747c478bd9Sstevel@tonic-gate /*  8 */	"unknown",
3757c478bd9Sstevel@tonic-gate /*  9 */	"unknown",
3767c478bd9Sstevel@tonic-gate /* 10 */	"IGNORE"
3777c478bd9Sstevel@tonic-gate };
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate const char	*idncmd_str[] = {
3807c478bd9Sstevel@tonic-gate /*  0 */	"unknown",
3817c478bd9Sstevel@tonic-gate /*  1 */	"SLABALLOC",
3827c478bd9Sstevel@tonic-gate /*  2 */	"SLABFREE",
3837c478bd9Sstevel@tonic-gate /*  3 */	"SLABREAP",
3847c478bd9Sstevel@tonic-gate /*  4 */	"NODENAME"
3857c478bd9Sstevel@tonic-gate };
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate const char	*idncon_str[] = {
3887c478bd9Sstevel@tonic-gate /*  0 */	"OFF",
3897c478bd9Sstevel@tonic-gate /*  1 */	"NORMAL",
3907c478bd9Sstevel@tonic-gate /*  2 */	"QUERY"
3917c478bd9Sstevel@tonic-gate };
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate const char	*idnfin_str[] = {
3947c478bd9Sstevel@tonic-gate /*  0 */	"OFF",
3957c478bd9Sstevel@tonic-gate /*  1 */	"NORMAL",
3967c478bd9Sstevel@tonic-gate /*  2 */	"FORCE_SOFT",
3977c478bd9Sstevel@tonic-gate /*  3 */	"FORCE_HARD",
3987c478bd9Sstevel@tonic-gate /*  4 */	"QUERY"
3997c478bd9Sstevel@tonic-gate };
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate const char	*idnfinopt_str[] = {
4027c478bd9Sstevel@tonic-gate /*  0 */	"NONE",
4037c478bd9Sstevel@tonic-gate /*  1 */	"UNLINK",
4047c478bd9Sstevel@tonic-gate /*  2 */	"RELINK"
4057c478bd9Sstevel@tonic-gate };
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate const char	*idnfinarg_str[] = {
4087c478bd9Sstevel@tonic-gate /*  0 */	"NONE",
4097c478bd9Sstevel@tonic-gate /*  1 */	"SMRBAD",
4107c478bd9Sstevel@tonic-gate /*  2 */	"CPUCFG",
4117c478bd9Sstevel@tonic-gate /*  3 */	"HWERR",
4127c478bd9Sstevel@tonic-gate /*  4 */	"CFGERR_FATAL",
4137c478bd9Sstevel@tonic-gate /*  5 */	"CFGERR_MTU",
4147c478bd9Sstevel@tonic-gate /*  6 */	"CFGERR_BUF",
4157c478bd9Sstevel@tonic-gate /*  7 */	"CFGERR_SLAB",
4167c478bd9Sstevel@tonic-gate /*  8 */	"CFGERR_NWR",
4177c478bd9Sstevel@tonic-gate /*  9 */	"CFGERR_NETS",
4187c478bd9Sstevel@tonic-gate /* 10 */	"CFGERR_MBOX",
4197c478bd9Sstevel@tonic-gate /* 11 */	"CFGERR_NMCADR",
4207c478bd9Sstevel@tonic-gate /* 12 */	"CFGERR_MCADR",
4217c478bd9Sstevel@tonic-gate /* 13 */	"CFGERR_CKSUM",
4227c478bd9Sstevel@tonic-gate /* 14 */	"CFGERR_SMR",
4237c478bd9Sstevel@tonic-gate };
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate const char	*idnsync_str[] = {
4267c478bd9Sstevel@tonic-gate /*  0 */	"NIL",
4277c478bd9Sstevel@tonic-gate /*  1 */	"CONNECT",
4287c478bd9Sstevel@tonic-gate /*  2 */	"DISCONNECT"
4297c478bd9Sstevel@tonic-gate };
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate const char	*idnreg_str[] = {
4327c478bd9Sstevel@tonic-gate /*  0 */	"REG",
4337c478bd9Sstevel@tonic-gate /*  1 */	"NEW",
4347c478bd9Sstevel@tonic-gate /*  2 */	"QUERY"
4357c478bd9Sstevel@tonic-gate };
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate const char	*idnnack_str[] = {
4387c478bd9Sstevel@tonic-gate /*  0 */	"unknown",
4397c478bd9Sstevel@tonic-gate /*  1 */	"NOCONN",
4407c478bd9Sstevel@tonic-gate /*  2 */	"BADCHAN",
4417c478bd9Sstevel@tonic-gate /*  3 */	"BADCFG",
4427c478bd9Sstevel@tonic-gate /*  4 */	"BADCMD",
4437c478bd9Sstevel@tonic-gate /*  5 */	"RETRY",
4447c478bd9Sstevel@tonic-gate /*  6 */	"DUP",
4457c478bd9Sstevel@tonic-gate /*  7 */	"EXIT",
4467c478bd9Sstevel@tonic-gate /*  8 */	"--reserved1",
4477c478bd9Sstevel@tonic-gate /*  9 */	"--reserved2",
4487c478bd9Sstevel@tonic-gate /* 10 */	"--reserved3"
4497c478bd9Sstevel@tonic-gate };
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate const char	*idnop_str[] = {
4527c478bd9Sstevel@tonic-gate /*  0 */	"DISCONNECTED",
4537c478bd9Sstevel@tonic-gate /*  1 */	"CONNECTED",
4547c478bd9Sstevel@tonic-gate /*  2 */	"ERROR"
4557c478bd9Sstevel@tonic-gate };
4567c478bd9Sstevel@tonic-gate 
4577c478bd9Sstevel@tonic-gate const char	*chanop_str[] = {
4587c478bd9Sstevel@tonic-gate /*  0 */	"OPEN",
4597c478bd9Sstevel@tonic-gate /*  1 */	"SOFT_CLOSE",
4607c478bd9Sstevel@tonic-gate /*  2 */	"HARD_CLOSE",
4617c478bd9Sstevel@tonic-gate /*  3 */	"OFFLINE",
4627c478bd9Sstevel@tonic-gate /*  4 */	"ONLINE"
4637c478bd9Sstevel@tonic-gate };
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate const char	*chanaction_str[] = {
4667c478bd9Sstevel@tonic-gate /*  0 */	"DETACH",
4677c478bd9Sstevel@tonic-gate /*  1 */	"STOP",
4687c478bd9Sstevel@tonic-gate /*  2 */	"SUSPEND",
4697c478bd9Sstevel@tonic-gate /*  3 */	"RESUME",
4707c478bd9Sstevel@tonic-gate /*  4 */	"RESTART",
4717c478bd9Sstevel@tonic-gate /*  5 */	"ATTACH"
4727c478bd9Sstevel@tonic-gate };
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate const char	*timer_str[] = {
4757c478bd9Sstevel@tonic-gate /* 0 */		"NIL",
4767c478bd9Sstevel@tonic-gate /* 1 */		"MSG"
4777c478bd9Sstevel@tonic-gate };
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate static struct module_info idnrinfo = {
4807c478bd9Sstevel@tonic-gate 	IDNIDNUM,		/* mi_idnum */
4817c478bd9Sstevel@tonic-gate 	IDNNAME,		/* mi_idname */
4827c478bd9Sstevel@tonic-gate 	IDNMINPSZ,		/* mi_minpsz */
4837c478bd9Sstevel@tonic-gate 	IDNMAXPSZ,		/* mi_maxpsz */
4847c478bd9Sstevel@tonic-gate 	0,			/* mi_hiwat - see IDN_HIWAT */
4857c478bd9Sstevel@tonic-gate 	0			/* mi_lowat - see IDN_LOWAT */
4867c478bd9Sstevel@tonic-gate };
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate static struct module_info idnwinfo = {
4897c478bd9Sstevel@tonic-gate 	IDNIDNUM,		/* mi_idnum */
4907c478bd9Sstevel@tonic-gate 	IDNNAME,		/* mi_idname */
4917c478bd9Sstevel@tonic-gate 	IDNMINPSZ,		/* mi_minpsz */
4927c478bd9Sstevel@tonic-gate 	IDNMAXPSZ,		/* mi_maxpsz */
4937c478bd9Sstevel@tonic-gate 	0,			/* mi_hiwat - see IDN_HIWAT */
4947c478bd9Sstevel@tonic-gate 	0			/* mi_lowat - see IDN_LOWAT */
4957c478bd9Sstevel@tonic-gate };
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate static struct qinit idnrinit = {
4987c478bd9Sstevel@tonic-gate 	idnrput,		/* qi_putp */
4997c478bd9Sstevel@tonic-gate 	NULL,			/* qi_srvp */
5007c478bd9Sstevel@tonic-gate 	idnopen,		/* qi_qopen */
5017c478bd9Sstevel@tonic-gate 	idnclose,		/* qi_qclose */
5027c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
5037c478bd9Sstevel@tonic-gate 	&idnrinfo,		/* qi_minfo */
5047c478bd9Sstevel@tonic-gate 	NULL,			/* qi_mstat */
5057c478bd9Sstevel@tonic-gate 	NULL,			/* qi_rwp */
5067c478bd9Sstevel@tonic-gate 	NULL,			/* qi_infop */
5077c478bd9Sstevel@tonic-gate 	STRUIOT_DONTCARE	/* qi_struiot */
5087c478bd9Sstevel@tonic-gate };
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate static struct qinit idnwinit = {
5117c478bd9Sstevel@tonic-gate 	idnwput,		/* qi_putp */
5127c478bd9Sstevel@tonic-gate 	idnwsrv,		/* qi_srvp */
5137c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qopen */
5147c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qclose */
5157c478bd9Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
5167c478bd9Sstevel@tonic-gate 	&idnwinfo,		/* qi_minfo */
5177c478bd9Sstevel@tonic-gate 	NULL,			/* qi_mstat */
5187c478bd9Sstevel@tonic-gate 	NULL,			/* qi_rwp */
5197c478bd9Sstevel@tonic-gate 	NULL,			/* qi_infop */
5207c478bd9Sstevel@tonic-gate 	STRUIOT_DONTCARE	/* qi_struiot */
5217c478bd9Sstevel@tonic-gate };
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate struct streamtab idninfo = {
5247c478bd9Sstevel@tonic-gate 	&idnrinit,		/* st_rdinit */
5257c478bd9Sstevel@tonic-gate 	&idnwinit,		/* st_wrinit */
5267c478bd9Sstevel@tonic-gate 	NULL,			/* st_muxrinit */
5277c478bd9Sstevel@tonic-gate 	NULL,			/* st_muxwinit */
5287c478bd9Sstevel@tonic-gate };
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate /*
5317c478bd9Sstevel@tonic-gate  * Module linkage information (cb_ops & dev_ops) for the kernel.
5327c478bd9Sstevel@tonic-gate  */
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate static struct cb_ops cb_idnops = {
5357c478bd9Sstevel@tonic-gate 	nulldev,		/* cb_open */
5367c478bd9Sstevel@tonic-gate 	nulldev,		/* cb_close */
5377c478bd9Sstevel@tonic-gate 	nodev,			/* cb_strategy */
5387c478bd9Sstevel@tonic-gate 	nodev,			/* cb_print */
5397c478bd9Sstevel@tonic-gate 	nodev,			/* cb_dump */
5407c478bd9Sstevel@tonic-gate 	nodev,			/* cb_read */
5417c478bd9Sstevel@tonic-gate 	nodev,			/* cb_write */
5427c478bd9Sstevel@tonic-gate 	nodev,			/* cb_ioctl */
5437c478bd9Sstevel@tonic-gate 	nodev,			/* cb_devmap */
5447c478bd9Sstevel@tonic-gate 	nodev,			/* cb_mmap */
5457c478bd9Sstevel@tonic-gate 	nodev,			/* cb_segmap */
5467c478bd9Sstevel@tonic-gate 	nochpoll,		/* cb_chpoll */
5477c478bd9Sstevel@tonic-gate 	ddi_prop_op,		/* cb_prop_op */
5487c478bd9Sstevel@tonic-gate 	&idninfo,		/* cb_stream */
5497c478bd9Sstevel@tonic-gate 	D_MP,			/* cb_flag */
5507c478bd9Sstevel@tonic-gate 	CB_REV,			/* cb_rev */
5517c478bd9Sstevel@tonic-gate 	nodev,			/* cb_aread */
5527c478bd9Sstevel@tonic-gate 	nodev,			/* cb_awrite */
5537c478bd9Sstevel@tonic-gate };
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate static struct dev_ops idnops = {
5567c478bd9Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev */
5577c478bd9Sstevel@tonic-gate 	0,			/* devo_refcnt */
5587c478bd9Sstevel@tonic-gate 	ddi_no_info,		/* devo_getinfo */
5597c478bd9Sstevel@tonic-gate 	nulldev,		/* devo_identify */
5607c478bd9Sstevel@tonic-gate 	nulldev,		/* devo_probe */
5617c478bd9Sstevel@tonic-gate 	idnattach,		/* devo_attach */
5627c478bd9Sstevel@tonic-gate 	idndetach,		/* devo_detach */
5637c478bd9Sstevel@tonic-gate 	nodev,			/* devo_reset */
5647c478bd9Sstevel@tonic-gate 	&cb_idnops,		/* devo_cb_ops */
5657c478bd9Sstevel@tonic-gate 	(struct bus_ops *)NULL,	/* devo_bus_ops */
56619397407SSherry Moore 	NULL,			/* devo_power */
56719397407SSherry Moore 	ddi_quiesce_not_needed,		/* quiesce */
5687c478bd9Sstevel@tonic-gate };
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate extern cpuset_t	cpu_ready_set;
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
5737c478bd9Sstevel@tonic-gate 	&mod_driverops,		/* This module is a pseudo driver */
57419397407SSherry Moore 	IDNDESC " 1.58",
5757c478bd9Sstevel@tonic-gate 	&idnops
5767c478bd9Sstevel@tonic-gate };
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
5797c478bd9Sstevel@tonic-gate 	MODREV_1,
5807c478bd9Sstevel@tonic-gate 	&modldrv,
5817c478bd9Sstevel@tonic-gate 	NULL
5827c478bd9Sstevel@tonic-gate };
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate  * --------------------------------------------------
5867c478bd9Sstevel@tonic-gate  */
5877c478bd9Sstevel@tonic-gate int
5887c478bd9Sstevel@tonic-gate _init(void)
5897c478bd9Sstevel@tonic-gate {
5907c478bd9Sstevel@tonic-gate 	idn.version = IDN_VERSION;
5917c478bd9Sstevel@tonic-gate 
5927c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
5937c478bd9Sstevel@tonic-gate }
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate int
5967c478bd9Sstevel@tonic-gate _fini(void)
5977c478bd9Sstevel@tonic-gate {
5987c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate int
6027c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
6037c478bd9Sstevel@tonic-gate {
6047c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
6057c478bd9Sstevel@tonic-gate }
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate /*
6087c478bd9Sstevel@tonic-gate  * ----------------------------------------------
6097c478bd9Sstevel@tonic-gate  */
6107c478bd9Sstevel@tonic-gate static int
6117c478bd9Sstevel@tonic-gate idnattach(dev_info_t *dip, ddi_attach_cmd_t cmd)
6127c478bd9Sstevel@tonic-gate {
6137c478bd9Sstevel@tonic-gate 	int		instance;
6147c478bd9Sstevel@tonic-gate 	int		doinit = 0;
6157c478bd9Sstevel@tonic-gate 	processorid_t	bcpuid;
6167c478bd9Sstevel@tonic-gate 	struct idn	*sip;
6177c478bd9Sstevel@tonic-gate 	struct idnstr	*stp;
6187c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnattach";
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate #ifndef	lint
6227c478bd9Sstevel@tonic-gate 	ASSERT(sizeof (idnsb_t) == IDNSB_SIZE);
623ad9a7bd3SRichard Lowe 	ASSERT(offsetof(struct idnsb, id_hwchkpt[0]) == 0x40);
6247c478bd9Sstevel@tonic-gate #endif	/* lint */
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	switch (cmd) {
6277c478bd9Sstevel@tonic-gate 	case DDI_RESUME:
6287c478bd9Sstevel@tonic-gate 		sip = ddi_get_driver_private(dip);
6297c478bd9Sstevel@tonic-gate 		/*
6307c478bd9Sstevel@tonic-gate 		 * sip may have not yet been set if the
6317c478bd9Sstevel@tonic-gate 		 * OBP environment variable (idn-smr-size)
6327c478bd9Sstevel@tonic-gate 		 * was not set.
6337c478bd9Sstevel@tonic-gate 		 */
6347c478bd9Sstevel@tonic-gate 		if (sip == NULL)
6357c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
6367c478bd9Sstevel@tonic-gate 		/*
6377c478bd9Sstevel@tonic-gate 		 * RESUME IDN services.
6387c478bd9Sstevel@tonic-gate 		 */
6397c478bd9Sstevel@tonic-gate 		IDN_GLOCK_SHARED();
6407c478bd9Sstevel@tonic-gate 		if (idn.state != IDNGS_OFFLINE) {
6417c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
6427c478bd9Sstevel@tonic-gate 			    "IDN: 101: not in expected OFFLINE state "
6437c478bd9Sstevel@tonic-gate 			    "for DDI_RESUME");
6447c478bd9Sstevel@tonic-gate 			ASSERT(0);
6457c478bd9Sstevel@tonic-gate 		}
6467c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
6477c478bd9Sstevel@tonic-gate 
6487c478bd9Sstevel@tonic-gate 		/*
6497c478bd9Sstevel@tonic-gate 		 * RESUME DLPI services.
6507c478bd9Sstevel@tonic-gate 		 */
6517c478bd9Sstevel@tonic-gate 		sip->si_flags &= ~IDNSUSPENDED;
6527c478bd9Sstevel@tonic-gate 
6537c478bd9Sstevel@tonic-gate 		rw_enter(&idn.struprwlock, RW_READER);
6547c478bd9Sstevel@tonic-gate 		for (stp = idn.strup; stp; stp = stp->ss_nextp)
6557c478bd9Sstevel@tonic-gate 			if (stp->ss_sip == sip) {
6567c478bd9Sstevel@tonic-gate 				doinit = 1;
6577c478bd9Sstevel@tonic-gate 				break;
6587c478bd9Sstevel@tonic-gate 			}
6597c478bd9Sstevel@tonic-gate 		rw_exit(&idn.struprwlock);
6607c478bd9Sstevel@tonic-gate 		if (doinit)
6617c478bd9Sstevel@tonic-gate 			(void) idndl_init(sip);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	case DDI_ATTACH:
6667c478bd9Sstevel@tonic-gate 		break;
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	default:
6697c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6707c478bd9Sstevel@tonic-gate 	}
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 	PR_DRV("%s: instance = %d\n", proc, instance);
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate 	if (idn_check_conf(dip, &bcpuid) == IDN_GPROPS_ERROR)
6777c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.siplock);
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, IDNNAME, S_IFCHR, instance,
6827c478bd9Sstevel@tonic-gate 	    DDI_NT_NET, CLONE_DEV) == DDI_FAILURE) {
6837c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.siplock);
6847c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
6857c478bd9Sstevel@tonic-gate 	}
6867c478bd9Sstevel@tonic-gate 
6877c478bd9Sstevel@tonic-gate 	if (idn.smr.ready == 0) {
6887c478bd9Sstevel@tonic-gate 		if (idn_init_smr() == 0) {
6897c478bd9Sstevel@tonic-gate 			idn.enabled = 1;
6907c478bd9Sstevel@tonic-gate #ifdef DEBUG
6917c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE, "!IDN: Driver enabled");
6927c478bd9Sstevel@tonic-gate #endif /* DEBUG */
6937c478bd9Sstevel@tonic-gate 		} else {
6947c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE,
6957c478bd9Sstevel@tonic-gate 			    "!IDN: 102: driver disabled "
6967c478bd9Sstevel@tonic-gate 			    "- check OBP environment "
6977c478bd9Sstevel@tonic-gate 			    "(idn-smr-size)");
6987c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.siplock);
6997c478bd9Sstevel@tonic-gate 			return (DDI_SUCCESS);
7007c478bd9Sstevel@tonic-gate 		}
7017c478bd9Sstevel@tonic-gate 	}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	ASSERT(idn.smr.ready || idn.enabled);
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	if (idn.dip == NULL) {
7067c478bd9Sstevel@tonic-gate 		doinit = 1;
7077c478bd9Sstevel@tonic-gate 
7087c478bd9Sstevel@tonic-gate 		if (idn_size_check()) {
7097c478bd9Sstevel@tonic-gate 			idn_deinit_smr();
7107c478bd9Sstevel@tonic-gate 			ddi_remove_minor_node(dip, NULL);
7117c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.siplock);
7127c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
7137c478bd9Sstevel@tonic-gate 		}
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 		if (idn_init(dip)) {
7167c478bd9Sstevel@tonic-gate 			idn_deinit_smr();
7177c478bd9Sstevel@tonic-gate 			ddi_remove_minor_node(dip, NULL);
7187c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.siplock);
7197c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
7207c478bd9Sstevel@tonic-gate 		}
7217c478bd9Sstevel@tonic-gate 	}
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	ASSERT(idn.dip);
7247c478bd9Sstevel@tonic-gate 
7257c478bd9Sstevel@tonic-gate 	/*
7267c478bd9Sstevel@tonic-gate 	 * This must occur _after_ idn_init() since
7277c478bd9Sstevel@tonic-gate 	 * it assumes idn_chanservers_init() has been
7287c478bd9Sstevel@tonic-gate 	 * called.
7297c478bd9Sstevel@tonic-gate 	 */
7307c478bd9Sstevel@tonic-gate 	idn_chanserver_bind(ddi_get_instance(dip), bcpuid);
7317c478bd9Sstevel@tonic-gate 
7327c478bd9Sstevel@tonic-gate 	/*
7337c478bd9Sstevel@tonic-gate 	 * DLPI supporting stuff.
7347c478bd9Sstevel@tonic-gate 	 */
7357c478bd9Sstevel@tonic-gate 	sip = GETSTRUCT(struct idn, 1);
7367c478bd9Sstevel@tonic-gate 	sip->si_dip = dip;
7377c478bd9Sstevel@tonic-gate 	ddi_set_driver_private(dip, sip);
7387c478bd9Sstevel@tonic-gate 	sip->si_nextp = idn.sip;
7397c478bd9Sstevel@tonic-gate 	idn.sip = sip;
7407c478bd9Sstevel@tonic-gate 	IDN_SET_INST2SIP(instance, sip);
7417c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.siplock);
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 	if (doinit)
7447c478bd9Sstevel@tonic-gate 		idndl_dlpi_init();	/* initializes idninfoack */
7457c478bd9Sstevel@tonic-gate 	/*
7467c478bd9Sstevel@tonic-gate 	 * Get our local IDN ethernet address.
7477c478bd9Sstevel@tonic-gate 	 */
7487c478bd9Sstevel@tonic-gate 	idndl_localetheraddr(sip, &sip->si_ouraddr);
7497c478bd9Sstevel@tonic-gate 	idndl_statinit(sip);
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 	if (doinit) {
7527c478bd9Sstevel@tonic-gate 		idn_gkstat_init();
7537c478bd9Sstevel@tonic-gate 		/*
7547c478bd9Sstevel@tonic-gate 		 * Add our sigblock SSP interrupt handler.
7557c478bd9Sstevel@tonic-gate 		 */
7567c478bd9Sstevel@tonic-gate 		mutex_enter(&idn.sigbintr.sb_mutex);
7577c478bd9Sstevel@tonic-gate 		idn_sigbhandler_create();
7587c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.sigbintr.sb_mutex);
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate 		if (sgnblk_poll_register(idn_sigbhandler) == 0) {
7617c478bd9Sstevel@tonic-gate 			mutex_enter(&idn.sigbintr.sb_mutex);
7627c478bd9Sstevel@tonic-gate 			idn_sigbhandler_kill();
7637c478bd9Sstevel@tonic-gate 			idn.sigbintr.sb_cpuid = (uchar_t)-1;
7647c478bd9Sstevel@tonic-gate 			idn.sigbintr.sb_busy = IDNSIGB_INACTIVE;
7657c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.sigbintr.sb_mutex);
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate 			idn_gkstat_deinit();
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 			mutex_enter(&idn.siplock);
7707c478bd9Sstevel@tonic-gate 			(void) idn_deinit();
7717c478bd9Sstevel@tonic-gate 			IDN_SET_INST2SIP(instance, NULL);
7727c478bd9Sstevel@tonic-gate 			idn.sip = sip->si_nextp;
7737c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.siplock);
7747c478bd9Sstevel@tonic-gate 
7757c478bd9Sstevel@tonic-gate 			ddi_remove_minor_node(dip, NULL);
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
7787c478bd9Sstevel@tonic-gate 		}
7797c478bd9Sstevel@tonic-gate 		/*
7807c478bd9Sstevel@tonic-gate 		 * We require sigblkp[cpu0] to be mapped for hardware
7817c478bd9Sstevel@tonic-gate 		 * configuration determination and also auto-linking
7827c478bd9Sstevel@tonic-gate 		 * on bootup.
7837c478bd9Sstevel@tonic-gate 		 */
7847c478bd9Sstevel@tonic-gate 		if (sgnblk_poll_reference(idn_sigb_setup, NULL) != 0) {
78507d06da5SSurya Prakki 			(void) sgnblk_poll_unregister(idn_sigbhandler);
7867c478bd9Sstevel@tonic-gate 			mutex_enter(&idn.sigbintr.sb_mutex);
7877c478bd9Sstevel@tonic-gate 			idn_sigbhandler_kill();
7887c478bd9Sstevel@tonic-gate 			idn.sigbintr.sb_cpuid = (uchar_t)-1;
7897c478bd9Sstevel@tonic-gate 			idn.sigbintr.sb_busy = IDNSIGB_INACTIVE;
7907c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.sigbintr.sb_mutex);
7917c478bd9Sstevel@tonic-gate 
7927c478bd9Sstevel@tonic-gate 			idn_gkstat_deinit();
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 			mutex_enter(&idn.siplock);
7957c478bd9Sstevel@tonic-gate 			(void) idn_deinit();
7967c478bd9Sstevel@tonic-gate 			IDN_SET_INST2SIP(instance, NULL);
7977c478bd9Sstevel@tonic-gate 			idn.sip = sip->si_nextp;
7987c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.siplock);
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 			ddi_remove_minor_node(dip, NULL);
8017c478bd9Sstevel@tonic-gate 
8027c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
8037c478bd9Sstevel@tonic-gate 			    "IDN: 103: unable to reference sigblock area");
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
8067c478bd9Sstevel@tonic-gate 		}
8077c478bd9Sstevel@tonic-gate 
8087c478bd9Sstevel@tonic-gate 		idn_init_autolink();
8097c478bd9Sstevel@tonic-gate 	}
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 	ddi_report_dev(dip);
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
8147c478bd9Sstevel@tonic-gate }
8157c478bd9Sstevel@tonic-gate 
8167c478bd9Sstevel@tonic-gate /*
8177c478bd9Sstevel@tonic-gate  * ----------------------------------------------
8187c478bd9Sstevel@tonic-gate  */
8197c478bd9Sstevel@tonic-gate static int
8207c478bd9Sstevel@tonic-gate idndetach(dev_info_t *dip, ddi_detach_cmd_t cmd)
8217c478bd9Sstevel@tonic-gate {
8227c478bd9Sstevel@tonic-gate 	int		err = 0;
8237c478bd9Sstevel@tonic-gate 	int		instance;
8247c478bd9Sstevel@tonic-gate 	struct idn	*sip, *hsip, *tsip;
8257c478bd9Sstevel@tonic-gate 	procname_t	proc = "idndetach";
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 	sip = ddi_get_driver_private(dip);
8287c478bd9Sstevel@tonic-gate 	instance = ddi_get_instance(dip);
8297c478bd9Sstevel@tonic-gate 
8307c478bd9Sstevel@tonic-gate 	switch (cmd) {
8317c478bd9Sstevel@tonic-gate 	case DDI_SUSPEND:
8327c478bd9Sstevel@tonic-gate 		if (sip == NULL)
8337c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
8347c478bd9Sstevel@tonic-gate 		/*
8357c478bd9Sstevel@tonic-gate 		 * SUSPEND IDN services.
8367c478bd9Sstevel@tonic-gate 		 * - Actually don't suspend anything, we just
8377c478bd9Sstevel@tonic-gate 		 *   make sure we're not connected per DR protocol.
8387c478bd9Sstevel@tonic-gate 		 *   If we really wanted to suspend it should
8397c478bd9Sstevel@tonic-gate 		 *   be done _after_ DLPI is suspended so that
8407c478bd9Sstevel@tonic-gate 		 *   we're not competing with that traffic.
8417c478bd9Sstevel@tonic-gate 		 */
8427c478bd9Sstevel@tonic-gate 		IDN_GLOCK_SHARED();
8437c478bd9Sstevel@tonic-gate 
8447c478bd9Sstevel@tonic-gate 		if (idn.state != IDNGS_OFFLINE) {
8457c478bd9Sstevel@tonic-gate 			int	d;
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
8487c478bd9Sstevel@tonic-gate 			    "IDN: 104: cannot suspend while active "
8497c478bd9Sstevel@tonic-gate 			    "(state = %s)",
8507c478bd9Sstevel@tonic-gate 			    idngs_str[idn.state]);
8517c478bd9Sstevel@tonic-gate 
8527c478bd9Sstevel@tonic-gate 			for (d = 0; d < MAX_DOMAINS; d++) {
8537c478bd9Sstevel@tonic-gate 				idn_domain_t	*dp;
8547c478bd9Sstevel@tonic-gate 
8557c478bd9Sstevel@tonic-gate 				dp = &idn_domain[d];
8567c478bd9Sstevel@tonic-gate 				if (dp->dcpu < 0)
8577c478bd9Sstevel@tonic-gate 					continue;
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 				cmn_err(CE_CONT,
8607c478bd9Sstevel@tonic-gate 				    "IDN: 121: domain %d (CPU %d, name "
8617c478bd9Sstevel@tonic-gate 				    "\"%s\", state %s)\n",
8627c478bd9Sstevel@tonic-gate 				    d, dp->dcpu, dp->dname,
8637c478bd9Sstevel@tonic-gate 				    idnds_str[dp->dstate]);
8647c478bd9Sstevel@tonic-gate 			}
8657c478bd9Sstevel@tonic-gate 			err = 1;
8667c478bd9Sstevel@tonic-gate 		}
8677c478bd9Sstevel@tonic-gate 
8687c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
8697c478bd9Sstevel@tonic-gate 
8707c478bd9Sstevel@tonic-gate 		if (err)
8717c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
8727c478bd9Sstevel@tonic-gate 		/*
8737c478bd9Sstevel@tonic-gate 		 * SUSPEND DLPI services.
8747c478bd9Sstevel@tonic-gate 		 */
8757c478bd9Sstevel@tonic-gate 		sip->si_flags |= IDNSUSPENDED;
8767c478bd9Sstevel@tonic-gate 
8777c478bd9Sstevel@tonic-gate 		idndl_uninit(sip);
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
8807c478bd9Sstevel@tonic-gate 
8817c478bd9Sstevel@tonic-gate 	case DDI_DETACH:
8827c478bd9Sstevel@tonic-gate 		if (idn.enabled == 0) {
8837c478bd9Sstevel@tonic-gate 			ddi_remove_minor_node(dip, NULL);
8847c478bd9Sstevel@tonic-gate 			ASSERT(idn.dip == NULL);
8857c478bd9Sstevel@tonic-gate 			return (DDI_SUCCESS);
8867c478bd9Sstevel@tonic-gate 		}
8877c478bd9Sstevel@tonic-gate 		if (!IDN_MODUNLOADABLE)
8887c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
8897c478bd9Sstevel@tonic-gate 		break;
8907c478bd9Sstevel@tonic-gate 
8917c478bd9Sstevel@tonic-gate 	default:
8927c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
8937c478bd9Sstevel@tonic-gate 	}
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	PR_DRV("%s: instance = %d\n", proc, instance);
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	if (sip == NULL) {
8987c478bd9Sstevel@tonic-gate 		/*
8997c478bd9Sstevel@tonic-gate 		 * No resources allocated.
9007c478bd9Sstevel@tonic-gate 		 */
9017c478bd9Sstevel@tonic-gate 		return (DDI_SUCCESS);
9027c478bd9Sstevel@tonic-gate 	}
9037c478bd9Sstevel@tonic-gate 
9047c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.siplock);
9057c478bd9Sstevel@tonic-gate 	if (idn.sip && (idn.sip->si_nextp == NULL)) {
9067c478bd9Sstevel@tonic-gate 		/*
9077c478bd9Sstevel@tonic-gate 		 * This is our last stream connection
9087c478bd9Sstevel@tonic-gate 		 * going away.  Time to deinit and flag
9097c478bd9Sstevel@tonic-gate 		 * the SSP we're (IDN) DOWN.
9107c478bd9Sstevel@tonic-gate 		 */
9117c478bd9Sstevel@tonic-gate 		if (idn_deinit()) {
9127c478bd9Sstevel@tonic-gate 			/*
9137c478bd9Sstevel@tonic-gate 			 * Must still be active.
9147c478bd9Sstevel@tonic-gate 			 */
9157c478bd9Sstevel@tonic-gate 			mutex_exit(&idn.siplock);
9167c478bd9Sstevel@tonic-gate 			return (DDI_FAILURE);
9177c478bd9Sstevel@tonic-gate 		}
9187c478bd9Sstevel@tonic-gate 		idn_deinit_autolink();
9197c478bd9Sstevel@tonic-gate 		/*
9207c478bd9Sstevel@tonic-gate 		 * Remove our sigblock SSP interrupt handler.
9217c478bd9Sstevel@tonic-gate 		 */
92207d06da5SSurya Prakki 		(void) sgnblk_poll_unregister(idn_sigbhandler);
9237c478bd9Sstevel@tonic-gate 		mutex_enter(&idn.sigbintr.sb_mutex);
9247c478bd9Sstevel@tonic-gate 		idn_sigbhandler_kill();
9257c478bd9Sstevel@tonic-gate 		idn.sigbintr.sb_cpuid = (uchar_t)-1;
9267c478bd9Sstevel@tonic-gate 		idn.sigbintr.sb_busy = IDNSIGB_NOTREADY;
9277c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.sigbintr.sb_mutex);
9287c478bd9Sstevel@tonic-gate 		/*
9297c478bd9Sstevel@tonic-gate 		 * Remove our reference to the sigblock area.
9307c478bd9Sstevel@tonic-gate 		 */
9317c478bd9Sstevel@tonic-gate 		sgnblk_poll_unreference(idn_sigb_setup);
9327c478bd9Sstevel@tonic-gate 		idn_gkstat_deinit();
9337c478bd9Sstevel@tonic-gate 	}
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate 	ddi_remove_minor_node(dip, NULL);
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate 	/*
9387c478bd9Sstevel@tonic-gate 	 * Remove this instance from our linked list.
9397c478bd9Sstevel@tonic-gate 	 */
9407c478bd9Sstevel@tonic-gate 	IDN_SET_INST2SIP(instance, NULL);
9417c478bd9Sstevel@tonic-gate 	if ((hsip = tsip = idn.sip) == sip) {
9427c478bd9Sstevel@tonic-gate 		idn.sip = sip->si_nextp;
9437c478bd9Sstevel@tonic-gate 	} else {
9447c478bd9Sstevel@tonic-gate 		for (; hsip && (sip != hsip); tsip = hsip,
9457c478bd9Sstevel@tonic-gate 		    hsip = hsip->si_nextp)
9467c478bd9Sstevel@tonic-gate 			;
9477c478bd9Sstevel@tonic-gate 		if (hsip)
9487c478bd9Sstevel@tonic-gate 			tsip->si_nextp = hsip->si_nextp;
9497c478bd9Sstevel@tonic-gate 	}
9507c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.siplock);
9517c478bd9Sstevel@tonic-gate 	if (sip->si_ksp)
9527c478bd9Sstevel@tonic-gate 		kstat_delete(sip->si_ksp);
9537c478bd9Sstevel@tonic-gate 
9547c478bd9Sstevel@tonic-gate 	ddi_set_driver_private(dip, NULL);
9557c478bd9Sstevel@tonic-gate 
9567c478bd9Sstevel@tonic-gate 	FREESTRUCT(sip, struct idn, 1);
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
9597c478bd9Sstevel@tonic-gate }
9607c478bd9Sstevel@tonic-gate 
9617c478bd9Sstevel@tonic-gate /*
9627c478bd9Sstevel@tonic-gate  * ----------------------------------------------
9637c478bd9Sstevel@tonic-gate  */
9647c478bd9Sstevel@tonic-gate static idn_gprops_t
9657c478bd9Sstevel@tonic-gate idn_check_conf(dev_info_t *dip, processorid_t *cpuid)
9667c478bd9Sstevel@tonic-gate {
9677c478bd9Sstevel@tonic-gate 	static idn_gprops_t	global_props = IDN_GPROPS_UNCHECKED;
9687c478bd9Sstevel@tonic-gate 
9697c478bd9Sstevel@tonic-gate 	if (global_props == IDN_GPROPS_UNCHECKED) {
9707c478bd9Sstevel@tonic-gate 		int		p;
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 		global_props = IDN_GPROPS_OKAY;
9737c478bd9Sstevel@tonic-gate 
9747c478bd9Sstevel@tonic-gate 		for (p = 0; idn_global_props[p].p_string; p++) {
9757c478bd9Sstevel@tonic-gate 			char	*str;
9767c478bd9Sstevel@tonic-gate 			int	*var;
9777c478bd9Sstevel@tonic-gate 			int	val, v_min, v_max, v_def;
9787c478bd9Sstevel@tonic-gate 
9797c478bd9Sstevel@tonic-gate 			str = idn_global_props[p].p_string;
9807c478bd9Sstevel@tonic-gate 			var = (int *)idn_global_props[p].p_var;
9817c478bd9Sstevel@tonic-gate 			v_min = idn_global_props[p].p_min;
9827c478bd9Sstevel@tonic-gate 			v_max = idn_global_props[p].p_max;
9837c478bd9Sstevel@tonic-gate 			v_def = idn_global_props[p].p_def;
9847c478bd9Sstevel@tonic-gate 			ASSERT(str && var);
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 			val = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
9877c478bd9Sstevel@tonic-gate 			    DDI_PROP_DONTPASS |
9887c478bd9Sstevel@tonic-gate 			    DDI_PROP_NOTPROM,
9897c478bd9Sstevel@tonic-gate 			    str, v_def);
9907c478bd9Sstevel@tonic-gate 			if ((v_min != v_max) &&
9917c478bd9Sstevel@tonic-gate 			    ((val < v_min) || (val > v_max))) {
9927c478bd9Sstevel@tonic-gate 				cmn_err(CE_WARN,
9937c478bd9Sstevel@tonic-gate 				    "IDN: 105: driver parameter "
9947c478bd9Sstevel@tonic-gate 				    "(%s) specified (%d) out of "
9957c478bd9Sstevel@tonic-gate 				    "range [%d - %d]",
9967c478bd9Sstevel@tonic-gate 				    str, val, v_min, v_max);
9977c478bd9Sstevel@tonic-gate 				global_props = IDN_GPROPS_ERROR;
9987c478bd9Sstevel@tonic-gate 			} else {
9997c478bd9Sstevel@tonic-gate 				*var = val;
10007c478bd9Sstevel@tonic-gate 			}
10017c478bd9Sstevel@tonic-gate 		}
10027c478bd9Sstevel@tonic-gate 	}
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate 	*cpuid = ddi_prop_get_int(DDI_DEV_T_ANY, dip,
10057c478bd9Sstevel@tonic-gate 	    DDI_PROP_DONTPASS | DDI_PROP_NOTPROM,
10067c478bd9Sstevel@tonic-gate 	    "bind_cpu", -1);
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate 	return (global_props);
10097c478bd9Sstevel@tonic-gate }
10107c478bd9Sstevel@tonic-gate 
10117c478bd9Sstevel@tonic-gate static int
10127c478bd9Sstevel@tonic-gate idn_size_check()
10137c478bd9Sstevel@tonic-gate {
10147c478bd9Sstevel@tonic-gate 	int		i, cnt;
10157c478bd9Sstevel@tonic-gate 	int		rv = 0;
10167c478bd9Sstevel@tonic-gate 	ulong_t		mboxareasize;
10177c478bd9Sstevel@tonic-gate 	int		max_num_slabs;
10187c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_size_check";
10197c478bd9Sstevel@tonic-gate 
10207c478bd9Sstevel@tonic-gate 	if (IDN_NWR_SIZE == 0)
10217c478bd9Sstevel@tonic-gate 		IDN_NWR_SIZE = IDN_SMR_SIZE;
10227c478bd9Sstevel@tonic-gate 
10237c478bd9Sstevel@tonic-gate 	if (IDN_NWR_SIZE > IDN_SMR_SIZE) {
10247c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10257c478bd9Sstevel@tonic-gate 		    "IDN: 106: idn_nwr_size(%d) > idn_smr_size(%d)"
10267c478bd9Sstevel@tonic-gate 		    " - Limiting to %d MB",
10277c478bd9Sstevel@tonic-gate 		    IDN_NWR_SIZE, IDN_SMR_SIZE, IDN_SMR_SIZE);
10287c478bd9Sstevel@tonic-gate 		IDN_NWR_SIZE = IDN_SMR_SIZE;
10297c478bd9Sstevel@tonic-gate 	}
10307c478bd9Sstevel@tonic-gate 
10317c478bd9Sstevel@tonic-gate 	if (MB2B(IDN_NWR_SIZE) < IDN_SLAB_SIZE) {
10327c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10337c478bd9Sstevel@tonic-gate 		    "IDN: 107: memory region(%lu) < slab size(%u)",
10347c478bd9Sstevel@tonic-gate 		    MB2B(IDN_NWR_SIZE), IDN_SLAB_SIZE);
10357c478bd9Sstevel@tonic-gate 		rv = -1;
10367c478bd9Sstevel@tonic-gate 	}
10377c478bd9Sstevel@tonic-gate 
10387c478bd9Sstevel@tonic-gate 	if (IDN_LOWAT >= IDN_HIWAT) {
10397c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10407c478bd9Sstevel@tonic-gate 		    "IDN: 108: idn_lowat(%d) >= idn_hiwat(%d)",
10417c478bd9Sstevel@tonic-gate 		    IDN_LOWAT, IDN_HIWAT);
10427c478bd9Sstevel@tonic-gate 		rv = -1;
10437c478bd9Sstevel@tonic-gate 	}
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 	mboxareasize = (ulong_t)(IDN_MBOXAREA_SIZE + (IDN_SMR_BUFSIZE - 1));
10467c478bd9Sstevel@tonic-gate 	mboxareasize &= ~((ulong_t)IDN_SMR_BUFSIZE - 1);
10477c478bd9Sstevel@tonic-gate #ifdef DEBUG
10487c478bd9Sstevel@tonic-gate 	if ((ulong_t)IDN_SLAB_SIZE < mboxareasize) {
1049bf30efa4Smathue 		PR_DRV("%s: slab size(%d) < mailbox area(%ld)",
10507c478bd9Sstevel@tonic-gate 		    proc, IDN_SLAB_SIZE, mboxareasize);
10517c478bd9Sstevel@tonic-gate 		/* not fatal */
10527c478bd9Sstevel@tonic-gate 	}
10537c478bd9Sstevel@tonic-gate #endif /* DEBUG */
10547c478bd9Sstevel@tonic-gate 
10557c478bd9Sstevel@tonic-gate 	if ((mboxareasize + (ulong_t)IDN_SLAB_SIZE) > MB2B(IDN_NWR_SIZE)) {
10567c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10577c478bd9Sstevel@tonic-gate 		    "IDN: 109: mailbox area(%lu) + slab size(%u) "
10587c478bd9Sstevel@tonic-gate 		    "> nwr region(%lu)",
10597c478bd9Sstevel@tonic-gate 		    mboxareasize, IDN_SLAB_SIZE,
10607c478bd9Sstevel@tonic-gate 		    MB2B(IDN_NWR_SIZE));
10617c478bd9Sstevel@tonic-gate 		rv = -1;
10627c478bd9Sstevel@tonic-gate 	}
10637c478bd9Sstevel@tonic-gate 
10647c478bd9Sstevel@tonic-gate 	max_num_slabs = (int)((MB2B(IDN_NWR_SIZE) - mboxareasize) /
10657c478bd9Sstevel@tonic-gate 	    (ulong_t)IDN_SLAB_SIZE);
10667c478bd9Sstevel@tonic-gate 	if (max_num_slabs < IDN_SLAB_MINTOTAL) {
10677c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10687c478bd9Sstevel@tonic-gate 		    "IDN: 110: maximum number of slabs(%d) < "
10697c478bd9Sstevel@tonic-gate 		    "minimum required(%d)",
10707c478bd9Sstevel@tonic-gate 		    max_num_slabs, IDN_SLAB_MINTOTAL);
10717c478bd9Sstevel@tonic-gate 		rv = -1;
10727c478bd9Sstevel@tonic-gate 	} else {
10737c478bd9Sstevel@tonic-gate 		IDN_SLAB_MAXPERDOMAIN = max_num_slabs / IDN_SLAB_MINTOTAL;
10747c478bd9Sstevel@tonic-gate 	}
10757c478bd9Sstevel@tonic-gate 
10767c478bd9Sstevel@tonic-gate #if 0
10777c478bd9Sstevel@tonic-gate 	if ((IDN_MTU + sizeof (struct ether_header)) > IDN_DATA_SIZE) {
10787c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10797c478bd9Sstevel@tonic-gate 		    "IDN: (IDN_MTU(%d) + ether_header(%d)) "
10807c478bd9Sstevel@tonic-gate 		    "> IDN_DATA_SIZE(%lu)",
10817c478bd9Sstevel@tonic-gate 		    IDN_MTU, sizeof (struct ether_header),
10827c478bd9Sstevel@tonic-gate 		    IDN_DATA_SIZE);
10837c478bd9Sstevel@tonic-gate 		rv = -1;
10847c478bd9Sstevel@tonic-gate 	}
10857c478bd9Sstevel@tonic-gate #endif /* 0 */
10867c478bd9Sstevel@tonic-gate 
10877c478bd9Sstevel@tonic-gate 	if (IDN_SMR_BUFSIZE & (IDN_ALIGNSIZE - 1)) {
10887c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
10897c478bd9Sstevel@tonic-gate 		    "IDN: 111: idn_smr_bufsize(%d) not on a "
10907c478bd9Sstevel@tonic-gate 		    "64 byte boundary", IDN_SMR_BUFSIZE);
10917c478bd9Sstevel@tonic-gate 		rv = -1;
10927c478bd9Sstevel@tonic-gate 	}
10937c478bd9Sstevel@tonic-gate 
10947c478bd9Sstevel@tonic-gate 	for (i = cnt = 0;
10957c478bd9Sstevel@tonic-gate 	    (cnt <= 1) && (((ulong_t)1 << i) < MB2B(IDN_NWR_SIZE));
10967c478bd9Sstevel@tonic-gate 	    i++)
10977c478bd9Sstevel@tonic-gate 		if ((1 << i) & IDN_SMR_BUFSIZE)
10987c478bd9Sstevel@tonic-gate 			cnt++;
10997c478bd9Sstevel@tonic-gate 	if ((i > 0) && (!cnt || (cnt > 1))) {
11007c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
11017c478bd9Sstevel@tonic-gate 		    "IDN: 112: idn_smr_bufsize(%d) not a power of 2",
11027c478bd9Sstevel@tonic-gate 		    IDN_SMR_BUFSIZE);
11037c478bd9Sstevel@tonic-gate 		rv = -1;
11047c478bd9Sstevel@tonic-gate 	}
11057c478bd9Sstevel@tonic-gate 
11067c478bd9Sstevel@tonic-gate 	if ((IDN_MBOX_PER_NET & 1) == 0) {
11077c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
11087c478bd9Sstevel@tonic-gate 		    "IDN: 113: idn_mbox_per_net(%d) must be an "
11097c478bd9Sstevel@tonic-gate 		    "odd number", IDN_MBOX_PER_NET);
11107c478bd9Sstevel@tonic-gate 		rv = -1;
11117c478bd9Sstevel@tonic-gate 	}
11127c478bd9Sstevel@tonic-gate 
11137c478bd9Sstevel@tonic-gate 	if (idn.nchannels > 0)
11147c478bd9Sstevel@tonic-gate 		IDN_WINDOW_EMAX = IDN_WINDOW_MAX +
11157c478bd9Sstevel@tonic-gate 		    ((idn.nchannels - 1) * IDN_WINDOW_INCR);
11167c478bd9Sstevel@tonic-gate 
11177c478bd9Sstevel@tonic-gate 	if (IDN_NETSVR_WAIT_MIN > IDN_NETSVR_WAIT_MAX) {
11187c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
11197c478bd9Sstevel@tonic-gate 		    "IDN: 115: idn_netsvr_wait_min(%d) cannot be "
11207c478bd9Sstevel@tonic-gate 		    "greater than idn_netsvr_wait_max(%d)",
11217c478bd9Sstevel@tonic-gate 		    IDN_NETSVR_WAIT_MIN,
11227c478bd9Sstevel@tonic-gate 		    IDN_NETSVR_WAIT_MAX);
11237c478bd9Sstevel@tonic-gate 		rv = -1;
11247c478bd9Sstevel@tonic-gate 	}
11257c478bd9Sstevel@tonic-gate 
11267c478bd9Sstevel@tonic-gate 	return (rv);
11277c478bd9Sstevel@tonic-gate }
11287c478bd9Sstevel@tonic-gate 
11297c478bd9Sstevel@tonic-gate static int
11307c478bd9Sstevel@tonic-gate idn_init_smr()
11317c478bd9Sstevel@tonic-gate {
11327c478bd9Sstevel@tonic-gate 	uint64_t	obp_paddr;
11337c478bd9Sstevel@tonic-gate 	uint64_t	obp_size;	/* in Bytes */
11347c478bd9Sstevel@tonic-gate 	uint_t		smr_size;	/* in MBytes */
11357c478bd9Sstevel@tonic-gate 	pgcnt_t		npages;
11367c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_init_smr";
11377c478bd9Sstevel@tonic-gate 
11387c478bd9Sstevel@tonic-gate 	if (idn.smr.ready)
11397c478bd9Sstevel@tonic-gate 		return (0);
11407c478bd9Sstevel@tonic-gate 
11417c478bd9Sstevel@tonic-gate 	if (idn_prom_getsmr(&smr_size, &obp_paddr, &obp_size) < 0)
11427c478bd9Sstevel@tonic-gate 		return (-1);
11437c478bd9Sstevel@tonic-gate 
1144bf30efa4Smathue 	PR_PROTO("%s: smr_size = %d, obp_paddr = 0x%lx, obp_size = 0x%lx\n",
11457c478bd9Sstevel@tonic-gate 	    proc, smr_size, obp_paddr, obp_size);
11467c478bd9Sstevel@tonic-gate 
11477c478bd9Sstevel@tonic-gate 	if (IDN_SMR_SIZE)
11487c478bd9Sstevel@tonic-gate 		smr_size = MIN(smr_size, IDN_SMR_SIZE);
11497c478bd9Sstevel@tonic-gate 
11507c478bd9Sstevel@tonic-gate 	npages = btopr(MB2B(smr_size));
11517c478bd9Sstevel@tonic-gate 
11527c478bd9Sstevel@tonic-gate 	idn.smr.prom_paddr = obp_paddr;
11537c478bd9Sstevel@tonic-gate 	idn.smr.prom_size = obp_size;
11547c478bd9Sstevel@tonic-gate 	idn.smr.vaddr = vmem_alloc(heap_arena, ptob(npages), VM_SLEEP);
11557c478bd9Sstevel@tonic-gate 	ASSERT(((ulong_t)idn.smr.vaddr & MMU_PAGEOFFSET) == 0);
11567c478bd9Sstevel@tonic-gate 	idn.smr.locpfn = (pfn_t)(obp_paddr >> MMU_PAGESHIFT);
11577c478bd9Sstevel@tonic-gate 	idn.smr.rempfn = idn.smr.rempfnlim = PFN_INVALID;
11587c478bd9Sstevel@tonic-gate 	IDN_SMR_SIZE = smr_size;
11597c478bd9Sstevel@tonic-gate 
116007d06da5SSurya Prakki 	PR_PROTO("%s: smr vaddr = %p\n", proc, (void *)idn.smr.vaddr);
11617c478bd9Sstevel@tonic-gate 
11627c478bd9Sstevel@tonic-gate 	smr_remap(&kas, idn.smr.vaddr, idn.smr.locpfn, IDN_SMR_SIZE);
11637c478bd9Sstevel@tonic-gate 
11647c478bd9Sstevel@tonic-gate 	idn.localid = PADDR_TO_DOMAINID(obp_paddr);
11657c478bd9Sstevel@tonic-gate 
11667c478bd9Sstevel@tonic-gate 	idn.smr.ready = 1;
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 	return (0);
11697c478bd9Sstevel@tonic-gate }
11707c478bd9Sstevel@tonic-gate 
11717c478bd9Sstevel@tonic-gate static void
11727c478bd9Sstevel@tonic-gate idn_deinit_smr()
11737c478bd9Sstevel@tonic-gate {
11747c478bd9Sstevel@tonic-gate 	pgcnt_t		npages;
11757c478bd9Sstevel@tonic-gate 
11767c478bd9Sstevel@tonic-gate 	if (idn.smr.ready == 0)
11777c478bd9Sstevel@tonic-gate 		return;
11787c478bd9Sstevel@tonic-gate 
11797c478bd9Sstevel@tonic-gate 	smr_remap(&kas, idn.smr.vaddr, PFN_INVALID, IDN_SMR_SIZE);
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 	npages = btopr(MB2B(IDN_SMR_SIZE));
11827c478bd9Sstevel@tonic-gate 
11837c478bd9Sstevel@tonic-gate 	vmem_free(heap_arena, idn.smr.vaddr, ptob(npages));
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate 	idn.localid = IDN_NIL_DOMID;
11867c478bd9Sstevel@tonic-gate 
11877c478bd9Sstevel@tonic-gate 	IDN_SMR_SIZE = 0;
11887c478bd9Sstevel@tonic-gate 
11897c478bd9Sstevel@tonic-gate 	idn.smr.ready = 0;
11907c478bd9Sstevel@tonic-gate }
11917c478bd9Sstevel@tonic-gate 
11927c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
11937c478bd9Sstevel@tonic-gate static void
11947c478bd9Sstevel@tonic-gate idn_sigb_setup(cpu_sgnblk_t *sigbp, void *arg)
11957c478bd9Sstevel@tonic-gate {
11967c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_sigb_setup";
11977c478bd9Sstevel@tonic-gate 
119807d06da5SSurya Prakki 	PR_PROTO("%s: Setting sigb to %p\n", proc, (void *)sigbp);
11997c478bd9Sstevel@tonic-gate 
12007c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.idnsb_mutex);
12017c478bd9Sstevel@tonic-gate 	if (sigbp == NULL) {
12027c478bd9Sstevel@tonic-gate 		idn.idnsb = NULL;
12037c478bd9Sstevel@tonic-gate 		idn.idnsb_eventp = NULL;
12047c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
12057c478bd9Sstevel@tonic-gate 		return;
12067c478bd9Sstevel@tonic-gate 	}
12077c478bd9Sstevel@tonic-gate 	idn.idnsb_eventp = (idnsb_event_t *)sigbp->sigb_idn;
12087c478bd9Sstevel@tonic-gate 	idn.idnsb = (idnsb_t *)&idn.idnsb_eventp->idn_reserved1;
12097c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.idnsb_mutex);
12107c478bd9Sstevel@tonic-gate }
12117c478bd9Sstevel@tonic-gate 
12127c478bd9Sstevel@tonic-gate static int
12137c478bd9Sstevel@tonic-gate idn_init(dev_info_t *dip)
12147c478bd9Sstevel@tonic-gate {
12157c478bd9Sstevel@tonic-gate 	struct hwconfig	local_hw;
12167c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_init";
12177c478bd9Sstevel@tonic-gate 
12187c478bd9Sstevel@tonic-gate 
12197c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&idn.siplock));
12207c478bd9Sstevel@tonic-gate 
12217c478bd9Sstevel@tonic-gate 	if (!idn.enabled) {
12227c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
12237c478bd9Sstevel@tonic-gate 		    "IDN: 117: IDN not enabled");
12247c478bd9Sstevel@tonic-gate 		return (-1);
12257c478bd9Sstevel@tonic-gate 	}
12267c478bd9Sstevel@tonic-gate 
12277c478bd9Sstevel@tonic-gate 	if (idn.dip != NULL) {
1228bf30efa4Smathue 		PR_DRV("%s: already initialized (dip = 0x%p)\n",
122907d06da5SSurya Prakki 		    proc, (void *)idn.dip);
12307c478bd9Sstevel@tonic-gate 		return (0);
12317c478bd9Sstevel@tonic-gate 	}
12327c478bd9Sstevel@tonic-gate 
12337c478bd9Sstevel@tonic-gate 	/*
12347c478bd9Sstevel@tonic-gate 	 * Determine our local domain's hardware configuration.
12357c478bd9Sstevel@tonic-gate 	 */
12367c478bd9Sstevel@tonic-gate 	if (get_hw_config(&local_hw)) {
12377c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
12387c478bd9Sstevel@tonic-gate 		    "IDN: 118: hardware config not appropriate");
12397c478bd9Sstevel@tonic-gate 		return (-1);
12407c478bd9Sstevel@tonic-gate 	}
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate 	PR_DRV("%s: locpfn = 0x%lx\n", proc, idn.smr.locpfn);
12437c478bd9Sstevel@tonic-gate 	PR_DRV("%s: rempfn = 0x%lx\n", proc, idn.smr.rempfn);
12447c478bd9Sstevel@tonic-gate 	PR_DRV("%s: smrsize = %d MB\n", proc, IDN_SMR_SIZE);
12457c478bd9Sstevel@tonic-gate 
12467c478bd9Sstevel@tonic-gate 	rw_init(&idn.grwlock, NULL, RW_DEFAULT, NULL);
12477c478bd9Sstevel@tonic-gate 	rw_init(&idn.struprwlock, NULL, RW_DEFAULT, NULL);
12487c478bd9Sstevel@tonic-gate 	mutex_init(&idn.sync.sz_mutex, NULL, MUTEX_DEFAULT, NULL);
12497c478bd9Sstevel@tonic-gate 	mutex_init(&idn.sipwenlock, NULL, MUTEX_DEFAULT, NULL);
12507c478bd9Sstevel@tonic-gate 
12517c478bd9Sstevel@tonic-gate 	/*
12527c478bd9Sstevel@tonic-gate 	 * Calculate proper value for idn.bframe_shift.
12537c478bd9Sstevel@tonic-gate 	 * Kind of hokey as it assume knowledge of the format
12547c478bd9Sstevel@tonic-gate 	 * of the idnparam_t structure.
12557c478bd9Sstevel@tonic-gate 	 */
12567c478bd9Sstevel@tonic-gate 	{
12577c478bd9Sstevel@tonic-gate 		int		s;
12587c478bd9Sstevel@tonic-gate 
12597c478bd9Sstevel@tonic-gate 		for (s = 0; (1 << s) < IDN_SMR_BUFSIZE_MIN; s++)
12607c478bd9Sstevel@tonic-gate 			;
12617c478bd9Sstevel@tonic-gate 		idn.bframe_shift = s;
1262bf30efa4Smathue 		PR_DRV("%s: idn.bframe_shift = %d, minbuf = %d\n",
12637c478bd9Sstevel@tonic-gate 		    proc, idn.bframe_shift, IDN_SMR_BUFSIZE_MIN);
12647c478bd9Sstevel@tonic-gate 
12657c478bd9Sstevel@tonic-gate 		ASSERT((uint_t)IDN_OFFSET2BFRAME(MB2B(idn_smr_size)) <
12667c478bd9Sstevel@tonic-gate 		    (1 << 24));
12677c478bd9Sstevel@tonic-gate 	}
12687c478bd9Sstevel@tonic-gate 
12697c478bd9Sstevel@tonic-gate 	idn_xmit_monitor_init();
12707c478bd9Sstevel@tonic-gate 
12717c478bd9Sstevel@tonic-gate 	/*
12727c478bd9Sstevel@tonic-gate 	 * Initialize the domain op (dopers) stuff.
12737c478bd9Sstevel@tonic-gate 	 */
12747c478bd9Sstevel@tonic-gate 	idn_dopers_init();
12757c478bd9Sstevel@tonic-gate 
12767c478bd9Sstevel@tonic-gate 	/*
12777c478bd9Sstevel@tonic-gate 	 * Initialize the timer (kmem) cache used for timeout
12787c478bd9Sstevel@tonic-gate 	 * structures.
12797c478bd9Sstevel@tonic-gate 	 */
12807c478bd9Sstevel@tonic-gate 	idn_timercache_init();
12817c478bd9Sstevel@tonic-gate 
12827c478bd9Sstevel@tonic-gate 	/*
12837c478bd9Sstevel@tonic-gate 	 * Initialize the slab waiting areas.
12847c478bd9Sstevel@tonic-gate 	 */
12857c478bd9Sstevel@tonic-gate 	(void) smr_slabwaiter_init();
12867c478bd9Sstevel@tonic-gate 
12877c478bd9Sstevel@tonic-gate 	/*
12887c478bd9Sstevel@tonic-gate 	 * Initialize retryjob kmem cache.
12897c478bd9Sstevel@tonic-gate 	 */
12907c478bd9Sstevel@tonic-gate 	idn_retrytask_init();
12917c478bd9Sstevel@tonic-gate 
12927c478bd9Sstevel@tonic-gate 	idn_init_msg_waittime();
12937c478bd9Sstevel@tonic-gate 	idn_init_msg_retrytime();
12947c478bd9Sstevel@tonic-gate 
12957c478bd9Sstevel@tonic-gate 	/*
12967c478bd9Sstevel@tonic-gate 	 * Initialize idn_domains[] and local domains information
12977c478bd9Sstevel@tonic-gate 	 * include idn_global information.
12987c478bd9Sstevel@tonic-gate 	 */
12997c478bd9Sstevel@tonic-gate 	idn_domains_init(&local_hw);
13007c478bd9Sstevel@tonic-gate 
13017c478bd9Sstevel@tonic-gate 	/*
13027c478bd9Sstevel@tonic-gate 	 * Start up IDN protocol servers.
13037c478bd9Sstevel@tonic-gate 	 */
13047c478bd9Sstevel@tonic-gate 	if (idn_protocol_init(idn_protocol_nservers) <= 0) {
13057c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
13067c478bd9Sstevel@tonic-gate 		    "IDN: 119: failed to initialize %d protocol servers",
13077c478bd9Sstevel@tonic-gate 		    idn_protocol_nservers);
13087c478bd9Sstevel@tonic-gate 		idn_domains_deinit();
13097c478bd9Sstevel@tonic-gate 		idn_retrytask_deinit();
13107c478bd9Sstevel@tonic-gate 		smr_slabwaiter_deinit();
13117c478bd9Sstevel@tonic-gate 		idn_timercache_deinit();
13127c478bd9Sstevel@tonic-gate 		idn_dopers_deinit();
13137c478bd9Sstevel@tonic-gate 		idn_xmit_monitor_deinit();
13147c478bd9Sstevel@tonic-gate 		mutex_destroy(&idn.sipwenlock);
13157c478bd9Sstevel@tonic-gate 		mutex_destroy(&idn.sync.sz_mutex);
13167c478bd9Sstevel@tonic-gate 		rw_destroy(&idn.grwlock);
13177c478bd9Sstevel@tonic-gate 		rw_destroy(&idn.struprwlock);
13187c478bd9Sstevel@tonic-gate 		return (-1);
13197c478bd9Sstevel@tonic-gate 	}
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate 	/*
13227c478bd9Sstevel@tonic-gate 	 * Initialize chan_servers array.
13237c478bd9Sstevel@tonic-gate 	 */
13247c478bd9Sstevel@tonic-gate 	(void) idn_chanservers_init();
13257c478bd9Sstevel@tonic-gate 
13267c478bd9Sstevel@tonic-gate 	/*
13277c478bd9Sstevel@tonic-gate 	 * Need to register the IDN handler with the DMV subsystem.
13287c478bd9Sstevel@tonic-gate 	 *
13297c478bd9Sstevel@tonic-gate 	 * Need to prevent the IDN driver from being unloaded
13307c478bd9Sstevel@tonic-gate 	 * once loaded since DMV's may come in at any time.
13317c478bd9Sstevel@tonic-gate 	 * If the driver is not loaded and the idn_dmv_handler
13327c478bd9Sstevel@tonic-gate 	 * has been registered with the DMV, system will crash.
13337c478bd9Sstevel@tonic-gate 	 */
13347c478bd9Sstevel@tonic-gate 	(void) idn_init_handler();
13357c478bd9Sstevel@tonic-gate 
13367c478bd9Sstevel@tonic-gate 	idn.dip = dip;
13377c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
13387c478bd9Sstevel@tonic-gate 	IDN_GSTATE_TRANSITION(IDNGS_OFFLINE);
13397c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
13407c478bd9Sstevel@tonic-gate 
13417c478bd9Sstevel@tonic-gate 	return (0);
13427c478bd9Sstevel@tonic-gate }
13437c478bd9Sstevel@tonic-gate 
13447c478bd9Sstevel@tonic-gate static int
13457c478bd9Sstevel@tonic-gate idn_deinit()
13467c478bd9Sstevel@tonic-gate {
13477c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_deinit";
13487c478bd9Sstevel@tonic-gate 
13497c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&idn.siplock));
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
13527c478bd9Sstevel@tonic-gate 
13537c478bd9Sstevel@tonic-gate 	if (idn.state != IDNGS_OFFLINE) {
13547c478bd9Sstevel@tonic-gate 		int	d;
13557c478bd9Sstevel@tonic-gate 
13567c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
13577c478bd9Sstevel@tonic-gate 		    "IDN: 120: cannot deinit while active "
13587c478bd9Sstevel@tonic-gate 		    "(state = %s)", idngs_str[idn.state]);
13597c478bd9Sstevel@tonic-gate 
13607c478bd9Sstevel@tonic-gate 		for (d = 0; d < MAX_DOMAINS; d++) {
13617c478bd9Sstevel@tonic-gate 			idn_domain_t	*dp;
13627c478bd9Sstevel@tonic-gate 
13637c478bd9Sstevel@tonic-gate 			dp = &idn_domain[d];
13647c478bd9Sstevel@tonic-gate 			if (dp->dcpu < 0)
13657c478bd9Sstevel@tonic-gate 				continue;
13667c478bd9Sstevel@tonic-gate 
13677c478bd9Sstevel@tonic-gate 			cmn_err(CE_CONT,
13687c478bd9Sstevel@tonic-gate 			    "IDN: 121: domain %d (CPU %d, "
13697c478bd9Sstevel@tonic-gate 			    "name \"%s\", state %s)\n",
13707c478bd9Sstevel@tonic-gate 			    d, dp->dcpu, dp->dname,
13717c478bd9Sstevel@tonic-gate 			    idnds_str[dp->dstate]);
13727c478bd9Sstevel@tonic-gate 		}
13737c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
13747c478bd9Sstevel@tonic-gate 		return (-1);
13757c478bd9Sstevel@tonic-gate 	}
13767c478bd9Sstevel@tonic-gate 
13777c478bd9Sstevel@tonic-gate 	if (idn.dip == NULL) {
13787c478bd9Sstevel@tonic-gate 		PR_DRV("%s: already deinitialized\n", proc);
13797c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
13807c478bd9Sstevel@tonic-gate 		return (0);
13817c478bd9Sstevel@tonic-gate 	}
13827c478bd9Sstevel@tonic-gate 
13837c478bd9Sstevel@tonic-gate 	IDN_GSTATE_TRANSITION(IDNGS_IGNORE);
13847c478bd9Sstevel@tonic-gate 
13857c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
13867c478bd9Sstevel@tonic-gate 
13877c478bd9Sstevel@tonic-gate 	idn_xmit_monitor_deinit();
13887c478bd9Sstevel@tonic-gate 
13897c478bd9Sstevel@tonic-gate 	idn_deinit_handler();
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate 	idn_chanservers_deinit();
13927c478bd9Sstevel@tonic-gate 
13937c478bd9Sstevel@tonic-gate 	idn.nchannels = 0;
13947c478bd9Sstevel@tonic-gate 	ASSERT(idn.chan_servers == NULL);
13957c478bd9Sstevel@tonic-gate 
13967c478bd9Sstevel@tonic-gate 	smr_slabpool_deinit();
13977c478bd9Sstevel@tonic-gate 
13987c478bd9Sstevel@tonic-gate 	idn_protocol_deinit();
13997c478bd9Sstevel@tonic-gate 
14007c478bd9Sstevel@tonic-gate 	idn_domains_deinit();
14017c478bd9Sstevel@tonic-gate 
14027c478bd9Sstevel@tonic-gate 	smr_slabwaiter_deinit();
14037c478bd9Sstevel@tonic-gate 
14047c478bd9Sstevel@tonic-gate 	idn_retrytask_deinit();
14057c478bd9Sstevel@tonic-gate 
14067c478bd9Sstevel@tonic-gate 	idn_timercache_deinit();
14077c478bd9Sstevel@tonic-gate 
14087c478bd9Sstevel@tonic-gate 	idn_dopers_deinit();
14097c478bd9Sstevel@tonic-gate 
14107c478bd9Sstevel@tonic-gate 	ASSERT(idn.localid == IDN_NIL_DOMID);
14117c478bd9Sstevel@tonic-gate 
14127c478bd9Sstevel@tonic-gate 	IDN_SET_MASTERID(IDN_NIL_DOMID);
14137c478bd9Sstevel@tonic-gate 
14147c478bd9Sstevel@tonic-gate 	idn_deinit_smr();
14157c478bd9Sstevel@tonic-gate 
14167c478bd9Sstevel@tonic-gate 	mutex_destroy(&idn.sipwenlock);
14177c478bd9Sstevel@tonic-gate 	mutex_destroy(&idn.sync.sz_mutex);
14187c478bd9Sstevel@tonic-gate 	rw_destroy(&idn.grwlock);
14197c478bd9Sstevel@tonic-gate 	rw_destroy(&idn.struprwlock);
14207c478bd9Sstevel@tonic-gate 
14217c478bd9Sstevel@tonic-gate 	idn.dip = NULL;
14227c478bd9Sstevel@tonic-gate 
14237c478bd9Sstevel@tonic-gate 	return (0);
14247c478bd9Sstevel@tonic-gate }
14257c478bd9Sstevel@tonic-gate 
14267c478bd9Sstevel@tonic-gate static void
14277c478bd9Sstevel@tonic-gate idn_xmit_monitor_init()
14287c478bd9Sstevel@tonic-gate {
14297c478bd9Sstevel@tonic-gate 	mutex_init(&idn.xmit_lock, NULL, MUTEX_DEFAULT, NULL);
14307c478bd9Sstevel@tonic-gate 	idn.xmit_tid = (timeout_id_t)NULL;
14317c478bd9Sstevel@tonic-gate 	CHANSET_ZERO(idn.xmit_chanset_wanted);
14327c478bd9Sstevel@tonic-gate }
14337c478bd9Sstevel@tonic-gate 
14347c478bd9Sstevel@tonic-gate static void
14357c478bd9Sstevel@tonic-gate idn_xmit_monitor_deinit()
14367c478bd9Sstevel@tonic-gate {
14377c478bd9Sstevel@tonic-gate 	timeout_id_t	tid;
14387c478bd9Sstevel@tonic-gate 
14397c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.xmit_lock);
14407c478bd9Sstevel@tonic-gate 	CHANSET_ZERO(idn.xmit_chanset_wanted);
14417c478bd9Sstevel@tonic-gate 	if ((tid = idn.xmit_tid) != (timeout_id_t)NULL) {
14427c478bd9Sstevel@tonic-gate 		idn.xmit_tid = (timeout_id_t)NULL;
14437c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.xmit_lock);
14447c478bd9Sstevel@tonic-gate 		(void) untimeout(tid);
14457c478bd9Sstevel@tonic-gate 	} else {
14467c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.xmit_lock);
14477c478bd9Sstevel@tonic-gate 	}
14487c478bd9Sstevel@tonic-gate 	mutex_destroy(&idn.xmit_lock);
14497c478bd9Sstevel@tonic-gate }
14507c478bd9Sstevel@tonic-gate 
14517c478bd9Sstevel@tonic-gate static void
14527c478bd9Sstevel@tonic-gate idn_init_msg_waittime()
14537c478bd9Sstevel@tonic-gate {
14547c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_NULL] = -1;
14557c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_NEGO] = idn_msgwait_nego * hz;
14567c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_CFG]  = idn_msgwait_cfg * hz;
14577c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_CON]  = idn_msgwait_con * hz;
14587c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_FIN]  = idn_msgwait_fin * hz;
14597c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_CMD]  = idn_msgwait_cmd * hz;
14607c478bd9Sstevel@tonic-gate 	idn_msg_waittime[IDNP_DATA] = idn_msgwait_data * hz;
14617c478bd9Sstevel@tonic-gate }
14627c478bd9Sstevel@tonic-gate 
14637c478bd9Sstevel@tonic-gate static void
14647c478bd9Sstevel@tonic-gate idn_init_msg_retrytime()
14657c478bd9Sstevel@tonic-gate {
14667c478bd9Sstevel@tonic-gate 	idn_msg_retrytime[(int)IDNRETRY_NIL]	 = -1;
14677c478bd9Sstevel@tonic-gate 	idn_msg_retrytime[(int)IDNRETRY_NEGO]	 = idn_retryfreq_nego * hz;
14687c478bd9Sstevel@tonic-gate 	idn_msg_retrytime[(int)IDNRETRY_CON]	 = idn_retryfreq_con * hz;
14697c478bd9Sstevel@tonic-gate 	idn_msg_retrytime[(int)IDNRETRY_CONQ]	 = idn_retryfreq_con * hz;
14707c478bd9Sstevel@tonic-gate 	idn_msg_retrytime[(int)IDNRETRY_FIN]	 = idn_retryfreq_fin * hz;
14717c478bd9Sstevel@tonic-gate 	idn_msg_retrytime[(int)IDNRETRY_FINQ]	 = idn_retryfreq_fin * hz;
14727c478bd9Sstevel@tonic-gate }
14737c478bd9Sstevel@tonic-gate 
14747c478bd9Sstevel@tonic-gate /*
14757c478bd9Sstevel@tonic-gate  * ----------------------------------------------
14767c478bd9Sstevel@tonic-gate  */
14777c478bd9Sstevel@tonic-gate /*ARGSUSED*/
14787c478bd9Sstevel@tonic-gate static int
14797c478bd9Sstevel@tonic-gate idnopen(register queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *crp)
14807c478bd9Sstevel@tonic-gate {
14817c478bd9Sstevel@tonic-gate 	register int	err = 0;
14827c478bd9Sstevel@tonic-gate 	int		minordev;
14837c478bd9Sstevel@tonic-gate 	struct idnstr	*stp, **pstp;
14847c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnopen";
14857c478bd9Sstevel@tonic-gate 
14867c478bd9Sstevel@tonic-gate 	ASSERT(sflag != MODOPEN);
14877c478bd9Sstevel@tonic-gate 
14887c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
14897c478bd9Sstevel@tonic-gate 
14907c478bd9Sstevel@tonic-gate 	rw_enter(&idn.struprwlock, RW_WRITER);
14917c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.sipwenlock);
14927c478bd9Sstevel@tonic-gate 	pstp = &idn.strup;
14937c478bd9Sstevel@tonic-gate 
14947c478bd9Sstevel@tonic-gate 	if (idn.enabled == 0) {
14957c478bd9Sstevel@tonic-gate 		PR_DRV("%s: Driver disabled (check OBP:idn-smr-size)\n",
14967c478bd9Sstevel@tonic-gate 		    proc);
14977c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.sipwenlock);
14987c478bd9Sstevel@tonic-gate 		rw_exit(&idn.struprwlock);
14997c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
15007c478bd9Sstevel@tonic-gate 		return (EACCES);
15017c478bd9Sstevel@tonic-gate 	}
15027c478bd9Sstevel@tonic-gate 
15037c478bd9Sstevel@tonic-gate 	if (!idn_ndlist &&
15047c478bd9Sstevel@tonic-gate 	    idn_param_register(idn_param_arr, A_CNT(idn_param_arr))) {
15057c478bd9Sstevel@tonic-gate 		PR_DRV("%s: failed to register ndd parameters\n", proc);
15067c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.sipwenlock);
15077c478bd9Sstevel@tonic-gate 		rw_exit(&idn.struprwlock);
15087c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
15097c478bd9Sstevel@tonic-gate 		return (ENOMEM);
15107c478bd9Sstevel@tonic-gate 	}
15117c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
15127c478bd9Sstevel@tonic-gate 
15137c478bd9Sstevel@tonic-gate 	if (sflag == CLONEOPEN) {
15147c478bd9Sstevel@tonic-gate 		minordev = 0;
15157c478bd9Sstevel@tonic-gate 		for (stp = *pstp; stp; pstp = &stp->ss_nextp, stp = *pstp) {
15167c478bd9Sstevel@tonic-gate 			if (minordev < stp->ss_minor)
15177c478bd9Sstevel@tonic-gate 				break;
15187c478bd9Sstevel@tonic-gate 			minordev++;
15197c478bd9Sstevel@tonic-gate 		}
15207c478bd9Sstevel@tonic-gate 		*devp = makedevice(getmajor(*devp), minordev);
15217c478bd9Sstevel@tonic-gate 	} else {
15227c478bd9Sstevel@tonic-gate 		minordev = getminor(*devp);
15237c478bd9Sstevel@tonic-gate 	}
15247c478bd9Sstevel@tonic-gate 	if (rq->q_ptr)
15257c478bd9Sstevel@tonic-gate 		goto done;
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 	stp = GETSTRUCT(struct idnstr, 1);
15287c478bd9Sstevel@tonic-gate 	stp->ss_rq = rq;
15297c478bd9Sstevel@tonic-gate 	stp->ss_minor = minordev;
15307c478bd9Sstevel@tonic-gate 	rw_init(&stp->ss_rwlock, NULL, RW_DEFAULT, NULL);
15317c478bd9Sstevel@tonic-gate 	/*
15327c478bd9Sstevel@tonic-gate 	 * DLPI stuff
15337c478bd9Sstevel@tonic-gate 	 */
15347c478bd9Sstevel@tonic-gate 	stp->ss_sip = NULL;
15357c478bd9Sstevel@tonic-gate 	stp->ss_state = DL_UNATTACHED;
15367c478bd9Sstevel@tonic-gate 	stp->ss_sap = 0;
15377c478bd9Sstevel@tonic-gate 	stp->ss_flags = 0;
15387c478bd9Sstevel@tonic-gate 	stp->ss_mccount = 0;
15397c478bd9Sstevel@tonic-gate 	stp->ss_mctab = NULL;
15407c478bd9Sstevel@tonic-gate 
15417c478bd9Sstevel@tonic-gate 	/*
15427c478bd9Sstevel@tonic-gate 	 * Link new entry into list of actives.
15437c478bd9Sstevel@tonic-gate 	 */
15447c478bd9Sstevel@tonic-gate 	stp->ss_nextp = *pstp;
15457c478bd9Sstevel@tonic-gate 	*pstp = stp;
15467c478bd9Sstevel@tonic-gate 
15477c478bd9Sstevel@tonic-gate 	WR(rq)->q_ptr = rq->q_ptr = (void *)stp;
15487c478bd9Sstevel@tonic-gate 	/*
15497c478bd9Sstevel@tonic-gate 	 * Disable automatic enabling of our write service
15507c478bd9Sstevel@tonic-gate 	 * procedure.  We control this explicitly.
15517c478bd9Sstevel@tonic-gate 	 */
15527c478bd9Sstevel@tonic-gate 	noenable(WR(rq));
15537c478bd9Sstevel@tonic-gate 
15547c478bd9Sstevel@tonic-gate 	/*
15557c478bd9Sstevel@tonic-gate 	 * Set our STREAMs queue maximum packet size that
15567c478bd9Sstevel@tonic-gate 	 * we'll accept and our high/low water marks.
15577c478bd9Sstevel@tonic-gate 	 */
15587c478bd9Sstevel@tonic-gate 	(void) strqset(WR(rq), QMAXPSZ, 0, IDN_DATA_SIZE);
15597c478bd9Sstevel@tonic-gate 	(void) strqset(WR(rq), QLOWAT,  0, IDN_LOWAT);
15607c478bd9Sstevel@tonic-gate 	(void) strqset(WR(rq), QHIWAT,  0, IDN_HIWAT);
15617c478bd9Sstevel@tonic-gate 	(void) strqset(rq, QMAXPSZ, 0, IDN_DATA_SIZE);
15627c478bd9Sstevel@tonic-gate 	(void) strqset(rq, QLOWAT,  0, IDN_LOWAT);
15637c478bd9Sstevel@tonic-gate 	(void) strqset(rq, QHIWAT,  0, IDN_HIWAT);
15647c478bd9Sstevel@tonic-gate 
15657c478bd9Sstevel@tonic-gate done:
15667c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.sipwenlock);
15677c478bd9Sstevel@tonic-gate 	rw_exit(&idn.struprwlock);
15687c478bd9Sstevel@tonic-gate 
15697c478bd9Sstevel@tonic-gate 	(void) qassociate(rq, -1);
15707c478bd9Sstevel@tonic-gate 	qprocson(rq);
15717c478bd9Sstevel@tonic-gate 
15727c478bd9Sstevel@tonic-gate 	return (err);
15737c478bd9Sstevel@tonic-gate }
15747c478bd9Sstevel@tonic-gate 
15757c478bd9Sstevel@tonic-gate /*
15767c478bd9Sstevel@tonic-gate  * ----------------------------------------------
15777c478bd9Sstevel@tonic-gate  */
15787c478bd9Sstevel@tonic-gate /*ARGSUSED1*/
15797c478bd9Sstevel@tonic-gate static int
15807c478bd9Sstevel@tonic-gate idnclose(queue_t *rq, int flag, cred_t *crp)
15817c478bd9Sstevel@tonic-gate {
15827c478bd9Sstevel@tonic-gate 	struct idnstr	*stp, **pstp;
15837c478bd9Sstevel@tonic-gate 
15847c478bd9Sstevel@tonic-gate 	ASSERT(rq->q_ptr);
15857c478bd9Sstevel@tonic-gate 
15867c478bd9Sstevel@tonic-gate 	qprocsoff(rq);
15877c478bd9Sstevel@tonic-gate 	/*
15887c478bd9Sstevel@tonic-gate 	 * Guaranteed to be single threaded with respect
15897c478bd9Sstevel@tonic-gate 	 * to this stream at this point.
15907c478bd9Sstevel@tonic-gate 	 */
15917c478bd9Sstevel@tonic-gate 
15927c478bd9Sstevel@tonic-gate 	stp = (struct idnstr *)rq->q_ptr;
15937c478bd9Sstevel@tonic-gate 
15947c478bd9Sstevel@tonic-gate 	if (stp->ss_sip)
15957c478bd9Sstevel@tonic-gate 		idndl_dodetach(stp);
15967c478bd9Sstevel@tonic-gate 
15977c478bd9Sstevel@tonic-gate 	rw_enter(&idn.struprwlock, RW_WRITER);
15987c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.sipwenlock);
15997c478bd9Sstevel@tonic-gate 	pstp = &idn.strup;
16007c478bd9Sstevel@tonic-gate 	for (stp = *pstp; stp; pstp = &stp->ss_nextp, stp = *pstp)
16017c478bd9Sstevel@tonic-gate 		if (stp == (struct idnstr *)rq->q_ptr)
16027c478bd9Sstevel@tonic-gate 			break;
16037c478bd9Sstevel@tonic-gate 	ASSERT(stp);
16047c478bd9Sstevel@tonic-gate 	ASSERT(stp->ss_rq == rq);
16057c478bd9Sstevel@tonic-gate 	*pstp = stp->ss_nextp;
16067c478bd9Sstevel@tonic-gate 
16077c478bd9Sstevel@tonic-gate 	rw_destroy(&stp->ss_rwlock);
16087c478bd9Sstevel@tonic-gate 	FREESTRUCT(stp, struct idnstr, 1);
16097c478bd9Sstevel@tonic-gate 
16107c478bd9Sstevel@tonic-gate 	WR(rq)->q_ptr = rq->q_ptr = NULL;
16117c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.sipwenlock);
16127c478bd9Sstevel@tonic-gate 	rw_exit(&idn.struprwlock);
16137c478bd9Sstevel@tonic-gate 
16147c478bd9Sstevel@tonic-gate 	idn_param_cleanup();
16157c478bd9Sstevel@tonic-gate 	(void) qassociate(rq, -1);
16167c478bd9Sstevel@tonic-gate 
16177c478bd9Sstevel@tonic-gate 	return (0);
16187c478bd9Sstevel@tonic-gate }
16197c478bd9Sstevel@tonic-gate 
16207c478bd9Sstevel@tonic-gate /*
16217c478bd9Sstevel@tonic-gate  * ----------------------------------------------
16227c478bd9Sstevel@tonic-gate  */
16237c478bd9Sstevel@tonic-gate static int
16247c478bd9Sstevel@tonic-gate idnwput(register queue_t *wq, register mblk_t *mp)
16257c478bd9Sstevel@tonic-gate {
16267c478bd9Sstevel@tonic-gate 	register struct idnstr	*stp;
16277c478bd9Sstevel@tonic-gate 	struct idn		*sip;
16287c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnwput";
16297c478bd9Sstevel@tonic-gate 
16307c478bd9Sstevel@tonic-gate 	stp = (struct idnstr *)wq->q_ptr;
16317c478bd9Sstevel@tonic-gate 	sip = stp->ss_sip;
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate 	switch (DB_TYPE(mp)) {
16347c478bd9Sstevel@tonic-gate 	case M_IOCTL:
16357c478bd9Sstevel@tonic-gate 		idnioctl(wq, mp);
16367c478bd9Sstevel@tonic-gate 		break;
16377c478bd9Sstevel@tonic-gate 
16387c478bd9Sstevel@tonic-gate 	case M_DATA:
16397c478bd9Sstevel@tonic-gate 		if (((stp->ss_flags & (IDNSFAST|IDNSRAW)) == 0) ||
16407c478bd9Sstevel@tonic-gate 		    (stp->ss_state != DL_IDLE) ||
16417c478bd9Sstevel@tonic-gate 		    (sip == NULL)) {
1642bf30efa4Smathue 			PR_DLPI("%s: fl=0x%x, st=0x%x, ret(EPROTO)\n",
16437c478bd9Sstevel@tonic-gate 			    proc, stp->ss_flags, stp->ss_state);
16447c478bd9Sstevel@tonic-gate 			merror(wq, mp, EPROTO);
16457c478bd9Sstevel@tonic-gate 
16467c478bd9Sstevel@tonic-gate 		} else if (wq->q_first) {
16477c478bd9Sstevel@tonic-gate 			if (putq(wq, mp) == 0)
16487c478bd9Sstevel@tonic-gate 				freemsg(mp);
16497c478bd9Sstevel@tonic-gate 			/*
16507c478bd9Sstevel@tonic-gate 			 * We're only holding the reader lock,
16517c478bd9Sstevel@tonic-gate 			 * but that's okay since this field
16527c478bd9Sstevel@tonic-gate 			 * is just a soft-flag.
16537c478bd9Sstevel@tonic-gate 			 */
16547c478bd9Sstevel@tonic-gate 			sip->si_wantw = 1;
16557c478bd9Sstevel@tonic-gate 			qenable(wq);
16567c478bd9Sstevel@tonic-gate 
16577c478bd9Sstevel@tonic-gate 		} else if (sip->si_flags & IDNPROMISC) {
16587c478bd9Sstevel@tonic-gate 			if (putq(wq, mp) == 0) {
16597c478bd9Sstevel@tonic-gate 				PR_DLPI("%s: putq failed\n", proc);
16607c478bd9Sstevel@tonic-gate 				freemsg(mp);
16617c478bd9Sstevel@tonic-gate 			} else {
16627c478bd9Sstevel@tonic-gate 				PR_DLPI("%s: putq succeeded\n", proc);
16637c478bd9Sstevel@tonic-gate 			}
16647c478bd9Sstevel@tonic-gate 			qenable(wq);
16657c478bd9Sstevel@tonic-gate 
16667c478bd9Sstevel@tonic-gate 		} else {
1667bf30efa4Smathue 			PR_DLPI("%s: idndl_start(sip=0x%p)\n",
166807d06da5SSurya Prakki 			    proc, (void *)sip);
16697c478bd9Sstevel@tonic-gate 			rw_enter(&stp->ss_rwlock, RW_READER);
16707c478bd9Sstevel@tonic-gate 			(void) idndl_start(wq, mp, sip);
16717c478bd9Sstevel@tonic-gate 			rw_exit(&stp->ss_rwlock);
16727c478bd9Sstevel@tonic-gate 		}
16737c478bd9Sstevel@tonic-gate 		break;
16747c478bd9Sstevel@tonic-gate 
16757c478bd9Sstevel@tonic-gate 	case M_PROTO:
16767c478bd9Sstevel@tonic-gate 	case M_PCPROTO:
16777c478bd9Sstevel@tonic-gate 		/*
16787c478bd9Sstevel@tonic-gate 		 * Break the association between the current thread
16797c478bd9Sstevel@tonic-gate 		 * and the thread that calls idndl_proto() to resolve
16807c478bd9Sstevel@tonic-gate 		 * the problem of idn_chan_server() threads which
16817c478bd9Sstevel@tonic-gate 		 * loop back around to call idndl_proto and try to
16827c478bd9Sstevel@tonic-gate 		 * recursively acquire internal locks.
16837c478bd9Sstevel@tonic-gate 		 */
16847c478bd9Sstevel@tonic-gate 		if (putq(wq, mp) == 0)
16857c478bd9Sstevel@tonic-gate 			freemsg(mp);
16867c478bd9Sstevel@tonic-gate 		qenable(wq);
16877c478bd9Sstevel@tonic-gate 		break;
16887c478bd9Sstevel@tonic-gate 
16897c478bd9Sstevel@tonic-gate 	case M_FLUSH:
16907c478bd9Sstevel@tonic-gate 		PR_STR("%s: M_FLUSH request (flush = %d)\n",
16917c478bd9Sstevel@tonic-gate 		    proc, (int)*mp->b_rptr);
16927c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHW) {
16937c478bd9Sstevel@tonic-gate 			flushq(wq, FLUSHALL);
16947c478bd9Sstevel@tonic-gate 			*mp->b_rptr &= ~FLUSHW;
16957c478bd9Sstevel@tonic-gate 		}
16967c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR)
16977c478bd9Sstevel@tonic-gate 			qreply(wq, mp);
16987c478bd9Sstevel@tonic-gate 		else
16997c478bd9Sstevel@tonic-gate 			freemsg(mp);
17007c478bd9Sstevel@tonic-gate 		break;
17017c478bd9Sstevel@tonic-gate 
17027c478bd9Sstevel@tonic-gate 	default:
17037c478bd9Sstevel@tonic-gate 		PR_STR("%s: unexpected DB_TYPE 0x%x\n",
17047c478bd9Sstevel@tonic-gate 		    proc, DB_TYPE(mp));
17057c478bd9Sstevel@tonic-gate 		freemsg(mp);
17067c478bd9Sstevel@tonic-gate 		break;
17077c478bd9Sstevel@tonic-gate 	}
17087c478bd9Sstevel@tonic-gate 
17097c478bd9Sstevel@tonic-gate 	return (0);
17107c478bd9Sstevel@tonic-gate }
17117c478bd9Sstevel@tonic-gate 
17127c478bd9Sstevel@tonic-gate /*
17137c478bd9Sstevel@tonic-gate  * ----------------------------------------------
17147c478bd9Sstevel@tonic-gate  */
17157c478bd9Sstevel@tonic-gate static int
17167c478bd9Sstevel@tonic-gate idnwsrv(queue_t *wq)
17177c478bd9Sstevel@tonic-gate {
17187c478bd9Sstevel@tonic-gate 	mblk_t		*mp;
17197c478bd9Sstevel@tonic-gate 	int		err = 0;
17207c478bd9Sstevel@tonic-gate 	struct idnstr	*stp;
17217c478bd9Sstevel@tonic-gate 	struct idn	*sip;
17227c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnwsrv";
17237c478bd9Sstevel@tonic-gate 
17247c478bd9Sstevel@tonic-gate 	stp = (struct idnstr *)wq->q_ptr;
17257c478bd9Sstevel@tonic-gate 	sip = stp->ss_sip;
17267c478bd9Sstevel@tonic-gate 
17277c478bd9Sstevel@tonic-gate 	while (mp = getq(wq)) {
17287c478bd9Sstevel@tonic-gate 		switch (DB_TYPE(mp)) {
17297c478bd9Sstevel@tonic-gate 		case M_DATA:
17307c478bd9Sstevel@tonic-gate 			if (sip) {
1731bf30efa4Smathue 				PR_DLPI("%s: idndl_start(sip=0x%p)\n",
173207d06da5SSurya Prakki 				    proc, (void *)sip);
17337c478bd9Sstevel@tonic-gate 				rw_enter(&stp->ss_rwlock, RW_READER);
17347c478bd9Sstevel@tonic-gate 				err = idndl_start(wq, mp, sip);
17357c478bd9Sstevel@tonic-gate 				rw_exit(&stp->ss_rwlock);
17367c478bd9Sstevel@tonic-gate 				if (err)
17377c478bd9Sstevel@tonic-gate 					goto done;
17387c478bd9Sstevel@tonic-gate 			} else {
17397c478bd9Sstevel@tonic-gate 				PR_DLPI("%s: NO sip to start msg\n", proc);
17407c478bd9Sstevel@tonic-gate 				freemsg(mp);
17417c478bd9Sstevel@tonic-gate 			}
17427c478bd9Sstevel@tonic-gate 			break;
17437c478bd9Sstevel@tonic-gate 
17447c478bd9Sstevel@tonic-gate 		case M_PROTO:
17457c478bd9Sstevel@tonic-gate 		case M_PCPROTO:
17467c478bd9Sstevel@tonic-gate 			idndl_proto(wq, mp);
17477c478bd9Sstevel@tonic-gate 			break;
17487c478bd9Sstevel@tonic-gate 
17497c478bd9Sstevel@tonic-gate 		default:
17507c478bd9Sstevel@tonic-gate 			ASSERT(0);
17517c478bd9Sstevel@tonic-gate 			PR_STR("%s: unexpected db_type (%d)\n",
17527c478bd9Sstevel@tonic-gate 			    proc, DB_TYPE(mp));
17537c478bd9Sstevel@tonic-gate 			freemsg(mp);
17547c478bd9Sstevel@tonic-gate 			break;
17557c478bd9Sstevel@tonic-gate 		}
17567c478bd9Sstevel@tonic-gate 	}
17577c478bd9Sstevel@tonic-gate done:
17587c478bd9Sstevel@tonic-gate 	return (0);
17597c478bd9Sstevel@tonic-gate }
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate /*
17627c478bd9Sstevel@tonic-gate  * ----------------------------------------------
17637c478bd9Sstevel@tonic-gate  */
17647c478bd9Sstevel@tonic-gate static int
17657c478bd9Sstevel@tonic-gate idnrput(register queue_t *rq, register mblk_t *mp)
17667c478bd9Sstevel@tonic-gate {
17677c478bd9Sstevel@tonic-gate 	register int	err = 0;
17687c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnrput";
17697c478bd9Sstevel@tonic-gate 
17707c478bd9Sstevel@tonic-gate 	switch (DB_TYPE(mp)) {
17717c478bd9Sstevel@tonic-gate 	case M_DATA:
17727c478bd9Sstevel@tonic-gate 		/*
17737c478bd9Sstevel@tonic-gate 		 * Should not reach here with data packets
17747c478bd9Sstevel@tonic-gate 		 * if running DLPI.
17757c478bd9Sstevel@tonic-gate 		 */
17767c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
17777c478bd9Sstevel@tonic-gate 		    "IDN: 123: unexpected M_DATA packets for "
177807d06da5SSurya Prakki 		    "q_stream 0x%p", (void *)rq->q_stream);
17797c478bd9Sstevel@tonic-gate 		freemsg(mp);
17807c478bd9Sstevel@tonic-gate 		err = ENXIO;
17817c478bd9Sstevel@tonic-gate 		break;
17827c478bd9Sstevel@tonic-gate 
17837c478bd9Sstevel@tonic-gate 	case M_FLUSH:
17847c478bd9Sstevel@tonic-gate 		PR_STR("%s: M_FLUSH request (flush = %d)\n",
17857c478bd9Sstevel@tonic-gate 		    proc, (int)*mp->b_rptr);
17867c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR)
17877c478bd9Sstevel@tonic-gate 			flushq(rq, FLUSHALL);
17887c478bd9Sstevel@tonic-gate 		(void) putnext(rq, mp);
17897c478bd9Sstevel@tonic-gate 		break;
17907c478bd9Sstevel@tonic-gate 
17917c478bd9Sstevel@tonic-gate 	case M_ERROR:
17927c478bd9Sstevel@tonic-gate 		PR_STR("%s: M_ERROR (error = %d) coming through\n",
17937c478bd9Sstevel@tonic-gate 		    proc, (int)*mp->b_rptr);
17947c478bd9Sstevel@tonic-gate 		(void) putnext(rq, mp);
17957c478bd9Sstevel@tonic-gate 		break;
17967c478bd9Sstevel@tonic-gate 	default:
17977c478bd9Sstevel@tonic-gate 		PR_STR("%s: unexpected DB_TYPE 0x%x\n",
17987c478bd9Sstevel@tonic-gate 		    proc, DB_TYPE(mp));
17997c478bd9Sstevel@tonic-gate 		freemsg(mp);
18007c478bd9Sstevel@tonic-gate 		err = ENXIO;
18017c478bd9Sstevel@tonic-gate 		break;
18027c478bd9Sstevel@tonic-gate 	}
18037c478bd9Sstevel@tonic-gate 
18047c478bd9Sstevel@tonic-gate 	return (err);
18057c478bd9Sstevel@tonic-gate }
18067c478bd9Sstevel@tonic-gate 
18077c478bd9Sstevel@tonic-gate /*
18087c478bd9Sstevel@tonic-gate  * ----------------------------------------------
18097c478bd9Sstevel@tonic-gate  * Not allowed to enqueue messages!  Only M_DATA messages
18107c478bd9Sstevel@tonic-gate  * can be enqueued on the write stream.
18117c478bd9Sstevel@tonic-gate  * ----------------------------------------------
18127c478bd9Sstevel@tonic-gate  */
18137c478bd9Sstevel@tonic-gate static void
18147c478bd9Sstevel@tonic-gate idnioctl(register queue_t *wq, register mblk_t *mp)
18157c478bd9Sstevel@tonic-gate {
18167c478bd9Sstevel@tonic-gate 	register struct iocblk	*iocp;
18177c478bd9Sstevel@tonic-gate 	register int	cmd;
18187c478bd9Sstevel@tonic-gate 	idnop_t		*idnop = NULL;
18197c478bd9Sstevel@tonic-gate 	int		error = 0;
18207c478bd9Sstevel@tonic-gate 	int		argsize;
18217c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnioctl";
18227c478bd9Sstevel@tonic-gate 
18237c478bd9Sstevel@tonic-gate 	iocp = (struct iocblk *)mp->b_rptr;
18247c478bd9Sstevel@tonic-gate 	cmd  = iocp->ioc_cmd;
18257c478bd9Sstevel@tonic-gate 
18267c478bd9Sstevel@tonic-gate 	/*
18277c478bd9Sstevel@tonic-gate 	 * Intercept DLPI ioctl's.
18287c478bd9Sstevel@tonic-gate 	 */
18297c478bd9Sstevel@tonic-gate 	if (VALID_DLPIOP(cmd)) {
18307c478bd9Sstevel@tonic-gate 		PR_STR("%s: DLPI ioctl(%d)\n", proc, cmd);
18317c478bd9Sstevel@tonic-gate 		error = idnioc_dlpi(wq, mp, &argsize);
18327c478bd9Sstevel@tonic-gate 		goto done;
18337c478bd9Sstevel@tonic-gate 	}
18347c478bd9Sstevel@tonic-gate 
18357c478bd9Sstevel@tonic-gate 	/*
18367c478bd9Sstevel@tonic-gate 	 * Validate expected arguments.
18377c478bd9Sstevel@tonic-gate 	 */
18387c478bd9Sstevel@tonic-gate 	if (!VALID_IDNIOCTL(cmd)) {
18397c478bd9Sstevel@tonic-gate 		PR_STR("%s: invalid cmd (0x%x)\n", proc, cmd);
18407c478bd9Sstevel@tonic-gate 		error = EINVAL;
18417c478bd9Sstevel@tonic-gate 		goto done;
18427c478bd9Sstevel@tonic-gate 
18437c478bd9Sstevel@tonic-gate 	} else if (!VALID_NDOP(cmd)) {
18447c478bd9Sstevel@tonic-gate 		error = miocpullup(mp, sizeof (idnop_t));
18457c478bd9Sstevel@tonic-gate 		if (error != 0) {
18467c478bd9Sstevel@tonic-gate 			PR_STR("%s: idnioc(cmd = 0x%x) miocpullup "
18477c478bd9Sstevel@tonic-gate 			    "failed (%d)\n", proc, cmd, error);
18487c478bd9Sstevel@tonic-gate 			goto done;
18497c478bd9Sstevel@tonic-gate 		}
18507c478bd9Sstevel@tonic-gate 	}
18517c478bd9Sstevel@tonic-gate 
18527c478bd9Sstevel@tonic-gate 	argsize = mp->b_cont->b_wptr - mp->b_cont->b_rptr;
18537c478bd9Sstevel@tonic-gate 	idnop = (idnop_t *)mp->b_cont->b_rptr;
18547c478bd9Sstevel@tonic-gate 
18557c478bd9Sstevel@tonic-gate 	switch (cmd) {
18567c478bd9Sstevel@tonic-gate 	case IDNIOC_LINK:
18577c478bd9Sstevel@tonic-gate 		error = idnioc_link(idnop);
18587c478bd9Sstevel@tonic-gate 		break;
18597c478bd9Sstevel@tonic-gate 
18607c478bd9Sstevel@tonic-gate 	case IDNIOC_UNLINK:
18617c478bd9Sstevel@tonic-gate 		error = idnioc_unlink(idnop);
18627c478bd9Sstevel@tonic-gate 		break;
18637c478bd9Sstevel@tonic-gate 
18647c478bd9Sstevel@tonic-gate 	case IDNIOC_MEM_RW:
18657c478bd9Sstevel@tonic-gate 		error = idn_rw_mem(idnop);
18667c478bd9Sstevel@tonic-gate 		break;
18677c478bd9Sstevel@tonic-gate 
18687c478bd9Sstevel@tonic-gate 	case IDNIOC_PING:
18697c478bd9Sstevel@tonic-gate 		error = idn_send_ping(idnop);
18707c478bd9Sstevel@tonic-gate 		break;
18717c478bd9Sstevel@tonic-gate 
18727c478bd9Sstevel@tonic-gate 	case ND_SET:
18737c478bd9Sstevel@tonic-gate 		IDN_GLOCK_EXCL();
18747c478bd9Sstevel@tonic-gate 		if (!nd_getset(wq, idn_ndlist, mp)) {
18757c478bd9Sstevel@tonic-gate 			IDN_GUNLOCK();
18767c478bd9Sstevel@tonic-gate 			error = ENOENT;
18777c478bd9Sstevel@tonic-gate 			break;
18787c478bd9Sstevel@tonic-gate 		}
18797c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
18807c478bd9Sstevel@tonic-gate 		qreply(wq, mp);
18817c478bd9Sstevel@tonic-gate 		return;
18827c478bd9Sstevel@tonic-gate 
18837c478bd9Sstevel@tonic-gate 	case ND_GET:
18847c478bd9Sstevel@tonic-gate 		IDN_GLOCK_SHARED();
18857c478bd9Sstevel@tonic-gate 		if (!nd_getset(wq, idn_ndlist, mp)) {
18867c478bd9Sstevel@tonic-gate 			IDN_GUNLOCK();
18877c478bd9Sstevel@tonic-gate 			error = ENOENT;
18887c478bd9Sstevel@tonic-gate 			break;
18897c478bd9Sstevel@tonic-gate 		}
18907c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
18917c478bd9Sstevel@tonic-gate 		qreply(wq, mp);
18927c478bd9Sstevel@tonic-gate 		return;
18937c478bd9Sstevel@tonic-gate 
18947c478bd9Sstevel@tonic-gate 	default:
18957c478bd9Sstevel@tonic-gate 		PR_STR("%s: invalid cmd 0x%x\n", proc, cmd);
18967c478bd9Sstevel@tonic-gate 		error = EINVAL;
18977c478bd9Sstevel@tonic-gate 		break;
18987c478bd9Sstevel@tonic-gate 	}
18997c478bd9Sstevel@tonic-gate 
19007c478bd9Sstevel@tonic-gate done:
19017c478bd9Sstevel@tonic-gate 	if (error == 0)
19027c478bd9Sstevel@tonic-gate 		miocack(wq, mp, argsize, 0);
19037c478bd9Sstevel@tonic-gate 	else
19047c478bd9Sstevel@tonic-gate 		miocnak(wq, mp, 0, error);
19057c478bd9Sstevel@tonic-gate }
19067c478bd9Sstevel@tonic-gate 
19077c478bd9Sstevel@tonic-gate /*
19087c478bd9Sstevel@tonic-gate  * This thread actually services the SSI_LINK/UNLINK calls
19097c478bd9Sstevel@tonic-gate  * asynchronously that come via BBSRAM.  This is necessary
19107c478bd9Sstevel@tonic-gate  * since we can't process them from within the context of
19117c478bd9Sstevel@tonic-gate  * the interrupt handler in which idn_sigbhandler() is
19127c478bd9Sstevel@tonic-gate  * called.
19137c478bd9Sstevel@tonic-gate  */
19147c478bd9Sstevel@tonic-gate static void
19157c478bd9Sstevel@tonic-gate idn_sigbhandler_thread(struct sigbintr **sbpp)
19167c478bd9Sstevel@tonic-gate {
19177c478bd9Sstevel@tonic-gate 	int		d, pri, rv;
19187c478bd9Sstevel@tonic-gate 	struct sigbintr	*sbp;
19197c478bd9Sstevel@tonic-gate 	sigbmbox_t	*mbp;
19207c478bd9Sstevel@tonic-gate 	idn_fin_t	fintype;
19217c478bd9Sstevel@tonic-gate 	idnsb_data_t	*sdp;
19227c478bd9Sstevel@tonic-gate 	idnsb_info_t	*sfp;
19237c478bd9Sstevel@tonic-gate 	idnsb_error_t	*sep;
19247c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp;
19257c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_sigbhandler_thread";
19267c478bd9Sstevel@tonic-gate 
19277c478bd9Sstevel@tonic-gate 
19287c478bd9Sstevel@tonic-gate 	sbp = *sbpp;
19297c478bd9Sstevel@tonic-gate 
1930bf30efa4Smathue 	PR_PROTO("%s: KICKED OFF (sigbintr pointer = 0x%p)\n",
193107d06da5SSurya Prakki 	    proc, (void *)sbp);
19327c478bd9Sstevel@tonic-gate 
19337c478bd9Sstevel@tonic-gate 	ASSERT(sbp == &idn.sigbintr);
19347c478bd9Sstevel@tonic-gate 
19357c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.sigbintr.sb_mutex);
19367c478bd9Sstevel@tonic-gate 
19377c478bd9Sstevel@tonic-gate 	while (sbp->sb_busy != IDNSIGB_DIE) {
19387c478bd9Sstevel@tonic-gate 		cpu_sgnblk_t	*sigbp;
19397c478bd9Sstevel@tonic-gate 
19407c478bd9Sstevel@tonic-gate 		while ((sbp->sb_busy != IDNSIGB_ACTIVE) &&
19417c478bd9Sstevel@tonic-gate 		    (sbp->sb_busy != IDNSIGB_DIE)) {
19427c478bd9Sstevel@tonic-gate 			cv_wait(&sbp->sb_cv, &idn.sigbintr.sb_mutex);
19437c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: AWAKENED (busy = %d)\n",
19447c478bd9Sstevel@tonic-gate 			    proc, (int)sbp->sb_busy);
19457c478bd9Sstevel@tonic-gate 		}
19467c478bd9Sstevel@tonic-gate 		if (sbp->sb_busy == IDNSIGB_DIE) {
19477c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: DIE REQUESTED\n", proc);
19487c478bd9Sstevel@tonic-gate 			break;
19497c478bd9Sstevel@tonic-gate 		}
19507c478bd9Sstevel@tonic-gate 
19517c478bd9Sstevel@tonic-gate 		if ((sigbp = cpu_sgnblkp[sbp->sb_cpuid]) == NULL) {
19527c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
19537c478bd9Sstevel@tonic-gate 			    "IDN: 124: sigblk for CPU ID %d "
19547c478bd9Sstevel@tonic-gate 			    "is NULL", sbp->sb_cpuid);
19557c478bd9Sstevel@tonic-gate 			sbp->sb_busy = IDNSIGB_INACTIVE;
19567c478bd9Sstevel@tonic-gate 			continue;
19577c478bd9Sstevel@tonic-gate 		}
19587c478bd9Sstevel@tonic-gate 
19597c478bd9Sstevel@tonic-gate 		mbp = &sigbp->sigb_host_mbox;
19607c478bd9Sstevel@tonic-gate 
19617c478bd9Sstevel@tonic-gate 		if (mbp->flag != SIGB_MBOX_BUSY) {
19627c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: sigblk mbox flag (%d) != BUSY (%d)\n",
19637c478bd9Sstevel@tonic-gate 			    proc, mbp->flag, SIGB_MBOX_BUSY);
19647c478bd9Sstevel@tonic-gate 			sbp->sb_busy = IDNSIGB_INACTIVE;
19657c478bd9Sstevel@tonic-gate 			continue;
19667c478bd9Sstevel@tonic-gate 		}
19677c478bd9Sstevel@tonic-gate 		/*
19687c478bd9Sstevel@tonic-gate 		 * The sb_busy bit is set and the mailbox flag
19697c478bd9Sstevel@tonic-gate 		 * indicates BUSY also, so we effectively have things locked.
19707c478bd9Sstevel@tonic-gate 		 * So, we can drop the critical sb_mutex which we want to
19717c478bd9Sstevel@tonic-gate 		 * do since it pushes us to PIL 14 while we hold it and we
19727c478bd9Sstevel@tonic-gate 		 * don't want to run at PIL 14 across IDN code.
19737c478bd9Sstevel@tonic-gate 		 */
19747c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.sigbintr.sb_mutex);
19757c478bd9Sstevel@tonic-gate 
19767c478bd9Sstevel@tonic-gate 		sdp = (idnsb_data_t *)mbp->data;
19777c478bd9Sstevel@tonic-gate 		sep = (idnsb_error_t *)&sdp->ssb_error;
19787c478bd9Sstevel@tonic-gate 		INIT_IDNKERR(sep);
19797c478bd9Sstevel@tonic-gate 
19807c478bd9Sstevel@tonic-gate 		if (mbp->len != sizeof (idnsb_data_t)) {
19817c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: sigblk mbox length (%d) != "
1982bf30efa4Smathue 			    "expected (%lu)\n", proc, mbp->len,
19837c478bd9Sstevel@tonic-gate 			    sizeof (idnsb_data_t));
19847c478bd9Sstevel@tonic-gate 			SET_IDNKERR_ERRNO(sep, EINVAL);
19857c478bd9Sstevel@tonic-gate 			SET_IDNKERR_IDNERR(sep, IDNKERR_DATA_LEN);
19867c478bd9Sstevel@tonic-gate 			SET_IDNKERR_PARAM0(sep, sizeof (idnsb_data_t));
19877c478bd9Sstevel@tonic-gate 
19887c478bd9Sstevel@tonic-gate 			goto sberr;
19897c478bd9Sstevel@tonic-gate 
19907c478bd9Sstevel@tonic-gate 		}
19917c478bd9Sstevel@tonic-gate 		if (idn.enabled == 0) {
19927c478bd9Sstevel@tonic-gate #ifdef DEBUG
19937c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE,
19947c478bd9Sstevel@tonic-gate 			    "IDN: 102: driver disabled "
19957c478bd9Sstevel@tonic-gate 			    "- check OBP environment "
19967c478bd9Sstevel@tonic-gate 			    "(idn-smr-size)");
19977c478bd9Sstevel@tonic-gate #else /* DEBUG */
19987c478bd9Sstevel@tonic-gate 			cmn_err(CE_NOTE,
19997c478bd9Sstevel@tonic-gate 			    "!IDN: 102: driver disabled "
20007c478bd9Sstevel@tonic-gate 			    "- check OBP environment "
20017c478bd9Sstevel@tonic-gate 			    "(idn-smr-size)");
20027c478bd9Sstevel@tonic-gate #endif /* DEBUG */
20037c478bd9Sstevel@tonic-gate 			SET_IDNKERR_ERRNO(sep, EACCES);
20047c478bd9Sstevel@tonic-gate 			SET_IDNKERR_IDNERR(sep, IDNKERR_DRV_DISABLED);
20057c478bd9Sstevel@tonic-gate 
20067c478bd9Sstevel@tonic-gate 			goto sberr;
20077c478bd9Sstevel@tonic-gate 
20087c478bd9Sstevel@tonic-gate 		}
20097c478bd9Sstevel@tonic-gate 
20107c478bd9Sstevel@tonic-gate 		switch (mbp->cmd) {
20117c478bd9Sstevel@tonic-gate 
20127c478bd9Sstevel@tonic-gate 		case SSI_LINK:
20137c478bd9Sstevel@tonic-gate 		{
20147c478bd9Sstevel@tonic-gate 			idnsb_link_t	slp;
20157c478bd9Sstevel@tonic-gate 
20167c478bd9Sstevel@tonic-gate 			bcopy(&sdp->ssb_link, &slp, sizeof (slp));
20177c478bd9Sstevel@tonic-gate 
20187c478bd9Sstevel@tonic-gate 			if (slp.master_pri < 0) {
20197c478bd9Sstevel@tonic-gate 				pri = IDNVOTE_MINPRI;
20207c478bd9Sstevel@tonic-gate 			} else if (slp.master_pri > 0) {
20217c478bd9Sstevel@tonic-gate 				/*
20227c478bd9Sstevel@tonic-gate 				 * If I'm already in a IDN network,
20237c478bd9Sstevel@tonic-gate 				 * then my vote priority is set to
20247c478bd9Sstevel@tonic-gate 				 * the max, otherwise it's one-less.
20257c478bd9Sstevel@tonic-gate 				 */
20267c478bd9Sstevel@tonic-gate 				pri = IDNVOTE_MAXPRI;
20277c478bd9Sstevel@tonic-gate 				IDN_GLOCK_SHARED();
20287c478bd9Sstevel@tonic-gate 				if (idn.ndomains <= 1)
20297c478bd9Sstevel@tonic-gate 					pri--;
20307c478bd9Sstevel@tonic-gate 				IDN_GUNLOCK();
20317c478bd9Sstevel@tonic-gate 			} else {
20327c478bd9Sstevel@tonic-gate 				pri = IDNVOTE_DEFPRI;
20337c478bd9Sstevel@tonic-gate 			}
20347c478bd9Sstevel@tonic-gate 
20357c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: SSI_LINK(cpuid = %d, domid = %d, "
20367c478bd9Sstevel@tonic-gate 			    "pri = %d (req = %d), t/o = %d)\n",
20377c478bd9Sstevel@tonic-gate 			    proc, slp.cpuid, slp.domid, pri,
20387c478bd9Sstevel@tonic-gate 			    slp.master_pri, slp.timeout);
20397c478bd9Sstevel@tonic-gate 
20407c478bd9Sstevel@tonic-gate 			rv = idn_link(slp.domid, slp.cpuid, pri,
20417c478bd9Sstevel@tonic-gate 			    slp.timeout, sep);
20427c478bd9Sstevel@tonic-gate 			SET_IDNKERR_ERRNO(sep, rv);
20437c478bd9Sstevel@tonic-gate 			(void) idn_info(&sdp->ssb_info);
20447c478bd9Sstevel@tonic-gate 			break;
20457c478bd9Sstevel@tonic-gate 		}
20467c478bd9Sstevel@tonic-gate 
20477c478bd9Sstevel@tonic-gate 		case SSI_UNLINK:
20487c478bd9Sstevel@tonic-gate 		{
20497c478bd9Sstevel@tonic-gate 			idnsb_unlink_t	sup;
20507c478bd9Sstevel@tonic-gate 			idn_domain_t	*xdp;
20517c478bd9Sstevel@tonic-gate 			domainset_t	domset;
20527c478bd9Sstevel@tonic-gate 
20537c478bd9Sstevel@tonic-gate 			bcopy(&sdp->ssb_unlink, &sup, sizeof (sup));
20547c478bd9Sstevel@tonic-gate 
20557c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: SSI_UNLINK(c = %d, d = %d, bs = 0x%x, "
20567c478bd9Sstevel@tonic-gate 			    "f = %d, is = 0x%x, t/o = %d)\n",
20577c478bd9Sstevel@tonic-gate 			    proc, sup.cpuid, sup.domid, sup.boardset,
20587c478bd9Sstevel@tonic-gate 			    sup.force, sup.idnset, sup.timeout);
20597c478bd9Sstevel@tonic-gate 
20607c478bd9Sstevel@tonic-gate 			domset = idn.domset.ds_trans_on |
20617c478bd9Sstevel@tonic-gate 			    idn.domset.ds_connected |
20627c478bd9Sstevel@tonic-gate 			    idn.domset.ds_trans_off |
20637c478bd9Sstevel@tonic-gate 			    idn.domset.ds_awol |
20647c478bd9Sstevel@tonic-gate 			    idn.domset.ds_relink;
20657c478bd9Sstevel@tonic-gate 
20667c478bd9Sstevel@tonic-gate 			if (VALID_DOMAINID(sup.domid)) {
20677c478bd9Sstevel@tonic-gate 				dp = &idn_domain[sup.domid];
20687c478bd9Sstevel@tonic-gate 			} else if (VALID_CPUID(sup.cpuid)) {
20697c478bd9Sstevel@tonic-gate 				for (d = 0; d < MAX_DOMAINS; d++) {
20707c478bd9Sstevel@tonic-gate 					xdp = &idn_domain[d];
20717c478bd9Sstevel@tonic-gate 
20727c478bd9Sstevel@tonic-gate 					if ((xdp->dcpu == IDN_NIL_DCPU) &&
20737c478bd9Sstevel@tonic-gate 					    !DOMAIN_IN_SET(domset, d))
20747c478bd9Sstevel@tonic-gate 						continue;
20757c478bd9Sstevel@tonic-gate 
20767c478bd9Sstevel@tonic-gate 					if (CPU_IN_SET(xdp->dcpuset,
20777c478bd9Sstevel@tonic-gate 					    sup.cpuid))
20787c478bd9Sstevel@tonic-gate 						break;
20797c478bd9Sstevel@tonic-gate 				}
20807c478bd9Sstevel@tonic-gate 				dp = (d == MAX_DOMAINS) ? NULL : xdp;
20817c478bd9Sstevel@tonic-gate 			}
20827c478bd9Sstevel@tonic-gate 			if ((dp == NULL) && sup.boardset) {
20837c478bd9Sstevel@tonic-gate 				for (d = 0; d < MAX_DOMAINS; d++) {
20847c478bd9Sstevel@tonic-gate 					xdp = &idn_domain[d];
20857c478bd9Sstevel@tonic-gate 
20867c478bd9Sstevel@tonic-gate 					if ((xdp->dcpu == IDN_NIL_DCPU) &&
20877c478bd9Sstevel@tonic-gate 					    !DOMAIN_IN_SET(domset, d))
20887c478bd9Sstevel@tonic-gate 						continue;
20897c478bd9Sstevel@tonic-gate 
20907c478bd9Sstevel@tonic-gate 					if (xdp->dhw.dh_boardset &
20917c478bd9Sstevel@tonic-gate 					    sup.boardset)
20927c478bd9Sstevel@tonic-gate 						break;
20937c478bd9Sstevel@tonic-gate 				}
20947c478bd9Sstevel@tonic-gate 				dp = (d == MAX_DOMAINS) ? NULL : xdp;
20957c478bd9Sstevel@tonic-gate 			}
20967c478bd9Sstevel@tonic-gate 			if (dp == NULL) {
20977c478bd9Sstevel@tonic-gate 				SET_IDNKERR_ERRNO(sep, EINVAL);
20987c478bd9Sstevel@tonic-gate 				SET_IDNKERR_IDNERR(sep, IDNKERR_INVALID_DOMAIN);
20997c478bd9Sstevel@tonic-gate 				SET_IDNKERR_PARAM0(sep, sup.domid);
21007c478bd9Sstevel@tonic-gate 				SET_IDNKERR_PARAM1(sep, sup.cpuid);
21017c478bd9Sstevel@tonic-gate 				(void) idn_info(&sdp->ssb_info);
21027c478bd9Sstevel@tonic-gate 				goto sberr;
21037c478bd9Sstevel@tonic-gate 			} else {
21047c478bd9Sstevel@tonic-gate 				sup.domid = dp->domid;
21057c478bd9Sstevel@tonic-gate 			}
21067c478bd9Sstevel@tonic-gate 
21077c478bd9Sstevel@tonic-gate 			switch (sup.force) {
21087c478bd9Sstevel@tonic-gate 			case SSIFORCE_OFF:
21097c478bd9Sstevel@tonic-gate 				fintype = IDNFIN_NORMAL;
21107c478bd9Sstevel@tonic-gate 				break;
21117c478bd9Sstevel@tonic-gate 
21127c478bd9Sstevel@tonic-gate 			case SSIFORCE_SOFT:
21137c478bd9Sstevel@tonic-gate 				fintype = IDNFIN_FORCE_SOFT;
21147c478bd9Sstevel@tonic-gate 				break;
21157c478bd9Sstevel@tonic-gate 
21167c478bd9Sstevel@tonic-gate 			case SSIFORCE_HARD:
21177c478bd9Sstevel@tonic-gate 				fintype = IDNFIN_FORCE_HARD;
21187c478bd9Sstevel@tonic-gate 				break;
21197c478bd9Sstevel@tonic-gate 			default:
21207c478bd9Sstevel@tonic-gate 				SET_IDNKERR_ERRNO(sep, EINVAL);
21217c478bd9Sstevel@tonic-gate 				SET_IDNKERR_IDNERR(sep, IDNKERR_INVALID_FORCE);
21227c478bd9Sstevel@tonic-gate 				SET_IDNKERR_PARAM0(sep, sup.force);
21237c478bd9Sstevel@tonic-gate 				(void) idn_info(&sdp->ssb_info);
21247c478bd9Sstevel@tonic-gate 				goto sberr;
21257c478bd9Sstevel@tonic-gate 			}
21267c478bd9Sstevel@tonic-gate 
21277c478bd9Sstevel@tonic-gate 			rv = idn_unlink(sup.domid, sup.idnset, fintype,
21287c478bd9Sstevel@tonic-gate 			    IDNFIN_OPT_UNLINK, sup.timeout, sep);
21297c478bd9Sstevel@tonic-gate 			SET_IDNKERR_ERRNO(sep, rv);
21307c478bd9Sstevel@tonic-gate 			(void) idn_info(&sdp->ssb_info);
21317c478bd9Sstevel@tonic-gate 			break;
21327c478bd9Sstevel@tonic-gate 		}
21337c478bd9Sstevel@tonic-gate 
21347c478bd9Sstevel@tonic-gate 		case SSI_INFO:
21357c478bd9Sstevel@tonic-gate 			sfp = &sdp->ssb_info;
21367c478bd9Sstevel@tonic-gate 
21377c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: SSI_INFO\n", proc);
21387c478bd9Sstevel@tonic-gate 
21397c478bd9Sstevel@tonic-gate 			rv = idn_info(sfp);
21407c478bd9Sstevel@tonic-gate 			SET_IDNKERR_ERRNO(sep, rv);
21417c478bd9Sstevel@tonic-gate 			if (rv != 0) {
21427c478bd9Sstevel@tonic-gate 				SET_IDNKERR_IDNERR(sep, IDNKERR_INFO_FAILED);
21437c478bd9Sstevel@tonic-gate 			}
21447c478bd9Sstevel@tonic-gate 			break;
21457c478bd9Sstevel@tonic-gate 
21467c478bd9Sstevel@tonic-gate 		default:
21477c478bd9Sstevel@tonic-gate 			ASSERT(0);
21487c478bd9Sstevel@tonic-gate 			SET_IDNKERR_ERRNO(sep, EINVAL);
21497c478bd9Sstevel@tonic-gate 			SET_IDNKERR_IDNERR(sep, IDNKERR_INVALID_CMD);
21507c478bd9Sstevel@tonic-gate 			SET_IDNKERR_PARAM0(sep, mbp->cmd);
21517c478bd9Sstevel@tonic-gate 			break;
21527c478bd9Sstevel@tonic-gate 		}
21537c478bd9Sstevel@tonic-gate 
21547c478bd9Sstevel@tonic-gate sberr:
21557c478bd9Sstevel@tonic-gate 
21567c478bd9Sstevel@tonic-gate 		if (GET_IDNKERR_ERRNO(sep) != 0) {
21577c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
21587c478bd9Sstevel@tonic-gate #ifdef DEBUG
21597c478bd9Sstevel@tonic-gate 			    "IDN: 125: op (%s) failed, returning "
21607c478bd9Sstevel@tonic-gate 			    "(%d/0x%x [%d, %d, %d])",
21617c478bd9Sstevel@tonic-gate #else /* DEBUG */
21627c478bd9Sstevel@tonic-gate 			    "!IDN: 125: op (%s) failed, returning "
21637c478bd9Sstevel@tonic-gate 			    "(%d/0x%x [%d, %d, %d])",
21647c478bd9Sstevel@tonic-gate #endif /* DEBUG */
21657c478bd9Sstevel@tonic-gate 			    (mbp->cmd == SSI_LINK) ? "LINK" :
21667c478bd9Sstevel@tonic-gate 			    (mbp->cmd == SSI_UNLINK) ? "UNLINK" :
21677c478bd9Sstevel@tonic-gate 			    (mbp->cmd == SSI_INFO) ?
21687c478bd9Sstevel@tonic-gate 			    "INFO" : "UNKNOWN",
21697c478bd9Sstevel@tonic-gate 			    GET_IDNKERR_ERRNO(sep),
21707c478bd9Sstevel@tonic-gate 			    GET_IDNKERR_IDNERR(sep),
21717c478bd9Sstevel@tonic-gate 			    GET_IDNKERR_PARAM0(sep),
21727c478bd9Sstevel@tonic-gate 			    GET_IDNKERR_PARAM1(sep),
21737c478bd9Sstevel@tonic-gate 			    GET_IDNKERR_PARAM2(sep));
21747c478bd9Sstevel@tonic-gate 		}
21757c478bd9Sstevel@tonic-gate 
21767c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: returning errno = %d, idnerr = %d, "
21777c478bd9Sstevel@tonic-gate 		    "params = [%d, %d, %d]\n",
21787c478bd9Sstevel@tonic-gate 		    proc, GET_IDNKERR_ERRNO(sep), GET_IDNKERR_IDNERR(sep),
21797c478bd9Sstevel@tonic-gate 		    GET_IDNKERR_PARAM0(sep), GET_IDNKERR_PARAM1(sep),
21807c478bd9Sstevel@tonic-gate 		    GET_IDNKERR_PARAM2(sep));
21817c478bd9Sstevel@tonic-gate 
21827c478bd9Sstevel@tonic-gate 		mutex_enter(&idn.sigbintr.sb_mutex);
21837c478bd9Sstevel@tonic-gate 		ASSERT((sbp->sb_busy == IDNSIGB_ACTIVE) ||
21847c478bd9Sstevel@tonic-gate 		    (sbp->sb_busy == IDNSIGB_DIE));
21857c478bd9Sstevel@tonic-gate 		mbp->cmd |= SSI_ACK;
21867c478bd9Sstevel@tonic-gate 		if (sbp->sb_busy == IDNSIGB_ACTIVE)
21877c478bd9Sstevel@tonic-gate 			sbp->sb_busy = IDNSIGB_INACTIVE;
21887c478bd9Sstevel@tonic-gate 		/*
21897c478bd9Sstevel@tonic-gate 		 * Set flag which kicks off response to SSP.
21907c478bd9Sstevel@tonic-gate 		 */
21917c478bd9Sstevel@tonic-gate 		membar_stst_ldst();
21927c478bd9Sstevel@tonic-gate 		mbp->flag = HOST_TO_CBS;
21937c478bd9Sstevel@tonic-gate 	}
21947c478bd9Sstevel@tonic-gate 
21957c478bd9Sstevel@tonic-gate 	/*
21967c478bd9Sstevel@tonic-gate 	 * Wake up the dude that killed us!
21977c478bd9Sstevel@tonic-gate 	 */
21987c478bd9Sstevel@tonic-gate 	idn.sigb_threadp = NULL;
21997c478bd9Sstevel@tonic-gate 	cv_signal(&sbp->sb_cv);
22007c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.sigbintr.sb_mutex);
22017c478bd9Sstevel@tonic-gate 	thread_exit();
22027c478bd9Sstevel@tonic-gate }
22037c478bd9Sstevel@tonic-gate 
22047c478bd9Sstevel@tonic-gate /*
22057c478bd9Sstevel@tonic-gate  * Create the thread that will service sigb interrupts.
22067c478bd9Sstevel@tonic-gate  */
22077c478bd9Sstevel@tonic-gate static void
22087c478bd9Sstevel@tonic-gate idn_sigbhandler_create()
22097c478bd9Sstevel@tonic-gate {
22107c478bd9Sstevel@tonic-gate 	struct sigbintr	*sbp;
22117c478bd9Sstevel@tonic-gate 
22127c478bd9Sstevel@tonic-gate 	if (idn.sigb_threadp) {
22137c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
22147c478bd9Sstevel@tonic-gate 		    "IDN: 126: sigbhandler thread already "
221507d06da5SSurya Prakki 		    "exists (0x%p)", (void *)idn.sigb_threadp);
22167c478bd9Sstevel@tonic-gate 		return;
22177c478bd9Sstevel@tonic-gate 	}
22187c478bd9Sstevel@tonic-gate 	cv_init(&idn.sigbintr.sb_cv, NULL, CV_DEFAULT, NULL);
22197c478bd9Sstevel@tonic-gate 	sbp = &idn.sigbintr;
22207c478bd9Sstevel@tonic-gate 	sbp->sb_busy = IDNSIGB_INACTIVE;
22217c478bd9Sstevel@tonic-gate 	idn.sigb_threadp = thread_create(NULL, 0,
22227c478bd9Sstevel@tonic-gate 	    idn_sigbhandler_thread, &sbp, sizeof (sbp), &p0,
22237c478bd9Sstevel@tonic-gate 	    TS_RUN, minclsyspri);
22247c478bd9Sstevel@tonic-gate 	sbp->sb_inum = add_softintr((uint_t)idn_sigbpil,
2225b0fc0e77Sgovinda 	    idn_sigbhandler_wakeup, 0, SOFTINT_ST);
22267c478bd9Sstevel@tonic-gate }
22277c478bd9Sstevel@tonic-gate 
22287c478bd9Sstevel@tonic-gate static void
22297c478bd9Sstevel@tonic-gate idn_sigbhandler_kill()
22307c478bd9Sstevel@tonic-gate {
22317c478bd9Sstevel@tonic-gate 	if (idn.sigb_threadp) {
22327c478bd9Sstevel@tonic-gate 		struct sigbintr	*sbp;
22337c478bd9Sstevel@tonic-gate 
22347c478bd9Sstevel@tonic-gate 		sbp = &idn.sigbintr;
22357c478bd9Sstevel@tonic-gate 		if (sbp->sb_inum != 0)
2236b0fc0e77Sgovinda 			(void) rem_softintr(sbp->sb_inum);
22377c478bd9Sstevel@tonic-gate 		sbp->sb_inum = 0;
22387c478bd9Sstevel@tonic-gate 		sbp->sb_busy = IDNSIGB_DIE;
22397c478bd9Sstevel@tonic-gate 		cv_signal(&sbp->sb_cv);
22407c478bd9Sstevel@tonic-gate 		while (idn.sigb_threadp != NULL)
22417c478bd9Sstevel@tonic-gate 			cv_wait(&sbp->sb_cv, &idn.sigbintr.sb_mutex);
22427c478bd9Sstevel@tonic-gate 		sbp->sb_busy = IDNSIGB_INACTIVE;
22437c478bd9Sstevel@tonic-gate 		cv_destroy(&sbp->sb_cv);
22447c478bd9Sstevel@tonic-gate 	}
22457c478bd9Sstevel@tonic-gate }
22467c478bd9Sstevel@tonic-gate 
22477c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
22487c478bd9Sstevel@tonic-gate static uint_t
22497c478bd9Sstevel@tonic-gate idn_sigbhandler_wakeup(caddr_t arg1, caddr_t arg2)
22507c478bd9Sstevel@tonic-gate {
22517c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.sigbintr.sb_mutex);
22527c478bd9Sstevel@tonic-gate 	if (idn.sigbintr.sb_busy == IDNSIGB_STARTED) {
22537c478bd9Sstevel@tonic-gate 		idn.sigbintr.sb_busy = IDNSIGB_ACTIVE;
22547c478bd9Sstevel@tonic-gate 		cv_signal(&idn.sigbintr.sb_cv);
22557c478bd9Sstevel@tonic-gate 	}
22567c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.sigbintr.sb_mutex);
22577c478bd9Sstevel@tonic-gate 
22587c478bd9Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
22597c478bd9Sstevel@tonic-gate }
22607c478bd9Sstevel@tonic-gate 
22617c478bd9Sstevel@tonic-gate static void
22627c478bd9Sstevel@tonic-gate idn_sigbhandler(processorid_t cpuid, cpu_sgnblk_t *sgnblkp)
22637c478bd9Sstevel@tonic-gate {
22647c478bd9Sstevel@tonic-gate 	struct sigbintr	*sbp = &idn.sigbintr;
22657c478bd9Sstevel@tonic-gate 	sigbmbox_t	*mbp;
22667c478bd9Sstevel@tonic-gate 	idnsb_data_t	*sdp;
22677c478bd9Sstevel@tonic-gate 	idnsb_error_t	*sep;
22687c478bd9Sstevel@tonic-gate 	uint32_t	cmd;
22697c478bd9Sstevel@tonic-gate 	int		sigb_lock = 0;
22707c478bd9Sstevel@tonic-gate 
22717c478bd9Sstevel@tonic-gate 	ASSERT(sgnblkp);
22727c478bd9Sstevel@tonic-gate 
22737c478bd9Sstevel@tonic-gate 	mbp = &sgnblkp->sigb_host_mbox;
22747c478bd9Sstevel@tonic-gate 	sdp = (idnsb_data_t *)mbp->data;
22757c478bd9Sstevel@tonic-gate 	sep = &sdp->ssb_error;
22767c478bd9Sstevel@tonic-gate 	cmd = mbp->cmd;
22777c478bd9Sstevel@tonic-gate 
22787c478bd9Sstevel@tonic-gate 	if ((mbp->flag != CBS_TO_HOST) || !VALID_IDNSIGBCMD(cmd)) {
22797c478bd9Sstevel@tonic-gate 		/*
22807c478bd9Sstevel@tonic-gate 		 * Not a valid IDN command.  Just bail out.
22817c478bd9Sstevel@tonic-gate 		 */
22827c478bd9Sstevel@tonic-gate 		return;
22837c478bd9Sstevel@tonic-gate 	}
22847c478bd9Sstevel@tonic-gate 
22857c478bd9Sstevel@tonic-gate 	mbp->flag = SIGB_MBOX_BUSY;
22867c478bd9Sstevel@tonic-gate 	SET_IDNKERR_ERRNO(sep, 0);
22877c478bd9Sstevel@tonic-gate 
22887c478bd9Sstevel@tonic-gate 	if (cmd & SSI_ACK) {
22897c478bd9Sstevel@tonic-gate 		/*
22907c478bd9Sstevel@tonic-gate 		 * Hmmm...weird, the ACK bit is set.
22917c478bd9Sstevel@tonic-gate 		 */
22927c478bd9Sstevel@tonic-gate 		SET_IDNKERR_ERRNO(sep, EPROTO);
22937c478bd9Sstevel@tonic-gate 		SET_IDNKERR_IDNERR(sep, IDNKERR_INVALID_CMD);
22947c478bd9Sstevel@tonic-gate 		SET_IDNKERR_PARAM0(sep, cmd);
22957c478bd9Sstevel@tonic-gate 		goto sigb_done;
22967c478bd9Sstevel@tonic-gate 	}
22977c478bd9Sstevel@tonic-gate 
22987c478bd9Sstevel@tonic-gate 	if (!mutex_tryenter(&idn.sigbintr.sb_mutex)) {
22997c478bd9Sstevel@tonic-gate 		/*
23007c478bd9Sstevel@tonic-gate 		 * Couldn't get the lock.  Driver is either
23017c478bd9Sstevel@tonic-gate 		 * not quite all the way up or is shutting down
23027c478bd9Sstevel@tonic-gate 		 * for some reason.  Caller should spin again.
23037c478bd9Sstevel@tonic-gate 		 */
23047c478bd9Sstevel@tonic-gate 		cmd |= SSI_ACK;
23057c478bd9Sstevel@tonic-gate 		SET_IDNKERR_ERRNO(sep, EBUSY);
23067c478bd9Sstevel@tonic-gate 		SET_IDNKERR_IDNERR(sep, IDNKERR_SIGBINTR_LOCKED);
23077c478bd9Sstevel@tonic-gate 		goto sigb_done;
23087c478bd9Sstevel@tonic-gate 	}
23097c478bd9Sstevel@tonic-gate 	sigb_lock = 1;
23107c478bd9Sstevel@tonic-gate 
23117c478bd9Sstevel@tonic-gate 	if ((idn.sigb_threadp == NULL) ||
23127c478bd9Sstevel@tonic-gate 	    (sbp->sb_busy == IDNSIGB_NOTREADY)) {
23137c478bd9Sstevel@tonic-gate 		cmd |= SSI_ACK;
23147c478bd9Sstevel@tonic-gate 		SET_IDNKERR_ERRNO(sep, EAGAIN);
23157c478bd9Sstevel@tonic-gate 		SET_IDNKERR_IDNERR(sep, IDNKERR_SIGBINTR_NOTRDY);
23167c478bd9Sstevel@tonic-gate 		goto sigb_done;
23177c478bd9Sstevel@tonic-gate 	}
23187c478bd9Sstevel@tonic-gate 
23197c478bd9Sstevel@tonic-gate 	if (sbp->sb_busy != IDNSIGB_INACTIVE) {
23207c478bd9Sstevel@tonic-gate 		cmd |= SSI_ACK;
23217c478bd9Sstevel@tonic-gate 		SET_IDNKERR_ERRNO(sep, EBUSY);
23227c478bd9Sstevel@tonic-gate 		SET_IDNKERR_IDNERR(sep, IDNKERR_SIGBINTR_BUSY);
23237c478bd9Sstevel@tonic-gate 		goto sigb_done;
23247c478bd9Sstevel@tonic-gate 	}
23257c478bd9Sstevel@tonic-gate 
23267c478bd9Sstevel@tonic-gate 	sbp->sb_cpuid = (uchar_t)cpuid & 0xff;
23277c478bd9Sstevel@tonic-gate 	membar_stst_ldst();
23287c478bd9Sstevel@tonic-gate 	sbp->sb_busy = IDNSIGB_STARTED;
23297c478bd9Sstevel@tonic-gate 	/*
23307c478bd9Sstevel@tonic-gate 	 * The sb_busy bit is set and the mailbox flag
23317c478bd9Sstevel@tonic-gate 	 * indicates BUSY also, so we effectively have things locked.
23327c478bd9Sstevel@tonic-gate 	 * So, we can drop the critical sb_mutex which we want to
23337c478bd9Sstevel@tonic-gate 	 * do since it pushes us to PIL 14 while we hold it and we
23347c478bd9Sstevel@tonic-gate 	 * don't want to run at PIL 14 across IDN code.
23357c478bd9Sstevel@tonic-gate 	 *
23367c478bd9Sstevel@tonic-gate 	 * Send interrupt to cause idn_sigbhandler_thread to wakeup.
23377c478bd9Sstevel@tonic-gate 	 * We cannot do wakeup (cv_signal) directly from here since
23387c478bd9Sstevel@tonic-gate 	 * we're executing from a high-level (14) interrupt.
23397c478bd9Sstevel@tonic-gate 	 */
23407c478bd9Sstevel@tonic-gate 	setsoftint(sbp->sb_inum);
23417c478bd9Sstevel@tonic-gate 
23427c478bd9Sstevel@tonic-gate sigb_done:
23437c478bd9Sstevel@tonic-gate 
23447c478bd9Sstevel@tonic-gate 	if (GET_IDNKERR_ERRNO(sep) != 0) {
23457c478bd9Sstevel@tonic-gate 		mbp->len = sizeof (idnsb_data_t);
23467c478bd9Sstevel@tonic-gate 		mbp->cmd = cmd;
23477c478bd9Sstevel@tonic-gate 		membar_stst_ldst();
23487c478bd9Sstevel@tonic-gate 		mbp->flag = HOST_TO_CBS;
23497c478bd9Sstevel@tonic-gate 	}
23507c478bd9Sstevel@tonic-gate 
23517c478bd9Sstevel@tonic-gate 	if (sigb_lock)
23527c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.sigbintr.sb_mutex);
23537c478bd9Sstevel@tonic-gate }
23547c478bd9Sstevel@tonic-gate 
23557c478bd9Sstevel@tonic-gate static int
23567c478bd9Sstevel@tonic-gate idn_info(idnsb_info_t *sfp)
23577c478bd9Sstevel@tonic-gate {
23587c478bd9Sstevel@tonic-gate 	int		count, d;
23597c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp;
23607c478bd9Sstevel@tonic-gate 	idnsb_info_t	sinfo;
23617c478bd9Sstevel@tonic-gate 	int		local_id, master_id;
23627c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_info";
23637c478bd9Sstevel@tonic-gate 
23647c478bd9Sstevel@tonic-gate 	bzero(&sinfo, sizeof (sinfo));
23657c478bd9Sstevel@tonic-gate 	sinfo.master_index = (uchar_t)-1;
23667c478bd9Sstevel@tonic-gate 	sinfo.master_cpuid = (uchar_t)-1;
23677c478bd9Sstevel@tonic-gate 	sinfo.local_index  = (uchar_t)-1;
23687c478bd9Sstevel@tonic-gate 	sinfo.local_cpuid  = (uchar_t)-1;
23697c478bd9Sstevel@tonic-gate 
23707c478bd9Sstevel@tonic-gate 	IDN_GLOCK_SHARED();
23717c478bd9Sstevel@tonic-gate 
23727c478bd9Sstevel@tonic-gate 	sinfo.idn_state = (uchar_t)idn.state;
23737c478bd9Sstevel@tonic-gate 
23747c478bd9Sstevel@tonic-gate 	switch (idn.state) {
23757c478bd9Sstevel@tonic-gate 	case IDNGS_OFFLINE:
23767c478bd9Sstevel@tonic-gate 		sinfo.idn_active = SSISTATE_INACTIVE;
23777c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: idn_state (%s) = INACTIVE\n",
23787c478bd9Sstevel@tonic-gate 		    proc, idngs_str[idn.state]);
23797c478bd9Sstevel@tonic-gate 		break;
23807c478bd9Sstevel@tonic-gate 
23817c478bd9Sstevel@tonic-gate 	case IDNGS_IGNORE:
23827c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: IGNORING IDN_INFO call...\n", proc);
23837c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
23847c478bd9Sstevel@tonic-gate 		return (EIO);
23857c478bd9Sstevel@tonic-gate 
23867c478bd9Sstevel@tonic-gate 	default:
23877c478bd9Sstevel@tonic-gate 		sinfo.idn_active = SSISTATE_ACTIVE;
23887c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: idn_state (%s) = ACTIVE\n",
23897c478bd9Sstevel@tonic-gate 		    proc, idngs_str[idn.state]);
23907c478bd9Sstevel@tonic-gate 		break;
23917c478bd9Sstevel@tonic-gate 	}
23927c478bd9Sstevel@tonic-gate 	master_id = IDN_GET_MASTERID();
23937c478bd9Sstevel@tonic-gate 	local_id = idn.localid;
23947c478bd9Sstevel@tonic-gate 
23957c478bd9Sstevel@tonic-gate 	/*
23967c478bd9Sstevel@tonic-gate 	 * Need to drop idn.grwlock before acquiring domain locks.
23977c478bd9Sstevel@tonic-gate 	 */
23987c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
23997c478bd9Sstevel@tonic-gate 
24007c478bd9Sstevel@tonic-gate 	IDN_SYNC_LOCK();
24017c478bd9Sstevel@tonic-gate 
24027c478bd9Sstevel@tonic-gate 	sinfo.awol_domset = (ushort_t)idn.domset.ds_awol;
24037c478bd9Sstevel@tonic-gate 	sinfo.conn_domset = (ushort_t)(idn.domset.ds_connected &
24047c478bd9Sstevel@tonic-gate 	    ~idn.domset.ds_trans_on);
24057c478bd9Sstevel@tonic-gate 	DOMAINSET_ADD(sinfo.conn_domset, idn.localid);
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate 	count = 0;
24087c478bd9Sstevel@tonic-gate 	for (d = 0; d < MAX_DOMAINS; d++) {
24097c478bd9Sstevel@tonic-gate 		dp = &idn_domain[d];
24107c478bd9Sstevel@tonic-gate 
24117c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU)
24127c478bd9Sstevel@tonic-gate 			continue;
24137c478bd9Sstevel@tonic-gate 
24147c478bd9Sstevel@tonic-gate 		IDN_DLOCK_SHARED(d);
24157c478bd9Sstevel@tonic-gate 		if ((dp->dcpu == IDN_NIL_DCPU) ||
24167c478bd9Sstevel@tonic-gate 		    (dp->dstate == IDNDS_CLOSED)) {
24177c478bd9Sstevel@tonic-gate 			IDN_DUNLOCK(d);
24187c478bd9Sstevel@tonic-gate 			continue;
24197c478bd9Sstevel@tonic-gate 		}
24207c478bd9Sstevel@tonic-gate 
24217c478bd9Sstevel@tonic-gate 		count++;
24227c478bd9Sstevel@tonic-gate 		if (d == local_id) {
24237c478bd9Sstevel@tonic-gate 			sinfo.local_index = (uchar_t)d;
24247c478bd9Sstevel@tonic-gate 			sinfo.local_cpuid = (uchar_t)dp->dcpu;
24257c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: domid %d is LOCAL (cpuid = %d)\n",
24267c478bd9Sstevel@tonic-gate 			    proc, d, dp->dcpu);
24277c478bd9Sstevel@tonic-gate 		}
24287c478bd9Sstevel@tonic-gate 		if (d == master_id) {
24297c478bd9Sstevel@tonic-gate 			sinfo.master_index = (uchar_t)d;
24307c478bd9Sstevel@tonic-gate 			sinfo.master_cpuid = (uchar_t)dp->dcpu;
24317c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: domid %d is MASTER (cpuid = %d)\n",
24327c478bd9Sstevel@tonic-gate 			    proc, d, dp->dcpu);
24337c478bd9Sstevel@tonic-gate 		}
24347c478bd9Sstevel@tonic-gate 
24357c478bd9Sstevel@tonic-gate 		sinfo.domain_boardset[d] = (ushort_t)dp->dhw.dh_boardset;
24367c478bd9Sstevel@tonic-gate 
24377c478bd9Sstevel@tonic-gate 		IDN_DUNLOCK(d);
24387c478bd9Sstevel@tonic-gate 	}
24397c478bd9Sstevel@tonic-gate 
24407c478bd9Sstevel@tonic-gate 	IDN_SYNC_UNLOCK();
24417c478bd9Sstevel@tonic-gate 
24427c478bd9Sstevel@tonic-gate 	bcopy(&sinfo, sfp, sizeof (*sfp));
24437c478bd9Sstevel@tonic-gate 
24447c478bd9Sstevel@tonic-gate 	PR_PROTO("%s: Found %d domains within IDNnet\n", proc, count);
24457c478bd9Sstevel@tonic-gate 
24467c478bd9Sstevel@tonic-gate 	return (0);
24477c478bd9Sstevel@tonic-gate }
24487c478bd9Sstevel@tonic-gate 
24497c478bd9Sstevel@tonic-gate /*
24507c478bd9Sstevel@tonic-gate  * ----------------------------------------------
24517c478bd9Sstevel@tonic-gate  * ndd param support routines.
24527c478bd9Sstevel@tonic-gate  * - Borrowed from tcp.
24537c478bd9Sstevel@tonic-gate  * ----------------------------------------------
24547c478bd9Sstevel@tonic-gate  */
24557c478bd9Sstevel@tonic-gate static void
24567c478bd9Sstevel@tonic-gate idn_param_cleanup()
24577c478bd9Sstevel@tonic-gate {
24587c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
24597c478bd9Sstevel@tonic-gate 	if (!idn.strup && idn_ndlist)
24607c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
24617c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
24627c478bd9Sstevel@tonic-gate }
24637c478bd9Sstevel@tonic-gate 
24647c478bd9Sstevel@tonic-gate /*ARGSUSED*/
24657c478bd9Sstevel@tonic-gate static int
24667c478bd9Sstevel@tonic-gate idn_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
24677c478bd9Sstevel@tonic-gate {
24687c478bd9Sstevel@tonic-gate 	idnparam_t	*idnpa = (idnparam_t *)cp;
24697c478bd9Sstevel@tonic-gate 
24707c478bd9Sstevel@tonic-gate 	/*
24717c478bd9Sstevel@tonic-gate 	 * lock grabbed before calling nd_getset.
24727c478bd9Sstevel@tonic-gate 	 */
24737c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_HELD());
24747c478bd9Sstevel@tonic-gate 
24757c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "%ld", idnpa->sp_val);
24767c478bd9Sstevel@tonic-gate 
24777c478bd9Sstevel@tonic-gate 	return (0);
24787c478bd9Sstevel@tonic-gate }
24797c478bd9Sstevel@tonic-gate 
24807c478bd9Sstevel@tonic-gate /*ARGSUSED*/
24817c478bd9Sstevel@tonic-gate static int
24827c478bd9Sstevel@tonic-gate idn_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *cr)
24837c478bd9Sstevel@tonic-gate {
24847c478bd9Sstevel@tonic-gate 	char		*end;
24857c478bd9Sstevel@tonic-gate 	ulong_t		new_value;
24867c478bd9Sstevel@tonic-gate 	idnparam_t	*idnpa = (idnparam_t *)cp;
24877c478bd9Sstevel@tonic-gate 
24887c478bd9Sstevel@tonic-gate 	/*
24897c478bd9Sstevel@tonic-gate 	 * lock grabbed before calling nd_getset.
24907c478bd9Sstevel@tonic-gate 	 */
24917c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_EXCL());
24927c478bd9Sstevel@tonic-gate 
24937c478bd9Sstevel@tonic-gate 	new_value = (ulong_t)mi_strtol(value, &end, 10);
24947c478bd9Sstevel@tonic-gate 
24957c478bd9Sstevel@tonic-gate 	if ((end == value) ||
24967c478bd9Sstevel@tonic-gate 	    (new_value < idnpa->sp_min) ||
24977c478bd9Sstevel@tonic-gate 	    (new_value > idnpa->sp_max))
24987c478bd9Sstevel@tonic-gate 		return (EINVAL);
24997c478bd9Sstevel@tonic-gate 
25007c478bd9Sstevel@tonic-gate 	if (idn.enabled == 0) {
25017c478bd9Sstevel@tonic-gate #ifdef DEBUG
25027c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE,
25037c478bd9Sstevel@tonic-gate 		    "IDN: 102: driver disabled "
25047c478bd9Sstevel@tonic-gate 		    "- check OBP environment "
25057c478bd9Sstevel@tonic-gate 		    "(idn-smr-size)");
25067c478bd9Sstevel@tonic-gate #else /* DEBUG */
25077c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE,
25087c478bd9Sstevel@tonic-gate 		    "!IDN: 102: driver disabled "
25097c478bd9Sstevel@tonic-gate 		    "- check OBP environment "
25107c478bd9Sstevel@tonic-gate 		    "(idn-smr-size)");
25117c478bd9Sstevel@tonic-gate #endif /* DEBUG */
25127c478bd9Sstevel@tonic-gate 		return (EACCES);
25137c478bd9Sstevel@tonic-gate 	}
25147c478bd9Sstevel@tonic-gate 
25157c478bd9Sstevel@tonic-gate 	idnpa->sp_val = new_value;
25167c478bd9Sstevel@tonic-gate 
25177c478bd9Sstevel@tonic-gate 	return (0);
25187c478bd9Sstevel@tonic-gate }
25197c478bd9Sstevel@tonic-gate 
25207c478bd9Sstevel@tonic-gate static int
25217c478bd9Sstevel@tonic-gate idn_param_register(register idnparam_t *idnpa, int count)
25227c478bd9Sstevel@tonic-gate {
25237c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_EXCL());
25247c478bd9Sstevel@tonic-gate 
25257c478bd9Sstevel@tonic-gate 	for (; count > 0; count--, idnpa++) {
25267c478bd9Sstevel@tonic-gate 		if (idnpa->sp_name && idnpa->sp_name[0]) {
25277c478bd9Sstevel@tonic-gate 			register int	i;
25287c478bd9Sstevel@tonic-gate 			ndsetf_t	set_func;
25297c478bd9Sstevel@tonic-gate 			char		*p;
25307c478bd9Sstevel@tonic-gate 			/*
25317c478bd9Sstevel@tonic-gate 			 * Don't advertise in non-DEBUG parameters.
25327c478bd9Sstevel@tonic-gate 			 */
25337c478bd9Sstevel@tonic-gate 			for (i = 0; idn_param_debug_only[i]; i++) {
25347c478bd9Sstevel@tonic-gate 				p = idn_param_debug_only[i];
25357c478bd9Sstevel@tonic-gate 				if (strcmp(idnpa->sp_name, p) == 0)
25367c478bd9Sstevel@tonic-gate 					break;
25377c478bd9Sstevel@tonic-gate 			}
25387c478bd9Sstevel@tonic-gate 			if (idn_param_debug_only[i])
25397c478bd9Sstevel@tonic-gate 				continue;
25407c478bd9Sstevel@tonic-gate 
25417c478bd9Sstevel@tonic-gate 			/*
25427c478bd9Sstevel@tonic-gate 			 * Do not register a "set" function for
25437c478bd9Sstevel@tonic-gate 			 * read-only parameters.
25447c478bd9Sstevel@tonic-gate 			 */
25457c478bd9Sstevel@tonic-gate 			for (i = 0; idn_param_read_only[i]; i++) {
25467c478bd9Sstevel@tonic-gate 				p = idn_param_read_only[i];
25477c478bd9Sstevel@tonic-gate 				if (strcmp(idnpa->sp_name, p) == 0)
25487c478bd9Sstevel@tonic-gate 					break;
25497c478bd9Sstevel@tonic-gate 			}
25507c478bd9Sstevel@tonic-gate 			if (idn_param_read_only[i])
25517c478bd9Sstevel@tonic-gate 				set_func = NULL;
25527c478bd9Sstevel@tonic-gate 			else
25537c478bd9Sstevel@tonic-gate 				set_func = idn_param_set;
25547c478bd9Sstevel@tonic-gate 
25557c478bd9Sstevel@tonic-gate 			if (!nd_load(&idn_ndlist, idnpa->sp_name,
25567c478bd9Sstevel@tonic-gate 			    idn_param_get, set_func,
25577c478bd9Sstevel@tonic-gate 			    (caddr_t)idnpa)) {
25587c478bd9Sstevel@tonic-gate 				nd_free(&idn_ndlist);
25597c478bd9Sstevel@tonic-gate 				return (-1);
25607c478bd9Sstevel@tonic-gate 			}
25617c478bd9Sstevel@tonic-gate 		}
25627c478bd9Sstevel@tonic-gate 	}
25637c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_slabpool", idn_slabpool_report,
25647c478bd9Sstevel@tonic-gate 	    NULL, NULL)) {
25657c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25667c478bd9Sstevel@tonic-gate 		return (-1);
25677c478bd9Sstevel@tonic-gate 	}
25687c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_buffers", idn_buffer_report,
25697c478bd9Sstevel@tonic-gate 	    NULL, NULL)) {
25707c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25717c478bd9Sstevel@tonic-gate 		return (-1);
25727c478bd9Sstevel@tonic-gate 	}
25737c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_mboxtbl", idn_mboxtbl_report,
25747c478bd9Sstevel@tonic-gate 	    NULL, MBXTBL_PART_REPORT)) {
25757c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25767c478bd9Sstevel@tonic-gate 		return (-1);
25777c478bd9Sstevel@tonic-gate 	}
25787c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_mboxtbl_all", idn_mboxtbl_report,
25797c478bd9Sstevel@tonic-gate 	    NULL, MBXTBL_FULL_REPORT)) {
25807c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25817c478bd9Sstevel@tonic-gate 		return (-1);
25827c478bd9Sstevel@tonic-gate 	}
25837c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_mainmbox", idn_mainmbox_report,
25847c478bd9Sstevel@tonic-gate 	    NULL, NULL)) {
25857c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25867c478bd9Sstevel@tonic-gate 		return (-1);
25877c478bd9Sstevel@tonic-gate 	}
25887c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_global", idn_global_report,
25897c478bd9Sstevel@tonic-gate 	    NULL, NULL)) {
25907c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25917c478bd9Sstevel@tonic-gate 		return (-1);
25927c478bd9Sstevel@tonic-gate 	}
25937c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_domain", idn_domain_report,
25947c478bd9Sstevel@tonic-gate 	    NULL, (caddr_t)0)) {
25957c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
25967c478bd9Sstevel@tonic-gate 		return (-1);
25977c478bd9Sstevel@tonic-gate 	}
25987c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_domain_all", idn_domain_report,
25997c478bd9Sstevel@tonic-gate 	    NULL, (caddr_t)1)) {
26007c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
26017c478bd9Sstevel@tonic-gate 		return (-1);
26027c478bd9Sstevel@tonic-gate 	}
26037c478bd9Sstevel@tonic-gate 	if (!nd_load(&idn_ndlist, "idn_bind_net", idn_get_net_binding,
26047c478bd9Sstevel@tonic-gate 	    idn_set_net_binding, NULL)) {
26057c478bd9Sstevel@tonic-gate 		nd_free(&idn_ndlist);
26067c478bd9Sstevel@tonic-gate 		return (-1);
26077c478bd9Sstevel@tonic-gate 	}
26087c478bd9Sstevel@tonic-gate 
26097c478bd9Sstevel@tonic-gate 	return (0);
26107c478bd9Sstevel@tonic-gate }
26117c478bd9Sstevel@tonic-gate 
26127c478bd9Sstevel@tonic-gate /*ARGSUSED*/
26137c478bd9Sstevel@tonic-gate static int
26147c478bd9Sstevel@tonic-gate idn_set_net_binding(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *cr)
26157c478bd9Sstevel@tonic-gate {
26167c478bd9Sstevel@tonic-gate 	char		*end, *cpup;
26177c478bd9Sstevel@tonic-gate 	long		net;
26187c478bd9Sstevel@tonic-gate 	processorid_t	cpuid;
26197c478bd9Sstevel@tonic-gate 
26207c478bd9Sstevel@tonic-gate 	/*
26217c478bd9Sstevel@tonic-gate 	 * lock grabbed before calling nd_getset.
26227c478bd9Sstevel@tonic-gate 	 */
26237c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_EXCL());
26247c478bd9Sstevel@tonic-gate 
26257c478bd9Sstevel@tonic-gate 	if ((cpup = strchr(value, '=')) == NULL)
26267c478bd9Sstevel@tonic-gate 		return (EINVAL);
26277c478bd9Sstevel@tonic-gate 
26287c478bd9Sstevel@tonic-gate 	*cpup++ = '\0';
26297c478bd9Sstevel@tonic-gate 
26307c478bd9Sstevel@tonic-gate 	net = mi_strtol(value, &end, 10);
26317c478bd9Sstevel@tonic-gate 	if ((end == value) || (net < 0) || (net >= IDN_MAX_NETS) ||
26327c478bd9Sstevel@tonic-gate 	    !CHAN_IN_SET(idn.chanset, net))
26337c478bd9Sstevel@tonic-gate 		return (EINVAL);
26347c478bd9Sstevel@tonic-gate 
26357c478bd9Sstevel@tonic-gate 	cpuid = (processorid_t)mi_strtol(cpup, &end, 10);
26367c478bd9Sstevel@tonic-gate 	if ((end == cpup) || ((cpuid != -1) &&
26377c478bd9Sstevel@tonic-gate 	    (!VALID_CPUID(cpuid) ||
26387c478bd9Sstevel@tonic-gate 	    !CPU_IN_SET(cpu_ready_set, cpuid))))
26397c478bd9Sstevel@tonic-gate 		return (EINVAL);
26407c478bd9Sstevel@tonic-gate 
26417c478bd9Sstevel@tonic-gate 	idn_chanserver_bind(net, cpuid);
26427c478bd9Sstevel@tonic-gate 
26437c478bd9Sstevel@tonic-gate 	return (0);
26447c478bd9Sstevel@tonic-gate }
26457c478bd9Sstevel@tonic-gate 
26467c478bd9Sstevel@tonic-gate /*ARGSUSED*/
26477c478bd9Sstevel@tonic-gate static int
26487c478bd9Sstevel@tonic-gate idn_get_net_binding(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
26497c478bd9Sstevel@tonic-gate {
26507c478bd9Sstevel@tonic-gate 	int	c;
26517c478bd9Sstevel@tonic-gate 
26527c478bd9Sstevel@tonic-gate 	/*
26537c478bd9Sstevel@tonic-gate 	 * lock grabbed before calling nd_getset.
26547c478bd9Sstevel@tonic-gate 	 */
26557c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_HELD());
26567c478bd9Sstevel@tonic-gate 
26577c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp,
26587c478bd9Sstevel@tonic-gate 	    "IDN network interfaces/channels active = %d",
26597c478bd9Sstevel@tonic-gate 	    idn.nchannels);
26607c478bd9Sstevel@tonic-gate 
26617c478bd9Sstevel@tonic-gate 	if (idn.nchannels == 0)
26627c478bd9Sstevel@tonic-gate 		return (0);
26637c478bd9Sstevel@tonic-gate 
266407d06da5SSurya Prakki 	(void) mi_mpprintf(mp, "Net    Cpu");
26657c478bd9Sstevel@tonic-gate 
26667c478bd9Sstevel@tonic-gate 	for (c = 0; c < IDN_MAX_NETS; c++) {
26677c478bd9Sstevel@tonic-gate 		int		bc;
26687c478bd9Sstevel@tonic-gate 		idn_chansvr_t	*csp;
26697c478bd9Sstevel@tonic-gate 
26707c478bd9Sstevel@tonic-gate 		if (!CHAN_IN_SET(idn.chanset, c))
26717c478bd9Sstevel@tonic-gate 			continue;
26727c478bd9Sstevel@tonic-gate 
26737c478bd9Sstevel@tonic-gate 		csp = &idn.chan_servers[c];
26747c478bd9Sstevel@tonic-gate 
26757c478bd9Sstevel@tonic-gate 		if ((bc = csp->ch_bound_cpuid) == -1)
26767c478bd9Sstevel@tonic-gate 			bc = csp->ch_bound_cpuid_pending;
26777c478bd9Sstevel@tonic-gate 
26787c478bd9Sstevel@tonic-gate 		if (c < 10)
267907d06da5SSurya Prakki 			(void) mi_mpprintf(mp, " %d      %d", c, bc);
26807c478bd9Sstevel@tonic-gate 		else
268107d06da5SSurya Prakki 			(void) mi_mpprintf(mp, " %d     %d", c, bc);
26827c478bd9Sstevel@tonic-gate 	}
26837c478bd9Sstevel@tonic-gate 
26847c478bd9Sstevel@tonic-gate 	return (0);
26857c478bd9Sstevel@tonic-gate }
26867c478bd9Sstevel@tonic-gate 
26877c478bd9Sstevel@tonic-gate static int
26887c478bd9Sstevel@tonic-gate idnioc_link(idnop_t *idnop)
26897c478bd9Sstevel@tonic-gate {
26907c478bd9Sstevel@tonic-gate 	int		rv;
26917c478bd9Sstevel@tonic-gate 	int		pri;
26927c478bd9Sstevel@tonic-gate 	idnsb_error_t	err;
26937c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnioc_link";
26947c478bd9Sstevel@tonic-gate 
26957c478bd9Sstevel@tonic-gate 	if (idnop->link.master < 0)
26967c478bd9Sstevel@tonic-gate 		pri = IDNVOTE_MINPRI;
26977c478bd9Sstevel@tonic-gate 	else if (idnop->link.master > 0)
26987c478bd9Sstevel@tonic-gate 		pri = IDNVOTE_MAXPRI;
26997c478bd9Sstevel@tonic-gate 	else
27007c478bd9Sstevel@tonic-gate 		pri = IDNVOTE_DEFPRI;
27017c478bd9Sstevel@tonic-gate 
27027c478bd9Sstevel@tonic-gate 	PR_DRV("%s: domid = %d, cpuid = %d, pri = %d\n",
27037c478bd9Sstevel@tonic-gate 	    proc, idnop->link.domid, idnop->link.cpuid, pri);
27047c478bd9Sstevel@tonic-gate 
27057c478bd9Sstevel@tonic-gate 	rv = idn_link(idnop->link.domid, idnop->link.cpuid,
27067c478bd9Sstevel@tonic-gate 	    pri, idnop->link.wait, &err);
27077c478bd9Sstevel@tonic-gate 
27087c478bd9Sstevel@tonic-gate 	return (rv);
27097c478bd9Sstevel@tonic-gate }
27107c478bd9Sstevel@tonic-gate 
27117c478bd9Sstevel@tonic-gate static int
27127c478bd9Sstevel@tonic-gate idnioc_unlink(idnop_t *idnop)
27137c478bd9Sstevel@tonic-gate {
27147c478bd9Sstevel@tonic-gate 	int		d, cpuid, domid, rv;
27157c478bd9Sstevel@tonic-gate 	boardset_t	idnset;
27167c478bd9Sstevel@tonic-gate 	idn_fin_t	fintype;
27177c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp, *xdp;
27187c478bd9Sstevel@tonic-gate 	idnsb_error_t	err;
27197c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnioc_unlink";
27207c478bd9Sstevel@tonic-gate 
27217c478bd9Sstevel@tonic-gate 	PR_DRV("%s: domid = %d, cpuid = %d, force = %d\n",
27227c478bd9Sstevel@tonic-gate 	    proc, idnop->unlink.domid, idnop->unlink.cpuid,
27237c478bd9Sstevel@tonic-gate 	    idnop->unlink.force);
27247c478bd9Sstevel@tonic-gate 
27257c478bd9Sstevel@tonic-gate 	idnset = BOARDSET_ALL;
27267c478bd9Sstevel@tonic-gate 	domid = idnop->unlink.domid;
27277c478bd9Sstevel@tonic-gate 	cpuid = idnop->unlink.cpuid;
27287c478bd9Sstevel@tonic-gate 	dp = NULL;
27297c478bd9Sstevel@tonic-gate 
27307c478bd9Sstevel@tonic-gate 	if (domid == IDN_NIL_DOMID)
27317c478bd9Sstevel@tonic-gate 		domid = idn.localid;
27327c478bd9Sstevel@tonic-gate 
27337c478bd9Sstevel@tonic-gate 	if (VALID_DOMAINID(domid)) {
27347c478bd9Sstevel@tonic-gate 		dp = &idn_domain[domid];
27357c478bd9Sstevel@tonic-gate 		if (VALID_CPUID(cpuid) && (dp->dcpu != IDN_NIL_DCPU) &&
27367c478bd9Sstevel@tonic-gate 		    !CPU_IN_SET(dp->dcpuset, cpuid)) {
27377c478bd9Sstevel@tonic-gate 			dp = NULL;
27387c478bd9Sstevel@tonic-gate 			PR_PROTO("%s: ERROR: invalid cpuid "
27397c478bd9Sstevel@tonic-gate 			    "(%d) for domain (%d) [cset = 0x%x.x%x]\n",
27407c478bd9Sstevel@tonic-gate 			    proc, cpuid, domid,
27417c478bd9Sstevel@tonic-gate 			    UPPER32_CPUMASK(dp->dcpuset),
27427c478bd9Sstevel@tonic-gate 			    LOWER32_CPUMASK(dp->dcpuset));
27437c478bd9Sstevel@tonic-gate 		}
27447c478bd9Sstevel@tonic-gate 	} else if (VALID_CPUID(cpuid)) {
27457c478bd9Sstevel@tonic-gate 		for (d = 0; d < MAX_DOMAINS; d++) {
27467c478bd9Sstevel@tonic-gate 			xdp = &idn_domain[d];
27477c478bd9Sstevel@tonic-gate 
27487c478bd9Sstevel@tonic-gate 			if (xdp->dcpu == IDN_NIL_DCPU)
27497c478bd9Sstevel@tonic-gate 				continue;
27507c478bd9Sstevel@tonic-gate 
27517c478bd9Sstevel@tonic-gate 			if (CPU_IN_SET(xdp->dcpuset, cpuid))
27527c478bd9Sstevel@tonic-gate 				break;
27537c478bd9Sstevel@tonic-gate 		}
27547c478bd9Sstevel@tonic-gate 		dp = (d == MAX_DOMAINS) ? NULL : xdp;
27557c478bd9Sstevel@tonic-gate 	}
27567c478bd9Sstevel@tonic-gate 
27577c478bd9Sstevel@tonic-gate 	if ((dp == NULL) || (dp->dcpu == IDN_NIL_DCPU))
27587c478bd9Sstevel@tonic-gate 		return (0);
27597c478bd9Sstevel@tonic-gate 
27607c478bd9Sstevel@tonic-gate 	domid = dp->domid;
27617c478bd9Sstevel@tonic-gate 
27627c478bd9Sstevel@tonic-gate 	switch (idnop->unlink.force) {
27637c478bd9Sstevel@tonic-gate 	case SSIFORCE_OFF:
27647c478bd9Sstevel@tonic-gate 		fintype = IDNFIN_NORMAL;
27657c478bd9Sstevel@tonic-gate 		break;
27667c478bd9Sstevel@tonic-gate 
27677c478bd9Sstevel@tonic-gate 	case SSIFORCE_SOFT:
27687c478bd9Sstevel@tonic-gate 		fintype = IDNFIN_FORCE_SOFT;
27697c478bd9Sstevel@tonic-gate 		break;
27707c478bd9Sstevel@tonic-gate 
27717c478bd9Sstevel@tonic-gate 	case SSIFORCE_HARD:
27727c478bd9Sstevel@tonic-gate 		fintype = IDNFIN_FORCE_HARD;
27737c478bd9Sstevel@tonic-gate 		break;
27747c478bd9Sstevel@tonic-gate 	default:
27757c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: invalid force parameter \"%d\"",
27767c478bd9Sstevel@tonic-gate 		    proc, idnop->unlink.force);
27777c478bd9Sstevel@tonic-gate 		return (EINVAL);
27787c478bd9Sstevel@tonic-gate 	}
27797c478bd9Sstevel@tonic-gate 
27807c478bd9Sstevel@tonic-gate 	rv = idn_unlink(domid, idnset, fintype, IDNFIN_OPT_UNLINK,
27817c478bd9Sstevel@tonic-gate 	    idnop->unlink.wait, &err);
27827c478bd9Sstevel@tonic-gate 
27837c478bd9Sstevel@tonic-gate 	return (rv);
27847c478bd9Sstevel@tonic-gate }
27857c478bd9Sstevel@tonic-gate 
27867c478bd9Sstevel@tonic-gate static int
27877c478bd9Sstevel@tonic-gate idn_send_ping(idnop_t *idnop)
27887c478bd9Sstevel@tonic-gate {
27897c478bd9Sstevel@tonic-gate 	int		domid = idnop->ping.domid;
27907c478bd9Sstevel@tonic-gate 	int		cpuid = idnop->ping.cpuid;
27917c478bd9Sstevel@tonic-gate 	int		ocpuid;
27927c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp;
27937c478bd9Sstevel@tonic-gate 	idn_msgtype_t	mt;
27947c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_send_ping";
27957c478bd9Sstevel@tonic-gate 
27967c478bd9Sstevel@tonic-gate 	if ((domid == IDN_NIL_DOMID) && (cpuid == IDN_NIL_DCPU)) {
27977c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
27987c478bd9Sstevel@tonic-gate 		    "IDN: %s: no valid domain ID or CPU ID given",
27997c478bd9Sstevel@tonic-gate 		    proc);
28007c478bd9Sstevel@tonic-gate 		return (EINVAL);
28017c478bd9Sstevel@tonic-gate 	}
28027c478bd9Sstevel@tonic-gate 	if (domid == IDN_NIL_DOMID)
28037c478bd9Sstevel@tonic-gate 		domid = MAX_DOMAINS - 1;
28047c478bd9Sstevel@tonic-gate 
28057c478bd9Sstevel@tonic-gate 	dp = &idn_domain[domid];
28067c478bd9Sstevel@tonic-gate 	IDN_DLOCK_EXCL(domid);
28077c478bd9Sstevel@tonic-gate 	if ((dp->dcpu == IDN_NIL_DCPU) && (cpuid == IDN_NIL_DCPU)) {
28087c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
28097c478bd9Sstevel@tonic-gate 		    "IDN: %s: no valid target CPU specified",
28107c478bd9Sstevel@tonic-gate 		    proc);
28117c478bd9Sstevel@tonic-gate 		IDN_DUNLOCK(domid);
28127c478bd9Sstevel@tonic-gate 		return (EINVAL);
28137c478bd9Sstevel@tonic-gate 	}
28147c478bd9Sstevel@tonic-gate 	if (cpuid == IDN_NIL_DCPU)
28157c478bd9Sstevel@tonic-gate 		cpuid = dp->dcpu;
28167c478bd9Sstevel@tonic-gate 
28177c478bd9Sstevel@tonic-gate 	ocpuid = dp->dcpu;
28187c478bd9Sstevel@tonic-gate 	dp->dcpu = cpuid;
28197c478bd9Sstevel@tonic-gate 
28207c478bd9Sstevel@tonic-gate 	/*
28217c478bd9Sstevel@tonic-gate 	 * XXX - Need a special PING IDN command.
28227c478bd9Sstevel@tonic-gate 	 */
28237c478bd9Sstevel@tonic-gate 	mt.mt_mtype = IDNP_DATA | IDNP_ACK;
28247c478bd9Sstevel@tonic-gate 	mt.mt_atype = 0;
28257c478bd9Sstevel@tonic-gate 
28267c478bd9Sstevel@tonic-gate 	(void) IDNXDC(domid, &mt, 0x100, 0x200, 0x300, 0x400);
28277c478bd9Sstevel@tonic-gate 
28287c478bd9Sstevel@tonic-gate 	dp->dcpu = ocpuid;
28297c478bd9Sstevel@tonic-gate 	IDN_DUNLOCK(domid);
28307c478bd9Sstevel@tonic-gate 
28317c478bd9Sstevel@tonic-gate 	return (0);
28327c478bd9Sstevel@tonic-gate }
28337c478bd9Sstevel@tonic-gate 
28347c478bd9Sstevel@tonic-gate /*
28357c478bd9Sstevel@tonic-gate  * ----------------------------------------------
28367c478bd9Sstevel@tonic-gate  */
28377c478bd9Sstevel@tonic-gate static void
28387c478bd9Sstevel@tonic-gate idn_dopers_init()
28397c478bd9Sstevel@tonic-gate {
28407c478bd9Sstevel@tonic-gate 	int		i;
28417c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dwl;
28427c478bd9Sstevel@tonic-gate 
28437c478bd9Sstevel@tonic-gate 	if (idn.dopers)
28447c478bd9Sstevel@tonic-gate 		return;
28457c478bd9Sstevel@tonic-gate 
28467c478bd9Sstevel@tonic-gate 	idn.dopers = GETSTRUCT(struct dopers, 1);
28477c478bd9Sstevel@tonic-gate 
28487c478bd9Sstevel@tonic-gate 	bzero(idn.dopers, sizeof (struct dopers));
28497c478bd9Sstevel@tonic-gate 
28507c478bd9Sstevel@tonic-gate 	dwl = &idn.dopers->_dop_wcache[0];
28517c478bd9Sstevel@tonic-gate 	for (i = 0; i < (IDNOP_CACHE_SIZE-1); i++)
28527c478bd9Sstevel@tonic-gate 		dwl[i].dw_next = &dwl[i+1];
28537c478bd9Sstevel@tonic-gate 	dwl[i].dw_next = NULL;
28547c478bd9Sstevel@tonic-gate 
28557c478bd9Sstevel@tonic-gate 	idn.dopers->dop_freelist = &idn.dopers->_dop_wcache[0];
28567c478bd9Sstevel@tonic-gate 	idn.dopers->dop_waitcount = 0;
28577c478bd9Sstevel@tonic-gate 	idn.dopers->dop_domset = 0;
28587c478bd9Sstevel@tonic-gate 	idn.dopers->dop_waitlist = NULL;
28597c478bd9Sstevel@tonic-gate 
28607c478bd9Sstevel@tonic-gate 	cv_init(&idn.dopers->dop_cv, NULL, CV_DEFAULT, NULL);
28617c478bd9Sstevel@tonic-gate 	mutex_init(&idn.dopers->dop_mutex, NULL, MUTEX_DEFAULT, NULL);
28627c478bd9Sstevel@tonic-gate }
28637c478bd9Sstevel@tonic-gate 
28647c478bd9Sstevel@tonic-gate static void
28657c478bd9Sstevel@tonic-gate idn_dopers_deinit()
28667c478bd9Sstevel@tonic-gate {
28677c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dwl, *next_dwl;
28687c478bd9Sstevel@tonic-gate 
28697c478bd9Sstevel@tonic-gate 
28707c478bd9Sstevel@tonic-gate 	if (idn.dopers == NULL)
28717c478bd9Sstevel@tonic-gate 		return;
28727c478bd9Sstevel@tonic-gate 
28737c478bd9Sstevel@tonic-gate 	for (dwl = idn.dopers->dop_waitlist; dwl; dwl = next_dwl) {
28747c478bd9Sstevel@tonic-gate 		next_dwl = dwl->dw_next;
28757c478bd9Sstevel@tonic-gate 		if (!IDNOP_IN_CACHE(dwl))
28767c478bd9Sstevel@tonic-gate 			FREESTRUCT(dwl, dop_waitlist_t, 1);
28777c478bd9Sstevel@tonic-gate 	}
28787c478bd9Sstevel@tonic-gate 
28797c478bd9Sstevel@tonic-gate 	cv_destroy(&idn.dopers->dop_cv);
28807c478bd9Sstevel@tonic-gate 	mutex_destroy(&idn.dopers->dop_mutex);
28817c478bd9Sstevel@tonic-gate 
28827c478bd9Sstevel@tonic-gate 	FREESTRUCT(idn.dopers, struct dopers, 1);
28837c478bd9Sstevel@tonic-gate 	idn.dopers = NULL;
28847c478bd9Sstevel@tonic-gate }
28857c478bd9Sstevel@tonic-gate 
28867c478bd9Sstevel@tonic-gate /*
28877c478bd9Sstevel@tonic-gate  * Reset the dop_errset field in preparation for an
28887c478bd9Sstevel@tonic-gate  * IDN operation attempt.  This is only called from
28897c478bd9Sstevel@tonic-gate  * idn_link() and idn_unlink().
28907c478bd9Sstevel@tonic-gate  */
28917c478bd9Sstevel@tonic-gate void *
28927c478bd9Sstevel@tonic-gate idn_init_op(idn_opflag_t opflag, domainset_t domset, idnsb_error_t *sep)
28937c478bd9Sstevel@tonic-gate {
28947c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dwl;
28957c478bd9Sstevel@tonic-gate 	/*
28967c478bd9Sstevel@tonic-gate 	 * Clear any outstanding error ops in preparation
28977c478bd9Sstevel@tonic-gate 	 * for an IDN (link/unlink) operation.
28987c478bd9Sstevel@tonic-gate 	 */
28997c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.dopers->dop_mutex);
29007c478bd9Sstevel@tonic-gate 	if ((dwl = idn.dopers->dop_freelist) == NULL) {
29017c478bd9Sstevel@tonic-gate 		dwl = GETSTRUCT(dop_waitlist_t, 1);
29027c478bd9Sstevel@tonic-gate 	} else {
29037c478bd9Sstevel@tonic-gate 		idn.dopers->dop_freelist = dwl->dw_next;
29047c478bd9Sstevel@tonic-gate 		bzero(dwl, sizeof (*dwl));
29057c478bd9Sstevel@tonic-gate 	}
29067c478bd9Sstevel@tonic-gate 	dwl->dw_op = opflag;
29077c478bd9Sstevel@tonic-gate 	dwl->dw_reqset = domset;
29087c478bd9Sstevel@tonic-gate 	dwl->dw_idnerr = sep;
29097c478bd9Sstevel@tonic-gate 	dwl->dw_next = idn.dopers->dop_waitlist;
29107c478bd9Sstevel@tonic-gate 
29117c478bd9Sstevel@tonic-gate 	idn.dopers->dop_waitlist = dwl;
29127c478bd9Sstevel@tonic-gate 	idn.dopers->dop_waitcount++;
29137c478bd9Sstevel@tonic-gate 	idn.dopers->dop_domset |= domset;
29147c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.dopers->dop_mutex);
29157c478bd9Sstevel@tonic-gate 
29167c478bd9Sstevel@tonic-gate 	return (dwl);
29177c478bd9Sstevel@tonic-gate }
29187c478bd9Sstevel@tonic-gate 
29197c478bd9Sstevel@tonic-gate /*
29207c478bd9Sstevel@tonic-gate  * Anybody waiting on a opflag operation for any one
29217c478bd9Sstevel@tonic-gate  * of the domains in domset, needs to be updated to
29227c478bd9Sstevel@tonic-gate  * additionally wait for new domains in domset.
29237c478bd9Sstevel@tonic-gate  * This is used, for example, when needing to connect
29247c478bd9Sstevel@tonic-gate  * to more domains than known at the time of the
29257c478bd9Sstevel@tonic-gate  * original request.
29267c478bd9Sstevel@tonic-gate  */
29277c478bd9Sstevel@tonic-gate void
29287c478bd9Sstevel@tonic-gate idn_add_op(idn_opflag_t opflag, domainset_t domset)
29297c478bd9Sstevel@tonic-gate {
29307c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dwl;
29317c478bd9Sstevel@tonic-gate 
29327c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.dopers->dop_mutex);
29337c478bd9Sstevel@tonic-gate 	if ((idn.dopers->dop_waitcount == 0) ||
29347c478bd9Sstevel@tonic-gate 	    ((idn.dopers->dop_domset & domset) == 0)) {
29357c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.dopers->dop_mutex);
29367c478bd9Sstevel@tonic-gate 		return;
29377c478bd9Sstevel@tonic-gate 	}
29387c478bd9Sstevel@tonic-gate 	for (dwl = idn.dopers->dop_waitlist; dwl; dwl = dwl->dw_next)
29397c478bd9Sstevel@tonic-gate 		if ((dwl->dw_op == opflag) && (dwl->dw_reqset & domset))
29407c478bd9Sstevel@tonic-gate 			dwl->dw_reqset |= domset;
29417c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.dopers->dop_mutex);
29427c478bd9Sstevel@tonic-gate }
29437c478bd9Sstevel@tonic-gate 
29447c478bd9Sstevel@tonic-gate /*
29457c478bd9Sstevel@tonic-gate  * Mechanism to wakeup any potential users which may be waiting
29467c478bd9Sstevel@tonic-gate  * for a link/unlink operation to complete.  If an error occurred
29477c478bd9Sstevel@tonic-gate  * don't update dop_errset unless there was no previous error.
29487c478bd9Sstevel@tonic-gate  */
29497c478bd9Sstevel@tonic-gate void
29507c478bd9Sstevel@tonic-gate idn_update_op(idn_opflag_t opflag, domainset_t domset, idnsb_error_t *sep)
29517c478bd9Sstevel@tonic-gate {
29527c478bd9Sstevel@tonic-gate 	int		do_wakeup = 0;
29537c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dw;
29547c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_update_op";
29557c478bd9Sstevel@tonic-gate 
29567c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.dopers->dop_mutex);
29577c478bd9Sstevel@tonic-gate 	/*
29587c478bd9Sstevel@tonic-gate 	 * If there are no waiters, or nobody is waiting for
29597c478bd9Sstevel@tonic-gate 	 * the particular domainset in question, then
29607c478bd9Sstevel@tonic-gate 	 * just bail.
29617c478bd9Sstevel@tonic-gate 	 */
29627c478bd9Sstevel@tonic-gate 	if ((idn.dopers->dop_waitcount == 0) ||
29637c478bd9Sstevel@tonic-gate 	    ((idn.dopers->dop_domset & domset) == 0)) {
29647c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.dopers->dop_mutex);
29657c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: NO waiters exist (domset=0x%x)\n",
29667c478bd9Sstevel@tonic-gate 		    proc, domset);
29677c478bd9Sstevel@tonic-gate 		return;
29687c478bd9Sstevel@tonic-gate 	}
29697c478bd9Sstevel@tonic-gate 
29707c478bd9Sstevel@tonic-gate 	for (dw = idn.dopers->dop_waitlist; dw; dw = dw->dw_next) {
29717c478bd9Sstevel@tonic-gate 		int		d;
29727c478bd9Sstevel@tonic-gate 		domainset_t	dset, rset;
29737c478bd9Sstevel@tonic-gate 
29747c478bd9Sstevel@tonic-gate 		if ((dset = dw->dw_reqset & domset) == 0)
29757c478bd9Sstevel@tonic-gate 			continue;
29767c478bd9Sstevel@tonic-gate 
29777c478bd9Sstevel@tonic-gate 		if (opflag == IDNOP_ERROR) {
29787c478bd9Sstevel@tonic-gate 			dw->dw_errset |= dset;
29797c478bd9Sstevel@tonic-gate 			if (sep) {
29807c478bd9Sstevel@tonic-gate 				for (d = 0; d < MAX_DOMAINS; d++) {
29817c478bd9Sstevel@tonic-gate 					if (!DOMAIN_IN_SET(dset, d))
29827c478bd9Sstevel@tonic-gate 						continue;
29837c478bd9Sstevel@tonic-gate 
29847c478bd9Sstevel@tonic-gate 					dw->dw_errors[d] =
29857c478bd9Sstevel@tonic-gate 					    (short)GET_IDNKERR_ERRNO(sep);
29867c478bd9Sstevel@tonic-gate 				}
29877c478bd9Sstevel@tonic-gate 				bcopy(sep, dw->dw_idnerr, sizeof (*sep));
29887c478bd9Sstevel@tonic-gate 			}
29897c478bd9Sstevel@tonic-gate 		} else if (opflag == dw->dw_op) {
29907c478bd9Sstevel@tonic-gate 			dw->dw_domset |= dset;
29917c478bd9Sstevel@tonic-gate 		}
29927c478bd9Sstevel@tonic-gate 
29937c478bd9Sstevel@tonic-gate 		/*
29947c478bd9Sstevel@tonic-gate 		 * Check if all the domains are spoken for that
29957c478bd9Sstevel@tonic-gate 		 * a particular waiter may have been waiting for.
29967c478bd9Sstevel@tonic-gate 		 * If there's at least one, we'll need to broadcast.
29977c478bd9Sstevel@tonic-gate 		 */
29987c478bd9Sstevel@tonic-gate 		rset = (dw->dw_errset | dw->dw_domset) & dw->dw_reqset;
29997c478bd9Sstevel@tonic-gate 		if (rset == dw->dw_reqset)
30007c478bd9Sstevel@tonic-gate 			do_wakeup++;
30017c478bd9Sstevel@tonic-gate 	}
30027c478bd9Sstevel@tonic-gate 
30037c478bd9Sstevel@tonic-gate 	PR_PROTO("%s: found %d waiters ready for wakeup\n", proc, do_wakeup);
30047c478bd9Sstevel@tonic-gate 
30057c478bd9Sstevel@tonic-gate 	if (do_wakeup > 0)
30067c478bd9Sstevel@tonic-gate 		cv_broadcast(&idn.dopers->dop_cv);
30077c478bd9Sstevel@tonic-gate 
30087c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.dopers->dop_mutex);
30097c478bd9Sstevel@tonic-gate }
30107c478bd9Sstevel@tonic-gate 
30117c478bd9Sstevel@tonic-gate void
30127c478bd9Sstevel@tonic-gate idn_deinit_op(void *cookie)
30137c478bd9Sstevel@tonic-gate {
30147c478bd9Sstevel@tonic-gate 	domainset_t	domset;
30157c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*hw, *tw;
30167c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dwl = (dop_waitlist_t *)cookie;
30177c478bd9Sstevel@tonic-gate 
30187c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.dopers->dop_mutex);
30197c478bd9Sstevel@tonic-gate 
30207c478bd9Sstevel@tonic-gate 	ASSERT(idn.dopers->dop_waitlist);
30217c478bd9Sstevel@tonic-gate 
30227c478bd9Sstevel@tonic-gate 	if (dwl == idn.dopers->dop_waitlist) {
30237c478bd9Sstevel@tonic-gate 		idn.dopers->dop_waitlist = dwl->dw_next;
30247c478bd9Sstevel@tonic-gate 		if (IDNOP_IN_CACHE(dwl)) {
30257c478bd9Sstevel@tonic-gate 			dwl->dw_next = idn.dopers->dop_freelist;
30267c478bd9Sstevel@tonic-gate 			idn.dopers->dop_freelist = dwl;
30277c478bd9Sstevel@tonic-gate 		} else {
30287c478bd9Sstevel@tonic-gate 			FREESTRUCT(dwl, dop_waitlist_t, 1);
30297c478bd9Sstevel@tonic-gate 		}
30307c478bd9Sstevel@tonic-gate 	} else {
30317c478bd9Sstevel@tonic-gate 		for (tw = idn.dopers->dop_waitlist, hw = tw->dw_next;
30327c478bd9Sstevel@tonic-gate 		    hw;
30337c478bd9Sstevel@tonic-gate 		    tw = hw, hw = hw->dw_next) {
30347c478bd9Sstevel@tonic-gate 			if (dwl == hw)
30357c478bd9Sstevel@tonic-gate 				break;
30367c478bd9Sstevel@tonic-gate 		}
30377c478bd9Sstevel@tonic-gate 		ASSERT(hw);
30387c478bd9Sstevel@tonic-gate 
30397c478bd9Sstevel@tonic-gate 		tw->dw_next = hw->dw_next;
30407c478bd9Sstevel@tonic-gate 	}
30417c478bd9Sstevel@tonic-gate 
30427c478bd9Sstevel@tonic-gate 	/*
30437c478bd9Sstevel@tonic-gate 	 * Recompute domainset for which waiters might be waiting.
30447c478bd9Sstevel@tonic-gate 	 * It's possible there may be other waiters waiting for
30457c478bd9Sstevel@tonic-gate 	 * the same domainset that the current waiter that's leaving
30467c478bd9Sstevel@tonic-gate 	 * may have been waiting for, so we can't simply delete
30477c478bd9Sstevel@tonic-gate 	 * the leaving waiter's domainset from dop_domset.
30487c478bd9Sstevel@tonic-gate 	 */
30497c478bd9Sstevel@tonic-gate 	for (hw = idn.dopers->dop_waitlist, domset = 0; hw; hw = hw->dw_next)
30507c478bd9Sstevel@tonic-gate 		domset |= hw->dw_reqset;
30517c478bd9Sstevel@tonic-gate 
30527c478bd9Sstevel@tonic-gate 	idn.dopers->dop_waitcount--;
30537c478bd9Sstevel@tonic-gate 	idn.dopers->dop_domset = domset;
30547c478bd9Sstevel@tonic-gate 
30557c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.dopers->dop_mutex);
30567c478bd9Sstevel@tonic-gate }
30577c478bd9Sstevel@tonic-gate 
30587c478bd9Sstevel@tonic-gate /*
30597c478bd9Sstevel@tonic-gate  * Wait until the specified operation succeeds or fails with
30607c478bd9Sstevel@tonic-gate  * respect to the given domains.  Note the function terminates
30617c478bd9Sstevel@tonic-gate  * if at least one error occurs.
30627c478bd9Sstevel@tonic-gate  * This process is necessary since link/unlink operations occur
30637c478bd9Sstevel@tonic-gate  * asynchronously and we need some way of waiting to find out
30647c478bd9Sstevel@tonic-gate  * if it indeed completed.
30657c478bd9Sstevel@tonic-gate  * Timeout value is received indirectly from the SSP and
30667c478bd9Sstevel@tonic-gate  * represents seconds.
30677c478bd9Sstevel@tonic-gate  */
30687c478bd9Sstevel@tonic-gate int
30697c478bd9Sstevel@tonic-gate idn_wait_op(void *cookie, domainset_t *domsetp, int wait_timeout)
30707c478bd9Sstevel@tonic-gate {
30717c478bd9Sstevel@tonic-gate 	int	d, rv, err = 0;
30727c478bd9Sstevel@tonic-gate 	dop_waitlist_t	*dwl;
30737c478bd9Sstevel@tonic-gate 
30747c478bd9Sstevel@tonic-gate 
30757c478bd9Sstevel@tonic-gate 	dwl = (dop_waitlist_t *)cookie;
30767c478bd9Sstevel@tonic-gate 
30777c478bd9Sstevel@tonic-gate 	ASSERT(wait_timeout > 0);
30787c478bd9Sstevel@tonic-gate 	ASSERT((dwl->dw_op == IDNOP_CONNECTED) ||
30797c478bd9Sstevel@tonic-gate 	    (dwl->dw_op == IDNOP_DISCONNECTED));
30807c478bd9Sstevel@tonic-gate 
30817c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.dopers->dop_mutex);
30827c478bd9Sstevel@tonic-gate 
30837c478bd9Sstevel@tonic-gate 	while (((dwl->dw_domset | dwl->dw_errset) != dwl->dw_reqset) && !err) {
3084d3d50737SRafael Vanoni 		rv = cv_reltimedwait_sig(&idn.dopers->dop_cv,
3085d3d50737SRafael Vanoni 		    &idn.dopers->dop_mutex, (wait_timeout * hz), TR_CLOCK_TICK);
30867c478bd9Sstevel@tonic-gate 
30877c478bd9Sstevel@tonic-gate 		if ((dwl->dw_domset | dwl->dw_errset) == dwl->dw_reqset)
30887c478bd9Sstevel@tonic-gate 			break;
30897c478bd9Sstevel@tonic-gate 
30907c478bd9Sstevel@tonic-gate 		switch (rv) {
30917c478bd9Sstevel@tonic-gate 		case -1:
30927c478bd9Sstevel@tonic-gate 			/*
30937c478bd9Sstevel@tonic-gate 			 * timed out
30947c478bd9Sstevel@tonic-gate 			 */
30957c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
30967c478bd9Sstevel@tonic-gate 			    "!IDN: 129: %s operation timed out",
30977c478bd9Sstevel@tonic-gate 			    (dwl->dw_op == IDNOP_CONNECTED) ? "LINK" :
30987c478bd9Sstevel@tonic-gate 			    (dwl->dw_op == IDNOP_DISCONNECTED) ? "UNLINK" :
30997c478bd9Sstevel@tonic-gate 			    "UNKNOWN");
31007c478bd9Sstevel@tonic-gate 			/*FALLTHROUGH*/
31017c478bd9Sstevel@tonic-gate 		case 0:
31027c478bd9Sstevel@tonic-gate 			/*
31037c478bd9Sstevel@tonic-gate 			 * signal, e.g. kill(2)
31047c478bd9Sstevel@tonic-gate 			 */
31057c478bd9Sstevel@tonic-gate 			err = 1;
31067c478bd9Sstevel@tonic-gate 			break;
31077c478bd9Sstevel@tonic-gate 
31087c478bd9Sstevel@tonic-gate 		default:
31097c478bd9Sstevel@tonic-gate 			break;
31107c478bd9Sstevel@tonic-gate 		}
31117c478bd9Sstevel@tonic-gate 	}
31127c478bd9Sstevel@tonic-gate 
31137c478bd9Sstevel@tonic-gate 	if (dwl->dw_domset == dwl->dw_reqset) {
31147c478bd9Sstevel@tonic-gate 		rv = 0;
31157c478bd9Sstevel@tonic-gate 	} else {
31167c478bd9Sstevel@tonic-gate 		/*
31177c478bd9Sstevel@tonic-gate 		 * Op failed for some domains or we were awakened.
31187c478bd9Sstevel@tonic-gate 		 */
31197c478bd9Sstevel@tonic-gate 		for (d = rv = 0; (d < MAX_DOMAINS) && !rv; d++)
31207c478bd9Sstevel@tonic-gate 			rv = dwl->dw_errors[d];
31217c478bd9Sstevel@tonic-gate 	}
31227c478bd9Sstevel@tonic-gate 	*domsetp = dwl->dw_domset;
31237c478bd9Sstevel@tonic-gate 
31247c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.dopers->dop_mutex);
31257c478bd9Sstevel@tonic-gate 
31267c478bd9Sstevel@tonic-gate 	idn_deinit_op(cookie);
31277c478bd9Sstevel@tonic-gate 
31287c478bd9Sstevel@tonic-gate 	return (rv);
31297c478bd9Sstevel@tonic-gate }
31307c478bd9Sstevel@tonic-gate 
31317c478bd9Sstevel@tonic-gate /*
31327c478bd9Sstevel@tonic-gate  * --------------------------------------------------
31337c478bd9Sstevel@tonic-gate  * Return any valid (& ready) cpuid for the given board based on
31347c478bd9Sstevel@tonic-gate  * the given cpuset.
31357c478bd9Sstevel@tonic-gate  * --------------------------------------------------
31367c478bd9Sstevel@tonic-gate  */
31377c478bd9Sstevel@tonic-gate int
31387c478bd9Sstevel@tonic-gate board_to_ready_cpu(int board, cpuset_t cpuset)
31397c478bd9Sstevel@tonic-gate {
31407c478bd9Sstevel@tonic-gate 	int	base_cpuid;
31417c478bd9Sstevel@tonic-gate 	int	ncpu_board = MAX_CPU_PER_BRD;
31427c478bd9Sstevel@tonic-gate 
31437c478bd9Sstevel@tonic-gate 	board *= ncpu_board;
31447c478bd9Sstevel@tonic-gate 	for (base_cpuid = board;
31457c478bd9Sstevel@tonic-gate 	    base_cpuid < (board + ncpu_board);
31467c478bd9Sstevel@tonic-gate 	    base_cpuid++)
31477c478bd9Sstevel@tonic-gate 		if (CPU_IN_SET(cpuset, base_cpuid))
31487c478bd9Sstevel@tonic-gate 			return (base_cpuid);
31497c478bd9Sstevel@tonic-gate 
31507c478bd9Sstevel@tonic-gate 	return (-1);
31517c478bd9Sstevel@tonic-gate }
31527c478bd9Sstevel@tonic-gate 
31537c478bd9Sstevel@tonic-gate void
31547c478bd9Sstevel@tonic-gate idn_domain_resetentry(idn_domain_t *dp)
31557c478bd9Sstevel@tonic-gate {
31567c478bd9Sstevel@tonic-gate 	register int		i;
31577c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_domain_resetentry";
31587c478bd9Sstevel@tonic-gate 
31597c478bd9Sstevel@tonic-gate 	ASSERT(dp);
31607c478bd9Sstevel@tonic-gate 	ASSERT(dp->dstate == IDNDS_CLOSED);
31617c478bd9Sstevel@tonic-gate 	ASSERT(IDN_DLOCK_IS_EXCL(dp->domid));
31627c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_EXCL());
31637c478bd9Sstevel@tonic-gate 
31647c478bd9Sstevel@tonic-gate 	ASSERT(dp->domid == (dp - &idn_domain[0]));
31657c478bd9Sstevel@tonic-gate 
31667c478bd9Sstevel@tonic-gate 	IDN_FSTATE_TRANSITION(dp, IDNFIN_OFF);
31677c478bd9Sstevel@tonic-gate 	dp->dname[0]	= '\0';
31687c478bd9Sstevel@tonic-gate 	dp->dnetid	= (ushort_t)-1;
31697c478bd9Sstevel@tonic-gate 	dp->dmtu	= 0;
31707c478bd9Sstevel@tonic-gate 	dp->dbufsize	= 0;
31717c478bd9Sstevel@tonic-gate 	dp->dslabsize	= 0;
31727c478bd9Sstevel@tonic-gate 	dp->dnwrsize	= 0;
31737c478bd9Sstevel@tonic-gate 	dp->dncpus	= 0;
31747c478bd9Sstevel@tonic-gate 	dp->dcpuindex   = 0;
31757c478bd9Sstevel@tonic-gate 	CPUSET_ZERO(dp->dcpuset);
31767c478bd9Sstevel@tonic-gate 	dp->dcpu	= dp->dcpu_last = dp->dcpu_save = IDN_NIL_DCPU;
31777c478bd9Sstevel@tonic-gate 	dp->dvote.ticket = 0;
31787c478bd9Sstevel@tonic-gate 	dp->dslab	= NULL;
31797c478bd9Sstevel@tonic-gate 	dp->dslab_state = DSLAB_STATE_UNKNOWN;
31807c478bd9Sstevel@tonic-gate 	dp->dnslabs	= 0;
31817c478bd9Sstevel@tonic-gate 	dp->dio		= 0;
31827c478bd9Sstevel@tonic-gate 	dp->dioerr	= 0;
31837c478bd9Sstevel@tonic-gate 	lock_clear(&dp->diowanted);
31847c478bd9Sstevel@tonic-gate 	bzero(&dp->dhw, sizeof (dp->dhw));
31857c478bd9Sstevel@tonic-gate 	dp->dxp		= NULL;
31867c478bd9Sstevel@tonic-gate 	IDN_XSTATE_TRANSITION(dp, IDNXS_NIL);
31877c478bd9Sstevel@tonic-gate 	dp->dsync.s_cmd = IDNSYNC_NIL;
31887c478bd9Sstevel@tonic-gate 	dp->dfin_sync   = IDNFIN_SYNC_OFF;
31897c478bd9Sstevel@tonic-gate 	IDN_RESET_COOKIES(dp->domid);
31907c478bd9Sstevel@tonic-gate 	dp->dcookie_err = 0;
31917c478bd9Sstevel@tonic-gate 	bzero(&dp->dawol, sizeof (dp->dawol));
31927c478bd9Sstevel@tonic-gate 	dp->dtmp = -1;
31937c478bd9Sstevel@tonic-gate 
31947c478bd9Sstevel@tonic-gate 	if (dp->dtimerq.tq_queue != NULL) {
31957c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: WARNING: MSG timerq not empty (count = %d)\n",
31967c478bd9Sstevel@tonic-gate 		    proc, dp->dtimerq.tq_count);
31977c478bd9Sstevel@tonic-gate 		IDN_MSGTIMER_STOP(dp->domid, 0, 0);
31987c478bd9Sstevel@tonic-gate 	}
31997c478bd9Sstevel@tonic-gate 
32007c478bd9Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++)
32017c478bd9Sstevel@tonic-gate 		dp->dcpumap[i] = (uchar_t)-1;
32027c478bd9Sstevel@tonic-gate }
32037c478bd9Sstevel@tonic-gate 
32047c478bd9Sstevel@tonic-gate int
32057c478bd9Sstevel@tonic-gate idn_open_domain(int domid, int cpuid, uint_t ticket)
32067c478bd9Sstevel@tonic-gate {
32077c478bd9Sstevel@tonic-gate 	int		c, new_cpuid;
32087c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp, *ldp;
32097c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_open_domain";
32107c478bd9Sstevel@tonic-gate 
32117c478bd9Sstevel@tonic-gate 	ASSERT(IDN_SYNC_IS_LOCKED());
32127c478bd9Sstevel@tonic-gate 	ASSERT(IDN_DLOCK_IS_EXCL(domid));
32137c478bd9Sstevel@tonic-gate 
32147c478bd9Sstevel@tonic-gate 	if (!VALID_DOMAINID(domid)) {
32157c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: INVALID domainid (%d) "
32167c478bd9Sstevel@tonic-gate 		    "[cpuid = %d, ticket = 0x%x]\n",
32177c478bd9Sstevel@tonic-gate 		    proc, domid, cpuid, ticket);
32187c478bd9Sstevel@tonic-gate 		return (-1);
32197c478bd9Sstevel@tonic-gate 	}
32207c478bd9Sstevel@tonic-gate 
32217c478bd9Sstevel@tonic-gate 	dp = &idn_domain[domid];
32227c478bd9Sstevel@tonic-gate 	ldp = &idn_domain[idn.localid];
32237c478bd9Sstevel@tonic-gate 
32247c478bd9Sstevel@tonic-gate 	if (dp->dcpu >= 0) {
32257c478bd9Sstevel@tonic-gate 		PR_PROTO("%s:%d: domain already OPEN (state = %s)\n",
32267c478bd9Sstevel@tonic-gate 		    proc, domid, idnds_str[dp->dstate]);
32277c478bd9Sstevel@tonic-gate 		return (1);
32287c478bd9Sstevel@tonic-gate 	}
32297c478bd9Sstevel@tonic-gate 
32307c478bd9Sstevel@tonic-gate 	if (DOMAIN_IN_SET(idn.domset.ds_relink, domid)) {
32317c478bd9Sstevel@tonic-gate 		if (dp->dcpu_save == IDN_NIL_DCPU)
32327c478bd9Sstevel@tonic-gate 			new_cpuid = cpuid;
32337c478bd9Sstevel@tonic-gate 		else
32347c478bd9Sstevel@tonic-gate 			new_cpuid = dp->dcpu_save;
32357c478bd9Sstevel@tonic-gate 	} else {
32367c478bd9Sstevel@tonic-gate 		new_cpuid = cpuid;
32377c478bd9Sstevel@tonic-gate 	}
32387c478bd9Sstevel@tonic-gate 
32397c478bd9Sstevel@tonic-gate 	if (new_cpuid == IDN_NIL_DCPU) {
32407c478bd9Sstevel@tonic-gate 		PR_PROTO("%s:%d: WARNING: invalid cpuid (%d) specified\n",
32417c478bd9Sstevel@tonic-gate 		    proc, domid, new_cpuid);
32427c478bd9Sstevel@tonic-gate 		return (-1);
32437c478bd9Sstevel@tonic-gate 	}
32447c478bd9Sstevel@tonic-gate 
32457c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
32467c478bd9Sstevel@tonic-gate 
32477c478bd9Sstevel@tonic-gate 	idn_domain_resetentry(dp);
32487c478bd9Sstevel@tonic-gate 
32497c478bd9Sstevel@tonic-gate 	PR_STATE("%s:%d: requested cpuid %d, assigning cpuid %d\n",
32507c478bd9Sstevel@tonic-gate 	    proc, domid, cpuid, new_cpuid);
32517c478bd9Sstevel@tonic-gate 
32527c478bd9Sstevel@tonic-gate 	idn_assign_cookie(domid);
32537c478bd9Sstevel@tonic-gate 
32547c478bd9Sstevel@tonic-gate 	dp->dcpu = dp->dcpu_save = new_cpuid;
32557c478bd9Sstevel@tonic-gate 	dp->dvote.ticket = ticket;
32567c478bd9Sstevel@tonic-gate 	CPUSET_ADD(dp->dcpuset, new_cpuid);
32577c478bd9Sstevel@tonic-gate 	dp->dncpus = 1;
32587c478bd9Sstevel@tonic-gate 	for (c = 0; c < NCPU; c++)
32597c478bd9Sstevel@tonic-gate 		dp->dcpumap[c] = (uchar_t)new_cpuid;
32607c478bd9Sstevel@tonic-gate 	dp->dhw.dh_nboards = 1;
32617c478bd9Sstevel@tonic-gate 	dp->dhw.dh_boardset = BOARDSET(CPUID_TO_BOARDID(new_cpuid));
32627c478bd9Sstevel@tonic-gate 
32637c478bd9Sstevel@tonic-gate 	if (domid != idn.localid)
32647c478bd9Sstevel@tonic-gate 		IDN_DLOCK_EXCL(idn.localid);
32657c478bd9Sstevel@tonic-gate 
32667c478bd9Sstevel@tonic-gate 	if (idn.ndomains == 1) {
32677c478bd9Sstevel@tonic-gate 		struct hwconfig	local_hw;
32687c478bd9Sstevel@tonic-gate 
32697c478bd9Sstevel@tonic-gate 		/*
32707c478bd9Sstevel@tonic-gate 		 * We're attempting to connect to our first domain.
32717c478bd9Sstevel@tonic-gate 		 * Recheck our local hardware configuration before
32727c478bd9Sstevel@tonic-gate 		 * we go any further in case it changed due to a DR,
32737c478bd9Sstevel@tonic-gate 		 * and update any structs dependent on this.
32747c478bd9Sstevel@tonic-gate 		 * ASSUMPTION:
32757c478bd9Sstevel@tonic-gate 		 *	IDN is unlinked before performing any DRs.
32767c478bd9Sstevel@tonic-gate 		 */
32777c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: RECHECKING local HW config.\n", proc);
32787c478bd9Sstevel@tonic-gate 		if (get_hw_config(&local_hw)) {
32797c478bd9Sstevel@tonic-gate 			dp->dcpu = IDN_NIL_DCPU;
32807c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
32817c478bd9Sstevel@tonic-gate 			    "IDN: 118: hardware config not appropriate");
32827c478bd9Sstevel@tonic-gate 			if (domid != idn.localid)
32837c478bd9Sstevel@tonic-gate 				IDN_DUNLOCK(idn.localid);
32847c478bd9Sstevel@tonic-gate 			IDN_GUNLOCK();
32857c478bd9Sstevel@tonic-gate 			return (-1);
32867c478bd9Sstevel@tonic-gate 		}
32877c478bd9Sstevel@tonic-gate 		(void) update_local_hw_config(ldp, &local_hw);
32887c478bd9Sstevel@tonic-gate 	}
32897c478bd9Sstevel@tonic-gate 
32907c478bd9Sstevel@tonic-gate 	idn.ndomains++;
32917c478bd9Sstevel@tonic-gate 
32927c478bd9Sstevel@tonic-gate 	if (domid != idn.localid)
32937c478bd9Sstevel@tonic-gate 		IDN_DUNLOCK(idn.localid);
32947c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
32957c478bd9Sstevel@tonic-gate 
32967c478bd9Sstevel@tonic-gate 	IDN_MBOX_LOCK(domid);
32977c478bd9Sstevel@tonic-gate 	dp->dmbox.m_tbl = NULL;
32987c478bd9Sstevel@tonic-gate 
32997c478bd9Sstevel@tonic-gate 	if (domid != idn.localid) {
33007c478bd9Sstevel@tonic-gate 		dp->dmbox.m_send = idn_mainmbox_init(domid,
33017c478bd9Sstevel@tonic-gate 		    IDNMMBOX_TYPE_SEND);
33027c478bd9Sstevel@tonic-gate 		dp->dmbox.m_recv = idn_mainmbox_init(domid,
33037c478bd9Sstevel@tonic-gate 		    IDNMMBOX_TYPE_RECV);
33047c478bd9Sstevel@tonic-gate 	} else {
33057c478bd9Sstevel@tonic-gate 		/*
33067c478bd9Sstevel@tonic-gate 		 * The local domain does not need send/recv
33077c478bd9Sstevel@tonic-gate 		 * mailboxes in its idn_domain[] entry.
33087c478bd9Sstevel@tonic-gate 		 */
33097c478bd9Sstevel@tonic-gate 		dp->dmbox.m_send = NULL;
33107c478bd9Sstevel@tonic-gate 		dp->dmbox.m_recv = NULL;
33117c478bd9Sstevel@tonic-gate 	}
33127c478bd9Sstevel@tonic-gate 	IDN_MBOX_UNLOCK(domid);
33137c478bd9Sstevel@tonic-gate 
33147c478bd9Sstevel@tonic-gate 	PR_PROTO("%s:%d: new domain (cpu = %d, vote = 0x%x)\n",
33157c478bd9Sstevel@tonic-gate 	    proc, domid, dp->dcpu, dp->dvote.ticket);
33167c478bd9Sstevel@tonic-gate 
33177c478bd9Sstevel@tonic-gate 	return (0);
33187c478bd9Sstevel@tonic-gate }
33197c478bd9Sstevel@tonic-gate 
33207c478bd9Sstevel@tonic-gate /*
33217c478bd9Sstevel@tonic-gate  * The local domain never "closes" itself unless the driver
33227c478bd9Sstevel@tonic-gate  * is doing a idndetach.  It will be reopened during idnattach
33237c478bd9Sstevel@tonic-gate  * when idn_domains_init is called.
33247c478bd9Sstevel@tonic-gate  */
33257c478bd9Sstevel@tonic-gate void
33267c478bd9Sstevel@tonic-gate idn_close_domain(int domid)
33277c478bd9Sstevel@tonic-gate {
33287c478bd9Sstevel@tonic-gate 	uint_t		token;
33297c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp;
33307c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_close_domain";
33317c478bd9Sstevel@tonic-gate 
33327c478bd9Sstevel@tonic-gate 	ASSERT(IDN_SYNC_IS_LOCKED());
33337c478bd9Sstevel@tonic-gate 	ASSERT(IDN_DLOCK_IS_EXCL(domid));
33347c478bd9Sstevel@tonic-gate 
33357c478bd9Sstevel@tonic-gate 	dp = &idn_domain[domid];
33367c478bd9Sstevel@tonic-gate 
33377c478bd9Sstevel@tonic-gate 	ASSERT(dp->dstate == IDNDS_CLOSED);
33387c478bd9Sstevel@tonic-gate 
33397c478bd9Sstevel@tonic-gate 	if (dp->dcpu == IDN_NIL_DCPU) {
33407c478bd9Sstevel@tonic-gate 		PR_PROTO("%s:%d: DOMAIN ALREADY CLOSED!\n",
33417c478bd9Sstevel@tonic-gate 		    proc, domid);
33427c478bd9Sstevel@tonic-gate 		return;
33437c478bd9Sstevel@tonic-gate 	}
33447c478bd9Sstevel@tonic-gate 
33457c478bd9Sstevel@tonic-gate 	token = IDN_RETRY_TOKEN(domid, IDN_RETRY_TYPEALL);
33467c478bd9Sstevel@tonic-gate 
33477c478bd9Sstevel@tonic-gate 	(void) idn_retry_terminate(token);
33487c478bd9Sstevel@tonic-gate 
33497c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_trans_on, domid);
33507c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_ready_on, domid);
33517c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_connected, domid);
33527c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_trans_off, domid);
33537c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_ready_off, domid);
33547c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_hwlinked, domid);
33557c478bd9Sstevel@tonic-gate 	DOMAINSET_DEL(idn.domset.ds_flush, domid);
33567c478bd9Sstevel@tonic-gate 
33577c478bd9Sstevel@tonic-gate 	idn_sync_exit(domid, IDNSYNC_CONNECT);
33587c478bd9Sstevel@tonic-gate 	idn_sync_exit(domid, IDNSYNC_DISCONNECT);
33597c478bd9Sstevel@tonic-gate 
33607c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
33617c478bd9Sstevel@tonic-gate 
33627c478bd9Sstevel@tonic-gate 	if (DOMAIN_IN_SET(idn.domset.ds_awol, domid))
33637c478bd9Sstevel@tonic-gate 		idn_clear_awol(domid);
33647c478bd9Sstevel@tonic-gate 
33657c478bd9Sstevel@tonic-gate 	idn.ndomains--;
33667c478bd9Sstevel@tonic-gate 
33677c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
33687c478bd9Sstevel@tonic-gate 
33697c478bd9Sstevel@tonic-gate 	IDN_MBOX_LOCK(domid);
33707c478bd9Sstevel@tonic-gate 	dp->dmbox.m_tbl = NULL;
33717c478bd9Sstevel@tonic-gate 
33727c478bd9Sstevel@tonic-gate 	if (dp->dmbox.m_send)  {
33737c478bd9Sstevel@tonic-gate 		idn_mainmbox_deinit(domid, dp->dmbox.m_send);
33747c478bd9Sstevel@tonic-gate 		dp->dmbox.m_send = NULL;
33757c478bd9Sstevel@tonic-gate 	}
33767c478bd9Sstevel@tonic-gate 
33777c478bd9Sstevel@tonic-gate 	if (dp->dmbox.m_recv) {
33787c478bd9Sstevel@tonic-gate 		idn_mainmbox_deinit(domid, dp->dmbox.m_recv);
33797c478bd9Sstevel@tonic-gate 		dp->dmbox.m_recv = NULL;
33807c478bd9Sstevel@tonic-gate 	}
33817c478bd9Sstevel@tonic-gate 
33827c478bd9Sstevel@tonic-gate 	IDN_MBOX_UNLOCK(domid);
33837c478bd9Sstevel@tonic-gate 
33847c478bd9Sstevel@tonic-gate 	cmn_err(CE_NOTE,
33857c478bd9Sstevel@tonic-gate 	    "!IDN: 142: link (domain %d, CPU %d) disconnected",
33867c478bd9Sstevel@tonic-gate 	    dp->domid, dp->dcpu);
33877c478bd9Sstevel@tonic-gate 
33887c478bd9Sstevel@tonic-gate 	dp->dcpu = IDN_NIL_DCPU;	/* ultimate demise */
33897c478bd9Sstevel@tonic-gate 
33907c478bd9Sstevel@tonic-gate 	IDN_RESET_COOKIES(domid);
33917c478bd9Sstevel@tonic-gate 
33927c478bd9Sstevel@tonic-gate 	ASSERT(dp->dio <= 0);
33937c478bd9Sstevel@tonic-gate 	ASSERT(dp->dioerr == 0);
33947c478bd9Sstevel@tonic-gate 	ASSERT(dp->dslab == NULL);
33957c478bd9Sstevel@tonic-gate 	ASSERT(dp->dnslabs == 0);
33967c478bd9Sstevel@tonic-gate 
33977c478bd9Sstevel@tonic-gate 	IDN_GKSTAT_GLOBAL_EVENT(gk_unlinks, gk_unlink_last);
33987c478bd9Sstevel@tonic-gate }
33997c478bd9Sstevel@tonic-gate 
34007c478bd9Sstevel@tonic-gate 
34017c478bd9Sstevel@tonic-gate /*
34027c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
34037c478bd9Sstevel@tonic-gate  */
34047c478bd9Sstevel@tonic-gate static void
34057c478bd9Sstevel@tonic-gate idn_domains_init(struct hwconfig *local_hw)
34067c478bd9Sstevel@tonic-gate {
34077c478bd9Sstevel@tonic-gate 	register int		i, d;
34087c478bd9Sstevel@tonic-gate 	idn_domain_t		*ldp;
34097c478bd9Sstevel@tonic-gate 	uchar_t			*cpumap;
34107c478bd9Sstevel@tonic-gate 
34117c478bd9Sstevel@tonic-gate 	ASSERT(local_hw != NULL);
34127c478bd9Sstevel@tonic-gate 
34137c478bd9Sstevel@tonic-gate 	cpumap = GETSTRUCT(uchar_t, NCPU * MAX_DOMAINS);
34147c478bd9Sstevel@tonic-gate 
34157c478bd9Sstevel@tonic-gate 	for (d = 0; d < MAX_DOMAINS; d++) {
34167c478bd9Sstevel@tonic-gate 		register idn_domain_t	*dp;
34177c478bd9Sstevel@tonic-gate 
34187c478bd9Sstevel@tonic-gate 		dp = &idn_domain[d];
34197c478bd9Sstevel@tonic-gate 
34207c478bd9Sstevel@tonic-gate 		dp->domid = d;
34217c478bd9Sstevel@tonic-gate 
34227c478bd9Sstevel@tonic-gate 		rw_init(&dp->drwlock, NULL, RW_DEFAULT, NULL);
34237c478bd9Sstevel@tonic-gate 
34247c478bd9Sstevel@tonic-gate 		IDN_TIMERQ_INIT(&dp->dtimerq);
34257c478bd9Sstevel@tonic-gate 
34267c478bd9Sstevel@tonic-gate 		dp->dstate = IDNDS_CLOSED;
34277c478bd9Sstevel@tonic-gate 
34287c478bd9Sstevel@tonic-gate 		mutex_init(&dp->dmbox.m_mutex, NULL, MUTEX_DEFAULT, NULL);
34297c478bd9Sstevel@tonic-gate 
34307c478bd9Sstevel@tonic-gate 		dp->dcpumap = cpumap;
34317c478bd9Sstevel@tonic-gate 
34327c478bd9Sstevel@tonic-gate 		rw_init(&dp->dslab_rwlock, NULL, RW_DEFAULT, NULL);
34337c478bd9Sstevel@tonic-gate 
34347c478bd9Sstevel@tonic-gate 		IDN_DLOCK_EXCL(d);
34357c478bd9Sstevel@tonic-gate 		IDN_GLOCK_EXCL();
34367c478bd9Sstevel@tonic-gate 
34377c478bd9Sstevel@tonic-gate 		idn_domain_resetentry(dp);
34387c478bd9Sstevel@tonic-gate 
34397c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
34407c478bd9Sstevel@tonic-gate 
34417c478bd9Sstevel@tonic-gate 		IDNSB_DOMAIN_UPDATE(dp);
34427c478bd9Sstevel@tonic-gate 
34437c478bd9Sstevel@tonic-gate 		IDN_DUNLOCK(d);
34447c478bd9Sstevel@tonic-gate 
34457c478bd9Sstevel@tonic-gate 		cpumap += NCPU;
34467c478bd9Sstevel@tonic-gate 	}
34477c478bd9Sstevel@tonic-gate 
34487c478bd9Sstevel@tonic-gate 	IDN_SYNC_LOCK();
34497c478bd9Sstevel@tonic-gate 
34507c478bd9Sstevel@tonic-gate 	/*
34517c478bd9Sstevel@tonic-gate 	 * Update local domain information.
34527c478bd9Sstevel@tonic-gate 	 */
34537c478bd9Sstevel@tonic-gate 	ASSERT(idn.smr.locpfn);
34547c478bd9Sstevel@tonic-gate 	ASSERT(local_hw->dh_nboards && local_hw->dh_boardset);
34557c478bd9Sstevel@tonic-gate 
34567c478bd9Sstevel@tonic-gate 	idn.ndomains = 0;	/* note that open_domain will get us to 1 */
34577c478bd9Sstevel@tonic-gate 
34587c478bd9Sstevel@tonic-gate 	IDN_DLOCK_EXCL(idn.localid);
34597c478bd9Sstevel@tonic-gate 	d = idn_open_domain(idn.localid, (int)CPU->cpu_id, 0);
34607c478bd9Sstevel@tonic-gate 	ASSERT(d == 0);
34617c478bd9Sstevel@tonic-gate 	IDN_GLOCK_EXCL();
34627c478bd9Sstevel@tonic-gate 	IDN_SET_MASTERID(IDN_NIL_DOMID);
34637c478bd9Sstevel@tonic-gate 	IDN_SET_NEW_MASTERID(IDN_NIL_DOMID);
34647c478bd9Sstevel@tonic-gate 
34657c478bd9Sstevel@tonic-gate 	ldp = &idn_domain[idn.localid];
34667c478bd9Sstevel@tonic-gate 
346707d06da5SSurya Prakki 	(void) strncpy(ldp->dname, utsname.nodename, MAXDNAME - 1);
34687c478bd9Sstevel@tonic-gate 	ldp->dname[MAXDNAME-1] = '\0';
34697c478bd9Sstevel@tonic-gate 	bcopy(local_hw, &ldp->dhw, sizeof (ldp->dhw));
34707c478bd9Sstevel@tonic-gate 	ASSERT(idn.ndomains == 1);
34717c478bd9Sstevel@tonic-gate 	ASSERT((ldp->dhw.dh_nboards > 0) &&
34727c478bd9Sstevel@tonic-gate 	    (ldp->dhw.dh_nboards <= MAX_BOARDS));
34737c478bd9Sstevel@tonic-gate 	ldp->dnetid	= IDN_DOMID2NETID(ldp->domid);
34747c478bd9Sstevel@tonic-gate 	ldp->dmtu	= IDN_MTU;
34757c478bd9Sstevel@tonic-gate 	ldp->dbufsize	= IDN_SMR_BUFSIZE;
34767c478bd9Sstevel@tonic-gate 	ldp->dslabsize	= (short)IDN_SLAB_BUFCOUNT;
34777c478bd9Sstevel@tonic-gate 	ldp->dnwrsize	= (short)IDN_NWR_SIZE;
34787c478bd9Sstevel@tonic-gate 	ldp->dcpuset	= cpu_ready_set;
34797c478bd9Sstevel@tonic-gate 	ldp->dncpus	= (short)ncpus;
34807c478bd9Sstevel@tonic-gate 	ldp->dvote.ticket	= IDNVOTE_INITIAL_TICKET;
34817c478bd9Sstevel@tonic-gate 	ldp->dvote.v.master	= 0;
34827c478bd9Sstevel@tonic-gate 	ldp->dvote.v.nmembrds	= ldp->dhw.dh_nmcadr - 1;
34837c478bd9Sstevel@tonic-gate 	ldp->dvote.v.ncpus	= (int)ldp->dncpus - 1;
34847c478bd9Sstevel@tonic-gate 	ldp->dvote.v.board	= CPUID_TO_BOARDID(ldp->dcpu);
34857c478bd9Sstevel@tonic-gate 	i = -1;
34867c478bd9Sstevel@tonic-gate 	for (d = 0; d < NCPU; d++) {
34877c478bd9Sstevel@tonic-gate 		BUMP_INDEX(ldp->dcpuset, i);
34887c478bd9Sstevel@tonic-gate 		ldp->dcpumap[d] = (uchar_t)i;
34897c478bd9Sstevel@tonic-gate 	}
34907c478bd9Sstevel@tonic-gate 
34917c478bd9Sstevel@tonic-gate 	CPUSET_ZERO(idn.dc_cpuset);
34927c478bd9Sstevel@tonic-gate 	CPUSET_OR(idn.dc_cpuset, ldp->dcpuset);
34937c478bd9Sstevel@tonic-gate 	idn.dc_boardset = ldp->dhw.dh_boardset;
34947c478bd9Sstevel@tonic-gate 
34957c478bd9Sstevel@tonic-gate 	/*
34967c478bd9Sstevel@tonic-gate 	 * Setting the state for ourselves is only relevant
34977c478bd9Sstevel@tonic-gate 	 * for loopback performance testing.  Anyway, it
34987c478bd9Sstevel@tonic-gate 	 * makes sense that we always have an established
34997c478bd9Sstevel@tonic-gate 	 * connection with ourself regardless of IDN :-o
35007c478bd9Sstevel@tonic-gate 	 */
35017c478bd9Sstevel@tonic-gate 	IDN_DSTATE_TRANSITION(ldp, IDNDS_CONNECTED);
35027c478bd9Sstevel@tonic-gate 
35037c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
35047c478bd9Sstevel@tonic-gate 	IDN_DUNLOCK(idn.localid);
35057c478bd9Sstevel@tonic-gate 	IDN_SYNC_UNLOCK();
35067c478bd9Sstevel@tonic-gate }
35077c478bd9Sstevel@tonic-gate 
35087c478bd9Sstevel@tonic-gate static void
35097c478bd9Sstevel@tonic-gate idn_domains_deinit()
35107c478bd9Sstevel@tonic-gate {
35117c478bd9Sstevel@tonic-gate 	register int	d;
35127c478bd9Sstevel@tonic-gate 
35137c478bd9Sstevel@tonic-gate 	IDN_SYNC_LOCK();
35147c478bd9Sstevel@tonic-gate 	IDN_DLOCK_EXCL(idn.localid);
35157c478bd9Sstevel@tonic-gate 	IDN_DSTATE_TRANSITION(&idn_domain[idn.localid], IDNDS_CLOSED);
35167c478bd9Sstevel@tonic-gate 	idn_close_domain(idn.localid);
35177c478bd9Sstevel@tonic-gate 	IDN_DUNLOCK(idn.localid);
35187c478bd9Sstevel@tonic-gate 	IDN_SYNC_UNLOCK();
35197c478bd9Sstevel@tonic-gate 	idn.localid = IDN_NIL_DOMID;
35207c478bd9Sstevel@tonic-gate 
35217c478bd9Sstevel@tonic-gate 	FREESTRUCT(idn_domain[0].dcpumap, uchar_t, NCPU * MAX_DOMAINS);
35227c478bd9Sstevel@tonic-gate 
35237c478bd9Sstevel@tonic-gate 	for (d = 0; d < MAX_DOMAINS; d++) {
35247c478bd9Sstevel@tonic-gate 		idn_domain_t	*dp;
35257c478bd9Sstevel@tonic-gate 
35267c478bd9Sstevel@tonic-gate 		dp = &idn_domain[d];
35277c478bd9Sstevel@tonic-gate 
35287c478bd9Sstevel@tonic-gate 		rw_destroy(&dp->dslab_rwlock);
35297c478bd9Sstevel@tonic-gate 		mutex_destroy(&dp->dmbox.m_mutex);
35307c478bd9Sstevel@tonic-gate 		rw_destroy(&dp->drwlock);
35317c478bd9Sstevel@tonic-gate 		IDN_TIMERQ_DEINIT(&dp->dtimerq);
35327c478bd9Sstevel@tonic-gate 		dp->dcpumap = NULL;
35337c478bd9Sstevel@tonic-gate 	}
35347c478bd9Sstevel@tonic-gate }
35357c478bd9Sstevel@tonic-gate 
35367c478bd9Sstevel@tonic-gate /*
35377c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
35387c478bd9Sstevel@tonic-gate  */
35397c478bd9Sstevel@tonic-gate static void
35407c478bd9Sstevel@tonic-gate idn_retrytask_init()
35417c478bd9Sstevel@tonic-gate {
35427c478bd9Sstevel@tonic-gate 	ASSERT(idn.retryqueue.rq_cache == NULL);
35437c478bd9Sstevel@tonic-gate 
35447c478bd9Sstevel@tonic-gate 	mutex_init(&idn.retryqueue.rq_mutex, NULL, MUTEX_DEFAULT, NULL);
35457c478bd9Sstevel@tonic-gate 	idn.retryqueue.rq_cache = kmem_cache_create("idn_retryjob_cache",
35467c478bd9Sstevel@tonic-gate 	    sizeof (idn_retry_job_t),
35477c478bd9Sstevel@tonic-gate 	    0, NULL, NULL, NULL,
35487c478bd9Sstevel@tonic-gate 	    NULL, NULL, 0);
35497c478bd9Sstevel@tonic-gate }
35507c478bd9Sstevel@tonic-gate 
35517c478bd9Sstevel@tonic-gate static void
35527c478bd9Sstevel@tonic-gate idn_retrytask_deinit()
35537c478bd9Sstevel@tonic-gate {
35547c478bd9Sstevel@tonic-gate 	if (idn.retryqueue.rq_cache == NULL)
35557c478bd9Sstevel@tonic-gate 		return;
35567c478bd9Sstevel@tonic-gate 
35577c478bd9Sstevel@tonic-gate 	kmem_cache_destroy(idn.retryqueue.rq_cache);
35587c478bd9Sstevel@tonic-gate 	mutex_destroy(&idn.retryqueue.rq_mutex);
35597c478bd9Sstevel@tonic-gate 
35607c478bd9Sstevel@tonic-gate 	bzero(&idn.retryqueue, sizeof (idn.retryqueue));
35617c478bd9Sstevel@tonic-gate }
35627c478bd9Sstevel@tonic-gate 
35637c478bd9Sstevel@tonic-gate /*
35647c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
35657c478bd9Sstevel@tonic-gate  */
35667c478bd9Sstevel@tonic-gate static void
35677c478bd9Sstevel@tonic-gate idn_timercache_init()
35687c478bd9Sstevel@tonic-gate {
35697c478bd9Sstevel@tonic-gate 	ASSERT(idn.timer_cache == NULL);
35707c478bd9Sstevel@tonic-gate 
35717c478bd9Sstevel@tonic-gate 	idn.timer_cache = kmem_cache_create("idn_timer_cache",
35727c478bd9Sstevel@tonic-gate 	    sizeof (idn_timer_t),
35737c478bd9Sstevel@tonic-gate 	    0, NULL, NULL, NULL,
35747c478bd9Sstevel@tonic-gate 	    NULL, NULL, 0);
35757c478bd9Sstevel@tonic-gate }
35767c478bd9Sstevel@tonic-gate 
35777c478bd9Sstevel@tonic-gate static void
35787c478bd9Sstevel@tonic-gate idn_timercache_deinit()
35797c478bd9Sstevel@tonic-gate {
35807c478bd9Sstevel@tonic-gate 	if (idn.timer_cache == NULL)
35817c478bd9Sstevel@tonic-gate 		return;
35827c478bd9Sstevel@tonic-gate 
35837c478bd9Sstevel@tonic-gate 	kmem_cache_destroy(idn.timer_cache);
35847c478bd9Sstevel@tonic-gate 	idn.timer_cache = NULL;
35857c478bd9Sstevel@tonic-gate }
35867c478bd9Sstevel@tonic-gate 
35877c478bd9Sstevel@tonic-gate idn_timer_t *
35887c478bd9Sstevel@tonic-gate idn_timer_alloc()
35897c478bd9Sstevel@tonic-gate {
35907c478bd9Sstevel@tonic-gate 	idn_timer_t	*tp;
35917c478bd9Sstevel@tonic-gate 
35927c478bd9Sstevel@tonic-gate 	tp = kmem_cache_alloc(idn.timer_cache, KM_SLEEP);
35937c478bd9Sstevel@tonic-gate 	bzero(tp, sizeof (*tp));
35947c478bd9Sstevel@tonic-gate 	tp->t_forw = tp->t_back = tp;
35957c478bd9Sstevel@tonic-gate 
35967c478bd9Sstevel@tonic-gate 	return (tp);
35977c478bd9Sstevel@tonic-gate }
35987c478bd9Sstevel@tonic-gate 
35997c478bd9Sstevel@tonic-gate void
36007c478bd9Sstevel@tonic-gate idn_timer_free(idn_timer_t *tp)
36017c478bd9Sstevel@tonic-gate {
36027c478bd9Sstevel@tonic-gate 	if (tp == NULL)
36037c478bd9Sstevel@tonic-gate 		return;
36047c478bd9Sstevel@tonic-gate 	kmem_cache_free(idn.timer_cache, tp);
36057c478bd9Sstevel@tonic-gate }
36067c478bd9Sstevel@tonic-gate 
36077c478bd9Sstevel@tonic-gate void
36087c478bd9Sstevel@tonic-gate idn_timerq_init(idn_timerq_t *tq)
36097c478bd9Sstevel@tonic-gate {
36107c478bd9Sstevel@tonic-gate 	mutex_init(&tq->tq_mutex, NULL, MUTEX_DEFAULT, NULL);
36117c478bd9Sstevel@tonic-gate 	tq->tq_count = 0;
36127c478bd9Sstevel@tonic-gate 	tq->tq_queue = NULL;
36137c478bd9Sstevel@tonic-gate }
36147c478bd9Sstevel@tonic-gate 
36157c478bd9Sstevel@tonic-gate void
36167c478bd9Sstevel@tonic-gate idn_timerq_deinit(idn_timerq_t *tq)
36177c478bd9Sstevel@tonic-gate {
36187c478bd9Sstevel@tonic-gate 	ASSERT(tq->tq_queue == NULL);
36197c478bd9Sstevel@tonic-gate 	mutex_destroy(&tq->tq_mutex);
36207c478bd9Sstevel@tonic-gate }
36217c478bd9Sstevel@tonic-gate 
36227c478bd9Sstevel@tonic-gate /*
36237c478bd9Sstevel@tonic-gate  * Dequeue all the timers of the given subtype from the
36247c478bd9Sstevel@tonic-gate  * given timerQ.  If subtype is 0, then dequeue all the
36257c478bd9Sstevel@tonic-gate  * timers.
36267c478bd9Sstevel@tonic-gate  */
36277c478bd9Sstevel@tonic-gate idn_timer_t *
36287c478bd9Sstevel@tonic-gate idn_timer_get(idn_timerq_t *tq, int type, ushort_t tcookie)
36297c478bd9Sstevel@tonic-gate {
36307c478bd9Sstevel@tonic-gate 	register idn_timer_t	*tp, *tphead;
36317c478bd9Sstevel@tonic-gate 
36327c478bd9Sstevel@tonic-gate 	ASSERT(IDN_TIMERQ_IS_LOCKED(tq));
36337c478bd9Sstevel@tonic-gate 
36347c478bd9Sstevel@tonic-gate 	if ((tp = tq->tq_queue) == NULL)
36357c478bd9Sstevel@tonic-gate 		return (NULL);
36367c478bd9Sstevel@tonic-gate 
36377c478bd9Sstevel@tonic-gate 	if (!type) {
36387c478bd9Sstevel@tonic-gate 		tq->tq_queue = NULL;
36397c478bd9Sstevel@tonic-gate 		tq->tq_count = 0;
36407c478bd9Sstevel@tonic-gate 		tphead = tp;
36417c478bd9Sstevel@tonic-gate 	} else {
36427c478bd9Sstevel@tonic-gate 		int		count;
36437c478bd9Sstevel@tonic-gate 		idn_timer_t	*tpnext;
36447c478bd9Sstevel@tonic-gate 
36457c478bd9Sstevel@tonic-gate 		tphead = NULL;
36467c478bd9Sstevel@tonic-gate 		count = tq->tq_count;
36477c478bd9Sstevel@tonic-gate 		do {
36487c478bd9Sstevel@tonic-gate 			tpnext = tp->t_forw;
36497c478bd9Sstevel@tonic-gate 			if ((tp->t_type == type) &&
36507c478bd9Sstevel@tonic-gate 			    (!tcookie || (tp->t_cookie == tcookie))) {
36517c478bd9Sstevel@tonic-gate 				tp->t_forw->t_back = tp->t_back;
36527c478bd9Sstevel@tonic-gate 				tp->t_back->t_forw = tp->t_forw;
36537c478bd9Sstevel@tonic-gate 				if (tphead == NULL) {
36547c478bd9Sstevel@tonic-gate 					tp->t_forw = tp->t_back = tp;
36557c478bd9Sstevel@tonic-gate 				} else {
36567c478bd9Sstevel@tonic-gate 					tp->t_forw = tphead;
36577c478bd9Sstevel@tonic-gate 					tp->t_back = tphead->t_back;
36587c478bd9Sstevel@tonic-gate 					tp->t_back->t_forw = tp;
36597c478bd9Sstevel@tonic-gate 					tphead->t_back = tp;
36607c478bd9Sstevel@tonic-gate 				}
36617c478bd9Sstevel@tonic-gate 				tphead = tp;
36627c478bd9Sstevel@tonic-gate 				if (--(tq->tq_count) == 0)
36637c478bd9Sstevel@tonic-gate 					tq->tq_queue = NULL;
36647c478bd9Sstevel@tonic-gate 				else if (tq->tq_queue == tp)
36657c478bd9Sstevel@tonic-gate 					tq->tq_queue = tpnext;
36667c478bd9Sstevel@tonic-gate 			}
36677c478bd9Sstevel@tonic-gate 			tp = tpnext;
36687c478bd9Sstevel@tonic-gate 		} while (--count > 0);
36697c478bd9Sstevel@tonic-gate 	}
36707c478bd9Sstevel@tonic-gate 
36717c478bd9Sstevel@tonic-gate 	if (tphead) {
36727c478bd9Sstevel@tonic-gate 		tphead->t_back->t_forw = NULL;
36737c478bd9Sstevel@tonic-gate 
36747c478bd9Sstevel@tonic-gate 		for (tp = tphead; tp; tp = tp->t_forw)
36757c478bd9Sstevel@tonic-gate 			tp->t_onq = 0;
36767c478bd9Sstevel@tonic-gate 	}
36777c478bd9Sstevel@tonic-gate 
36787c478bd9Sstevel@tonic-gate 	return (tphead);
36797c478bd9Sstevel@tonic-gate }
36807c478bd9Sstevel@tonic-gate 
36817c478bd9Sstevel@tonic-gate ushort_t
36827c478bd9Sstevel@tonic-gate idn_timer_start(idn_timerq_t *tq, idn_timer_t *tp, clock_t tval)
36837c478bd9Sstevel@tonic-gate {
36847c478bd9Sstevel@tonic-gate 	idn_timer_t	*otp;
36857c478bd9Sstevel@tonic-gate 	ushort_t	tcookie;
36867c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_timer_start";
36877c478bd9Sstevel@tonic-gate 	STRING(str);
36887c478bd9Sstevel@tonic-gate 
36897c478bd9Sstevel@tonic-gate 	ASSERT(tq && tp && (tval > 0));
36907c478bd9Sstevel@tonic-gate 	ASSERT((tp->t_forw == tp) && (tp->t_back == tp));
36917c478bd9Sstevel@tonic-gate 	ASSERT(tp->t_type != 0);
36927c478bd9Sstevel@tonic-gate 
36937c478bd9Sstevel@tonic-gate 	IDN_TIMERQ_LOCK(tq);
36947c478bd9Sstevel@tonic-gate 	/*
36957c478bd9Sstevel@tonic-gate 	 * Assign a unique non-zero 8-bit cookie to this timer
36967c478bd9Sstevel@tonic-gate 	 * if the caller hasn't already preassigned one.
36977c478bd9Sstevel@tonic-gate 	 */
36987c478bd9Sstevel@tonic-gate 	while ((tcookie = tp->t_cookie) == 0) {
36997c478bd9Sstevel@tonic-gate 		tp->t_cookie = (tp->t_type & 0xf) |
37007c478bd9Sstevel@tonic-gate 		    ((++tq->tq_cookie & 0xf) << 4);
37017c478bd9Sstevel@tonic-gate 		/*
37027c478bd9Sstevel@tonic-gate 		 * Calculated cookie must never conflict
37037c478bd9Sstevel@tonic-gate 		 * with the public timer cookie.
37047c478bd9Sstevel@tonic-gate 		 */
37057c478bd9Sstevel@tonic-gate 		ASSERT(tp->t_cookie != IDN_TIMER_PUBLIC_COOKIE);
37067c478bd9Sstevel@tonic-gate 	}
37077c478bd9Sstevel@tonic-gate 
37087c478bd9Sstevel@tonic-gate 	/*
37097c478bd9Sstevel@tonic-gate 	 * First have to remove old timers of the
37107c478bd9Sstevel@tonic-gate 	 * same type and cookie, and get rid of them.
37117c478bd9Sstevel@tonic-gate 	 */
37127c478bd9Sstevel@tonic-gate 	otp = idn_timer_get(tq, tp->t_type, tcookie);
37137c478bd9Sstevel@tonic-gate 
37147c478bd9Sstevel@tonic-gate 	tq->tq_count++;
37157c478bd9Sstevel@tonic-gate 
37167c478bd9Sstevel@tonic-gate 	if (tq->tq_queue == NULL) {
37177c478bd9Sstevel@tonic-gate 		tq->tq_queue = tp;
37187c478bd9Sstevel@tonic-gate 		ASSERT((tp->t_forw == tp) && (tp->t_back == tp));
37197c478bd9Sstevel@tonic-gate 	} else {
37207c478bd9Sstevel@tonic-gate 		/*
37217c478bd9Sstevel@tonic-gate 		 * Put me at the end of the list.
37227c478bd9Sstevel@tonic-gate 		 */
37237c478bd9Sstevel@tonic-gate 		tp->t_forw = tq->tq_queue;
37247c478bd9Sstevel@tonic-gate 		tp->t_back = tq->tq_queue->t_back;
37257c478bd9Sstevel@tonic-gate 		tp->t_back->t_forw = tp;
37267c478bd9Sstevel@tonic-gate 		tp->t_forw->t_back = tp;
37277c478bd9Sstevel@tonic-gate 	}
37287c478bd9Sstevel@tonic-gate 
37297c478bd9Sstevel@tonic-gate 	tp->t_onq = 1;
37307c478bd9Sstevel@tonic-gate 	tp->t_q = tq;
37317c478bd9Sstevel@tonic-gate 	tp->t_id = timeout(idn_timer_expired, (caddr_t)tp, tval);
37327c478bd9Sstevel@tonic-gate 
37337c478bd9Sstevel@tonic-gate 
37347c478bd9Sstevel@tonic-gate 	INUM2STR(tp->t_type, str);
37357c478bd9Sstevel@tonic-gate 	PR_TIMER("%s: started %s timer (domain = %d, cookie = 0x%x)\n",
37367c478bd9Sstevel@tonic-gate 	    proc, str, tp->t_domid, tcookie);
37377c478bd9Sstevel@tonic-gate 
37387c478bd9Sstevel@tonic-gate 	IDN_TIMERQ_UNLOCK(tq);
37397c478bd9Sstevel@tonic-gate 
37407c478bd9Sstevel@tonic-gate 	if (otp)
37417c478bd9Sstevel@tonic-gate 		(void) idn_timer_stopall(otp);
37427c478bd9Sstevel@tonic-gate 
37437c478bd9Sstevel@tonic-gate 	return (tcookie);
37447c478bd9Sstevel@tonic-gate }
37457c478bd9Sstevel@tonic-gate 
37467c478bd9Sstevel@tonic-gate /*
37477c478bd9Sstevel@tonic-gate  * Stop all timers of the given subtype.
37487c478bd9Sstevel@tonic-gate  * If subtype is 0, then stop all timers
37497c478bd9Sstevel@tonic-gate  * in this timerQ.
37507c478bd9Sstevel@tonic-gate  */
37517c478bd9Sstevel@tonic-gate void
37527c478bd9Sstevel@tonic-gate idn_timer_stop(idn_timerq_t *tq, int type, ushort_t tcookie)
37537c478bd9Sstevel@tonic-gate {
37547c478bd9Sstevel@tonic-gate 	idn_timer_t	*tphead;
37557c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_timer_stop";
37567c478bd9Sstevel@tonic-gate 	STRING(str);
37577c478bd9Sstevel@tonic-gate 
37587c478bd9Sstevel@tonic-gate 	ASSERT(tq);
37597c478bd9Sstevel@tonic-gate 
37607c478bd9Sstevel@tonic-gate 	INUM2STR(type, str);
37617c478bd9Sstevel@tonic-gate 
37627c478bd9Sstevel@tonic-gate 	IDN_TIMERQ_LOCK(tq);
37637c478bd9Sstevel@tonic-gate 
37647c478bd9Sstevel@tonic-gate 	if (tq->tq_count == 0) {
37657c478bd9Sstevel@tonic-gate 		PR_TIMER("%s: found no %s timers (count=0)\n", proc, str);
37667c478bd9Sstevel@tonic-gate 		IDN_TIMERQ_UNLOCK(tq);
37677c478bd9Sstevel@tonic-gate 		return;
37687c478bd9Sstevel@tonic-gate 	}
37697c478bd9Sstevel@tonic-gate 	tphead = idn_timer_get(tq, type, tcookie);
37707c478bd9Sstevel@tonic-gate #ifdef DEBUG
37717c478bd9Sstevel@tonic-gate 	if (tphead == NULL)
37727c478bd9Sstevel@tonic-gate 		PR_TIMER("%s: found no %s (cookie = 0x%x) "
37737c478bd9Sstevel@tonic-gate 		    "timers (count=%d)!!\n",
37747c478bd9Sstevel@tonic-gate 		    proc, str, tcookie, tq->tq_count);
37757c478bd9Sstevel@tonic-gate #endif /* DEBUG */
37767c478bd9Sstevel@tonic-gate 	IDN_TIMERQ_UNLOCK(tq);
37777c478bd9Sstevel@tonic-gate 
37787c478bd9Sstevel@tonic-gate 	if (tphead)
37797c478bd9Sstevel@tonic-gate 		(void) idn_timer_stopall(tphead);
37807c478bd9Sstevel@tonic-gate }
37817c478bd9Sstevel@tonic-gate 
37827c478bd9Sstevel@tonic-gate int
37837c478bd9Sstevel@tonic-gate idn_timer_stopall(idn_timer_t *tp)
37847c478bd9Sstevel@tonic-gate {
37857c478bd9Sstevel@tonic-gate 	int		count = 0;
37867c478bd9Sstevel@tonic-gate 	int		nonactive;
37877c478bd9Sstevel@tonic-gate 	uint_t		type;
37887c478bd9Sstevel@tonic-gate 	idn_timer_t	*ntp;
37897c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_timer_stopall";
37907c478bd9Sstevel@tonic-gate 	STRING(str);
37917c478bd9Sstevel@tonic-gate 
37927c478bd9Sstevel@tonic-gate 	nonactive = 0;
37937c478bd9Sstevel@tonic-gate 
37947c478bd9Sstevel@tonic-gate 	if (tp) {
37957c478bd9Sstevel@tonic-gate 		/*
37967c478bd9Sstevel@tonic-gate 		 * Circle should have been broken.
37977c478bd9Sstevel@tonic-gate 		 */
37987c478bd9Sstevel@tonic-gate 		ASSERT(tp->t_back->t_forw == NULL);
37997c478bd9Sstevel@tonic-gate 		type = tp->t_type;
38007c478bd9Sstevel@tonic-gate 		INUM2STR(type, str);
38017c478bd9Sstevel@tonic-gate 	}
38027c478bd9Sstevel@tonic-gate 
38037c478bd9Sstevel@tonic-gate 	for (; tp; tp = ntp) {
38047c478bd9Sstevel@tonic-gate 		ntp = tp->t_forw;
38057c478bd9Sstevel@tonic-gate 		count++;
38067c478bd9Sstevel@tonic-gate 		ASSERT(tp->t_id != (timeout_id_t)0);
38077c478bd9Sstevel@tonic-gate 		if (untimeout(tp->t_id) < 0) {
38087c478bd9Sstevel@tonic-gate 			nonactive++;
38097c478bd9Sstevel@tonic-gate 			PR_TIMER("%s: bad %s untimeout (domain=%d)\n",
38107c478bd9Sstevel@tonic-gate 			    proc, str, tp->t_domid);
38117c478bd9Sstevel@tonic-gate 		} else {
38127c478bd9Sstevel@tonic-gate 			PR_TIMER("%s: good %s untimeout (domain=%d)\n",
38137c478bd9Sstevel@tonic-gate 			    proc, str, tp->t_domid);
38147c478bd9Sstevel@tonic-gate 		}
38157c478bd9Sstevel@tonic-gate 		/*
38167c478bd9Sstevel@tonic-gate 		 * There are two possible outcomes from
38177c478bd9Sstevel@tonic-gate 		 * the untimeout().  Each ultimately result
38187c478bd9Sstevel@tonic-gate 		 * in us having to free the timeout structure.
38197c478bd9Sstevel@tonic-gate 		 *
38207c478bd9Sstevel@tonic-gate 		 * 1. We successfully aborted a timeout call.
38217c478bd9Sstevel@tonic-gate 		 *
38227c478bd9Sstevel@tonic-gate 		 * 2. We failed to find the given timer.  He
38237c478bd9Sstevel@tonic-gate 		 *    probably just fired off.
38247c478bd9Sstevel@tonic-gate 		 */
38257c478bd9Sstevel@tonic-gate 		idn_timer_free(tp);
38267c478bd9Sstevel@tonic-gate 	}
38277c478bd9Sstevel@tonic-gate 	PR_TIMER("%s: stopped %d of %d %s timers\n",
38287c478bd9Sstevel@tonic-gate 	    proc, count - nonactive, count, str);
38297c478bd9Sstevel@tonic-gate 
38307c478bd9Sstevel@tonic-gate 	return (count);
38317c478bd9Sstevel@tonic-gate }
38327c478bd9Sstevel@tonic-gate 
38337c478bd9Sstevel@tonic-gate void
38347c478bd9Sstevel@tonic-gate idn_timer_dequeue(idn_timerq_t *tq, idn_timer_t *tp)
38357c478bd9Sstevel@tonic-gate {
38367c478bd9Sstevel@tonic-gate 	ASSERT(tq && tp);
38377c478bd9Sstevel@tonic-gate 	ASSERT(IDN_TIMERQ_IS_LOCKED(tq));
38387c478bd9Sstevel@tonic-gate 
38397c478bd9Sstevel@tonic-gate 	ASSERT(tp->t_q == tq);
38407c478bd9Sstevel@tonic-gate 
38417c478bd9Sstevel@tonic-gate 	if (tp->t_onq == 0) {
38427c478bd9Sstevel@tonic-gate 		/*
38437c478bd9Sstevel@tonic-gate 		 * We've already been dequeued.
38447c478bd9Sstevel@tonic-gate 		 */
38457c478bd9Sstevel@tonic-gate 		ASSERT(tp == tp->t_forw);
38467c478bd9Sstevel@tonic-gate 		ASSERT(tp == tp->t_back);
38477c478bd9Sstevel@tonic-gate 	} else {
38487c478bd9Sstevel@tonic-gate 		/*
38497c478bd9Sstevel@tonic-gate 		 * We're still in the queue, get out.
38507c478bd9Sstevel@tonic-gate 		 */
38517c478bd9Sstevel@tonic-gate 		if (tq->tq_queue == tp)
38527c478bd9Sstevel@tonic-gate 			tq->tq_queue = tp->t_forw;
38537c478bd9Sstevel@tonic-gate 		tp->t_forw->t_back = tp->t_back;
38547c478bd9Sstevel@tonic-gate 		tp->t_back->t_forw = tp->t_forw;
38557c478bd9Sstevel@tonic-gate 		tp->t_onq = 0;
38567c478bd9Sstevel@tonic-gate 		if (--(tq->tq_count) == 0) {
38577c478bd9Sstevel@tonic-gate 			ASSERT(tq->tq_queue == tp);
38587c478bd9Sstevel@tonic-gate 			tq->tq_queue = NULL;
38597c478bd9Sstevel@tonic-gate 		}
38607c478bd9Sstevel@tonic-gate 		tp->t_forw = tp->t_back = tp;
38617c478bd9Sstevel@tonic-gate 	}
38627c478bd9Sstevel@tonic-gate }
38637c478bd9Sstevel@tonic-gate 
38647c478bd9Sstevel@tonic-gate /*
38657c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------------
38667c478bd9Sstevel@tonic-gate  */
38677c478bd9Sstevel@tonic-gate /*ARGSUSED*/
38687c478bd9Sstevel@tonic-gate static int
38697c478bd9Sstevel@tonic-gate idn_slabpool_report(queue_t *wq, mblk_t *mp, caddr_t cp, cred_t *cr)
38707c478bd9Sstevel@tonic-gate {
38717c478bd9Sstevel@tonic-gate 	register int	p, nfree;
38727c478bd9Sstevel@tonic-gate 	char		dsetstr[128];
38737c478bd9Sstevel@tonic-gate 
38747c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_HELD());
38757c478bd9Sstevel@tonic-gate 
38767c478bd9Sstevel@tonic-gate 	if (idn.slabpool == NULL) {
38777c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
38787c478bd9Sstevel@tonic-gate 		    "IDN slabpool not initialized (masterid = %d)",
38797c478bd9Sstevel@tonic-gate 		    IDN_GET_MASTERID());
38807c478bd9Sstevel@tonic-gate 		return (0);
38817c478bd9Sstevel@tonic-gate 	}
38827c478bd9Sstevel@tonic-gate 
38837c478bd9Sstevel@tonic-gate 	for (p = nfree = 0; p < idn.slabpool->npools; p++)
38847c478bd9Sstevel@tonic-gate 		nfree += idn.slabpool->pool[p].nfree;
38857c478bd9Sstevel@tonic-gate 
38867c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp,
38877c478bd9Sstevel@tonic-gate 	    "IDN slabpool (ntotal_slabs = %d, nalloc = %d, "
38887c478bd9Sstevel@tonic-gate 	    "npools = %d)",
38897c478bd9Sstevel@tonic-gate 	    idn.slabpool->ntotslabs,
38907c478bd9Sstevel@tonic-gate 	    idn.slabpool->ntotslabs - nfree,
38917c478bd9Sstevel@tonic-gate 	    idn.slabpool->npools);
38927c478bd9Sstevel@tonic-gate 
38937c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "pool  nslabs  nfree domains");
38947c478bd9Sstevel@tonic-gate 
38957c478bd9Sstevel@tonic-gate 	for (p = 0; p < idn.slabpool->npools; p++) {
38967c478bd9Sstevel@tonic-gate 		register int	d, s;
38977c478bd9Sstevel@tonic-gate 		uint_t		domset;
38987c478bd9Sstevel@tonic-gate 
38997c478bd9Sstevel@tonic-gate 		domset = 0;
39007c478bd9Sstevel@tonic-gate 		for (s = 0; s < idn.slabpool->pool[p].nslabs; s++) {
39017c478bd9Sstevel@tonic-gate 			short	dd;
39027c478bd9Sstevel@tonic-gate 
39037c478bd9Sstevel@tonic-gate 			dd = idn.slabpool->pool[p].sarray[s].sl_domid;
39047c478bd9Sstevel@tonic-gate 			if (dd != (short)IDN_NIL_DOMID)
39057c478bd9Sstevel@tonic-gate 				DOMAINSET_ADD(domset, dd);
39067c478bd9Sstevel@tonic-gate 		}
39077c478bd9Sstevel@tonic-gate 		dsetstr[0] = '\0';
39087c478bd9Sstevel@tonic-gate 		if (domset) {
39097c478bd9Sstevel@tonic-gate 			for (d = 0; d < MAX_DOMAINS; d++) {
39107c478bd9Sstevel@tonic-gate 				if (!DOMAIN_IN_SET(domset, d))
39117c478bd9Sstevel@tonic-gate 					continue;
39127c478bd9Sstevel@tonic-gate 
39137c478bd9Sstevel@tonic-gate 				if (dsetstr[0] == '\0')
39147c478bd9Sstevel@tonic-gate 					(void) sprintf(dsetstr, "%d", d);
39157c478bd9Sstevel@tonic-gate 				else
39167c478bd9Sstevel@tonic-gate 					(void) sprintf(dsetstr, "%s %d",
39177c478bd9Sstevel@tonic-gate 					    dsetstr, d);
39187c478bd9Sstevel@tonic-gate 			}
39197c478bd9Sstevel@tonic-gate 		}
39207c478bd9Sstevel@tonic-gate 
39217c478bd9Sstevel@tonic-gate 		if (p < 10)
39227c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "  %d     %d       %d    %s",
39237c478bd9Sstevel@tonic-gate 			    p, idn.slabpool->pool[p].nslabs,
39247c478bd9Sstevel@tonic-gate 			    idn.slabpool->pool[p].nfree,
39257c478bd9Sstevel@tonic-gate 			    dsetstr);
39267c478bd9Sstevel@tonic-gate 		else
39277c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, " %d     %d       %d    %s",
39287c478bd9Sstevel@tonic-gate 			    p, idn.slabpool->pool[p].nslabs,
39297c478bd9Sstevel@tonic-gate 			    idn.slabpool->pool[p].nfree,
39307c478bd9Sstevel@tonic-gate 			    dsetstr);
39317c478bd9Sstevel@tonic-gate 	}
39327c478bd9Sstevel@tonic-gate 	return (0);
39337c478bd9Sstevel@tonic-gate }
39347c478bd9Sstevel@tonic-gate 
39357c478bd9Sstevel@tonic-gate /*ARGSUSED*/
39367c478bd9Sstevel@tonic-gate static int
39377c478bd9Sstevel@tonic-gate idn_buffer_report(queue_t *wq, mblk_t *mp, caddr_t cp, cred_t *cr)
39387c478bd9Sstevel@tonic-gate {
39397c478bd9Sstevel@tonic-gate 	smr_slab_t	*sp;
39407c478bd9Sstevel@tonic-gate 	register int	d, cnt;
39417c478bd9Sstevel@tonic-gate 	int		bufcount[MAX_DOMAINS];
39427c478bd9Sstevel@tonic-gate 	int		spl;
39437c478bd9Sstevel@tonic-gate 
39447c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_HELD());
39457c478bd9Sstevel@tonic-gate 
39467c478bd9Sstevel@tonic-gate 	if (idn.localid == IDN_NIL_DOMID) {
39477c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "IDN not initialized (localid = %d)",
39487c478bd9Sstevel@tonic-gate 		    idn.localid);
39497c478bd9Sstevel@tonic-gate 		return (0);
39507c478bd9Sstevel@tonic-gate 	}
39517c478bd9Sstevel@tonic-gate 
39527c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "Local domain has %d slabs allocated.",
39537c478bd9Sstevel@tonic-gate 	    idn_domain[idn.localid].dnslabs);
39547c478bd9Sstevel@tonic-gate 
39557c478bd9Sstevel@tonic-gate 	DSLAB_LOCK_SHARED(idn.localid);
39567c478bd9Sstevel@tonic-gate 	if ((sp = idn_domain[idn.localid].dslab) == NULL) {
39577c478bd9Sstevel@tonic-gate 		DSLAB_UNLOCK(idn.localid);
39587c478bd9Sstevel@tonic-gate 		return (0);
39597c478bd9Sstevel@tonic-gate 	}
39607c478bd9Sstevel@tonic-gate 
39617c478bd9Sstevel@tonic-gate 	bzero(bufcount, sizeof (bufcount));
39627c478bd9Sstevel@tonic-gate 	cnt = 0;
39637c478bd9Sstevel@tonic-gate 
39647c478bd9Sstevel@tonic-gate 	spl = splhi();
39657c478bd9Sstevel@tonic-gate 	for (; sp; sp = sp->sl_next) {
39667c478bd9Sstevel@tonic-gate 		smr_slabbuf_t	*bp;
39677c478bd9Sstevel@tonic-gate 
39687c478bd9Sstevel@tonic-gate 		while (!lock_try(&sp->sl_lock))
39697c478bd9Sstevel@tonic-gate 			;
39707c478bd9Sstevel@tonic-gate 		for (bp = sp->sl_inuse; bp; bp = bp->sb_next) {
39717c478bd9Sstevel@tonic-gate 			bufcount[bp->sb_domid]++;
39727c478bd9Sstevel@tonic-gate 			cnt++;
39737c478bd9Sstevel@tonic-gate 		}
39747c478bd9Sstevel@tonic-gate 		lock_clear(&sp->sl_lock);
39757c478bd9Sstevel@tonic-gate 	}
39767c478bd9Sstevel@tonic-gate 	splx(spl);
39777c478bd9Sstevel@tonic-gate 
39787c478bd9Sstevel@tonic-gate 	DSLAB_UNLOCK(idn.localid);
39797c478bd9Sstevel@tonic-gate 
39807c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "Local domain has %d buffers outstanding.", cnt);
39817c478bd9Sstevel@tonic-gate 	if (cnt == 0)
39827c478bd9Sstevel@tonic-gate 		return (0);
39837c478bd9Sstevel@tonic-gate 
39847c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "Domain  nbufs");
39857c478bd9Sstevel@tonic-gate 	for (d = 0; d < MAX_DOMAINS; d++)
39867c478bd9Sstevel@tonic-gate 		if (bufcount[d]) {
39877c478bd9Sstevel@tonic-gate 			if (d < 10)
39887c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp, "   %d      %d",
39897c478bd9Sstevel@tonic-gate 				    d, bufcount[d]);
39907c478bd9Sstevel@tonic-gate 			else
39917c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp, "  %d      %d",
39927c478bd9Sstevel@tonic-gate 				    d, bufcount[d]);
39937c478bd9Sstevel@tonic-gate 		}
39947c478bd9Sstevel@tonic-gate 
39957c478bd9Sstevel@tonic-gate 	return (0);
39967c478bd9Sstevel@tonic-gate }
39977c478bd9Sstevel@tonic-gate 
39987c478bd9Sstevel@tonic-gate static const char *
39997c478bd9Sstevel@tonic-gate _get_spaces(int w, int s, int W)
40007c478bd9Sstevel@tonic-gate {
40017c478bd9Sstevel@tonic-gate 	static const char *const _spaces[] = {
40027c478bd9Sstevel@tonic-gate 		"",			/* 0 */
40037c478bd9Sstevel@tonic-gate 		" ",			/* 1 */
40047c478bd9Sstevel@tonic-gate 		"  ", 			/* 2 */
40057c478bd9Sstevel@tonic-gate 		"   ", 			/* 3 */
40067c478bd9Sstevel@tonic-gate 		"    ", 		/* 4 */
40077c478bd9Sstevel@tonic-gate 		"     ", 		/* 5 */
40087c478bd9Sstevel@tonic-gate 		"      ", 		/* 6 */
40097c478bd9Sstevel@tonic-gate 		"       ", 		/* 7 */
40107c478bd9Sstevel@tonic-gate 		"        ", 		/* 8 */
40117c478bd9Sstevel@tonic-gate 		"         ", 		/* 9 */
40127c478bd9Sstevel@tonic-gate 		"          ", 		/* 10 */
40137c478bd9Sstevel@tonic-gate 		"           ", 		/* 11 */
40147c478bd9Sstevel@tonic-gate 		"            ", 	/* 12 */
40157c478bd9Sstevel@tonic-gate 		"             ", 	/* 13 */
40167c478bd9Sstevel@tonic-gate 		"              ", 	/* 14 */
40177c478bd9Sstevel@tonic-gate 		"               ", 	/* 15 */
40187c478bd9Sstevel@tonic-gate 		"                ", 	/* 16 */
40197c478bd9Sstevel@tonic-gate 		"                 ", 	/* 17 */
40207c478bd9Sstevel@tonic-gate 		"                  ", 	/* 18 */
40217c478bd9Sstevel@tonic-gate 		"                   ", 	/* 19 */
40227c478bd9Sstevel@tonic-gate 	};
40237c478bd9Sstevel@tonic-gate 	return (_spaces[w+s-W]);
40247c478bd9Sstevel@tonic-gate }
40257c478bd9Sstevel@tonic-gate 
40267c478bd9Sstevel@tonic-gate #define	_SSS(X, W, w, s) \
40277c478bd9Sstevel@tonic-gate 	(((w) >= (W)) && (X)) ? _get_spaces((w), (s), (W))
40287c478bd9Sstevel@tonic-gate 
40297c478bd9Sstevel@tonic-gate static const char *
40307c478bd9Sstevel@tonic-gate _hexspace(uint64_t v, int sz, int width, int padding)
40317c478bd9Sstevel@tonic-gate {
40327c478bd9Sstevel@tonic-gate 	int	maxnbl = 16;
40337c478bd9Sstevel@tonic-gate 	int	diff;
40347c478bd9Sstevel@tonic-gate 	uchar_t	*np;
40357c478bd9Sstevel@tonic-gate 
40367c478bd9Sstevel@tonic-gate 	diff = sizeof (uint64_t) - sz;
40377c478bd9Sstevel@tonic-gate 	np = (uchar_t *)&v + diff;
40387c478bd9Sstevel@tonic-gate 	maxnbl -= diff << 1;
40397c478bd9Sstevel@tonic-gate 	while (sz-- > 0) {
40407c478bd9Sstevel@tonic-gate 		if ((*np & 0xf0) && (width >= maxnbl))
40417c478bd9Sstevel@tonic-gate 			return (_get_spaces(width, padding, maxnbl));
40427c478bd9Sstevel@tonic-gate 		maxnbl--;
40437c478bd9Sstevel@tonic-gate 		if ((*np & 0x0f) && (width >= maxnbl))
40447c478bd9Sstevel@tonic-gate 			return (_get_spaces(width, padding, maxnbl));
40457c478bd9Sstevel@tonic-gate 		maxnbl--;
40467c478bd9Sstevel@tonic-gate 		np++;
40477c478bd9Sstevel@tonic-gate 	}
40487c478bd9Sstevel@tonic-gate 	return (_get_spaces(width, padding, 1));
40497c478bd9Sstevel@tonic-gate }
40507c478bd9Sstevel@tonic-gate 
40517c478bd9Sstevel@tonic-gate #define	HEXSPACE(v, t, w, s)	_hexspace((uint64_t)(v), sizeof (t), (w), (s))
40527c478bd9Sstevel@tonic-gate 
40537c478bd9Sstevel@tonic-gate #define	DECSPACE(n, w, s) \
4054bf30efa4Smathue 	(_SSS((uint_t)(n) >= 10000000, 8, (w), (s)) : \
4055bf30efa4Smathue 	_SSS((uint_t)(n) >= 1000000, 7, (w), (s)) : \
4056bf30efa4Smathue 	_SSS((uint_t)(n) >= 100000, 6, (w), (s)) : \
4057bf30efa4Smathue 	_SSS((uint_t)(n) >= 10000, 5, (w), (s)) : \
4058bf30efa4Smathue 	_SSS((uint_t)(n) >= 1000, 4, (w), (s)) : \
4059bf30efa4Smathue 	_SSS((uint_t)(n) >= 100, 3, (w), (s)) : \
4060bf30efa4Smathue 	_SSS((uint_t)(n) >= 10, 2, (w), (s)) : \
4061bf30efa4Smathue 	_get_spaces((w), (s), 1))
4062bf30efa4Smathue 
4063bf30efa4Smathue #define	DECSPACE16(n, w, s) \
4064bf30efa4Smathue 	(_SSS((n) >= 10000, 5, (w), (s)) : \
40657c478bd9Sstevel@tonic-gate 	_SSS((n) >= 1000, 4, (w), (s)) : \
40667c478bd9Sstevel@tonic-gate 	_SSS((n) >= 100, 3, (w), (s)) : \
40677c478bd9Sstevel@tonic-gate 	_SSS((n) >= 10, 2, (w), (s)) : \
40687c478bd9Sstevel@tonic-gate 	_get_spaces((w), (s), 1))
40697c478bd9Sstevel@tonic-gate 
40707c478bd9Sstevel@tonic-gate #define	MBXINFO(mtp) \
407107d06da5SSurya Prakki 	(void *)&mtp->mt_header, \
40727c478bd9Sstevel@tonic-gate 		HEXSPACE(&mtp->mt_header, &mtp->mt_header, 16, 2), \
40737c478bd9Sstevel@tonic-gate 	mtp->mt_header.mh_svr_ready_ptr, \
40747c478bd9Sstevel@tonic-gate 		HEXSPACE(mtp->mt_header.mh_svr_ready_ptr, \
40757c478bd9Sstevel@tonic-gate 			mtp->mt_header.mh_svr_ready_ptr, 8, 1), \
40767c478bd9Sstevel@tonic-gate 	mtp->mt_header.mh_svr_active_ptr, \
40777c478bd9Sstevel@tonic-gate 		HEXSPACE(mtp->mt_header.mh_svr_active_ptr, \
40787c478bd9Sstevel@tonic-gate 			mtp->mt_header.mh_svr_active_ptr, 8, 2), \
40797c478bd9Sstevel@tonic-gate 	*(ushort_t *)(IDN_OFFSET2ADDR(mtp->mt_header.mh_svr_ready_ptr)), \
4080bf30efa4Smathue 	DECSPACE16(*(ushort_t *) \
40817c478bd9Sstevel@tonic-gate 			(IDN_OFFSET2ADDR(mtp->mt_header.mh_svr_ready_ptr)), \
40827c478bd9Sstevel@tonic-gate 			1, 1), \
40837c478bd9Sstevel@tonic-gate 	*(ushort_t *)(IDN_OFFSET2ADDR(mtp->mt_header.mh_svr_active_ptr)), \
4084bf30efa4Smathue 	DECSPACE16(*(ushort_t *) \
40857c478bd9Sstevel@tonic-gate 			(IDN_OFFSET2ADDR(mtp->mt_header.mh_svr_active_ptr)), \
40867c478bd9Sstevel@tonic-gate 			1, 5), \
40877c478bd9Sstevel@tonic-gate 	mtp->mt_header.mh_cookie, \
40887c478bd9Sstevel@tonic-gate 		HEXSPACE(mtp->mt_header.mh_cookie, \
40897c478bd9Sstevel@tonic-gate 			mtp->mt_header.mh_cookie, 8, 2), \
409007d06da5SSurya Prakki 	(void *)&mtp->mt_queue[0], \
40917c478bd9Sstevel@tonic-gate 		HEXSPACE(&mtp->mt_queue[0], &mtp->mt_queue[0], 16, 2)
40927c478bd9Sstevel@tonic-gate 
40937c478bd9Sstevel@tonic-gate /*ARGSUSED*/
40947c478bd9Sstevel@tonic-gate static int
40957c478bd9Sstevel@tonic-gate idn_mboxtbl_report(queue_t *wq, mblk_t *mp, caddr_t cp, cred_t *cr)
40967c478bd9Sstevel@tonic-gate {
40977c478bd9Sstevel@tonic-gate 	register int		c, n, domid, subdomid;
40987c478bd9Sstevel@tonic-gate 	register idn_mboxtbl_t	*mtp;
40997c478bd9Sstevel@tonic-gate 	register idn_mboxmsg_t	*msp;
41007c478bd9Sstevel@tonic-gate 	idn_mboxtbl_t		*map, *mtbasep;
41017c478bd9Sstevel@tonic-gate 
41027c478bd9Sstevel@tonic-gate 
41037c478bd9Sstevel@tonic-gate 	ASSERT((cp == MBXTBL_PART_REPORT) || (cp == MBXTBL_FULL_REPORT));
41047c478bd9Sstevel@tonic-gate 
41057c478bd9Sstevel@tonic-gate 	if (IDN_GLOCK_TRY_SHARED() == 0) {
41067c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Local domain busy, try again.");
41077c478bd9Sstevel@tonic-gate 		return (0);
41087c478bd9Sstevel@tonic-gate 	}
41097c478bd9Sstevel@tonic-gate 
41107c478bd9Sstevel@tonic-gate 	if ((map = idn.mboxarea) == NULL) {
41117c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
41127c478bd9Sstevel@tonic-gate 		    "WARNING: Local domain is not master, "
41137c478bd9Sstevel@tonic-gate 		    "ASSUMING idn.smr.vaddr.");
41147c478bd9Sstevel@tonic-gate 		map = (idn_mboxtbl_t *)idn.smr.vaddr;
41157c478bd9Sstevel@tonic-gate 	}
41167c478bd9Sstevel@tonic-gate 
41177c478bd9Sstevel@tonic-gate 	if (map) {
41187c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Mailbox Area starts @ 0x%p",
411907d06da5SSurya Prakki 		    (void *)map);
41207c478bd9Sstevel@tonic-gate 	} else {
41217c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Mailbox Area not found.");
41227c478bd9Sstevel@tonic-gate 		goto repdone;
41237c478bd9Sstevel@tonic-gate 	}
41247c478bd9Sstevel@tonic-gate 
41257c478bd9Sstevel@tonic-gate 	if (!idn.nchannels) {
41267c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "No OPEN channels found");
41277c478bd9Sstevel@tonic-gate 		goto repdone;
41287c478bd9Sstevel@tonic-gate 	}
41297c478bd9Sstevel@tonic-gate 
41307c478bd9Sstevel@tonic-gate 	for (c = 0; c < IDN_MAX_NETS; c++) {
41317c478bd9Sstevel@tonic-gate 
41327c478bd9Sstevel@tonic-gate 		IDN_CHAN_LOCK_GLOBAL(&idn.chan_servers[c]);
41337c478bd9Sstevel@tonic-gate 		if (!IDN_CHANNEL_IS_ATTACHED(&idn.chan_servers[c])) {
41347c478bd9Sstevel@tonic-gate 			IDN_CHAN_UNLOCK_GLOBAL(&idn.chan_servers[c]);
41357c478bd9Sstevel@tonic-gate 			continue;
41367c478bd9Sstevel@tonic-gate 		}
41377c478bd9Sstevel@tonic-gate 
41387c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
41397c478bd9Sstevel@tonic-gate 		    "Channel %d ---------------------------"
41407c478bd9Sstevel@tonic-gate 		    "--------------------------"
41417c478bd9Sstevel@tonic-gate 		    "-----------------------------", c);
41427c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
41437c478bd9Sstevel@tonic-gate 		    "  Domain   Header	    "
41447c478bd9Sstevel@tonic-gate 		    "Ready/Active Ptrs    "
41457c478bd9Sstevel@tonic-gate 		    "rdy/actv  cookie    Queue	     "
41467c478bd9Sstevel@tonic-gate 		    "busy");
41477c478bd9Sstevel@tonic-gate 
41487c478bd9Sstevel@tonic-gate 		for (domid = 0; domid < MAX_DOMAINS; domid++) {
41497c478bd9Sstevel@tonic-gate 			register int	busy_count;
41507c478bd9Sstevel@tonic-gate 
41517c478bd9Sstevel@tonic-gate 			if ((cp == MBXTBL_PART_REPORT) &&
41527c478bd9Sstevel@tonic-gate 			    (idn_domain[domid].dcpu == IDN_NIL_DCPU))
41537c478bd9Sstevel@tonic-gate 				continue;
41547c478bd9Sstevel@tonic-gate 
41557c478bd9Sstevel@tonic-gate 			mtbasep = IDN_MBOXAREA_BASE(map, domid);
41567c478bd9Sstevel@tonic-gate 
41577c478bd9Sstevel@tonic-gate 			for (subdomid = 0; subdomid < MAX_DOMAINS;
41587c478bd9Sstevel@tonic-gate 			    subdomid++) {
41597c478bd9Sstevel@tonic-gate 				mtp = IDN_MBOXTBL_PTR(mtbasep, subdomid);
41607c478bd9Sstevel@tonic-gate 				mtp = IDN_MBOXTBL_PTR_CHAN(mtp, c);
41617c478bd9Sstevel@tonic-gate 
41627c478bd9Sstevel@tonic-gate 				if (subdomid == domid) {
41637c478bd9Sstevel@tonic-gate 					if (subdomid == 0)
41647c478bd9Sstevel@tonic-gate 						(void) mi_mpprintf(mp,
41657c478bd9Sstevel@tonic-gate 						    "   %x.%x-%d%s%s",
41667c478bd9Sstevel@tonic-gate 						    domid, subdomid, c,
41677c478bd9Sstevel@tonic-gate 							/*CONSTCOND*/
41687c478bd9Sstevel@tonic-gate 						    DECSPACE(c, 2, 2),
41697c478bd9Sstevel@tonic-gate 						    "-- unused --");
41707c478bd9Sstevel@tonic-gate 					else
41717c478bd9Sstevel@tonic-gate 						(void) mi_mpprintf(mp,
41727c478bd9Sstevel@tonic-gate 						    "    .%x-%d%s%s",
41737c478bd9Sstevel@tonic-gate 						    subdomid, c,
41747c478bd9Sstevel@tonic-gate 							/*CONSTCOND*/
41757c478bd9Sstevel@tonic-gate 						    DECSPACE(c, 2, 2),
41767c478bd9Sstevel@tonic-gate 						    "-- unused --");
41777c478bd9Sstevel@tonic-gate 					continue;
41787c478bd9Sstevel@tonic-gate 				}
41797c478bd9Sstevel@tonic-gate 				busy_count = 0;
41807c478bd9Sstevel@tonic-gate 				msp = &mtp->mt_queue[0];
41817c478bd9Sstevel@tonic-gate 				for (n = 0; n < IDN_MMBOX_NUMENTRIES; n++) {
41827c478bd9Sstevel@tonic-gate 					if (msp[n].ms_owner)
41837c478bd9Sstevel@tonic-gate 						busy_count++;
41847c478bd9Sstevel@tonic-gate 				}
41857c478bd9Sstevel@tonic-gate 				if (subdomid == 0) {
41867c478bd9Sstevel@tonic-gate 					(void) mi_mpprintf(mp,
41877c478bd9Sstevel@tonic-gate 					    "   %x.%x-%d%s%p%s%x%s/ %x%s"
41887c478bd9Sstevel@tonic-gate 					    "%d%s/ %d%s%x%s%p%s%d%s",
41897c478bd9Sstevel@tonic-gate 					    domid, subdomid, c,
41907c478bd9Sstevel@tonic-gate 						/*CONSTCOND*/
41917c478bd9Sstevel@tonic-gate 					    DECSPACE(c, 2, 2),
41927c478bd9Sstevel@tonic-gate 					    MBXINFO(mtp), busy_count,
41937c478bd9Sstevel@tonic-gate 					    busy_count ? " <<<<<":"");
41947c478bd9Sstevel@tonic-gate 				} else {
41957c478bd9Sstevel@tonic-gate 					(void) mi_mpprintf(mp,
41967c478bd9Sstevel@tonic-gate 					    "    .%x-%d%s%p%s%x%s/ %x%s"
41977c478bd9Sstevel@tonic-gate 					    "%d%s/ %d%s%x%s%p%s%d%s",
41987c478bd9Sstevel@tonic-gate 					    subdomid, c,
41997c478bd9Sstevel@tonic-gate 						/*CONSTCOND*/
42007c478bd9Sstevel@tonic-gate 					    DECSPACE(c, 2, 2),
42017c478bd9Sstevel@tonic-gate 					    MBXINFO(mtp), busy_count,
42027c478bd9Sstevel@tonic-gate 					    busy_count ? " <<<<<":"");
42037c478bd9Sstevel@tonic-gate 				}
42047c478bd9Sstevel@tonic-gate 			}
42057c478bd9Sstevel@tonic-gate 		}
42067c478bd9Sstevel@tonic-gate 		IDN_CHAN_UNLOCK_GLOBAL(&idn.chan_servers[c]);
42077c478bd9Sstevel@tonic-gate 	}
42087c478bd9Sstevel@tonic-gate 
42097c478bd9Sstevel@tonic-gate repdone:
42107c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
42117c478bd9Sstevel@tonic-gate 
42127c478bd9Sstevel@tonic-gate 	return (0);
42137c478bd9Sstevel@tonic-gate }
42147c478bd9Sstevel@tonic-gate 
42157c478bd9Sstevel@tonic-gate /*ARGSUSED*/
42167c478bd9Sstevel@tonic-gate static void
42177c478bd9Sstevel@tonic-gate idn_mainmbox_domain_report(queue_t *wq, mblk_t *mp, int domid,
42187c478bd9Sstevel@tonic-gate 					idn_mainmbox_t *mmp, char *mbxtype)
42197c478bd9Sstevel@tonic-gate {
42207c478bd9Sstevel@tonic-gate 	register int	c;
42217c478bd9Sstevel@tonic-gate 
42227c478bd9Sstevel@tonic-gate 	if (mmp == NULL) {
42237c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, " %x.%s  -- none --", domid, mbxtype);
42247c478bd9Sstevel@tonic-gate 		return;
42257c478bd9Sstevel@tonic-gate 	}
42267c478bd9Sstevel@tonic-gate 
42277c478bd9Sstevel@tonic-gate 	for (c = 0; c < IDN_MAX_NETS; mmp++, c++) {
42287c478bd9Sstevel@tonic-gate 		int	mm_count;
42297c478bd9Sstevel@tonic-gate 
42307c478bd9Sstevel@tonic-gate 		IDN_CHAN_LOCK_GLOBAL(&idn.chan_servers[c]);
42317c478bd9Sstevel@tonic-gate 		if (IDN_CHANNEL_IS_DETACHED(&idn.chan_servers[c])) {
42327c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, " %x.%s  %u  -- not open --",
42337c478bd9Sstevel@tonic-gate 			    domid, mbxtype, (int)mmp->mm_channel);
42347c478bd9Sstevel@tonic-gate 			IDN_CHAN_UNLOCK_GLOBAL(&idn.chan_servers[c]);
42357c478bd9Sstevel@tonic-gate 			continue;
42367c478bd9Sstevel@tonic-gate 		}
42377c478bd9Sstevel@tonic-gate 
42387c478bd9Sstevel@tonic-gate 		mm_count = ((mmp->mm_count < 0) ? 0 : mmp->mm_count) / 1000;
42397c478bd9Sstevel@tonic-gate 
42407c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, " %x.%s  %d%s%d%s%d%s%p%s%p%s%p%s%d/%d",
42417c478bd9Sstevel@tonic-gate 		    domid, mbxtype,
42427c478bd9Sstevel@tonic-gate 		    (int)mmp->mm_channel,
42437c478bd9Sstevel@tonic-gate 					/*CONSTCOND*/
42447c478bd9Sstevel@tonic-gate 		    DECSPACE((int)mmp->mm_channel, 5, 2),
42457c478bd9Sstevel@tonic-gate 		    mm_count, DECSPACE(mm_count, 8, 2),
42467c478bd9Sstevel@tonic-gate 		    mmp->mm_dropped,
42477c478bd9Sstevel@tonic-gate 		    DECSPACE(mmp->mm_dropped, 8, 2),
424807d06da5SSurya Prakki 		    (void *)mmp->mm_smr_mboxp,
42497c478bd9Sstevel@tonic-gate 		    HEXSPACE(mmp->mm_smr_mboxp,
42507c478bd9Sstevel@tonic-gate 		    mmp->mm_smr_mboxp, 16, 2),
425107d06da5SSurya Prakki 		    (void *)mmp->mm_smr_readyp,
42527c478bd9Sstevel@tonic-gate 		    HEXSPACE(mmp->mm_smr_readyp,
42537c478bd9Sstevel@tonic-gate 		    mmp->mm_smr_readyp, 16, 2),
425407d06da5SSurya Prakki 		    (void *)mmp->mm_smr_activep,
42557c478bd9Sstevel@tonic-gate 		    HEXSPACE(mmp->mm_smr_activep,
42567c478bd9Sstevel@tonic-gate 		    mmp->mm_smr_activep, 16, 2),
42577c478bd9Sstevel@tonic-gate 		    mmp->mm_qiget, mmp->mm_qiput);
42587c478bd9Sstevel@tonic-gate 		IDN_CHAN_UNLOCK_GLOBAL(&idn.chan_servers[c]);
42597c478bd9Sstevel@tonic-gate 	}
42607c478bd9Sstevel@tonic-gate }
42617c478bd9Sstevel@tonic-gate 
42627c478bd9Sstevel@tonic-gate /*ARGSUSED2*/
42637c478bd9Sstevel@tonic-gate static int
42647c478bd9Sstevel@tonic-gate idn_mainmbox_report(queue_t *wq, mblk_t *mp, caddr_t cp, cred_t *cr)
42657c478bd9Sstevel@tonic-gate {
42667c478bd9Sstevel@tonic-gate 	int	domid;
42677c478bd9Sstevel@tonic-gate 	int	header = 0;
42687c478bd9Sstevel@tonic-gate 
42697c478bd9Sstevel@tonic-gate 	/*
42707c478bd9Sstevel@tonic-gate 	 * Domain 0 never has a send/recv mainmbox so
42717c478bd9Sstevel@tonic-gate 	 * don't bother printing him.
42727c478bd9Sstevel@tonic-gate 	 */
42737c478bd9Sstevel@tonic-gate 	for (domid = 1; domid < MAX_DOMAINS; domid++) {
42747c478bd9Sstevel@tonic-gate 		idn_domain_t	*dp;
42757c478bd9Sstevel@tonic-gate 
42767c478bd9Sstevel@tonic-gate 		dp = &idn_domain[domid];
42777c478bd9Sstevel@tonic-gate 
42787c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU)
42797c478bd9Sstevel@tonic-gate 			continue;
42807c478bd9Sstevel@tonic-gate 		IDN_DLOCK_SHARED(domid);
42817c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU) {
42827c478bd9Sstevel@tonic-gate 			IDN_DUNLOCK(domid);
42837c478bd9Sstevel@tonic-gate 			continue;
42847c478bd9Sstevel@tonic-gate 		}
42857c478bd9Sstevel@tonic-gate 		if (!header) {
42867c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp,
42877c478bd9Sstevel@tonic-gate 			    "Domain  Chan   PktCntK   "
42887c478bd9Sstevel@tonic-gate 			    "PktDrop   SMRMbox	   "
42897c478bd9Sstevel@tonic-gate 			    "ReadyPtr	  "
42907c478bd9Sstevel@tonic-gate 			    "ActvPtr	  Miget/Miput");
42917c478bd9Sstevel@tonic-gate 			header = 1;
42927c478bd9Sstevel@tonic-gate 		}
42937c478bd9Sstevel@tonic-gate 
42947c478bd9Sstevel@tonic-gate 		mutex_enter(&dp->dmbox.m_mutex);
42957c478bd9Sstevel@tonic-gate 		idn_mainmbox_domain_report(wq, mp, domid,
42967c478bd9Sstevel@tonic-gate 		    idn_domain[domid].dmbox.m_send,
42977c478bd9Sstevel@tonic-gate 		    "snd");
42987c478bd9Sstevel@tonic-gate 		idn_mainmbox_domain_report(wq, mp, domid,
42997c478bd9Sstevel@tonic-gate 		    idn_domain[domid].dmbox.m_recv,
43007c478bd9Sstevel@tonic-gate 		    "rcv");
43017c478bd9Sstevel@tonic-gate 		mutex_exit(&dp->dmbox.m_mutex);
43027c478bd9Sstevel@tonic-gate 
43037c478bd9Sstevel@tonic-gate 		IDN_DUNLOCK(domid);
43047c478bd9Sstevel@tonic-gate 
43057c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
43067c478bd9Sstevel@tonic-gate 		    "  ---------------------------------------"
43077c478bd9Sstevel@tonic-gate 		    "------------------------"
43087c478bd9Sstevel@tonic-gate 		    "----------------------------");
43097c478bd9Sstevel@tonic-gate 	}
43107c478bd9Sstevel@tonic-gate 
43117c478bd9Sstevel@tonic-gate 	if (!header)
43127c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "No ACTIVE domain connections exist");
43137c478bd9Sstevel@tonic-gate 
43147c478bd9Sstevel@tonic-gate 	return (0);
43157c478bd9Sstevel@tonic-gate }
43167c478bd9Sstevel@tonic-gate 
43177c478bd9Sstevel@tonic-gate /*ARGSUSED*/
43187c478bd9Sstevel@tonic-gate static int
43197c478bd9Sstevel@tonic-gate idn_global_report(queue_t *wq, mblk_t *mp, caddr_t cp, cred_t *cr)
43207c478bd9Sstevel@tonic-gate {
43217c478bd9Sstevel@tonic-gate 	int		i, nactive, masterid, nretry;
43227c478bd9Sstevel@tonic-gate 	uint_t		locpfn_upper, locpfn_lower,
43237c478bd9Sstevel@tonic-gate 	    rempfn_upper, rempfn_lower;
43247c478bd9Sstevel@tonic-gate 	uint_t		marea_upper, marea_lower,
43257c478bd9Sstevel@tonic-gate 	    iarea_upper, iarea_lower;
43267c478bd9Sstevel@tonic-gate 	char		alt_dbuffer[64];
43277c478bd9Sstevel@tonic-gate 	idn_retry_job_t	*rp;
43287c478bd9Sstevel@tonic-gate 	domainset_t	retryset;
43297c478bd9Sstevel@tonic-gate 	domainset_t	connected;
43307c478bd9Sstevel@tonic-gate 	idn_synczone_t	*zp;
43317c478bd9Sstevel@tonic-gate 	idn_syncop_t	*sp;
43327c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp;
43337c478bd9Sstevel@tonic-gate 	char		*dbp, *dbuffer;
43347c478bd9Sstevel@tonic-gate 
43357c478bd9Sstevel@tonic-gate 	if (IDN_SYNC_TRYLOCK() == 0) {
43367c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Sync lock busy, try again.");
43377c478bd9Sstevel@tonic-gate 		return (0);
43387c478bd9Sstevel@tonic-gate 	}
43397c478bd9Sstevel@tonic-gate 
43407c478bd9Sstevel@tonic-gate 	if (IDN_GLOCK_TRY_SHARED() == 0) {
43417c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Local domain busy, try again.");
43427c478bd9Sstevel@tonic-gate 		IDN_SYNC_UNLOCK();
43437c478bd9Sstevel@tonic-gate 		return (0);
43447c478bd9Sstevel@tonic-gate 	}
43457c478bd9Sstevel@tonic-gate 	if ((dbp = dbuffer = ALLOC_DISPSTRING()) == NULL)
43467c478bd9Sstevel@tonic-gate 		dbp = alt_dbuffer;
43477c478bd9Sstevel@tonic-gate 
43487c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "IDN\n    Global State = %s (%d)",
43497c478bd9Sstevel@tonic-gate 	    idngs_str[idn.state], idn.state);
43507c478bd9Sstevel@tonic-gate 
43517c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "SMR");
43527c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    vaddr                ");
435307d06da5SSurya Prakki 	(void) mi_mpprintf(mp, "    0x%p", (void *)idn.smr.vaddr);
43547c478bd9Sstevel@tonic-gate 
43557c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    paddr-local     paddr-remote");
43567c478bd9Sstevel@tonic-gate 	masterid = IDN_GET_MASTERID();
43577c478bd9Sstevel@tonic-gate 	locpfn_upper = (uint_t)(idn.smr.locpfn >> (32 - PAGESHIFT));
43587c478bd9Sstevel@tonic-gate 	locpfn_lower = (uint_t)(idn.smr.locpfn << PAGESHIFT);
43597c478bd9Sstevel@tonic-gate 	if (idn.smr.rempfn == PFN_INVALID) {
43607c478bd9Sstevel@tonic-gate 		rempfn_upper = rempfn_lower = 0;
43617c478bd9Sstevel@tonic-gate 	} else {
43627c478bd9Sstevel@tonic-gate 		rempfn_upper = (uint_t)(idn.smr.rempfn >> (32 - PAGESHIFT));
43637c478bd9Sstevel@tonic-gate 		rempfn_lower = (uint_t)(idn.smr.rempfn << PAGESHIFT);
43647c478bd9Sstevel@tonic-gate 	}
43657c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    0x%x.%x%s0x%x.%x",
43667c478bd9Sstevel@tonic-gate 	    locpfn_upper, locpfn_lower,
43677c478bd9Sstevel@tonic-gate 	    HEXSPACE(locpfn_lower, locpfn_lower, 8,
43687c478bd9Sstevel@tonic-gate 	    (locpfn_upper < 0x10) ? 4 : 3),
43697c478bd9Sstevel@tonic-gate 	    rempfn_upper, rempfn_lower);
43707c478bd9Sstevel@tonic-gate 
43717c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    SMR length  = %d MBytes", IDN_SMR_SIZE);
43727c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    SMR bufsize = %d Bytes", IDN_SMR_BUFSIZE);
43737c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    NWR length  = %d MBytes", IDN_NWR_SIZE);
43747c478bd9Sstevel@tonic-gate 	marea_upper = (uint_t)((uint64_t)IDN_MBOXAREA_SIZE >> 32);
43757c478bd9Sstevel@tonic-gate 	marea_lower = (uint_t)((uint64_t)IDN_MBOXAREA_SIZE & 0xffffffff);
43767c478bd9Sstevel@tonic-gate 	iarea_upper = (uint_t)((uint64_t)(MB2B(IDN_NWR_SIZE) -
43777c478bd9Sstevel@tonic-gate 	    (size_t)IDN_MBOXAREA_SIZE) >> 32);
43787c478bd9Sstevel@tonic-gate 	iarea_lower = (uint_t)((MB2B(IDN_NWR_SIZE) -
43797c478bd9Sstevel@tonic-gate 	    (size_t)IDN_MBOXAREA_SIZE) & 0xffffffff);
43807c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp,
43817c478bd9Sstevel@tonic-gate 	    "    [ mbox area = 0x%x.%x Bytes, "
43827c478bd9Sstevel@tonic-gate 	    "iobuf area = 0x%x.%x Bytes ]",
43837c478bd9Sstevel@tonic-gate 	    marea_upper, marea_lower, iarea_upper, iarea_lower);
43847c478bd9Sstevel@tonic-gate 
43857c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp,
43867c478bd9Sstevel@tonic-gate 	    "\nIDNnet (local domain [id:%d] [name:%s] is %s)",
43877c478bd9Sstevel@tonic-gate 	    idn.localid,
43887c478bd9Sstevel@tonic-gate 	    idn_domain[idn.localid].dname,
43897c478bd9Sstevel@tonic-gate 	    (masterid == IDN_NIL_DOMID) ? "IDLE" :
43907c478bd9Sstevel@tonic-gate 	    (idn.localid == masterid) ? "MASTER" :
43917c478bd9Sstevel@tonic-gate 	    "SLAVE");
43927c478bd9Sstevel@tonic-gate 	nactive = 0;
43937c478bd9Sstevel@tonic-gate 	for (i = 0; i < IDN_MAX_NETS; i++) {
43947c478bd9Sstevel@tonic-gate 		IDN_CHAN_LOCK_GLOBAL(&idn.chan_servers[i]);
43957c478bd9Sstevel@tonic-gate 		if (IDN_CHANNEL_IS_ACTIVE(&idn.chan_servers[i]))
43967c478bd9Sstevel@tonic-gate 			nactive++;
43977c478bd9Sstevel@tonic-gate 		IDN_CHAN_UNLOCK_GLOBAL(&idn.chan_servers[i]);
43987c478bd9Sstevel@tonic-gate 	}
43997c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    I/O Networks: (Open = %d, "
44007c478bd9Sstevel@tonic-gate 	    "Active = %d, Max = %d)",
44017c478bd9Sstevel@tonic-gate 	    idn.nchannels, nactive, IDN_MAX_NETS);
44027c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Number of Domains  = %d", idn.ndomains);
44037c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Number of AWOLs    = %d", idn.nawols);
44047c478bd9Sstevel@tonic-gate 	/*
44057c478bd9Sstevel@tonic-gate 	 * During connect domains can possibly be in ds_connected
44067c478bd9Sstevel@tonic-gate 	 * while still in ds_trans_on.  Only once they leave ds_trans_on
44077c478bd9Sstevel@tonic-gate 	 * are they really connected.
44087c478bd9Sstevel@tonic-gate 	 */
44097c478bd9Sstevel@tonic-gate 	connected = idn.domset.ds_connected & ~idn.domset.ds_trans_on;
44107c478bd9Sstevel@tonic-gate 	DOMAINSET_ADD(connected, idn.localid);
44117c478bd9Sstevel@tonic-gate 	boardset2str(connected, dbp);
44127c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Connected Domains      = %s", dbp);
44137c478bd9Sstevel@tonic-gate 	domainset2str(idn.domset.ds_trans_on, dbp);
44147c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Pending Domain Links   = %s",
44157c478bd9Sstevel@tonic-gate 	    idn.domset.ds_trans_on ? dbp : "<>");
44167c478bd9Sstevel@tonic-gate 	domainset2str(idn.domset.ds_trans_off, dbp);
44177c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Pending Domain Unlinks = %s",
44187c478bd9Sstevel@tonic-gate 	    idn.domset.ds_trans_off ? dbp : "<>");
44197c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.retryqueue.rq_mutex);
44207c478bd9Sstevel@tonic-gate 	nretry = idn.retryqueue.rq_count;
44217c478bd9Sstevel@tonic-gate 	retryset = 0;
44227c478bd9Sstevel@tonic-gate 	for (i = 0, rp = idn.retryqueue.rq_jobs; i < nretry; i++,
44237c478bd9Sstevel@tonic-gate 	    rp = rp->rj_next) {
44247c478bd9Sstevel@tonic-gate 		int	domid;
44257c478bd9Sstevel@tonic-gate 
44267c478bd9Sstevel@tonic-gate 		domid = IDN_RETRY_TOKEN2DOMID(rp->rj_token);
44277c478bd9Sstevel@tonic-gate 		if (VALID_DOMAINID(domid)) {
44287c478bd9Sstevel@tonic-gate 			DOMAINSET_ADD(retryset, domid);
44297c478bd9Sstevel@tonic-gate 		}
44307c478bd9Sstevel@tonic-gate 	}
44317c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.retryqueue.rq_mutex);
44327c478bd9Sstevel@tonic-gate 	domainset2str(retryset, dbp);
44337c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Retry Jobs:Domains     = %d:%s",
44347c478bd9Sstevel@tonic-gate 	    nretry, retryset ? dbp : "<>");
44357c478bd9Sstevel@tonic-gate 	domainset2str(idn.domset.ds_hitlist, dbp);
44367c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Hitlist Domains        = %s",
44377c478bd9Sstevel@tonic-gate 	    idn.domset.ds_hitlist ? dbp : "<>");
44387c478bd9Sstevel@tonic-gate 	domainset2str(idn.domset.ds_relink, dbp);
44397c478bd9Sstevel@tonic-gate 	(void) mi_mpprintf(mp, "    Reconfig Domains       = %s",
44407c478bd9Sstevel@tonic-gate 	    idn.domset.ds_relink ? dbp : "<>");
44417c478bd9Sstevel@tonic-gate 	if (idn.domset.ds_relink)
44427c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "         new master id = %d",
44437c478bd9Sstevel@tonic-gate 		    IDN_GET_NEW_MASTERID());
44447c478bd9Sstevel@tonic-gate 	if (masterid == IDN_NIL_DOMID) {
44457c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    Master Domain: no master");
44467c478bd9Sstevel@tonic-gate 	} else {
44477c478bd9Sstevel@tonic-gate 		idn_domain_t	*mdp;
44487c478bd9Sstevel@tonic-gate 
44497c478bd9Sstevel@tonic-gate 		mdp = &idn_domain[masterid];
44507c478bd9Sstevel@tonic-gate 
44517c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
44527c478bd9Sstevel@tonic-gate 		    "    Master Domain (id:name/brds - state):");
44537c478bd9Sstevel@tonic-gate 
44547c478bd9Sstevel@tonic-gate 		if (strlen(mdp->dname) > 0)
445507d06da5SSurya Prakki 			(void) strcpy(dbp, mdp->dname);
44567c478bd9Sstevel@tonic-gate 		else
44577c478bd9Sstevel@tonic-gate 			boardset2str(mdp->dhw.dh_boardset, dbp);
44587c478bd9Sstevel@tonic-gate 		if (masterid < 10)
44597c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "         %d: %s - %s",
44607c478bd9Sstevel@tonic-gate 			    masterid, dbp,
44617c478bd9Sstevel@tonic-gate 			    idnds_str[mdp->dstate]);
44627c478bd9Sstevel@tonic-gate 		else
44637c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "        %d: %s - %s",
44647c478bd9Sstevel@tonic-gate 			    masterid, dbp,
44657c478bd9Sstevel@tonic-gate 			    idnds_str[mdp->dstate]);
44667c478bd9Sstevel@tonic-gate 	}
44677c478bd9Sstevel@tonic-gate 	if (idn.ndomains <= 1) {
44687c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    Slave Domains: none");
44697c478bd9Sstevel@tonic-gate 	} else {
44707c478bd9Sstevel@tonic-gate 		int	d;
44717c478bd9Sstevel@tonic-gate 
44727c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
44737c478bd9Sstevel@tonic-gate 		    "    Slave Domains (id:name/brds - state):");
44747c478bd9Sstevel@tonic-gate 		for (d = 0; d < MAX_DOMAINS; d++) {
44757c478bd9Sstevel@tonic-gate 			dp = &idn_domain[d];
44767c478bd9Sstevel@tonic-gate 
44777c478bd9Sstevel@tonic-gate 			if ((dp->dcpu == IDN_NIL_DCPU) || (d == masterid))
44787c478bd9Sstevel@tonic-gate 				continue;
44797c478bd9Sstevel@tonic-gate 
44807c478bd9Sstevel@tonic-gate 			if (strlen(dp->dname) > 0)
448107d06da5SSurya Prakki 				(void) strcpy(dbp, dp->dname);
44827c478bd9Sstevel@tonic-gate 			else
44837c478bd9Sstevel@tonic-gate 				boardset2str(dp->dhw.dh_boardset, dbp);
44847c478bd9Sstevel@tonic-gate 			if (d < 10)
44857c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp, "         %d: %s - %s",
44867c478bd9Sstevel@tonic-gate 				    d, dbp,
44877c478bd9Sstevel@tonic-gate 				    idnds_str[dp->dstate]);
44887c478bd9Sstevel@tonic-gate 			else
44897c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp, "        %d: %s - %s",
44907c478bd9Sstevel@tonic-gate 				    d, dbp,
44917c478bd9Sstevel@tonic-gate 				    idnds_str[dp->dstate]);
44927c478bd9Sstevel@tonic-gate 		}
44937c478bd9Sstevel@tonic-gate 	}
44947c478bd9Sstevel@tonic-gate 
44957c478bd9Sstevel@tonic-gate 	if (idn.nawols == 0) {
44967c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    AWOL Domains: none");
44977c478bd9Sstevel@tonic-gate 	} else {
44987c478bd9Sstevel@tonic-gate 		int	d;
44997c478bd9Sstevel@tonic-gate 
45007c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    AWOL Domains (id:name/brds):");
45017c478bd9Sstevel@tonic-gate 		for (d = 0; d < MAX_DOMAINS; d++) {
45027c478bd9Sstevel@tonic-gate 			dp = &idn_domain[d];
45037c478bd9Sstevel@tonic-gate 
45047c478bd9Sstevel@tonic-gate 			if (!DOMAIN_IN_SET(idn.domset.ds_awol, d) ||
45057c478bd9Sstevel@tonic-gate 			    (dp->dcpu == IDN_NIL_DCPU))
45067c478bd9Sstevel@tonic-gate 				continue;
45077c478bd9Sstevel@tonic-gate 
45087c478bd9Sstevel@tonic-gate 			if (strlen(dp->dname) > 0)
450907d06da5SSurya Prakki 				(void) strcpy(dbp, dp->dname);
45107c478bd9Sstevel@tonic-gate 			else
45117c478bd9Sstevel@tonic-gate 				boardset2str(dp->dhw.dh_boardset, dbp);
45127c478bd9Sstevel@tonic-gate 			if (d < 10)
45137c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp, "         %d: %s",
45147c478bd9Sstevel@tonic-gate 				    d, dbp);
45157c478bd9Sstevel@tonic-gate 			else
45167c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp, "        %d: %s",
45177c478bd9Sstevel@tonic-gate 				    d, dbp);
45187c478bd9Sstevel@tonic-gate 		}
45197c478bd9Sstevel@tonic-gate 	}
45207c478bd9Sstevel@tonic-gate 
45217c478bd9Sstevel@tonic-gate 	/*CONSTCOND*/
45227c478bd9Sstevel@tonic-gate 	i = IDN_SYNC_GETZONE(IDNSYNC_CONNECT);
45237c478bd9Sstevel@tonic-gate 	zp = &idn.sync.sz_zone[i];
45247c478bd9Sstevel@tonic-gate 	if (zp->sc_cnt == 0) {
45257c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    Sync Zone (con): [empty]");
45267c478bd9Sstevel@tonic-gate 	} else {
45277c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    Sync Zone (con): [%d domains]",
45287c478bd9Sstevel@tonic-gate 		    zp->sc_cnt);
45297c478bd9Sstevel@tonic-gate 		sp = zp->sc_op;
45307c478bd9Sstevel@tonic-gate 		for (i = 0; (i < zp->sc_cnt) && sp; i++) {
45317c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp,
45327c478bd9Sstevel@tonic-gate 			    "	             "
45337c478bd9Sstevel@tonic-gate 			    "%x: x_set =%s0x%x, r_set =%s0x%x",
45347c478bd9Sstevel@tonic-gate 			    sp->s_domid,
45357c478bd9Sstevel@tonic-gate 			    HEXSPACE(sp->s_set_exp,
45367c478bd9Sstevel@tonic-gate 			    sp->s_set_exp, 4, 1),
45377c478bd9Sstevel@tonic-gate 			    sp->s_set_exp,
45387c478bd9Sstevel@tonic-gate 			    HEXSPACE(sp->s_set_rdy,
45397c478bd9Sstevel@tonic-gate 			    sp->s_set_rdy, 4, 1),
45407c478bd9Sstevel@tonic-gate 			    sp->s_set_rdy);
45417c478bd9Sstevel@tonic-gate 			sp = sp->s_next;
45427c478bd9Sstevel@tonic-gate 		}
45437c478bd9Sstevel@tonic-gate 	}
45447c478bd9Sstevel@tonic-gate 	/*CONSTCOND*/
45457c478bd9Sstevel@tonic-gate 	i = IDN_SYNC_GETZONE(IDNSYNC_DISCONNECT);
45467c478bd9Sstevel@tonic-gate 	zp = &idn.sync.sz_zone[i];
45477c478bd9Sstevel@tonic-gate 	if (zp->sc_cnt == 0) {
45487c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    Sync Zone (dis): [empty]");
45497c478bd9Sstevel@tonic-gate 	} else {
45507c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "    Sync Zone (dis): [%d domains]",
45517c478bd9Sstevel@tonic-gate 		    zp->sc_cnt);
45527c478bd9Sstevel@tonic-gate 		sp = zp->sc_op;
45537c478bd9Sstevel@tonic-gate 		for (i = 0; (i < zp->sc_cnt) && sp; i++) {
45547c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp,
45557c478bd9Sstevel@tonic-gate 			    "	             "
45567c478bd9Sstevel@tonic-gate 			    "%x: x_set =%s0x%x, r_set =%s0x%x",
45577c478bd9Sstevel@tonic-gate 			    sp->s_domid,
45587c478bd9Sstevel@tonic-gate 			    HEXSPACE(sp->s_set_exp,
45597c478bd9Sstevel@tonic-gate 			    sp->s_set_exp, 4, 1),
45607c478bd9Sstevel@tonic-gate 			    sp->s_set_exp,
45617c478bd9Sstevel@tonic-gate 			    HEXSPACE(sp->s_set_rdy,
45627c478bd9Sstevel@tonic-gate 			    sp->s_set_rdy, 4, 1),
45637c478bd9Sstevel@tonic-gate 			    sp->s_set_rdy);
45647c478bd9Sstevel@tonic-gate 			sp = sp->s_next;
45657c478bd9Sstevel@tonic-gate 		}
45667c478bd9Sstevel@tonic-gate 	}
45677c478bd9Sstevel@tonic-gate 
45687c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
45697c478bd9Sstevel@tonic-gate 	IDN_SYNC_UNLOCK();
45707c478bd9Sstevel@tonic-gate 
45717c478bd9Sstevel@tonic-gate 	if (dbuffer) {
45727c478bd9Sstevel@tonic-gate 		FREE_DISPSTRING(dbuffer);
45737c478bd9Sstevel@tonic-gate 	}
45747c478bd9Sstevel@tonic-gate 
45757c478bd9Sstevel@tonic-gate 	return (0);
45767c478bd9Sstevel@tonic-gate }
45777c478bd9Sstevel@tonic-gate 
45787c478bd9Sstevel@tonic-gate /*ARGSUSED*/
45797c478bd9Sstevel@tonic-gate static int
45807c478bd9Sstevel@tonic-gate idn_domain_report(queue_t *wq, mblk_t *mp, caddr_t cp, cred_t *cr)
45817c478bd9Sstevel@tonic-gate {
45827c478bd9Sstevel@tonic-gate 	int		d, nchan;
45837c478bd9Sstevel@tonic-gate 	uint_t		domset;
45847c478bd9Sstevel@tonic-gate 	idn_chanset_t	chanset;
45857c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp;
45867c478bd9Sstevel@tonic-gate 	uint_t		pset_upper, pset_lower;
45877c478bd9Sstevel@tonic-gate 	char		*dbuffer, *dbp;
45887c478bd9Sstevel@tonic-gate 	char		alt_dbuffer[64];
45897c478bd9Sstevel@tonic-gate 
45907c478bd9Sstevel@tonic-gate 
45917c478bd9Sstevel@tonic-gate 	if (IDN_SYNC_TRYLOCK() == 0) {
45927c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Sync lock busy, try again.");
45937c478bd9Sstevel@tonic-gate 		return (0);
45947c478bd9Sstevel@tonic-gate 	}
45957c478bd9Sstevel@tonic-gate 
45967c478bd9Sstevel@tonic-gate 	if (IDN_GLOCK_TRY_SHARED() == 0) {
45977c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "Local domain busy, try again.");
45987c478bd9Sstevel@tonic-gate 		IDN_SYNC_UNLOCK();
45997c478bd9Sstevel@tonic-gate 		return (0);
46007c478bd9Sstevel@tonic-gate 	}
46017c478bd9Sstevel@tonic-gate 
46027c478bd9Sstevel@tonic-gate 	if ((dbp = dbuffer = ALLOC_DISPSTRING()) == NULL)
46037c478bd9Sstevel@tonic-gate 		dbp = alt_dbuffer;
46047c478bd9Sstevel@tonic-gate 
4605bf30efa4Smathue 	if (cp == NULL)
46067c478bd9Sstevel@tonic-gate 		domset = DOMAINSET(idn.localid);
46077c478bd9Sstevel@tonic-gate 	else
46087c478bd9Sstevel@tonic-gate 		domset = DOMAINSET_ALL;
46097c478bd9Sstevel@tonic-gate 
46107c478bd9Sstevel@tonic-gate 	for (d = 0; d < MAX_DOMAINS; d++) {
46117c478bd9Sstevel@tonic-gate 
46127c478bd9Sstevel@tonic-gate 		if (DOMAIN_IN_SET(domset, d) == 0)
46137c478bd9Sstevel@tonic-gate 			continue;
46147c478bd9Sstevel@tonic-gate 
46157c478bd9Sstevel@tonic-gate 		dp = &idn_domain[d];
46167c478bd9Sstevel@tonic-gate 
46177c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU)
46187c478bd9Sstevel@tonic-gate 			continue;
46197c478bd9Sstevel@tonic-gate 
46207c478bd9Sstevel@tonic-gate 		if (IDN_DLOCK_TRY_SHARED(d) == 0) {
46217c478bd9Sstevel@tonic-gate 			if (d < 10)
46227c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp,
46237c478bd9Sstevel@tonic-gate 				    "Domain %d   (0x%p) busy...",
462407d06da5SSurya Prakki 				    d, (void *)dp);
46257c478bd9Sstevel@tonic-gate 			else
46267c478bd9Sstevel@tonic-gate 				(void) mi_mpprintf(mp,
46277c478bd9Sstevel@tonic-gate 				    "Domain %d  (0x%p) busy...",
462807d06da5SSurya Prakki 				    d, (void *)dp);
46297c478bd9Sstevel@tonic-gate 			continue;
46307c478bd9Sstevel@tonic-gate 		}
46317c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU) {
46327c478bd9Sstevel@tonic-gate 			IDN_DUNLOCK(d);
46337c478bd9Sstevel@tonic-gate 			continue;
46347c478bd9Sstevel@tonic-gate 		}
46357c478bd9Sstevel@tonic-gate 		if (d < 10)
46367c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "%sDomain %d   (0x%p)",
46377c478bd9Sstevel@tonic-gate 			    (d && (idn.ndomains > 1)) ? "\n" : "",
463807d06da5SSurya Prakki 			    d, (void *)dp);
46397c478bd9Sstevel@tonic-gate 		else
46407c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "%sDomain %d  (0x%p)",
46417c478bd9Sstevel@tonic-gate 			    (d && (idn.ndomains > 1)) ? "\n" : "",
464207d06da5SSurya Prakki 			    d, (void *)dp);
46437c478bd9Sstevel@tonic-gate 
46447c478bd9Sstevel@tonic-gate 		if (d == idn.localid)
46457c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "  (local)  State = %s (%d)",
46467c478bd9Sstevel@tonic-gate 			    idnds_str[dp->dstate], dp->dstate);
46477c478bd9Sstevel@tonic-gate 		else
46487c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "           State = %s (%d)",
46497c478bd9Sstevel@tonic-gate 			    idnds_str[dp->dstate], dp->dstate);
46507c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Name = %s, Netid = %d",
46517c478bd9Sstevel@tonic-gate 		    (strlen(dp->dname) > 0) ? dp->dname : "<>",
46527c478bd9Sstevel@tonic-gate 		    (int)dp->dnetid);
46537c478bd9Sstevel@tonic-gate 
46547c478bd9Sstevel@tonic-gate 		CHANSET_ZERO(chanset);
46557c478bd9Sstevel@tonic-gate 		nchan = idn_domain_is_registered(d, -1, &chanset);
46567c478bd9Sstevel@tonic-gate 		if (dbuffer)
46577c478bd9Sstevel@tonic-gate 			mask2str(chanset, dbp, 32);
46587c478bd9Sstevel@tonic-gate 		else
46597c478bd9Sstevel@tonic-gate 			(void) sprintf(dbp, "0x%x", chanset);
46607c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Nchans = %d, Chanset = %s",
46617c478bd9Sstevel@tonic-gate 		    nchan, nchan ? dbp : "<>");
46627c478bd9Sstevel@tonic-gate 		pset_upper = UPPER32_CPUMASK(dp->dcpuset);
46637c478bd9Sstevel@tonic-gate 		pset_lower = LOWER32_CPUMASK(dp->dcpuset);
46647c478bd9Sstevel@tonic-gate 		if (dbuffer)
46657c478bd9Sstevel@tonic-gate 			boardset2str(dp->dhw.dh_boardset, dbp);
46667c478bd9Sstevel@tonic-gate 		else
46677c478bd9Sstevel@tonic-gate 			(void) sprintf(dbp, "0x%x", dp->dhw.dh_boardset);
46687c478bd9Sstevel@tonic-gate 
46697c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Nboards = %d, Brdset = %s",
46707c478bd9Sstevel@tonic-gate 		    dp->dhw.dh_nboards,
46717c478bd9Sstevel@tonic-gate 		    dp->dhw.dh_nboards ? dbp : "<>");
46727c478bd9Sstevel@tonic-gate 		(void) sprintf(dbp, "0x%x.%x", pset_upper, pset_lower);
46737c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Ncpus = %d, Cpuset = %s",
46747c478bd9Sstevel@tonic-gate 		    dp->dncpus, dp->dncpus ? dbp : "<>");
46757c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Nmcadr = %d",
46767c478bd9Sstevel@tonic-gate 		    dp->dhw.dh_nmcadr);
46777c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp,
46787c478bd9Sstevel@tonic-gate 		    "	   MsgTimer = %s  (cnt = %d)",
46797c478bd9Sstevel@tonic-gate 		    (dp->dtimerq.tq_count > 0)
46807c478bd9Sstevel@tonic-gate 		    ? "active" : "idle",
46817c478bd9Sstevel@tonic-gate 		    dp->dtimerq.tq_count);
46827c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Dcpu = %d  "
46837c478bd9Sstevel@tonic-gate 		    "(lastcpu = %d, cpuindex = %d)",
46847c478bd9Sstevel@tonic-gate 		    dp->dcpu, dp->dcpu_last, dp->dcpuindex);
46857c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Dio = %d  "
46867c478bd9Sstevel@tonic-gate 		    "(ioerr = %d, iochk = %d, iowanted = %d)",
46877c478bd9Sstevel@tonic-gate 		    dp->dio, dp->dioerr, dp->diocheck ? 1 : 0,
46887c478bd9Sstevel@tonic-gate 		    dp->diowanted ? 1 : 0);
46897c478bd9Sstevel@tonic-gate 		if (dp->dsync.s_cmd == IDNSYNC_NIL) {
46907c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp, "           Dsync = %s",
46917c478bd9Sstevel@tonic-gate 			    idnsync_str[IDNSYNC_NIL]);
46927c478bd9Sstevel@tonic-gate 		} else {
46937c478bd9Sstevel@tonic-gate 			(void) mi_mpprintf(mp,
46947c478bd9Sstevel@tonic-gate 			    "	   Dsync = %s "
46957c478bd9Sstevel@tonic-gate 			    "(x_set = 0x%x, r_set = 0x%x)",
46967c478bd9Sstevel@tonic-gate 			    idnsync_str[dp->dsync.s_cmd],
46977c478bd9Sstevel@tonic-gate 			    (uint_t)dp->dsync.s_set_exp,
46987c478bd9Sstevel@tonic-gate 			    (uint_t)dp->dsync.s_set_rdy);
46997c478bd9Sstevel@tonic-gate 		}
47007c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Dvote = 0x%x",
47017c478bd9Sstevel@tonic-gate 		    dp->dvote.ticket);
47027c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Dfin = %s (Sync = %s)",
47037c478bd9Sstevel@tonic-gate 		    idnfin_str[dp->dfin],
47047c478bd9Sstevel@tonic-gate 		    (dp->dfin_sync == IDNFIN_SYNC_OFF) ? "OFF" :
47057c478bd9Sstevel@tonic-gate 		    (dp->dfin_sync == IDNFIN_SYNC_YES) ? "YES" :
47067c478bd9Sstevel@tonic-gate 		    "NO");
47077c478bd9Sstevel@tonic-gate 		(void) mi_mpprintf(mp, "           Dcookie_err = %s (cnt = %d)",
47087c478bd9Sstevel@tonic-gate 		    dp->dcookie_err ? "YES" : "NO",
47097c478bd9Sstevel@tonic-gate 		    dp->dcookie_errcnt);
47107c478bd9Sstevel@tonic-gate 		IDN_DUNLOCK(d);
47117c478bd9Sstevel@tonic-gate 	}
47127c478bd9Sstevel@tonic-gate 
47137c478bd9Sstevel@tonic-gate 	IDN_GUNLOCK();
47147c478bd9Sstevel@tonic-gate 
47157c478bd9Sstevel@tonic-gate 	if (dbuffer) {
47167c478bd9Sstevel@tonic-gate 		FREE_DISPSTRING(dbuffer);
47177c478bd9Sstevel@tonic-gate 	}
47187c478bd9Sstevel@tonic-gate 
47197c478bd9Sstevel@tonic-gate 	IDN_SYNC_UNLOCK();
47207c478bd9Sstevel@tonic-gate 
47217c478bd9Sstevel@tonic-gate 	return (0);
47227c478bd9Sstevel@tonic-gate }
47237c478bd9Sstevel@tonic-gate 
47247c478bd9Sstevel@tonic-gate #define	SNOOP_ENTRIES	2048	/* power of 2 */
47257c478bd9Sstevel@tonic-gate 
47267c478bd9Sstevel@tonic-gate struct snoop_buffer {
47277c478bd9Sstevel@tonic-gate /*  0 */	char	io;
47287c478bd9Sstevel@tonic-gate /*  1 */	char	board;
47297c478bd9Sstevel@tonic-gate /*  2 */	char	trans[14];
47307c478bd9Sstevel@tonic-gate 
47317c478bd9Sstevel@tonic-gate /* 10 */	uint_t	xargs[4];
47327c478bd9Sstevel@tonic-gate } *snoop_data, snoop_buffer[SNOOP_ENTRIES+1];
47337c478bd9Sstevel@tonic-gate 
47347c478bd9Sstevel@tonic-gate 
47357c478bd9Sstevel@tonic-gate int		snoop_index;
47367c478bd9Sstevel@tonic-gate kmutex_t	snoop_mutex;
47377c478bd9Sstevel@tonic-gate static char	_bd2hexascii[] = {
47387c478bd9Sstevel@tonic-gate 	'0', '1', '2', '3', '4', '5', '6', '7',
47397c478bd9Sstevel@tonic-gate 	'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
47407c478bd9Sstevel@tonic-gate };
47417c478bd9Sstevel@tonic-gate 
47427c478bd9Sstevel@tonic-gate #define	SNOOP_IDN(in, tr, bd, arg1, arg2, arg3, arg4) \
47437c478bd9Sstevel@tonic-gate { \
47447c478bd9Sstevel@tonic-gate 	if (idn_snoop) { \
47457c478bd9Sstevel@tonic-gate 		mutex_enter(&snoop_mutex); \
47467c478bd9Sstevel@tonic-gate 		if (snoop_data == NULL) { \
47477c478bd9Sstevel@tonic-gate 			snoop_data = (struct snoop_buffer *) \
4748*e0731422SRichard Lowe 				(((uint_t)(uintptr_t)snoop_buffer + 0xf) & \
4749*e0731422SRichard Lowe 				    ~0xf);				\
47507c478bd9Sstevel@tonic-gate 		} \
47517c478bd9Sstevel@tonic-gate 		snoop_data[snoop_index].io = ((in) == 0) ? 'o' : 'i'; \
47527c478bd9Sstevel@tonic-gate 		snoop_data[snoop_index].board = \
47537c478bd9Sstevel@tonic-gate 				((bd) == -1) ? 'X' : _bd2hexascii[bd]; \
47547c478bd9Sstevel@tonic-gate 		(void) strncpy(snoop_data[snoop_index].trans, (tr), 14); \
47557c478bd9Sstevel@tonic-gate 		snoop_data[snoop_index].xargs[0] = (arg1); \
47567c478bd9Sstevel@tonic-gate 		snoop_data[snoop_index].xargs[1] = (arg2); \
47577c478bd9Sstevel@tonic-gate 		snoop_data[snoop_index].xargs[2] = (arg3); \
47587c478bd9Sstevel@tonic-gate 		snoop_data[snoop_index].xargs[3] = (arg4); \
47597c478bd9Sstevel@tonic-gate 		snoop_index++; \
47607c478bd9Sstevel@tonic-gate 		snoop_index &= SNOOP_ENTRIES - 1; \
47617c478bd9Sstevel@tonic-gate 		mutex_exit(&snoop_mutex); \
47627c478bd9Sstevel@tonic-gate 	} \
47637c478bd9Sstevel@tonic-gate }
47647c478bd9Sstevel@tonic-gate 
47657c478bd9Sstevel@tonic-gate /*
47667c478bd9Sstevel@tonic-gate  * Allocate the circular buffers to be used for
47677c478bd9Sstevel@tonic-gate  * DMV interrupt processing.
47687c478bd9Sstevel@tonic-gate  */
47697c478bd9Sstevel@tonic-gate static int
47707c478bd9Sstevel@tonic-gate idn_init_handler()
47717c478bd9Sstevel@tonic-gate {
47727c478bd9Sstevel@tonic-gate 	int		i, c;
47737c478bd9Sstevel@tonic-gate 	size_t		len;
47747c478bd9Sstevel@tonic-gate 	idn_dmv_msg_t	*basep, *ivp;
47757c478bd9Sstevel@tonic-gate 	uint32_t	ivp_offset;
47767c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_init_handler";
47777c478bd9Sstevel@tonic-gate 
47787c478bd9Sstevel@tonic-gate 	if (idn.intr.dmv_data != NULL) {
47797c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
47807c478bd9Sstevel@tonic-gate 		    "IDN: 130: IDN DMV handler already initialized");
47817c478bd9Sstevel@tonic-gate 		return (-1);
47827c478bd9Sstevel@tonic-gate 	}
47837c478bd9Sstevel@tonic-gate 
47847c478bd9Sstevel@tonic-gate 	/*
47857c478bd9Sstevel@tonic-gate 	 * This memory will be touched by the low-level
47867c478bd9Sstevel@tonic-gate 	 * DMV trap handler for IDN.
47877c478bd9Sstevel@tonic-gate 	 */
47887c478bd9Sstevel@tonic-gate 	len = sizeof (idn_dmv_data_t);
47897c478bd9Sstevel@tonic-gate 	len = roundup(len, sizeof (uint64_t));
47907c478bd9Sstevel@tonic-gate 	len += NCPU * idn_dmv_pending_max * sizeof (idn_dmv_msg_t);
47917c478bd9Sstevel@tonic-gate 	len = roundup(len, PAGESIZE);
47927c478bd9Sstevel@tonic-gate 
4793bf30efa4Smathue 	PR_PROTO("%s: sizeof (idn_dmv_data_t) = %lu\n",
47947c478bd9Sstevel@tonic-gate 	    proc, sizeof (idn_dmv_data_t));
4795bf30efa4Smathue 	PR_PROTO("%s: allocating %lu bytes for dmv data area\n", proc, len);
47967c478bd9Sstevel@tonic-gate 
47977c478bd9Sstevel@tonic-gate 	idn.intr.dmv_data_len = len;
47987c478bd9Sstevel@tonic-gate 	idn.intr.dmv_data = kmem_zalloc(len, KM_SLEEP);
47997c478bd9Sstevel@tonic-gate 
480007d06da5SSurya Prakki 	PR_PROTO("%s: DMV data area = %p\n", proc, (void *)idn.intr.dmv_data);
48017c478bd9Sstevel@tonic-gate 
48027c478bd9Sstevel@tonic-gate 	idn_dmv_data = (idn_dmv_data_t *)idn.intr.dmv_data;
48037c478bd9Sstevel@tonic-gate 	basep = (idn_dmv_msg_t *)roundup((size_t)idn.intr.dmv_data +
48047c478bd9Sstevel@tonic-gate 	    sizeof (idn_dmv_data_t),
48057c478bd9Sstevel@tonic-gate 	    sizeof (uint64_t));
48067c478bd9Sstevel@tonic-gate 	idn_dmv_data->idn_dmv_qbase = (uint64_t)basep;
48077c478bd9Sstevel@tonic-gate 
48087c478bd9Sstevel@tonic-gate 	ivp = basep;
48097c478bd9Sstevel@tonic-gate 	ivp_offset = 0;
48107c478bd9Sstevel@tonic-gate 	/*
48117c478bd9Sstevel@tonic-gate 	 * The buffer queues are allocated per-cpu.
48127c478bd9Sstevel@tonic-gate 	 */
48137c478bd9Sstevel@tonic-gate 	for (c = 0, ivp = basep; c < NCPU; ivp++, c++) {
48147c478bd9Sstevel@tonic-gate 		idn_dmv_data->idn_dmv_cpu[c].idn_dmv_current = ivp_offset;
48157c478bd9Sstevel@tonic-gate 		idn_iv_queue[c] = ivp;
48167c478bd9Sstevel@tonic-gate 		ivp_offset += sizeof (idn_dmv_msg_t);
48177c478bd9Sstevel@tonic-gate 		for (i = 1; i < idn_dmv_pending_max; ivp++, i++) {
48187c478bd9Sstevel@tonic-gate 			ivp->iv_next = ivp_offset;
48197c478bd9Sstevel@tonic-gate 			ivp->iv_ready = 0;
48207c478bd9Sstevel@tonic-gate 			lock_set(&ivp->iv_ready);
48217c478bd9Sstevel@tonic-gate 			ivp_offset += sizeof (idn_dmv_msg_t);
48227c478bd9Sstevel@tonic-gate 		}
48237c478bd9Sstevel@tonic-gate 		ivp->iv_next = idn_dmv_data->idn_dmv_cpu[c].idn_dmv_current;
48247c478bd9Sstevel@tonic-gate 		ivp->iv_ready = 0;
48257c478bd9Sstevel@tonic-gate 		lock_set(&ivp->iv_ready);
48267c478bd9Sstevel@tonic-gate 	}
48277c478bd9Sstevel@tonic-gate 
48287c478bd9Sstevel@tonic-gate 	idn.intr.dmv_inum = STARFIRE_DMV_IDN_BASE;
4829b0fc0e77Sgovinda 	idn.intr.soft_inum = add_softintr((uint_t)idn_pil, idn_handler, 0,
4830b0fc0e77Sgovinda 	    SOFTINT_ST);
48317c478bd9Sstevel@tonic-gate 	idn_dmv_data->idn_soft_inum = idn.intr.soft_inum;
48327c478bd9Sstevel@tonic-gate 	/*
48337c478bd9Sstevel@tonic-gate 	 * Make sure everything is out there before
48347c478bd9Sstevel@tonic-gate 	 * we effectively set it free for use.
48357c478bd9Sstevel@tonic-gate 	 */
48367c478bd9Sstevel@tonic-gate 	membar_stld_stst();
48377c478bd9Sstevel@tonic-gate 
48387c478bd9Sstevel@tonic-gate 	if (dmv_add_intr(idn.intr.dmv_inum, idn_dmv_handler,
48397c478bd9Sstevel@tonic-gate 	    (caddr_t)idn_dmv_data)) {
48407c478bd9Sstevel@tonic-gate 		idn_deinit_handler();
48417c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "IDN: 132: failed to add IDN DMV handler");
48427c478bd9Sstevel@tonic-gate 		return (-1);
48437c478bd9Sstevel@tonic-gate 	}
48447c478bd9Sstevel@tonic-gate 
48457c478bd9Sstevel@tonic-gate 	return (0);
48467c478bd9Sstevel@tonic-gate }
48477c478bd9Sstevel@tonic-gate 
48487c478bd9Sstevel@tonic-gate static void
48497c478bd9Sstevel@tonic-gate idn_deinit_handler()
48507c478bd9Sstevel@tonic-gate {
48517c478bd9Sstevel@tonic-gate 	if (idn.intr.dmv_data == NULL)
48527c478bd9Sstevel@tonic-gate 		return;
48537c478bd9Sstevel@tonic-gate 
48547c478bd9Sstevel@tonic-gate 	(void) dmv_rem_intr(idn.intr.dmv_inum);
4855b0fc0e77Sgovinda 	(void) rem_softintr(idn.intr.soft_inum);
48567c478bd9Sstevel@tonic-gate 	kmem_free(idn.intr.dmv_data, idn.intr.dmv_data_len);
48577c478bd9Sstevel@tonic-gate 	idn.intr.dmv_data = NULL;
48587c478bd9Sstevel@tonic-gate }
48597c478bd9Sstevel@tonic-gate 
48607c478bd9Sstevel@tonic-gate /*
48617c478bd9Sstevel@tonic-gate  * High-level (soft interrupt) handler for DMV interrupts
48627c478bd9Sstevel@tonic-gate  */
48637c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
48647c478bd9Sstevel@tonic-gate static uint_t
48657c478bd9Sstevel@tonic-gate idn_handler(caddr_t unused, caddr_t unused2)
48667c478bd9Sstevel@tonic-gate {
48677c478bd9Sstevel@tonic-gate #ifdef DEBUG
48687c478bd9Sstevel@tonic-gate 	int		count = 0;
48697c478bd9Sstevel@tonic-gate #endif /* DEBUG */
48707c478bd9Sstevel@tonic-gate 	int		cpuid = (int)CPU->cpu_id;
48717c478bd9Sstevel@tonic-gate 	ushort_t	mtype, atype;
48727c478bd9Sstevel@tonic-gate 	idn_dmv_msg_t	*xp, *xplimit;
48737c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_handler";
48747c478bd9Sstevel@tonic-gate 
48757c478bd9Sstevel@tonic-gate 	ASSERT(getpil() >= idn_pil);
48767c478bd9Sstevel@tonic-gate 	flush_windows();
48777c478bd9Sstevel@tonic-gate 
48787c478bd9Sstevel@tonic-gate 	/*
48797c478bd9Sstevel@tonic-gate 	 * Clear the synchronization flag to indicate that
48807c478bd9Sstevel@tonic-gate 	 * processing has started.  As long as idn_dmv_active
48817c478bd9Sstevel@tonic-gate 	 * is non-zero, idn_dmv_handler will queue work without
48827c478bd9Sstevel@tonic-gate 	 * initiating a soft interrupt.  Since we clear it
48837c478bd9Sstevel@tonic-gate 	 * first thing at most one pil-interrupt for IDN will
48847c478bd9Sstevel@tonic-gate 	 * queue up behind the currently active one.  We don't
48857c478bd9Sstevel@tonic-gate 	 * want to clear this flag at the end because it leaves
48867c478bd9Sstevel@tonic-gate 	 * a window where an interrupt could get lost (unless it's
48877c478bd9Sstevel@tonic-gate 	 * pushed by a subsequent interrupt).  The objective in
4888b0fc0e77Sgovinda 	 * doing this is to prevent exhausting a cpu's intr_vec
48897c478bd9Sstevel@tonic-gate 	 * structures with interrupts of the same pil level.
48907c478bd9Sstevel@tonic-gate 	 */
48917c478bd9Sstevel@tonic-gate 	lock_clear(&idn_dmv_data->idn_dmv_cpu[cpuid].idn_dmv_active);
48927c478bd9Sstevel@tonic-gate 
48937c478bd9Sstevel@tonic-gate 	xp = idn_iv_queue[cpuid];
48947c478bd9Sstevel@tonic-gate 	xplimit = xp + idn_dmv_pending_max;
48957c478bd9Sstevel@tonic-gate 	xp += idn_intr_index[cpuid];
48967c478bd9Sstevel@tonic-gate 	/*
48977c478bd9Sstevel@tonic-gate 	 * As long as there's stuff that's READY in the
48987c478bd9Sstevel@tonic-gate 	 * queue, keep processing.
48997c478bd9Sstevel@tonic-gate 	 */
49007c478bd9Sstevel@tonic-gate 	while (lock_try(&xp->iv_ready)) {
49017c478bd9Sstevel@tonic-gate 
49027c478bd9Sstevel@tonic-gate 		ASSERT(lock_try(&xp->iv_inuse) == 0);
49037c478bd9Sstevel@tonic-gate 
49047c478bd9Sstevel@tonic-gate 		mtype = (ushort_t)xp->iv_mtype;
49057c478bd9Sstevel@tonic-gate 		mtype &= IDNP_MSGTYPE_MASK | IDNP_ACKNACK_MASK;
49067c478bd9Sstevel@tonic-gate 		atype = (ushort_t)xp->iv_atype;
49077c478bd9Sstevel@tonic-gate 
49087c478bd9Sstevel@tonic-gate 		if (((int)xp->iv_ver == idn.version) && mtype) {
49097c478bd9Sstevel@tonic-gate 			idn_protojob_t	*jp;
49107c478bd9Sstevel@tonic-gate #ifdef DEBUG
49117c478bd9Sstevel@tonic-gate 			STRING(mstr);
49127c478bd9Sstevel@tonic-gate 			STRING(astr);
49137c478bd9Sstevel@tonic-gate 
49147c478bd9Sstevel@tonic-gate 			INUM2STR(mtype, mstr);
49157c478bd9Sstevel@tonic-gate 			if ((mtype & IDNP_MSGTYPE_MASK) == 0) {
49167c478bd9Sstevel@tonic-gate 				INUM2STR(atype, astr);
491707d06da5SSurya Prakki 				(void) strcat(mstr, "/");
491807d06da5SSurya Prakki 				(void) strcat(mstr, astr);
49197c478bd9Sstevel@tonic-gate 			}
49207c478bd9Sstevel@tonic-gate 
49217c478bd9Sstevel@tonic-gate 			count++;
49227c478bd9Sstevel@tonic-gate 
49237c478bd9Sstevel@tonic-gate 			PR_XDC("%s:%d:%d RECV: scpu = %d, msg = 0x%x(%s)\n",
49247c478bd9Sstevel@tonic-gate 			    proc, (int)xp->iv_domid, count,
49257c478bd9Sstevel@tonic-gate 			    (int)xp->iv_cpuid, mtype, mstr);
49267c478bd9Sstevel@tonic-gate 			PR_XDC("%s:%d:%d R-DATA: a0 = 0x%x, a1 = 0x%x\n",
49277c478bd9Sstevel@tonic-gate 			    proc, (int)xp->iv_domid, count,
49287c478bd9Sstevel@tonic-gate 			    xp->iv_xargs0, xp->iv_xargs1);
49297c478bd9Sstevel@tonic-gate 			PR_XDC("%s:%d:%d R-DATA: a2 = 0x%x, a3 = 0x%x\n",
49307c478bd9Sstevel@tonic-gate 			    proc, (int)xp->iv_domid, count,
49317c478bd9Sstevel@tonic-gate 			    xp->iv_xargs2, xp->iv_xargs3);
49327c478bd9Sstevel@tonic-gate #endif /* DEBUG */
49337c478bd9Sstevel@tonic-gate 
49347c478bd9Sstevel@tonic-gate 			if (mtype == IDNP_DATA) {
49357c478bd9Sstevel@tonic-gate 				jp = NULL;
49367c478bd9Sstevel@tonic-gate 				/*
49377c478bd9Sstevel@tonic-gate 				 * The only time we receive pure
49387c478bd9Sstevel@tonic-gate 				 * data messages at this level is
49397c478bd9Sstevel@tonic-gate 				 * to wake up the channel server.
49407c478bd9Sstevel@tonic-gate 				 * Since this is often an urgent
49417c478bd9Sstevel@tonic-gate 				 * request we'll do it from here
49427c478bd9Sstevel@tonic-gate 				 * instead of waiting for a proto
49437c478bd9Sstevel@tonic-gate 				 * server to do it.
49447c478bd9Sstevel@tonic-gate 				 */
49457c478bd9Sstevel@tonic-gate 				idn_signal_data_server((int)xp->iv_domid,
49467c478bd9Sstevel@tonic-gate 				    (ushort_t)xp->iv_xargs0);
49477c478bd9Sstevel@tonic-gate 			} else {
49487c478bd9Sstevel@tonic-gate 				jp = idn_protojob_alloc(KM_NOSLEEP);
49497c478bd9Sstevel@tonic-gate 				/*
49507c478bd9Sstevel@tonic-gate 				 * If the allocation fails, just drop
49517c478bd9Sstevel@tonic-gate 				 * the message and get on with life.
49527c478bd9Sstevel@tonic-gate 				 * If memory pressure is this great then
49537c478bd9Sstevel@tonic-gate 				 * dropping this message is probably
49547c478bd9Sstevel@tonic-gate 				 * the least of our worries!
49557c478bd9Sstevel@tonic-gate 				 */
49567c478bd9Sstevel@tonic-gate 				if (jp) {
49577c478bd9Sstevel@tonic-gate 					jp->j_msg.m_domid = (int)xp->iv_domid;
49587c478bd9Sstevel@tonic-gate 					jp->j_msg.m_cpuid = (int)xp->iv_cpuid;
49597c478bd9Sstevel@tonic-gate 					jp->j_msg.m_msgtype = mtype;
49607c478bd9Sstevel@tonic-gate 					jp->j_msg.m_acktype = atype;
49617c478bd9Sstevel@tonic-gate 					jp->j_msg.m_cookie = xp->iv_cookie;
49627c478bd9Sstevel@tonic-gate 					SET_XARGS(jp->j_msg.m_xargs,
49637c478bd9Sstevel@tonic-gate 					    xp->iv_xargs0, xp->iv_xargs1,
49647c478bd9Sstevel@tonic-gate 					    xp->iv_xargs2, xp->iv_xargs3);
49657c478bd9Sstevel@tonic-gate 				}
49667c478bd9Sstevel@tonic-gate 
49677c478bd9Sstevel@tonic-gate 			}
49687c478bd9Sstevel@tonic-gate 			membar_ldst_stst();
49697c478bd9Sstevel@tonic-gate 
49707c478bd9Sstevel@tonic-gate 			lock_clear(&xp->iv_inuse);
49717c478bd9Sstevel@tonic-gate 
49727c478bd9Sstevel@tonic-gate 			if (jp)
49737c478bd9Sstevel@tonic-gate 				idn_protojob_submit(jp->j_msg.m_domid, jp);
49747c478bd9Sstevel@tonic-gate 		} else {
49757c478bd9Sstevel@tonic-gate 			membar_ldst_stst();
49767c478bd9Sstevel@tonic-gate 			IDN_GKSTAT_INC(gk_dropped_intrs);
49777c478bd9Sstevel@tonic-gate 			lock_clear(&xp->iv_inuse);
49787c478bd9Sstevel@tonic-gate 		}
49797c478bd9Sstevel@tonic-gate 
49807c478bd9Sstevel@tonic-gate 		if (++xp == xplimit)
49817c478bd9Sstevel@tonic-gate 			xp = idn_iv_queue[cpuid];
49827c478bd9Sstevel@tonic-gate 	}
49837c478bd9Sstevel@tonic-gate 
49847c478bd9Sstevel@tonic-gate 	idn_intr_index[cpuid] = xp - idn_iv_queue[cpuid];
49857c478bd9Sstevel@tonic-gate 
49867c478bd9Sstevel@tonic-gate 	return (DDI_INTR_CLAIMED);
49877c478bd9Sstevel@tonic-gate }
49887c478bd9Sstevel@tonic-gate 
49897c478bd9Sstevel@tonic-gate void
49907c478bd9Sstevel@tonic-gate idn_awol_event_set(boardset_t boardset)
49917c478bd9Sstevel@tonic-gate {
49927c478bd9Sstevel@tonic-gate 	idnsb_event_t	*sbp;
49937c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_awol_event_set";
49947c478bd9Sstevel@tonic-gate 
49957c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_EXCL());
49967c478bd9Sstevel@tonic-gate 
49977c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.idnsb_mutex);
49987c478bd9Sstevel@tonic-gate 	sbp = idn.idnsb_eventp;
49997c478bd9Sstevel@tonic-gate 	if (sbp == NULL) {
50007c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "IDN: 133: sigblock event area missing");
50017c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT,
50027c478bd9Sstevel@tonic-gate 		    "IDN: 134: unable to mark boardset (0x%x) AWOL\n",
50037c478bd9Sstevel@tonic-gate 		    boardset);
50047c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
50057c478bd9Sstevel@tonic-gate 		return;
50067c478bd9Sstevel@tonic-gate 	}
50077c478bd9Sstevel@tonic-gate 
50087c478bd9Sstevel@tonic-gate 	if (boardset == 0) {
50097c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: AWOL BOARDSET is 0, NO EVENT <<<<<<<<<<<<<<<\n",
50107c478bd9Sstevel@tonic-gate 		    proc);
50117c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
50127c478bd9Sstevel@tonic-gate 		return;
50137c478bd9Sstevel@tonic-gate 	} else {
50147c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: MARKING BOARDSET (0x%x) AWOL\n", proc, boardset);
50157c478bd9Sstevel@tonic-gate 	}
50167c478bd9Sstevel@tonic-gate 	SSIEVENT_ADD(sbp, SSIEVENT_AWOL, boardset);
50177c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.idnsb_mutex);
50187c478bd9Sstevel@tonic-gate }
50197c478bd9Sstevel@tonic-gate 
50207c478bd9Sstevel@tonic-gate void
50217c478bd9Sstevel@tonic-gate idn_awol_event_clear(boardset_t boardset)
50227c478bd9Sstevel@tonic-gate {
50237c478bd9Sstevel@tonic-gate 	idnsb_event_t	*sbp;
50247c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_awol_event_clear";
50257c478bd9Sstevel@tonic-gate 
50267c478bd9Sstevel@tonic-gate 	ASSERT(IDN_GLOCK_IS_EXCL());
50277c478bd9Sstevel@tonic-gate 
50287c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.idnsb_mutex);
50297c478bd9Sstevel@tonic-gate 	sbp = idn.idnsb_eventp;
50307c478bd9Sstevel@tonic-gate 	if (sbp == NULL) {
50317c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "IDN: 133: sigblock event area missing");
50327c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT,
50337c478bd9Sstevel@tonic-gate 		    "IDN: 134: unable to mark boardset (0x%x) AWOL\n",
50347c478bd9Sstevel@tonic-gate 		    boardset);
50357c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
50367c478bd9Sstevel@tonic-gate 		return;
50377c478bd9Sstevel@tonic-gate 	}
50387c478bd9Sstevel@tonic-gate 
50397c478bd9Sstevel@tonic-gate 	if (boardset == 0) {
50407c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: AWOL BOARDSET is 0, NO EVENT <<<<<<<<<<<<<<<\n",
50417c478bd9Sstevel@tonic-gate 		    proc);
50427c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
50437c478bd9Sstevel@tonic-gate 		return;
50447c478bd9Sstevel@tonic-gate 	} else {
50457c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: CLEARING BOARDSET (0x%x) AWOL\n", proc, boardset);
50467c478bd9Sstevel@tonic-gate 	}
50477c478bd9Sstevel@tonic-gate 	SSIEVENT_DEL(sbp, SSIEVENT_AWOL, boardset);
50487c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.idnsb_mutex);
50497c478bd9Sstevel@tonic-gate }
50507c478bd9Sstevel@tonic-gate 
50517c478bd9Sstevel@tonic-gate static void
50527c478bd9Sstevel@tonic-gate idn_gkstat_init()
50537c478bd9Sstevel@tonic-gate {
50547c478bd9Sstevel@tonic-gate 	struct	kstat			*ksp;
50557c478bd9Sstevel@tonic-gate 	struct	idn_gkstat_named	*sgkp;
50567c478bd9Sstevel@tonic-gate 
50577c478bd9Sstevel@tonic-gate #ifdef	kstat
50587c478bd9Sstevel@tonic-gate 	if ((ksp = kstat_create(IDNNAME, ddi_get_instance(idn.dip),
50597c478bd9Sstevel@tonic-gate 	    IDNNAME, "net", KSTAT_TYPE_NAMED,
50607c478bd9Sstevel@tonic-gate 	    sizeof (struct idn_gkstat_named) / sizeof (kstat_named_t),
50617c478bd9Sstevel@tonic-gate 	    KSTAT_FLAG_PERSISTENT)) == NULL) {
50627c478bd9Sstevel@tonic-gate #else
50637c478bd9Sstevel@tonic-gate 	if ((ksp = kstat_create(IDNNAME, ddi_get_instance(idn.dip),
50647c478bd9Sstevel@tonic-gate 	    IDNNAME, "net", KSTAT_TYPE_NAMED,
50657c478bd9Sstevel@tonic-gate 	    sizeof (struct idn_gkstat_named) /
50667c478bd9Sstevel@tonic-gate 	    sizeof (kstat_named_t), 0)) == NULL) {
50677c478bd9Sstevel@tonic-gate #endif /* kstat */
50687c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "IDN: 135: %s: %s\n",
50697c478bd9Sstevel@tonic-gate 		    IDNNAME, "kstat_create failed");
50707c478bd9Sstevel@tonic-gate 		return;
50717c478bd9Sstevel@tonic-gate 	}
50727c478bd9Sstevel@tonic-gate 
50737c478bd9Sstevel@tonic-gate 	idn.ksp = ksp;
50747c478bd9Sstevel@tonic-gate 	sgkp = (struct idn_gkstat_named *)(ksp->ks_data);
50757c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_curtime,		"curtime",
50767c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50777c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_reconfigs,		"reconfigs",
50787c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50797c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_reconfig_last,	"reconfig_last",
50807c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50817c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_reaps,		"reaps",
50827c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50837c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_reap_last,		"reap_last",
50847c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50857c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_links,		"links",
50867c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50877c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_link_last,		"link_last",
50887c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50897c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_unlinks,		"unlinks",
50907c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50917c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_unlink_last,		"unlink_last",
50927c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50937c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_buffail,		"buf_fail",
50947c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50957c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_buffail_last,	"buf_fail_last",
50967c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50977c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_slabfail,		"slab_fail",
50987c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
50997c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_slabfail_last,	"slab_fail_last",
51007c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
51017c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_slabfail_last,	"slab_fail_last",
51027c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
51037c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_reap_count,		"reap_count",
51047c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
51057c478bd9Sstevel@tonic-gate 	kstat_named_init(&sgkp->sk_dropped_intrs,	"dropped_intrs",
51067c478bd9Sstevel@tonic-gate 	    KSTAT_DATA_ULONG);
51077c478bd9Sstevel@tonic-gate 	ksp->ks_update = idn_gkstat_update;
51087c478bd9Sstevel@tonic-gate 	ksp->ks_private = (void *)NULL;
51097c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
51107c478bd9Sstevel@tonic-gate }
51117c478bd9Sstevel@tonic-gate 
51127c478bd9Sstevel@tonic-gate static void
51137c478bd9Sstevel@tonic-gate idn_gkstat_deinit()
51147c478bd9Sstevel@tonic-gate {
51157c478bd9Sstevel@tonic-gate 	if (idn.ksp)
51167c478bd9Sstevel@tonic-gate 		kstat_delete(idn.ksp);
51177c478bd9Sstevel@tonic-gate 	idn.ksp = NULL;
51187c478bd9Sstevel@tonic-gate }
51197c478bd9Sstevel@tonic-gate 
51207c478bd9Sstevel@tonic-gate static int
51217c478bd9Sstevel@tonic-gate idn_gkstat_update(kstat_t *ksp, int rw)
51227c478bd9Sstevel@tonic-gate {
51237c478bd9Sstevel@tonic-gate 	struct idn_gkstat_named	*sgkp;
51247c478bd9Sstevel@tonic-gate 
51257c478bd9Sstevel@tonic-gate 	sgkp = (struct idn_gkstat_named *)ksp->ks_data;
51267c478bd9Sstevel@tonic-gate 
51277c478bd9Sstevel@tonic-gate 	if (rw == KSTAT_WRITE) {
51287c478bd9Sstevel@tonic-gate 		sg_kstat.gk_reconfigs	    = sgkp->sk_reconfigs.value.ul;
51297c478bd9Sstevel@tonic-gate 		sg_kstat.gk_reconfig_last   = sgkp->sk_reconfig_last.value.ul;
51307c478bd9Sstevel@tonic-gate 		sg_kstat.gk_reaps	    = sgkp->sk_reaps.value.ul;
51317c478bd9Sstevel@tonic-gate 		sg_kstat.gk_reap_last	    = sgkp->sk_reap_last.value.ul;
51327c478bd9Sstevel@tonic-gate 		sg_kstat.gk_links	    = sgkp->sk_links.value.ul;
51337c478bd9Sstevel@tonic-gate 		sg_kstat.gk_link_last	    = sgkp->sk_link_last.value.ul;
51347c478bd9Sstevel@tonic-gate 		sg_kstat.gk_unlinks	    = sgkp->sk_unlinks.value.ul;
51357c478bd9Sstevel@tonic-gate 		sg_kstat.gk_unlink_last	    = sgkp->sk_unlink_last.value.ul;
51367c478bd9Sstevel@tonic-gate 		sg_kstat.gk_buffail	    = sgkp->sk_buffail.value.ul;
51377c478bd9Sstevel@tonic-gate 		sg_kstat.gk_buffail_last    = sgkp->sk_buffail_last.value.ul;
51387c478bd9Sstevel@tonic-gate 		sg_kstat.gk_slabfail	    = sgkp->sk_slabfail.value.ul;
51397c478bd9Sstevel@tonic-gate 		sg_kstat.gk_slabfail_last   = sgkp->sk_slabfail_last.value.ul;
51407c478bd9Sstevel@tonic-gate 		sg_kstat.gk_reap_count	    = sgkp->sk_reap_count.value.ul;
51417c478bd9Sstevel@tonic-gate 		sg_kstat.gk_dropped_intrs   = sgkp->sk_dropped_intrs.value.ul;
51427c478bd9Sstevel@tonic-gate 	} else {
5143d3d50737SRafael Vanoni 		sgkp->sk_curtime.value.ul	  = ddi_get_lbolt();
51447c478bd9Sstevel@tonic-gate 		sgkp->sk_reconfigs.value.ul	  = sg_kstat.gk_reconfigs;
51457c478bd9Sstevel@tonic-gate 		sgkp->sk_reconfig_last.value.ul	  = sg_kstat.gk_reconfig_last;
51467c478bd9Sstevel@tonic-gate 		sgkp->sk_reaps.value.ul		  = sg_kstat.gk_reaps;
51477c478bd9Sstevel@tonic-gate 		sgkp->sk_reap_last.value.ul	  = sg_kstat.gk_reap_last;
51487c478bd9Sstevel@tonic-gate 		sgkp->sk_links.value.ul		  = sg_kstat.gk_links;
51497c478bd9Sstevel@tonic-gate 		sgkp->sk_link_last.value.ul	  = sg_kstat.gk_link_last;
51507c478bd9Sstevel@tonic-gate 		sgkp->sk_unlinks.value.ul	  = sg_kstat.gk_unlinks;
51517c478bd9Sstevel@tonic-gate 		sgkp->sk_unlink_last.value.ul	  = sg_kstat.gk_unlink_last;
51527c478bd9Sstevel@tonic-gate 		sgkp->sk_buffail.value.ul	  = sg_kstat.gk_buffail;
51537c478bd9Sstevel@tonic-gate 		sgkp->sk_buffail_last.value.ul    = sg_kstat.gk_buffail_last;
51547c478bd9Sstevel@tonic-gate 		sgkp->sk_slabfail.value.ul	  = sg_kstat.gk_slabfail;
51557c478bd9Sstevel@tonic-gate 		sgkp->sk_slabfail_last.value.ul   = sg_kstat.gk_slabfail_last;
51567c478bd9Sstevel@tonic-gate 		sgkp->sk_reap_count.value.ul	  = sg_kstat.gk_reap_count;
51577c478bd9Sstevel@tonic-gate 		sgkp->sk_dropped_intrs.value.ul	  = sg_kstat.gk_dropped_intrs;
51587c478bd9Sstevel@tonic-gate 	}
51597c478bd9Sstevel@tonic-gate 
51607c478bd9Sstevel@tonic-gate 	return (0);
51617c478bd9Sstevel@tonic-gate }
51627c478bd9Sstevel@tonic-gate 
51637c478bd9Sstevel@tonic-gate #ifdef DEBUG
51647c478bd9Sstevel@tonic-gate #define	RW_HISTORY	100
51657c478bd9Sstevel@tonic-gate static uint_t	rw_history[NCPU][RW_HISTORY];
51667c478bd9Sstevel@tonic-gate static int	rw_index[NCPU];
51677c478bd9Sstevel@tonic-gate #endif /* DEBUG */
51687c478bd9Sstevel@tonic-gate 
51697c478bd9Sstevel@tonic-gate static int
51707c478bd9Sstevel@tonic-gate idn_rw_mem(idnop_t *idnop)
51717c478bd9Sstevel@tonic-gate {
51727c478bd9Sstevel@tonic-gate 	uint_t		lo_off, hi_off;
51737c478bd9Sstevel@tonic-gate 	int		rw, blksize, num;
51747c478bd9Sstevel@tonic-gate 	int		cpuid;
51757c478bd9Sstevel@tonic-gate 	register int	n, idx;
51767c478bd9Sstevel@tonic-gate 	char 		*ibuf, *obuf;
51777c478bd9Sstevel@tonic-gate 	char		*smraddr;
51787c478bd9Sstevel@tonic-gate 	struct seg	*segp;
51797c478bd9Sstevel@tonic-gate 	ulong_t		randx;
51807c478bd9Sstevel@tonic-gate 	kmutex_t	slock;
51817c478bd9Sstevel@tonic-gate 	kcondvar_t	scv;
51827c478bd9Sstevel@tonic-gate 	static int	orig_gstate = IDNGS_IGNORE;
51837c478bd9Sstevel@tonic-gate 	extern struct  seg	ktextseg;
51847c478bd9Sstevel@tonic-gate 
5185d3d50737SRafael Vanoni #define	RANDOM_INIT()	(randx = ddi_get_lbolt())
51867c478bd9Sstevel@tonic-gate #define	RANDOM(a, b)	\
51877c478bd9Sstevel@tonic-gate 	(((a) >= (b)) ? \
51887c478bd9Sstevel@tonic-gate 	(a) : (((randx = randx * 1103515245L + 12345) % ((b)-(a))) + (a)))
51897c478bd9Sstevel@tonic-gate 
51907c478bd9Sstevel@tonic-gate 	RANDOM_INIT();
51917c478bd9Sstevel@tonic-gate 
51927c478bd9Sstevel@tonic-gate 	lo_off  = idnop->rwmem.lo_off;
51937c478bd9Sstevel@tonic-gate 	hi_off  = idnop->rwmem.hi_off;
51947c478bd9Sstevel@tonic-gate 	blksize = idnop->rwmem.blksize;
51957c478bd9Sstevel@tonic-gate 	num	= idnop->rwmem.num;
51967c478bd9Sstevel@tonic-gate 	rw	= idnop->rwmem.rw;	/* 0 = rd, 1 = wr, 2 = rd/wr */
51977c478bd9Sstevel@tonic-gate 
51987c478bd9Sstevel@tonic-gate 	if (((hi_off > (uint_t)MB2B(IDN_SMR_SIZE)) || (lo_off >= hi_off) ||
51997c478bd9Sstevel@tonic-gate 	    (blksize <= 0) || (blksize > (hi_off - lo_off)) || (num <= 0)) &&
52007c478bd9Sstevel@tonic-gate 	    (idnop->rwmem.goawol == -1)) {
52017c478bd9Sstevel@tonic-gate 		return (EINVAL);
52027c478bd9Sstevel@tonic-gate 	}
52037c478bd9Sstevel@tonic-gate 
52047c478bd9Sstevel@tonic-gate 	if (idnop->rwmem.goawol && (orig_gstate == IDNGS_IGNORE)) {
52057c478bd9Sstevel@tonic-gate 		IDN_GLOCK_EXCL();
52067c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "IDN: Local domain going into IGNORE MODE!!");
52077c478bd9Sstevel@tonic-gate 		orig_gstate = idn.state;
52087c478bd9Sstevel@tonic-gate 		IDN_GSTATE_TRANSITION(IDNGS_IGNORE);
52097c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
52107c478bd9Sstevel@tonic-gate 
52117c478bd9Sstevel@tonic-gate 	} else if (!idnop->rwmem.goawol && (orig_gstate != IDNGS_IGNORE)) {
52127c478bd9Sstevel@tonic-gate 		IDN_GLOCK_EXCL();
52137c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
52147c478bd9Sstevel@tonic-gate 		    "IDN: Local domain restoring original state %s(%d)",
52157c478bd9Sstevel@tonic-gate 		    idngs_str[orig_gstate], (int)orig_gstate);
52167c478bd9Sstevel@tonic-gate 		IDN_GSTATE_TRANSITION(orig_gstate);
52177c478bd9Sstevel@tonic-gate 		orig_gstate = IDNGS_IGNORE;
52187c478bd9Sstevel@tonic-gate 		IDN_GUNLOCK();
52197c478bd9Sstevel@tonic-gate 	}
52207c478bd9Sstevel@tonic-gate 	/*
52217c478bd9Sstevel@tonic-gate 	 * Just requested AWOL.
52227c478bd9Sstevel@tonic-gate 	 */
52237c478bd9Sstevel@tonic-gate 	if (num == 0)
52247c478bd9Sstevel@tonic-gate 		return (0);
52257c478bd9Sstevel@tonic-gate 	/*
52267c478bd9Sstevel@tonic-gate 	 * Default READ only.
52277c478bd9Sstevel@tonic-gate 	 */
52287c478bd9Sstevel@tonic-gate 	ibuf = (char *)kmem_alloc(blksize, KM_SLEEP);
52297c478bd9Sstevel@tonic-gate 	if (rw == 1) {
52307c478bd9Sstevel@tonic-gate 		/*
52317c478bd9Sstevel@tonic-gate 		 * WRITE only.
52327c478bd9Sstevel@tonic-gate 		 */
52337c478bd9Sstevel@tonic-gate 		obuf = ibuf;
52347c478bd9Sstevel@tonic-gate 		ibuf = NULL;
52357c478bd9Sstevel@tonic-gate 	} else if (rw == 2) {
52367c478bd9Sstevel@tonic-gate 		/*
52377c478bd9Sstevel@tonic-gate 		 * READ/WRITE.
52387c478bd9Sstevel@tonic-gate 		 */
52397c478bd9Sstevel@tonic-gate 		obuf = (char *)kmem_alloc(blksize, KM_SLEEP);
52407c478bd9Sstevel@tonic-gate 		for (segp = &ktextseg; segp; segp = AS_SEGNEXT(&kas, segp)) {
52417c478bd9Sstevel@tonic-gate 			if (segp->s_size >= blksize)
52427c478bd9Sstevel@tonic-gate 				break;
52437c478bd9Sstevel@tonic-gate 		}
52447c478bd9Sstevel@tonic-gate 		if (segp == NULL) {
52457c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
52467c478bd9Sstevel@tonic-gate 			    "IDN: blksize (%d) too large", blksize);
52477c478bd9Sstevel@tonic-gate 			return (EINVAL);
52487c478bd9Sstevel@tonic-gate 		}
52497c478bd9Sstevel@tonic-gate 		bcopy(segp->s_base, obuf, blksize);
52507c478bd9Sstevel@tonic-gate 	}
52517c478bd9Sstevel@tonic-gate 
52527c478bd9Sstevel@tonic-gate 	mutex_init(&slock, NULL, MUTEX_DEFAULT, NULL);
52537c478bd9Sstevel@tonic-gate 	cv_init(&scv, NULL, CV_DEFAULT, NULL);
52547c478bd9Sstevel@tonic-gate 
52557c478bd9Sstevel@tonic-gate 	cmn_err(CE_NOTE,
52567c478bd9Sstevel@tonic-gate 	    "IDN: starting %s of %d blocks of %d bytes each...",
52577c478bd9Sstevel@tonic-gate 	    (rw == 1) ? "W-ONLY" : (rw == 2) ? "RW" : "R-ONLY",
52587c478bd9Sstevel@tonic-gate 	    num, blksize);
52597c478bd9Sstevel@tonic-gate 
52607c478bd9Sstevel@tonic-gate 	for (n = 0; n < num; n++) {
52617c478bd9Sstevel@tonic-gate 		uint_t	rpos;
52627c478bd9Sstevel@tonic-gate 
52637c478bd9Sstevel@tonic-gate 		if ((hi_off - lo_off) > blksize)
52647c478bd9Sstevel@tonic-gate 			rpos = RANDOM(lo_off, (hi_off - blksize));
52657c478bd9Sstevel@tonic-gate 		else
52667c478bd9Sstevel@tonic-gate 			rpos = lo_off;
52677c478bd9Sstevel@tonic-gate 		smraddr = IDN_OFFSET2ADDR(rpos);
52687c478bd9Sstevel@tonic-gate 
52697c478bd9Sstevel@tonic-gate 		cpuid = (int)CPU->cpu_id;
52707c478bd9Sstevel@tonic-gate #ifdef DEBUG
52717c478bd9Sstevel@tonic-gate 		idx = rw_index[cpuid]++ % RW_HISTORY;
52727c478bd9Sstevel@tonic-gate 		rw_history[cpuid][idx] = rpos;
52737c478bd9Sstevel@tonic-gate #endif /* DEBUG */
52747c478bd9Sstevel@tonic-gate 
52757c478bd9Sstevel@tonic-gate 		switch (rw) {
52767c478bd9Sstevel@tonic-gate 		case 0:
52777c478bd9Sstevel@tonic-gate 			bcopy(smraddr, ibuf, blksize);
52787c478bd9Sstevel@tonic-gate 			break;
52797c478bd9Sstevel@tonic-gate 		case 1:
52807c478bd9Sstevel@tonic-gate 			bcopy(obuf, smraddr, blksize);
52817c478bd9Sstevel@tonic-gate 			break;
52827c478bd9Sstevel@tonic-gate 		case 2:
52837c478bd9Sstevel@tonic-gate 			if (n & 1)
52847c478bd9Sstevel@tonic-gate 				bcopy(obuf, smraddr, blksize);
52857c478bd9Sstevel@tonic-gate 			else
52867c478bd9Sstevel@tonic-gate 				bcopy(smraddr, ibuf, blksize);
52877c478bd9Sstevel@tonic-gate 			break;
52887c478bd9Sstevel@tonic-gate 		default:
52897c478bd9Sstevel@tonic-gate 			break;
52907c478bd9Sstevel@tonic-gate 		}
52917c478bd9Sstevel@tonic-gate 		if (!(n % 1000)) {
52927c478bd9Sstevel@tonic-gate 			int	rv;
52937c478bd9Sstevel@tonic-gate 
52947c478bd9Sstevel@tonic-gate 			mutex_enter(&slock);
5295d3d50737SRafael Vanoni 			rv = cv_reltimedwait_sig(&scv, &slock, hz,
5296d3d50737SRafael Vanoni 			    TR_CLOCK_TICK);
52977c478bd9Sstevel@tonic-gate 			mutex_exit(&slock);
52987c478bd9Sstevel@tonic-gate 			if (rv == 0)
52997c478bd9Sstevel@tonic-gate 				break;
53007c478bd9Sstevel@tonic-gate 		}
53017c478bd9Sstevel@tonic-gate 	}
53027c478bd9Sstevel@tonic-gate 
53037c478bd9Sstevel@tonic-gate 	cv_destroy(&scv);
53047c478bd9Sstevel@tonic-gate 	mutex_destroy(&slock);
53057c478bd9Sstevel@tonic-gate 
53067c478bd9Sstevel@tonic-gate 	if (ibuf)
53077c478bd9Sstevel@tonic-gate 		kmem_free(ibuf, blksize);
53087c478bd9Sstevel@tonic-gate 	if (obuf)
53097c478bd9Sstevel@tonic-gate 		kmem_free(obuf, blksize);
53107c478bd9Sstevel@tonic-gate 
53117c478bd9Sstevel@tonic-gate 	return (0);
53127c478bd9Sstevel@tonic-gate }
53137c478bd9Sstevel@tonic-gate 
53147c478bd9Sstevel@tonic-gate void
53157c478bd9Sstevel@tonic-gate inum2str(uint_t inum, char str[])
53167c478bd9Sstevel@tonic-gate {
53177c478bd9Sstevel@tonic-gate 	uint_t	acknack;
53187c478bd9Sstevel@tonic-gate 
53197c478bd9Sstevel@tonic-gate 	str[0] = '\0';
53207c478bd9Sstevel@tonic-gate 
53217c478bd9Sstevel@tonic-gate 	acknack = (inum & IDNP_ACKNACK_MASK);
53227c478bd9Sstevel@tonic-gate 	inum &= ~IDNP_ACKNACK_MASK;
53237c478bd9Sstevel@tonic-gate 
53247c478bd9Sstevel@tonic-gate 	if (!inum && !acknack) {
532507d06da5SSurya Prakki 		(void) strcpy(str, idnm_str[0]);
53267c478bd9Sstevel@tonic-gate 		return;
53277c478bd9Sstevel@tonic-gate 	}
53287c478bd9Sstevel@tonic-gate 
53297c478bd9Sstevel@tonic-gate 	if (inum == 0) {
533007d06da5SSurya Prakki 		(void) strcpy(str, (acknack & IDNP_ACK) ? "ack" : "nack");
53317c478bd9Sstevel@tonic-gate 	} else {
53327c478bd9Sstevel@tonic-gate 		if (inum < IDN_NUM_MSGTYPES)
533307d06da5SSurya Prakki 			(void) strcpy(str, idnm_str[inum]);
53347c478bd9Sstevel@tonic-gate 		else
533507d06da5SSurya Prakki 			(void) sprintf(str, "0x%x?", inum);
53367c478bd9Sstevel@tonic-gate 		if (acknack) {
53377c478bd9Sstevel@tonic-gate 			if (acknack & IDNP_ACK)
533807d06da5SSurya Prakki 				(void) strcat(str, "+ack");
53397c478bd9Sstevel@tonic-gate 			else
534007d06da5SSurya Prakki 				(void) strcat(str, "+nack");
53417c478bd9Sstevel@tonic-gate 		}
53427c478bd9Sstevel@tonic-gate 	}
53437c478bd9Sstevel@tonic-gate }
53447c478bd9Sstevel@tonic-gate 
53457c478bd9Sstevel@tonic-gate boardset_t
53467c478bd9Sstevel@tonic-gate cpuset2boardset(cpuset_t portset)
53477c478bd9Sstevel@tonic-gate {
53487c478bd9Sstevel@tonic-gate 	register int		c;
53497c478bd9Sstevel@tonic-gate 	register boardset_t	bset;
53507c478bd9Sstevel@tonic-gate 
53517c478bd9Sstevel@tonic-gate 	bset = 0;
53527c478bd9Sstevel@tonic-gate 	for (c = 0; c < NCPU; )
53537c478bd9Sstevel@tonic-gate 		if (CPU_IN_SET(portset, c)) {
53547c478bd9Sstevel@tonic-gate 			BOARDSET_ADD(bset, CPUID_TO_BOARDID(c));
53557c478bd9Sstevel@tonic-gate 			c = (c + 4) & ~3;
53567c478bd9Sstevel@tonic-gate 		} else {
53577c478bd9Sstevel@tonic-gate 			c++;
53587c478bd9Sstevel@tonic-gate 		}
53597c478bd9Sstevel@tonic-gate 
53607c478bd9Sstevel@tonic-gate 	return (bset);
53617c478bd9Sstevel@tonic-gate }
53627c478bd9Sstevel@tonic-gate 
53637c478bd9Sstevel@tonic-gate void
53647c478bd9Sstevel@tonic-gate cpuset2str(cpuset_t cset, char buffer[])
53657c478bd9Sstevel@tonic-gate {
53667c478bd9Sstevel@tonic-gate 	register int	c, n;
53677c478bd9Sstevel@tonic-gate 
53687c478bd9Sstevel@tonic-gate 	buffer[0] = '\0';
53697c478bd9Sstevel@tonic-gate 	for (c = n = 0; c < NCPU; c++) {
53707c478bd9Sstevel@tonic-gate 		if (!CPU_IN_SET(cset, c))
53717c478bd9Sstevel@tonic-gate 			continue;
53727c478bd9Sstevel@tonic-gate #ifdef DEBUG
53737c478bd9Sstevel@tonic-gate 		if (strlen(buffer) >= _DSTRLEN) {
53747c478bd9Sstevel@tonic-gate 			PR_PROTO("************* WARNING WARNING WARNING\n");
53757c478bd9Sstevel@tonic-gate 			PR_PROTO("cpuset2str(cpu = %d) buffer "
53767c478bd9Sstevel@tonic-gate 			    "OVERFLOW <<<<<<\n", c);
53777c478bd9Sstevel@tonic-gate 			PR_PROTO("*******************************\n");
5378bf30efa4Smathue 			(void) sprintf(&buffer[_DSTRLEN-6], "*OVER");
53797c478bd9Sstevel@tonic-gate 			return;
53807c478bd9Sstevel@tonic-gate 		}
53817c478bd9Sstevel@tonic-gate #endif /* DEBUG */
53827c478bd9Sstevel@tonic-gate 		if (n == 0)
5383bf30efa4Smathue 			(void) sprintf(buffer, "%d", c);
53847c478bd9Sstevel@tonic-gate 		else
5385bf30efa4Smathue 			(void) sprintf(buffer, "%s, %d", buffer, c);
53867c478bd9Sstevel@tonic-gate 		n++;
53877c478bd9Sstevel@tonic-gate 	}
53887c478bd9Sstevel@tonic-gate }
53897c478bd9Sstevel@tonic-gate 
53907c478bd9Sstevel@tonic-gate void
53917c478bd9Sstevel@tonic-gate domainset2str(domainset_t dset, char buffer[])
53927c478bd9Sstevel@tonic-gate {
53937c478bd9Sstevel@tonic-gate 	/*
53947c478bd9Sstevel@tonic-gate 	 * Since domainset_t and boardset_t are the
53957c478bd9Sstevel@tonic-gate 	 * same (max = MAX_DOMAINS = MAX_BOARDS) we
53967c478bd9Sstevel@tonic-gate 	 * can just overload boardset2str().
53977c478bd9Sstevel@tonic-gate 	 */
53987c478bd9Sstevel@tonic-gate 	mask2str((uint_t)dset, buffer, MAX_DOMAINS);
53997c478bd9Sstevel@tonic-gate }
54007c478bd9Sstevel@tonic-gate 
54017c478bd9Sstevel@tonic-gate void
54027c478bd9Sstevel@tonic-gate boardset2str(boardset_t bset, char buffer[])
54037c478bd9Sstevel@tonic-gate {
54047c478bd9Sstevel@tonic-gate 	mask2str((uint_t)bset, buffer, MAX_BOARDS);
54057c478bd9Sstevel@tonic-gate }
54067c478bd9Sstevel@tonic-gate 
54077c478bd9Sstevel@tonic-gate void
54087c478bd9Sstevel@tonic-gate mask2str(uint_t mask, char buffer[], int maxnum)
54097c478bd9Sstevel@tonic-gate {
54107c478bd9Sstevel@tonic-gate 	int	n, i;
54117c478bd9Sstevel@tonic-gate 
54127c478bd9Sstevel@tonic-gate 	buffer[0] = '\0';
54137c478bd9Sstevel@tonic-gate 	for (i = n = 0; i < maxnum; i++) {
54147c478bd9Sstevel@tonic-gate 		if ((mask & (1 << i)) == 0)
54157c478bd9Sstevel@tonic-gate 			continue;
54167c478bd9Sstevel@tonic-gate 		if (n == 0)
5417bf30efa4Smathue 			(void) sprintf(buffer, "%d", i);
54187c478bd9Sstevel@tonic-gate 		else
5419bf30efa4Smathue 			(void) sprintf(buffer, "%s, %d", buffer, i);
54207c478bd9Sstevel@tonic-gate 		n++;
54217c478bd9Sstevel@tonic-gate 	}
54227c478bd9Sstevel@tonic-gate }
54237c478bd9Sstevel@tonic-gate 
54247c478bd9Sstevel@tonic-gate int
54257c478bd9Sstevel@tonic-gate idnxdc(int domid, idn_msgtype_t *mtp,
54267c478bd9Sstevel@tonic-gate 	uint_t arg1, uint_t arg2,
54277c478bd9Sstevel@tonic-gate 	uint_t arg3, uint_t arg4)
54287c478bd9Sstevel@tonic-gate {
54297c478bd9Sstevel@tonic-gate 	int		rv, cpuid, tcpuid;
54307c478bd9Sstevel@tonic-gate 	uint_t		cookie;
54317c478bd9Sstevel@tonic-gate 	uint64_t	pdata;
54327c478bd9Sstevel@tonic-gate 	uint64_t	dmv_word0, dmv_word1, dmv_word2;
54337c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp = &idn_domain[domid];
54347c478bd9Sstevel@tonic-gate 	extern kmutex_t	xc_sys_mutex;
54357c478bd9Sstevel@tonic-gate 	extern int	xc_spl_enter[];
54367c478bd9Sstevel@tonic-gate 	procname_t	proc = "idnxdc";
54377c478bd9Sstevel@tonic-gate 
54387c478bd9Sstevel@tonic-gate 
54397c478bd9Sstevel@tonic-gate 	if (idn_snoop) {
54407c478bd9Sstevel@tonic-gate 		int	bd;
54417c478bd9Sstevel@tonic-gate 		STRING(str);
54427c478bd9Sstevel@tonic-gate 		STRING(mstr);
54437c478bd9Sstevel@tonic-gate 		STRING(astr);
54447c478bd9Sstevel@tonic-gate 
54457c478bd9Sstevel@tonic-gate 		INUM2STR(mtp->mt_mtype, mstr);
54467c478bd9Sstevel@tonic-gate 		if ((mtp->mt_mtype & IDNP_MSGTYPE_MASK) == 0) {
54477c478bd9Sstevel@tonic-gate 			INUM2STR(arg1, astr);
544807d06da5SSurya Prakki 			(void) sprintf(str, "%s/%s", mstr, astr);
54497c478bd9Sstevel@tonic-gate 		} else {
545007d06da5SSurya Prakki 			(void) strcpy(str, mstr);
54517c478bd9Sstevel@tonic-gate 		}
54527c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU)
54537c478bd9Sstevel@tonic-gate 			bd = -1;
54547c478bd9Sstevel@tonic-gate 		else
54557c478bd9Sstevel@tonic-gate 			bd = CPUID_TO_BOARDID(dp->dcpu);
54567c478bd9Sstevel@tonic-gate 		SNOOP_IDN(0, str, bd, arg1, arg2, arg3, arg4);
54577c478bd9Sstevel@tonic-gate 	}
54587c478bd9Sstevel@tonic-gate 
54597c478bd9Sstevel@tonic-gate 	/*
54607c478bd9Sstevel@tonic-gate 	 * For NEGO messages we send the remote domain the cookie we
54617c478bd9Sstevel@tonic-gate 	 * expect it to use in subsequent messages that it sends
54627c478bd9Sstevel@tonic-gate 	 * to us (dcookie_recv).
54637c478bd9Sstevel@tonic-gate 	 * For other messages, we must use the cookie that the
54647c478bd9Sstevel@tonic-gate 	 * remote domain assigned to us for sending (dcookie_send).
54657c478bd9Sstevel@tonic-gate 	 */
54667c478bd9Sstevel@tonic-gate 	if ((mtp->mt_mtype & IDNP_MSGTYPE_MASK) == IDNP_NEGO)
54677c478bd9Sstevel@tonic-gate 		cookie = IDN_MAKE_COOKIE(dp->dcookie_recv, mtp->mt_cookie);
54687c478bd9Sstevel@tonic-gate 	else
54697c478bd9Sstevel@tonic-gate 		cookie = IDN_MAKE_COOKIE(dp->dcookie_send, mtp->mt_cookie);
54707c478bd9Sstevel@tonic-gate 
54717c478bd9Sstevel@tonic-gate 	pdata = IDN_MAKE_PDATA(mtp->mt_mtype, mtp->mt_atype, cookie);
54727c478bd9Sstevel@tonic-gate 
54737c478bd9Sstevel@tonic-gate 	dmv_word0 = DMV_MAKE_DMV(idn.intr.dmv_inum, pdata);
54747c478bd9Sstevel@tonic-gate 	dmv_word1 = ((uint64_t)arg1 << 32) | (uint64_t)arg2;
54757c478bd9Sstevel@tonic-gate 	dmv_word2 = ((uint64_t)arg3 << 32) | (uint64_t)arg4;
54767c478bd9Sstevel@tonic-gate 
54777c478bd9Sstevel@tonic-gate 	ASSERT((dp->dcpu != IDN_NIL_DCPU) ||
54787c478bd9Sstevel@tonic-gate 	    (dp->dcpu_last != IDN_NIL_DCPU));
54797c478bd9Sstevel@tonic-gate 
54807c478bd9Sstevel@tonic-gate 	tcpuid = (dp->dcpu == IDN_NIL_DCPU) ?
54817c478bd9Sstevel@tonic-gate 	    dp->dcpu_last : dp->dcpu;
54827c478bd9Sstevel@tonic-gate 
54837c478bd9Sstevel@tonic-gate 	if (tcpuid == IDN_NIL_DCPU) {
54847c478bd9Sstevel@tonic-gate 		PR_PROTO("%s:%d: cpu/cpu_last == NIL_DCPU\n",
54857c478bd9Sstevel@tonic-gate 		    proc, domid);
54867c478bd9Sstevel@tonic-gate 		return (-1);
54877c478bd9Sstevel@tonic-gate 	}
54887c478bd9Sstevel@tonic-gate 
54897c478bd9Sstevel@tonic-gate 	mutex_enter(&xc_sys_mutex);
54907c478bd9Sstevel@tonic-gate 	cpuid = (int)CPU->cpu_id;
54917c478bd9Sstevel@tonic-gate 	xc_spl_enter[cpuid] = 1;
54927c478bd9Sstevel@tonic-gate 
54937c478bd9Sstevel@tonic-gate 	idnxf_init_mondo(dmv_word0, dmv_word1, dmv_word2);
54947c478bd9Sstevel@tonic-gate 
54957c478bd9Sstevel@tonic-gate 	rv = idnxf_send_mondo(STARFIRE_UPAID2HWMID(tcpuid));
54967c478bd9Sstevel@tonic-gate 
54977c478bd9Sstevel@tonic-gate 	xc_spl_enter[cpuid] = 0;
54987c478bd9Sstevel@tonic-gate 	mutex_exit(&xc_sys_mutex);
54997c478bd9Sstevel@tonic-gate 
55007c478bd9Sstevel@tonic-gate 	return (rv);
55017c478bd9Sstevel@tonic-gate }
55027c478bd9Sstevel@tonic-gate 
55037c478bd9Sstevel@tonic-gate void
55047c478bd9Sstevel@tonic-gate idnxdc_broadcast(domainset_t domset, idn_msgtype_t *mtp,
55057c478bd9Sstevel@tonic-gate 		uint_t arg1, uint_t arg2,
55067c478bd9Sstevel@tonic-gate 		uint_t arg3, uint_t arg4)
55077c478bd9Sstevel@tonic-gate {
55087c478bd9Sstevel@tonic-gate 	int	d;
55097c478bd9Sstevel@tonic-gate 
55107c478bd9Sstevel@tonic-gate 	for (d = 0; d < MAX_DOMAINS; d++) {
55117c478bd9Sstevel@tonic-gate 		idn_domain_t	*dp;
55127c478bd9Sstevel@tonic-gate 
55137c478bd9Sstevel@tonic-gate 		if (!DOMAIN_IN_SET(domset, d))
55147c478bd9Sstevel@tonic-gate 			continue;
55157c478bd9Sstevel@tonic-gate 
55167c478bd9Sstevel@tonic-gate 		dp = &idn_domain[d];
55177c478bd9Sstevel@tonic-gate 		if (dp->dcpu == IDN_NIL_DCPU)
55187c478bd9Sstevel@tonic-gate 			continue;
55197c478bd9Sstevel@tonic-gate 
55207c478bd9Sstevel@tonic-gate 		(void) IDNXDC(d, mtp, arg1, arg2, arg3, arg4);
55217c478bd9Sstevel@tonic-gate 	}
55227c478bd9Sstevel@tonic-gate }
55237c478bd9Sstevel@tonic-gate 
55247c478bd9Sstevel@tonic-gate #define	PROM_SMRSIZE	0x1
55257c478bd9Sstevel@tonic-gate #define	PROM_SMRADDR	0x2
55267c478bd9Sstevel@tonic-gate #define	PROM_SMRPROPS	(PROM_SMRSIZE | PROM_SMRADDR)
55277c478bd9Sstevel@tonic-gate /*
55287c478bd9Sstevel@tonic-gate  * Locate the idn-smr-size property to determine the size of the SMR
55297c478bd9Sstevel@tonic-gate  * region for the SSI.  Value inherently enables/disables SSI capability.
55307c478bd9Sstevel@tonic-gate  */
55317c478bd9Sstevel@tonic-gate static int
55327c478bd9Sstevel@tonic-gate idn_prom_getsmr(uint_t *smrsz, uint64_t *paddrp, uint64_t *sizep)
55337c478bd9Sstevel@tonic-gate {
5534fa9e4066Sahrens 	pnode_t		nodeid;
55357c478bd9Sstevel@tonic-gate 	int		found = 0;
55367c478bd9Sstevel@tonic-gate 	int		len;
55377c478bd9Sstevel@tonic-gate 	uint_t		smrsize = 0;
55387c478bd9Sstevel@tonic-gate 	uint64_t	obpaddr, obpsize;
55397c478bd9Sstevel@tonic-gate 	struct smraddr {
55407c478bd9Sstevel@tonic-gate 		uint32_t	hi_addr;
55417c478bd9Sstevel@tonic-gate 		uint32_t	lo_addr;
55427c478bd9Sstevel@tonic-gate 		uint32_t	hi_size;
55437c478bd9Sstevel@tonic-gate 		uint32_t	lo_size;
55447c478bd9Sstevel@tonic-gate 	} smraddr;
55457c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_prom_getsmr";
55467c478bd9Sstevel@tonic-gate 
55477c478bd9Sstevel@tonic-gate 	bzero(&smraddr, sizeof (smraddr));
55487c478bd9Sstevel@tonic-gate 	/*
55497c478bd9Sstevel@tonic-gate 	 * idn-smr-size is a property of the "memory" node and
55507c478bd9Sstevel@tonic-gate 	 * is defined in megabytes.
55517c478bd9Sstevel@tonic-gate 	 */
55527c478bd9Sstevel@tonic-gate 	nodeid = prom_finddevice("/memory");
55537c478bd9Sstevel@tonic-gate 
55547c478bd9Sstevel@tonic-gate 	if (nodeid != OBP_NONODE) {
55557c478bd9Sstevel@tonic-gate 		len = prom_getproplen(nodeid, IDN_PROP_SMRSIZE);
55567c478bd9Sstevel@tonic-gate 		if (len == sizeof (smrsize)) {
55577c478bd9Sstevel@tonic-gate 			(void) prom_getprop(nodeid, IDN_PROP_SMRSIZE,
55587c478bd9Sstevel@tonic-gate 			    (caddr_t)&smrsize);
55597c478bd9Sstevel@tonic-gate 			found |= PROM_SMRSIZE;
55607c478bd9Sstevel@tonic-gate 		}
55617c478bd9Sstevel@tonic-gate 		len = prom_getproplen(nodeid, IDN_PROP_SMRADDR);
55627c478bd9Sstevel@tonic-gate 		if (len  == sizeof (smraddr)) {
55637c478bd9Sstevel@tonic-gate 			(void) prom_getprop(nodeid, IDN_PROP_SMRADDR,
55647c478bd9Sstevel@tonic-gate 			    (caddr_t)&smraddr);
55657c478bd9Sstevel@tonic-gate 			found |= PROM_SMRADDR;
55667c478bd9Sstevel@tonic-gate 		}
55677c478bd9Sstevel@tonic-gate 	}
55687c478bd9Sstevel@tonic-gate 
55697c478bd9Sstevel@tonic-gate 	if (found != PROM_SMRPROPS) {
55707c478bd9Sstevel@tonic-gate 		if ((found & PROM_SMRSIZE) == 0)
55717c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
55727c478bd9Sstevel@tonic-gate 			    "IDN: 136: \"%s\" property not found, "
55737c478bd9Sstevel@tonic-gate 			    "disabling IDN",
55747c478bd9Sstevel@tonic-gate 			    IDN_PROP_SMRSIZE);
55757c478bd9Sstevel@tonic-gate 		if (smrsize && ((found & PROM_SMRADDR) == 0))
55767c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
55777c478bd9Sstevel@tonic-gate 			    "IDN: 136: \"%s\" property not found, "
55787c478bd9Sstevel@tonic-gate 			    "disabling IDN",
55797c478bd9Sstevel@tonic-gate 			    IDN_PROP_SMRADDR);
55807c478bd9Sstevel@tonic-gate 		return (-1);
55817c478bd9Sstevel@tonic-gate 	}
55827c478bd9Sstevel@tonic-gate 
55837c478bd9Sstevel@tonic-gate 	if (smrsize == 0) {
55847c478bd9Sstevel@tonic-gate 		PR_SMR("%s: IDN DISABLED (idn_smr_size = 0)\n", proc);
55857c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!IDN: 137: SMR size is 0, disabling IDN");
55867c478bd9Sstevel@tonic-gate 
55877c478bd9Sstevel@tonic-gate 	} else if (smrsize > IDN_SMR_MAXSIZE) {
55887c478bd9Sstevel@tonic-gate 		PR_SMR("%s: IDN DISABLED (idn_smr_size too big %d > %d MB)\n",
55897c478bd9Sstevel@tonic-gate 		    proc, smrsize, IDN_SMR_MAXSIZE);
55907c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
55917c478bd9Sstevel@tonic-gate 		    "!IDN: 138: SMR size (%dMB) is too big (max = %dMB), "
55927c478bd9Sstevel@tonic-gate 		    "disabling IDN",
55937c478bd9Sstevel@tonic-gate 		    smrsize, IDN_SMR_MAXSIZE);
55947c478bd9Sstevel@tonic-gate 		smrsize = 0;
55957c478bd9Sstevel@tonic-gate 	} else {
55967c478bd9Sstevel@tonic-gate 		*smrsz = smrsize;
55977c478bd9Sstevel@tonic-gate 		found &= ~PROM_SMRSIZE;
55987c478bd9Sstevel@tonic-gate 	}
55997c478bd9Sstevel@tonic-gate 
56007c478bd9Sstevel@tonic-gate 	obpaddr = ((uint64_t)smraddr.hi_addr << 32) |
56017c478bd9Sstevel@tonic-gate 	    (uint64_t)smraddr.lo_addr;
56027c478bd9Sstevel@tonic-gate 	obpsize = ((uint64_t)smraddr.hi_size << 32) |
56037c478bd9Sstevel@tonic-gate 	    (uint64_t)smraddr.lo_size;
56047c478bd9Sstevel@tonic-gate 
56057c478bd9Sstevel@tonic-gate 	if (obpsize == 0) {
56067c478bd9Sstevel@tonic-gate 		if (smrsize > 0) {
56077c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN, "!IDN: 139: OBP region for "
56087c478bd9Sstevel@tonic-gate 			    "SMR is 0 length");
56097c478bd9Sstevel@tonic-gate 		}
56107c478bd9Sstevel@tonic-gate 	} else if (obpsize < (uint64_t)MB2B(smrsize)) {
56117c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
5612bf30efa4Smathue 		    "!IDN: 140: OBP region (%ld B) smaller "
56137c478bd9Sstevel@tonic-gate 		    "than requested size (%ld B)",
56147c478bd9Sstevel@tonic-gate 		    obpsize, MB2B(smrsize));
56157c478bd9Sstevel@tonic-gate 	} else if ((obpaddr & ((uint64_t)IDN_SMR_ALIGN - 1)) != 0) {
56167c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN,
5617bf30efa4Smathue 		    "!IDN: 141: OBP region (0x%lx) not on (0x%x) "
56187c478bd9Sstevel@tonic-gate 		    "boundary", obpaddr, IDN_SMR_ALIGN);
56197c478bd9Sstevel@tonic-gate 	} else {
56207c478bd9Sstevel@tonic-gate 		*sizep = obpsize;
56217c478bd9Sstevel@tonic-gate 		*paddrp = obpaddr;
56227c478bd9Sstevel@tonic-gate 		found &= ~PROM_SMRADDR;
56237c478bd9Sstevel@tonic-gate 	}
56247c478bd9Sstevel@tonic-gate 
56257c478bd9Sstevel@tonic-gate 	return (found ? -1 : 0);
56267c478bd9Sstevel@tonic-gate }
56277c478bd9Sstevel@tonic-gate 
56287c478bd9Sstevel@tonic-gate void
56297c478bd9Sstevel@tonic-gate idn_init_autolink()
56307c478bd9Sstevel@tonic-gate {
56317c478bd9Sstevel@tonic-gate 	idnsb_event_t	*sbp;
56327c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_init_autolink";
56337c478bd9Sstevel@tonic-gate 
56347c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.idnsb_mutex);
56357c478bd9Sstevel@tonic-gate 	if ((sbp = idn.idnsb_eventp) == NULL) {
56367c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: IDN private sigb (event) area is NULL\n", proc);
56377c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
56387c478bd9Sstevel@tonic-gate 		return;
56397c478bd9Sstevel@tonic-gate 	}
56407c478bd9Sstevel@tonic-gate 
56417c478bd9Sstevel@tonic-gate 	PR_PROTO("%s: marking domain IDN ready.\n", proc);
56427c478bd9Sstevel@tonic-gate 
56437c478bd9Sstevel@tonic-gate 	bzero(sbp, sizeof (*sbp));
56447c478bd9Sstevel@tonic-gate 
56457c478bd9Sstevel@tonic-gate 	sbp->idn_version = (uchar_t)idn.version;
56467c478bd9Sstevel@tonic-gate 	SSIEVENT_SET(sbp, SSIEVENT_BOOT, 0);
56477c478bd9Sstevel@tonic-gate 	(void) strncpy(sbp->idn_cookie_str, SSIEVENT_COOKIE,
56487c478bd9Sstevel@tonic-gate 	    SSIEVENT_COOKIE_LEN);
56497c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.idnsb_mutex);
56507c478bd9Sstevel@tonic-gate }
56517c478bd9Sstevel@tonic-gate 
56527c478bd9Sstevel@tonic-gate void
56537c478bd9Sstevel@tonic-gate idn_deinit_autolink()
56547c478bd9Sstevel@tonic-gate {
56557c478bd9Sstevel@tonic-gate 	idnsb_event_t	*sbp;
56567c478bd9Sstevel@tonic-gate 	procname_t	proc = "idn_deinit_autolink";
56577c478bd9Sstevel@tonic-gate 
56587c478bd9Sstevel@tonic-gate 	mutex_enter(&idn.idnsb_mutex);
56597c478bd9Sstevel@tonic-gate 	if ((sbp = idn.idnsb_eventp) == NULL) {
56607c478bd9Sstevel@tonic-gate 		PR_PROTO("%s: IDN private sigb (event) area is NULL\n", proc);
56617c478bd9Sstevel@tonic-gate 		mutex_exit(&idn.idnsb_mutex);
56627c478bd9Sstevel@tonic-gate 		return;
56637c478bd9Sstevel@tonic-gate 	}
56647c478bd9Sstevel@tonic-gate 
56657c478bd9Sstevel@tonic-gate 	PR_PROTO("%s: marking domain IDN unavailable.\n", proc);
56667c478bd9Sstevel@tonic-gate 
56677c478bd9Sstevel@tonic-gate 	sbp->idn_version = (uchar_t)idn.version;
56687c478bd9Sstevel@tonic-gate 	SSIEVENT_CLEAR(sbp, SSIEVENT_BOOT, 0);
56697c478bd9Sstevel@tonic-gate 	(void) strncpy(sbp->idn_cookie_str, SSIEVENT_COOKIE,
56707c478bd9Sstevel@tonic-gate 	    SSIEVENT_COOKIE_LEN);
56717c478bd9Sstevel@tonic-gate 	mutex_exit(&idn.idnsb_mutex);
56727c478bd9Sstevel@tonic-gate }
56737c478bd9Sstevel@tonic-gate 
56747c478bd9Sstevel@tonic-gate void
56757c478bd9Sstevel@tonic-gate _make64cpumask(cpuset_t *csetp, uint_t upper, uint_t lower)
56767c478bd9Sstevel@tonic-gate {
56777c478bd9Sstevel@tonic-gate 	int	c;
56787c478bd9Sstevel@tonic-gate 
56797c478bd9Sstevel@tonic-gate 	CPUSET_ZERO(*csetp);
56807c478bd9Sstevel@tonic-gate 
56817c478bd9Sstevel@tonic-gate 	for (c = 0; c < 32; c++) {
56827c478bd9Sstevel@tonic-gate 		if (lower & (1 << c)) {
56837c478bd9Sstevel@tonic-gate 			CPUSET_ADD(*csetp, c);
56847c478bd9Sstevel@tonic-gate 		}
56857c478bd9Sstevel@tonic-gate 		if (upper & (1 << (c + 32))) {
56867c478bd9Sstevel@tonic-gate 			CPUSET_ADD(*csetp, c + 32);
56877c478bd9Sstevel@tonic-gate 		}
56887c478bd9Sstevel@tonic-gate 	}
56897c478bd9Sstevel@tonic-gate }
56907c478bd9Sstevel@tonic-gate 
56917c478bd9Sstevel@tonic-gate uint_t
56927c478bd9Sstevel@tonic-gate _lower32cpumask(cpuset_t cset)
56937c478bd9Sstevel@tonic-gate {
56947c478bd9Sstevel@tonic-gate 	int	c;
56957c478bd9Sstevel@tonic-gate 	uint_t	set = 0;
56967c478bd9Sstevel@tonic-gate 
56977c478bd9Sstevel@tonic-gate 	for (c = 0; c < 32; c++)
56987c478bd9Sstevel@tonic-gate 		if (CPU_IN_SET(cset, c))
56997c478bd9Sstevel@tonic-gate 			set |= 1 << c;
57007c478bd9Sstevel@tonic-gate 
57017c478bd9Sstevel@tonic-gate 	return (set);
57027c478bd9Sstevel@tonic-gate }
57037c478bd9Sstevel@tonic-gate 
57047c478bd9Sstevel@tonic-gate uint_t
57057c478bd9Sstevel@tonic-gate _upper32cpumask(cpuset_t cset)
57067c478bd9Sstevel@tonic-gate {
57077c478bd9Sstevel@tonic-gate 	int	c;
57087c478bd9Sstevel@tonic-gate 	uint_t	set = 0;
57097c478bd9Sstevel@tonic-gate 
57107c478bd9Sstevel@tonic-gate 	for (c = 32; c < NCPU; c++)
57117c478bd9Sstevel@tonic-gate 		if (CPU_IN_SET(cset, c))
57127c478bd9Sstevel@tonic-gate 			set |= 1 << (c - 32);
57137c478bd9Sstevel@tonic-gate 
57147c478bd9Sstevel@tonic-gate 	return (set);
57157c478bd9Sstevel@tonic-gate }
57167c478bd9Sstevel@tonic-gate 
57177c478bd9Sstevel@tonic-gate #ifdef DEBUG
57187c478bd9Sstevel@tonic-gate int
57197c478bd9Sstevel@tonic-gate debug_idnxdc(char *f, int domid, idn_msgtype_t *mtp,
57207c478bd9Sstevel@tonic-gate 		uint_t a1, uint_t a2, uint_t a3, uint_t a4)
57217c478bd9Sstevel@tonic-gate {
57227c478bd9Sstevel@tonic-gate 	idn_domain_t	*dp = &idn_domain[domid];
57237c478bd9Sstevel@tonic-gate 	int		rv, cpuid, bd;
57247c478bd9Sstevel@tonic-gate 	static int	xx = 0;
57257c478bd9Sstevel@tonic-gate 	STRING(str);
57267c478bd9Sstevel@tonic-gate 	STRING(mstr);
57277c478bd9Sstevel@tonic-gate 	STRING(astr);
57287c478bd9Sstevel@tonic-gate 
57297c478bd9Sstevel@tonic-gate 	xx++;
57307c478bd9Sstevel@tonic-gate 	INUM2STR(mtp->mt_mtype, mstr);
57317c478bd9Sstevel@tonic-gate 	if ((mtp->mt_mtype & IDNP_MSGTYPE_MASK) == 0) {
57327c478bd9Sstevel@tonic-gate 		INUM2STR(a1, astr);
573307d06da5SSurya Prakki 		(void) sprintf(str, "%s/%s", mstr, astr);
57347c478bd9Sstevel@tonic-gate 	} else {
573507d06da5SSurya Prakki 		(void) strcpy(str, mstr);
57367c478bd9Sstevel@tonic-gate 	}
57377c478bd9Sstevel@tonic-gate 
57387c478bd9Sstevel@tonic-gate 	if ((cpuid = dp->dcpu) == IDN_NIL_DCPU)
57397c478bd9Sstevel@tonic-gate 		bd = -1;
57407c478bd9Sstevel@tonic-gate 	else
57417c478bd9Sstevel@tonic-gate 		bd = CPUID_TO_BOARDID(cpuid);
57427c478bd9Sstevel@tonic-gate 
57437c478bd9Sstevel@tonic-gate 	SNOOP_IDN(0, str, bd, a1, a2, a3, a4);
57447c478bd9Sstevel@tonic-gate 
57457c478bd9Sstevel@tonic-gate 	PR_XDC("%s:%d:%d SENT: scpu = %d, msg = 0x%x(%s)\n",
57467c478bd9Sstevel@tonic-gate 	    f, domid, xx, cpuid, mtp->mt_mtype, str);
57477c478bd9Sstevel@tonic-gate 	PR_XDC("%s:%d:%d S-DATA: a1 = 0x%x, a2 = 0x%x\n",
57487c478bd9Sstevel@tonic-gate 	    f, domid, xx, a1, a2);
57497c478bd9Sstevel@tonic-gate 	PR_XDC("%s:%d:%d S-DATA: a3 = 0x%x, a4 = 0x%x\n",
57507c478bd9Sstevel@tonic-gate 	    f, domid, xx, a3, a4);
57517c478bd9Sstevel@tonic-gate 
57527c478bd9Sstevel@tonic-gate 	rv = idnxdc(domid, mtp, a1, a2, a3, a4);
57537c478bd9Sstevel@tonic-gate 	if (rv != 0) {
57547c478bd9Sstevel@tonic-gate 		PR_XDC("%s:%d:%d: WARNING: idnxdc(cpu %d) FAILED\n",
57557c478bd9Sstevel@tonic-gate 		    f, domid, xx, cpuid);
57567c478bd9Sstevel@tonic-gate 	}
57577c478bd9Sstevel@tonic-gate 
57587c478bd9Sstevel@tonic-gate 	return (rv);
57597c478bd9Sstevel@tonic-gate }
57607c478bd9Sstevel@tonic-gate 
57617c478bd9Sstevel@tonic-gate caddr_t
57627c478bd9Sstevel@tonic-gate _idn_getstruct(char *structname, int size)
57637c478bd9Sstevel@tonic-gate {
57647c478bd9Sstevel@tonic-gate 	caddr_t		ptr;
57657c478bd9Sstevel@tonic-gate 	procname_t	proc = "GETSTRUCT";
57667c478bd9Sstevel@tonic-gate 
57677c478bd9Sstevel@tonic-gate 	ptr = kmem_zalloc(size, KM_SLEEP);
57687c478bd9Sstevel@tonic-gate 
5769bf30efa4Smathue 	PR_ALLOC("%s: ptr 0x%p, struct(%s), size = %d\n",
577007d06da5SSurya Prakki 	    proc, (void *)ptr, structname, size);
57717c478bd9Sstevel@tonic-gate 
57727c478bd9Sstevel@tonic-gate 	return (ptr);
57737c478bd9Sstevel@tonic-gate }
57747c478bd9Sstevel@tonic-gate 
57757c478bd9Sstevel@tonic-gate void
57767c478bd9Sstevel@tonic-gate _idn_freestruct(caddr_t ptr, char *structname, int size)
57777c478bd9Sstevel@tonic-gate {
57787c478bd9Sstevel@tonic-gate 	procname_t	proc = "FREESTRUCT";
57797c478bd9Sstevel@tonic-gate 
5780bf30efa4Smathue 	PR_ALLOC("%s: ptr 0x%p, struct(%s), size = %d\n",
578107d06da5SSurya Prakki 	    proc, (void *)ptr, structname, size);
57827c478bd9Sstevel@tonic-gate 
57837c478bd9Sstevel@tonic-gate 	ASSERT(ptr != NULL);
57847c478bd9Sstevel@tonic-gate 	kmem_free(ptr, size);
57857c478bd9Sstevel@tonic-gate }
57867c478bd9Sstevel@tonic-gate #endif /* DEBUG */
5787