xref: /illumos-gate/usr/src/cmd/mdb/common/modules/ipp/ipp.c (revision 24537d3e)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2001-2002 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/time.h>
287c478bd9Sstevel@tonic-gate #include <ipp/ipp.h>
297c478bd9Sstevel@tonic-gate #include <ipp/ipp_impl.h>
307c478bd9Sstevel@tonic-gate #include <mdb/mdb_modapi.h>
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate static uintptr_t	ipp_mod_byid;
337c478bd9Sstevel@tonic-gate static uintptr_t	ipp_action_byid;
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate static int	byid_walk_init(mdb_walk_state_t *);
367c478bd9Sstevel@tonic-gate static int	byid_walk_step(mdb_walk_state_t *);
377c478bd9Sstevel@tonic-gate static void	byid_walk_fini(mdb_walk_state_t *);
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate static int	action(uintptr_t, uint_t, int, const mdb_arg_t *);
407c478bd9Sstevel@tonic-gate static int	action_format(uintptr_t, const void *, void *);
417c478bd9Sstevel@tonic-gate static int	action_dump(uintptr_t, ipp_action_t *, boolean_t);
427c478bd9Sstevel@tonic-gate static int	action_summary(uintptr_t, ipp_action_t *, boolean_t);
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate static int	cfglock(uintptr_t, uint_t, int, const mdb_arg_t *);
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate static int	mod(uintptr_t, uint_t, int, const mdb_arg_t *);
477c478bd9Sstevel@tonic-gate static int	mod_format(uintptr_t, const void *, void *);
487c478bd9Sstevel@tonic-gate static int	mod_dump(uintptr_t, ipp_mod_t *, boolean_t);
497c478bd9Sstevel@tonic-gate static int	mod_summary(uintptr_t, ipp_mod_t *, boolean_t);
507c478bd9Sstevel@tonic-gate static int	cfglock(uintptr_t, uint_t, int, const mdb_arg_t *);
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static int	ippops(uintptr_t, uint_t, int, const mdb_arg_t *);
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate static int	packet(uintptr_t, uint_t, int, const mdb_arg_t *);
557c478bd9Sstevel@tonic-gate static void	dump_classes(uintptr_t, uint_t);
567c478bd9Sstevel@tonic-gate static void	dump_log(uintptr_t, uint_t);
577c478bd9Sstevel@tonic-gate static void	aid2aname(ipp_action_id_t, char *);
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate static int	ref_walk_init(mdb_walk_state_t *);
607c478bd9Sstevel@tonic-gate static int	ref_walk_step(mdb_walk_state_t *);
617c478bd9Sstevel@tonic-gate static void	ref_walk_fini(mdb_walk_state_t *);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate typedef	struct afdata {
647c478bd9Sstevel@tonic-gate 	boolean_t	af_banner;
657c478bd9Sstevel@tonic-gate 	uint_t		af_flags;
667c478bd9Sstevel@tonic-gate } afdata_t;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #define	AF_VERBOSE	1
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate typedef	struct mfdata {
717c478bd9Sstevel@tonic-gate 	boolean_t	mf_banner;
727c478bd9Sstevel@tonic-gate 	uint_t		mf_flags;
737c478bd9Sstevel@tonic-gate } mfdata_t;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate #define	MF_VERBOSE	1
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * walker. Skips entries that are NULL.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static int
byid_walk_init(mdb_walk_state_t * wsp)827c478bd9Sstevel@tonic-gate byid_walk_init(
837c478bd9Sstevel@tonic-gate 	mdb_walk_state_t *wsp)
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	uintptr_t	start;
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	if (mdb_vread(&start, sizeof (uintptr_t), wsp->walk_addr) == -1) {
887c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read from address %p", wsp->walk_addr);
897c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
907c478bd9Sstevel@tonic-gate 	}
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	wsp->walk_addr = start;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
957c478bd9Sstevel@tonic-gate }
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate static int
byid_walk_step(mdb_walk_state_t * wsp)987c478bd9Sstevel@tonic-gate byid_walk_step(
997c478bd9Sstevel@tonic-gate 	mdb_walk_state_t *wsp)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate 	int		status;
102892ad162SToomas Soome 	void		*ptr;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	if (mdb_vread(&ptr, sizeof (void *), wsp->walk_addr) == -1) {
1057c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read from address %p", wsp->walk_addr);
1067c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
1077c478bd9Sstevel@tonic-gate 	}
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	if (ptr == (void *)-1) {
1107c478bd9Sstevel@tonic-gate 		status = WALK_DONE;
1117c478bd9Sstevel@tonic-gate 	} else if (ptr == NULL) {
1127c478bd9Sstevel@tonic-gate 		status = WALK_NEXT;
1137c478bd9Sstevel@tonic-gate 	} else {
1147c478bd9Sstevel@tonic-gate 		status = wsp->walk_callback((uintptr_t)ptr, NULL,
1157c478bd9Sstevel@tonic-gate 		    wsp->walk_cbdata);
1167c478bd9Sstevel@tonic-gate 	}
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	wsp->walk_addr += sizeof (void *);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	return (status);
1217c478bd9Sstevel@tonic-gate }
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1247c478bd9Sstevel@tonic-gate static void
byid_walk_fini(mdb_walk_state_t * wsp)1257c478bd9Sstevel@tonic-gate byid_walk_fini(
1267c478bd9Sstevel@tonic-gate 	mdb_walk_state_t *wsp)
1277c478bd9Sstevel@tonic-gate {
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1327c478bd9Sstevel@tonic-gate static int
action(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)1337c478bd9Sstevel@tonic-gate action(
1347c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
1357c478bd9Sstevel@tonic-gate 	uint_t		flags,
1367c478bd9Sstevel@tonic-gate 	int		argc,
1377c478bd9Sstevel@tonic-gate 	const mdb_arg_t	*argv)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate 	int		status;
1407c478bd9Sstevel@tonic-gate 	int		rc = DCMD_OK;
1417c478bd9Sstevel@tonic-gate 	afdata_t	*afp;
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate 	afp = mdb_zalloc(sizeof (afdata_t), UM_SLEEP);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
1467c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, AF_VERBOSE, &afp->af_flags,
1477c478bd9Sstevel@tonic-gate 	    NULL) != argc)
1487c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP))
1517c478bd9Sstevel@tonic-gate 		afp->af_banner = B_TRUE;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC) {
1547c478bd9Sstevel@tonic-gate 		status = action_format(addr, NULL, afp);
1557c478bd9Sstevel@tonic-gate 		rc = (status == WALK_NEXT) ? DCMD_OK : DCMD_ERR;
1567c478bd9Sstevel@tonic-gate 		goto cleanup;
1577c478bd9Sstevel@tonic-gate 	}
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("ipp_byid", action_format, afp,
1607c478bd9Sstevel@tonic-gate 	    ipp_action_byid) == -1) {
1617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to execute ipp_byid walk");
1627c478bd9Sstevel@tonic-gate 		rc = DCMD_ERR;
1637c478bd9Sstevel@tonic-gate 	}
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate cleanup:
1667c478bd9Sstevel@tonic-gate 	mdb_free(afp, sizeof (afdata_t));
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	return (rc);
1697c478bd9Sstevel@tonic-gate }
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1727c478bd9Sstevel@tonic-gate static int
action_format(uintptr_t addr,const void * data,void * arg)1737c478bd9Sstevel@tonic-gate action_format(
1747c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
1757c478bd9Sstevel@tonic-gate 	const void	*data,
1767c478bd9Sstevel@tonic-gate 	void		*arg)
1777c478bd9Sstevel@tonic-gate {
1787c478bd9Sstevel@tonic-gate 	afdata_t	*afp = (afdata_t *)arg;
1797c478bd9Sstevel@tonic-gate 	ipp_action_t	*ap;
1807c478bd9Sstevel@tonic-gate 	int		rc;
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	ap = mdb_alloc(sizeof (ipp_action_t), UM_SLEEP);
1837c478bd9Sstevel@tonic-gate 	if (mdb_vread(ap, sizeof (ipp_action_t), addr) == -1) {
1847c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_action_t at %p", addr);
1857c478bd9Sstevel@tonic-gate 		rc = WALK_ERR;
1867c478bd9Sstevel@tonic-gate 		goto done;
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	if (afp->af_flags & AF_VERBOSE)
1907c478bd9Sstevel@tonic-gate 		rc = action_dump(addr, ap, afp->af_banner);
1917c478bd9Sstevel@tonic-gate 	else
1927c478bd9Sstevel@tonic-gate 		rc = action_summary(addr, ap, afp->af_banner);
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	afp->af_banner = B_FALSE;
1957c478bd9Sstevel@tonic-gate done:
1967c478bd9Sstevel@tonic-gate 	mdb_free(ap, sizeof (ipp_action_t));
1977c478bd9Sstevel@tonic-gate 	return (rc);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2017c478bd9Sstevel@tonic-gate static int
action_dump(uintptr_t addr,ipp_action_t * ap,boolean_t banner)2027c478bd9Sstevel@tonic-gate action_dump(
2037c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
2047c478bd9Sstevel@tonic-gate 	ipp_action_t	*ap,
2057c478bd9Sstevel@tonic-gate 	boolean_t	banner)
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 	mdb_printf("%?p: %20s = %d\n", addr, "id", ap->ippa_id);
2087c478bd9Sstevel@tonic-gate 	if (!ap->ippa_nameless) {
2097c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = %s\n", "", "name", ap->ippa_name);
2107c478bd9Sstevel@tonic-gate 	}
2117c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "mod", ap->ippa_mod);
2127c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "ref", ap->ippa_ref);
2137c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "refby", ap->ippa_refby);
2147c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "ptr", ap->ippa_ptr);
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = ", "", "state");
2177c478bd9Sstevel@tonic-gate 	switch (ap->ippa_state) {
2187c478bd9Sstevel@tonic-gate 	case IPP_ASTATE_PROTO:
2197c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "PROTO");
2207c478bd9Sstevel@tonic-gate 		break;
2217c478bd9Sstevel@tonic-gate 	case IPP_ASTATE_CONFIG_PENDING:
2227c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "CONFIG_PENDING");
2237c478bd9Sstevel@tonic-gate 		break;
2247c478bd9Sstevel@tonic-gate 	case IPP_ASTATE_AVAILABLE:
2257c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "AVAILABLE");
2267c478bd9Sstevel@tonic-gate 		break;
2277c478bd9Sstevel@tonic-gate 	default:
2287c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "<unknown>");
2297c478bd9Sstevel@tonic-gate 		break;
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %d\n", "", "packets", ap->ippa_packets);
2337c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %d\n", "", "hold_count", ap->ippa_hold_count);
2347c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %s\n", "", "destruct_pending",
2357c478bd9Sstevel@tonic-gate 	    (ap->ippa_destruct_pending) ? "TRUE" : "FALSE");
2367c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "lock",
2377c478bd9Sstevel@tonic-gate 	    addr + ((uintptr_t)ap->ippa_lock - (uintptr_t)ap));
2387c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "config_lock",
2397c478bd9Sstevel@tonic-gate 	    addr + ((uintptr_t)ap->ippa_config_lock - (uintptr_t)ap));
2407c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
2417c478bd9Sstevel@tonic-gate 
2427c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate static int
action_summary(uintptr_t addr,ipp_action_t * ap,boolean_t banner)2467c478bd9Sstevel@tonic-gate action_summary(
2477c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
2487c478bd9Sstevel@tonic-gate 	ipp_action_t	*ap,
2497c478bd9Sstevel@tonic-gate 	boolean_t	banner)
2507c478bd9Sstevel@tonic-gate {
2517c478bd9Sstevel@tonic-gate 	ipp_mod_t	*imp;
2527c478bd9Sstevel@tonic-gate 	uintptr_t	ptr;
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 	if (banner)
2557c478bd9Sstevel@tonic-gate 		mdb_printf("%?s %<u>%20s %5s %20s%</u>\n",
2567c478bd9Sstevel@tonic-gate 		    "", "NAME", "ID", "MODNAME");
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 	imp = mdb_alloc(sizeof (ipp_mod_t), UM_SLEEP);
2597c478bd9Sstevel@tonic-gate 	ptr = (uintptr_t)ap->ippa_mod;
2607c478bd9Sstevel@tonic-gate 	if (mdb_vread(imp, sizeof (ipp_mod_t), ptr) == -1) {
2617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_mod_t at %p", ptr);
2627c478bd9Sstevel@tonic-gate 		mdb_free(imp, sizeof (ipp_mod_t));
2637c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2647c478bd9Sstevel@tonic-gate 	}
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	mdb_printf("%?p:%20s %5d %20s\n", addr, ap->ippa_name, ap->ippa_id,
2677c478bd9Sstevel@tonic-gate 	    imp->ippm_name);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	mdb_free(imp, sizeof (ipp_mod_t));
2707c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2747c478bd9Sstevel@tonic-gate static int
cfglock(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)2757c478bd9Sstevel@tonic-gate cfglock(
2767c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
2777c478bd9Sstevel@tonic-gate 	uint_t		flags,
2787c478bd9Sstevel@tonic-gate 	int		argc,
2797c478bd9Sstevel@tonic-gate 	const mdb_arg_t	*argv)
2807c478bd9Sstevel@tonic-gate {
2817c478bd9Sstevel@tonic-gate 	cfglock_t	*clp;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
2847c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	clp = mdb_alloc(sizeof (cfglock_t), UM_SLEEP);
2877c478bd9Sstevel@tonic-gate 	if (mdb_vread(clp, sizeof (cfglock_t), addr) == -1) {
2887c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read cfglock_t at %p", addr);
2897c478bd9Sstevel@tonic-gate 		mdb_free(clp, sizeof (cfglock_t));
2907c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	mdb_printf("%?p: %20s = %p\n", addr, "owner", clp->cl_owner);
2947c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %s\n", "", "reader",
2957c478bd9Sstevel@tonic-gate 	    clp->cl_reader ? "TRUE" : "FALSE");
2967c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %d\n", "", "writers", clp->cl_writers);
2977c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "mutex",
2987c478bd9Sstevel@tonic-gate 	    addr + ((uintptr_t)clp->cl_mutex - (uintptr_t)clp));
2997c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "cv",
3007c478bd9Sstevel@tonic-gate 	    addr + ((uintptr_t)clp->cl_cv - (uintptr_t)clp));
3017c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	mdb_free(clp, sizeof (cfglock_t));
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3097c478bd9Sstevel@tonic-gate static int
mod(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3107c478bd9Sstevel@tonic-gate mod(
3117c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
3127c478bd9Sstevel@tonic-gate 	uint_t		flags,
3137c478bd9Sstevel@tonic-gate 	int		argc,
3147c478bd9Sstevel@tonic-gate 	const mdb_arg_t	*argv)
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate 	int		status;
3177c478bd9Sstevel@tonic-gate 	int		rc = DCMD_OK;
3187c478bd9Sstevel@tonic-gate 	mfdata_t	*mfp;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	mfp = mdb_zalloc(sizeof (mfdata_t), UM_SLEEP);
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
3237c478bd9Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, MF_VERBOSE, &mfp->mf_flags,
3247c478bd9Sstevel@tonic-gate 	    NULL) != argc)
3257c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_LOOPFIRST) || !(flags & DCMD_LOOP))
3287c478bd9Sstevel@tonic-gate 		mfp->mf_banner = B_TRUE;
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC) {
3317c478bd9Sstevel@tonic-gate 		status = mod_format(addr, NULL, mfp);
3327c478bd9Sstevel@tonic-gate 		rc = (status == WALK_NEXT) ? DCMD_OK : DCMD_ERR;
3337c478bd9Sstevel@tonic-gate 		goto cleanup;
3347c478bd9Sstevel@tonic-gate 	}
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 	if (mdb_pwalk("ipp_byid", mod_format, mfp,
3377c478bd9Sstevel@tonic-gate 	    ipp_mod_byid) == -1) {
3387c478bd9Sstevel@tonic-gate 		mdb_warn("failed to execute ipp_byid walk");
3397c478bd9Sstevel@tonic-gate 		rc = DCMD_ERR;
3407c478bd9Sstevel@tonic-gate 	}
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate cleanup:
3437c478bd9Sstevel@tonic-gate 	mdb_free(mfp, sizeof (mfdata_t));
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	return (rc);
3467c478bd9Sstevel@tonic-gate }
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3497c478bd9Sstevel@tonic-gate static int
mod_format(uintptr_t addr,const void * data,void * arg)3507c478bd9Sstevel@tonic-gate mod_format(
3517c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
3527c478bd9Sstevel@tonic-gate 	const void	*data,
3537c478bd9Sstevel@tonic-gate 	void		*arg)
3547c478bd9Sstevel@tonic-gate {
3557c478bd9Sstevel@tonic-gate 	mfdata_t	*mfp = (mfdata_t *)arg;
3567c478bd9Sstevel@tonic-gate 	ipp_mod_t	*imp;
3577c478bd9Sstevel@tonic-gate 	int		rc;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	imp = mdb_alloc(sizeof (ipp_mod_t), UM_SLEEP);
3607c478bd9Sstevel@tonic-gate 	if (mdb_vread(imp, sizeof (ipp_mod_t), addr) == -1) {
3617c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_mod_t at %p", addr);
3627c478bd9Sstevel@tonic-gate 		rc = WALK_ERR;
3637c478bd9Sstevel@tonic-gate 		goto done;
3647c478bd9Sstevel@tonic-gate 	}
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	if (mfp->mf_flags & MF_VERBOSE)
3677c478bd9Sstevel@tonic-gate 		rc = mod_dump(addr, imp, mfp->mf_banner);
3687c478bd9Sstevel@tonic-gate 	else
3697c478bd9Sstevel@tonic-gate 		rc = mod_summary(addr, imp, mfp->mf_banner);
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	mfp->mf_banner = B_FALSE;
3727c478bd9Sstevel@tonic-gate done:
3737c478bd9Sstevel@tonic-gate 	mdb_free(imp, sizeof (ipp_mod_t));
3747c478bd9Sstevel@tonic-gate 	return (rc);
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3787c478bd9Sstevel@tonic-gate static int
mod_dump(uintptr_t addr,ipp_mod_t * imp,boolean_t banner)3797c478bd9Sstevel@tonic-gate mod_dump(
3807c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
3817c478bd9Sstevel@tonic-gate 	ipp_mod_t	*imp,
3827c478bd9Sstevel@tonic-gate 	boolean_t	banner)
3837c478bd9Sstevel@tonic-gate {
3847c478bd9Sstevel@tonic-gate 	mdb_printf("%?p: %20s = %d\n", addr, "id", imp->ippm_id);
3857c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %s\n", "", "name", imp->ippm_name);
3867c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "ops", imp->ippm_ops);
3877c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "action", imp->ippm_action);
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = ", "", "state");
3907c478bd9Sstevel@tonic-gate 	switch (imp->ippm_state) {
3917c478bd9Sstevel@tonic-gate 	case IPP_MODSTATE_PROTO:
3927c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "PROTO");
3937c478bd9Sstevel@tonic-gate 		break;
3947c478bd9Sstevel@tonic-gate 	case IPP_MODSTATE_AVAILABLE:
3957c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "AVAILABLE");
3967c478bd9Sstevel@tonic-gate 		break;
3977c478bd9Sstevel@tonic-gate 	default:
3987c478bd9Sstevel@tonic-gate 		mdb_printf("%s\n", "<unknown>");
3997c478bd9Sstevel@tonic-gate 		break;
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %d\n", "", "hold_count", imp->ippm_hold_count);
4037c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = %s\n", "", "destruct_pending",
4047c478bd9Sstevel@tonic-gate 	    (imp->ippm_destruct_pending) ? "TRUE" : "FALSE");
4057c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "lock",
4067c478bd9Sstevel@tonic-gate 	    addr + ((uintptr_t)imp->ippm_lock - (uintptr_t)imp));
4077c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4107c478bd9Sstevel@tonic-gate }
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate static int
mod_summary(uintptr_t addr,ipp_mod_t * imp,boolean_t banner)4137c478bd9Sstevel@tonic-gate mod_summary(
4147c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
4157c478bd9Sstevel@tonic-gate 	ipp_mod_t	*imp,
4167c478bd9Sstevel@tonic-gate 	boolean_t	banner)
4177c478bd9Sstevel@tonic-gate {
4187c478bd9Sstevel@tonic-gate 	if (banner)
4197c478bd9Sstevel@tonic-gate 		mdb_printf("%?s %<u>%20s %5s%</u>\n",
4207c478bd9Sstevel@tonic-gate 		    "", "NAME", "ID");
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	mdb_printf("%?p:%20s %5d\n", addr, imp->ippm_name, imp->ippm_id);
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4287c478bd9Sstevel@tonic-gate static int
ippops(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4297c478bd9Sstevel@tonic-gate ippops(
4307c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
4317c478bd9Sstevel@tonic-gate 	uint_t		flags,
4327c478bd9Sstevel@tonic-gate 	int		argc,
4337c478bd9Sstevel@tonic-gate 	const mdb_arg_t	*argv)
4347c478bd9Sstevel@tonic-gate {
4357c478bd9Sstevel@tonic-gate 	ipp_ops_t	*ippo;
4367c478bd9Sstevel@tonic-gate 	GElf_Sym	sym;
4377c478bd9Sstevel@tonic-gate 	char		buf[MDB_SYM_NAMLEN];
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
4407c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 	ippo = mdb_alloc(sizeof (ipp_ops_t), UM_SLEEP);
4437c478bd9Sstevel@tonic-gate 	if (mdb_vread(ippo, sizeof (ipp_ops_t), addr) == -1) {
4447c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_ops_t at %p", addr);
4457c478bd9Sstevel@tonic-gate 		mdb_free(ippo, sizeof (ipp_ops_t));
4467c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4477c478bd9Sstevel@tonic-gate 	}
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate 	mdb_printf("%?p: %20s = %d\n", addr, "rev", ippo->ippo_rev);
4507c478bd9Sstevel@tonic-gate 
4517c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_create,
4527c478bd9Sstevel@tonic-gate 	    MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
4537c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = %s\n", "", "action_create", buf);
4547c478bd9Sstevel@tonic-gate 	else
4557c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = 0x%p\n", "", "action_create",
4567c478bd9Sstevel@tonic-gate 		    ippo->ippo_action_create);
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_modify,
4597c478bd9Sstevel@tonic-gate 	    MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
4607c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = %s\n", "", "action_modify", buf);
4617c478bd9Sstevel@tonic-gate 	else
4627c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = 0x%p\n", "", "action_modify",
4637c478bd9Sstevel@tonic-gate 		    ippo->ippo_action_modify);
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_destroy,
4667c478bd9Sstevel@tonic-gate 	    MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
4677c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = %s\n", "", "action_destroy", buf);
4687c478bd9Sstevel@tonic-gate 	else
4697c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = 0x%p\n", "", "action_destroy",
4707c478bd9Sstevel@tonic-gate 		    ippo->ippo_action_destroy);
4717c478bd9Sstevel@tonic-gate 
4727c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_info,
4737c478bd9Sstevel@tonic-gate 	    MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
4747c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = %s\n", "", "action_info", buf);
4757c478bd9Sstevel@tonic-gate 	else
4767c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = 0x%p\n", "", "action_info",
4777c478bd9Sstevel@tonic-gate 		    ippo->ippo_action_info);
4787c478bd9Sstevel@tonic-gate 
4797c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_addr((uintptr_t)ippo->ippo_action_invoke,
4807c478bd9Sstevel@tonic-gate 	    MDB_SYM_EXACT, buf, MDB_SYM_NAMLEN, &sym) == 0)
4817c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = %s\n", "", "action_invoke", buf);
4827c478bd9Sstevel@tonic-gate 	else
4837c478bd9Sstevel@tonic-gate 		mdb_printf("%?s  %20s = 0x%p\n", "", "action_invoke",
4847c478bd9Sstevel@tonic-gate 		    ippo->ippo_action_invoke);
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 	mdb_printf("\n");
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate 	mdb_free(ippo, sizeof (ipp_ops_t));
4897c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate 
4927c478bd9Sstevel@tonic-gate static int
ref_walk_init(mdb_walk_state_t * wsp)4937c478bd9Sstevel@tonic-gate ref_walk_init(
4947c478bd9Sstevel@tonic-gate 	mdb_walk_state_t *wsp)
4957c478bd9Sstevel@tonic-gate {
496892ad162SToomas Soome 	if (wsp->walk_addr == 0)
4977c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate static int
ref_walk_step(mdb_walk_state_t * wsp)5037c478bd9Sstevel@tonic-gate ref_walk_step(
5047c478bd9Sstevel@tonic-gate 	mdb_walk_state_t *wsp)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate 	ipp_ref_t	*rp;
5077c478bd9Sstevel@tonic-gate 	int		status;
5087c478bd9Sstevel@tonic-gate 
509892ad162SToomas Soome 	if (wsp->walk_addr == 0)
5107c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	rp = mdb_alloc(sizeof (ipp_ref_t), UM_SLEEP);
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate 	if (mdb_vread(rp, sizeof (ipp_ref_t), wsp->walk_addr) == -1) {
5157c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_ref_t at %p", wsp->walk_addr);
5167c478bd9Sstevel@tonic-gate 		mdb_free(rp, sizeof (ipp_ref_t));
5177c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
5187c478bd9Sstevel@tonic-gate 	}
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback((uintptr_t)rp->ippr_ptr, NULL,
5217c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata);
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)(rp->ippr_nextp);
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 	mdb_free(rp, sizeof (ipp_ref_t));
5267c478bd9Sstevel@tonic-gate 	return (status);
5277c478bd9Sstevel@tonic-gate }
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5307c478bd9Sstevel@tonic-gate static void
ref_walk_fini(mdb_walk_state_t * wsp)5317c478bd9Sstevel@tonic-gate ref_walk_fini(
5327c478bd9Sstevel@tonic-gate 	mdb_walk_state_t *wsp)
5337c478bd9Sstevel@tonic-gate {
5347c478bd9Sstevel@tonic-gate }
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5377c478bd9Sstevel@tonic-gate static int
packet(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)5387c478bd9Sstevel@tonic-gate packet(
5397c478bd9Sstevel@tonic-gate 	uintptr_t	addr,
5407c478bd9Sstevel@tonic-gate 	uint_t		flags,
5417c478bd9Sstevel@tonic-gate 	int		argc,
5427c478bd9Sstevel@tonic-gate 	const mdb_arg_t	*argv)
5437c478bd9Sstevel@tonic-gate {
5447c478bd9Sstevel@tonic-gate 	ipp_packet_t	*pp;
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == 0)
5477c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5487c478bd9Sstevel@tonic-gate 
5497c478bd9Sstevel@tonic-gate 	pp = mdb_alloc(sizeof (ipp_packet_t), UM_SLEEP);
5507c478bd9Sstevel@tonic-gate 	if (mdb_vread(pp, sizeof (ipp_packet_t), addr) == -1) {
5517c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_packet_t at %p", addr);
5527c478bd9Sstevel@tonic-gate 		mdb_free(pp, sizeof (ipp_packet_t));
5537c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5547c478bd9Sstevel@tonic-gate 	}
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	mdb_printf("%?p: %20s = 0x%p\n", addr, "data", pp->ippp_data);
5577c478bd9Sstevel@tonic-gate 	mdb_printf("%?s  %20s = 0x%p\n", "", "private", pp->ippp_private);
5587c478bd9Sstevel@tonic-gate 	dump_classes((uintptr_t)pp->ippp_class_array, pp->ippp_class_windex);
5597c478bd9Sstevel@tonic-gate 	dump_log((uintptr_t)pp->ippp_log, pp->ippp_log_windex);
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	mdb_free(pp, sizeof (ipp_packet_t));
5627c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate static void
dump_classes(uintptr_t ptr,uint_t nelt)5667c478bd9Sstevel@tonic-gate dump_classes(
5677c478bd9Sstevel@tonic-gate 	uintptr_t	ptr,
5687c478bd9Sstevel@tonic-gate 	uint_t		nelt)
5697c478bd9Sstevel@tonic-gate {
5707c478bd9Sstevel@tonic-gate 	ipp_class_t	*array;
571*24537d3eSToomas Soome 	ipp_class_t	*cp = NULL;
5727c478bd9Sstevel@tonic-gate 	uint_t		i;
5737c478bd9Sstevel@tonic-gate 	boolean_t	first_time = B_TRUE;
5747c478bd9Sstevel@tonic-gate 	char		buf[MAXNAMELEN];
5757c478bd9Sstevel@tonic-gate 
5767c478bd9Sstevel@tonic-gate 	array = mdb_alloc(sizeof (ipp_class_t) * nelt, UM_SLEEP);
5777c478bd9Sstevel@tonic-gate 	if (mdb_vread(array, sizeof (ipp_class_t) * nelt, ptr) == -1) {
5787c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_class_t array at %p", ptr);
5797c478bd9Sstevel@tonic-gate 		return;
5807c478bd9Sstevel@tonic-gate 	}
5817c478bd9Sstevel@tonic-gate 
5827c478bd9Sstevel@tonic-gate 	for (i = 0; i < nelt; i++) {
5837c478bd9Sstevel@tonic-gate 		if (first_time) {
5847c478bd9Sstevel@tonic-gate 			mdb_printf("%20s  %?s   %<u>%15s %15s%</u>\n", "",
5857c478bd9Sstevel@tonic-gate 			    "classes", "NAME", "ACTION");
5867c478bd9Sstevel@tonic-gate 			first_time = B_FALSE;
5877c478bd9Sstevel@tonic-gate 		}
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 		cp = &(array[i]);
5907c478bd9Sstevel@tonic-gate 		aid2aname(cp->ippc_aid, buf);
5917c478bd9Sstevel@tonic-gate 		mdb_printf("%20s  %?p:  %15s %15s%\n", "",
5927c478bd9Sstevel@tonic-gate 		    ptr + (i * sizeof (ipp_class_t)), cp->ippc_name, buf);
5937c478bd9Sstevel@tonic-gate 	}
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	mdb_free(cp, sizeof (ipp_class_t) * nelt);
5967c478bd9Sstevel@tonic-gate }
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate static void
dump_log(uintptr_t ptr,uint_t nelt)5997c478bd9Sstevel@tonic-gate dump_log(
6007c478bd9Sstevel@tonic-gate 	uintptr_t	ptr,
6017c478bd9Sstevel@tonic-gate 	uint_t		nelt)
6027c478bd9Sstevel@tonic-gate {
6037c478bd9Sstevel@tonic-gate 	ipp_log_t	*array;
604*24537d3eSToomas Soome 	ipp_log_t	*lp = NULL;
6057c478bd9Sstevel@tonic-gate 	uint_t		i;
6067c478bd9Sstevel@tonic-gate 	boolean_t	first_time = B_TRUE;
6077c478bd9Sstevel@tonic-gate 	char		buf[MAXNAMELEN];
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate 	array = mdb_alloc(sizeof (ipp_log_t) * nelt, UM_SLEEP);
6107c478bd9Sstevel@tonic-gate 	if (mdb_vread(array, sizeof (ipp_log_t) * nelt, ptr) == -1) {
6117c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read ipp_log_t array at %p", ptr);
6127c478bd9Sstevel@tonic-gate 		return;
6137c478bd9Sstevel@tonic-gate 	}
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	for (i = 0; i < nelt; i++) {
6167c478bd9Sstevel@tonic-gate 		if (first_time) {
6177c478bd9Sstevel@tonic-gate 			mdb_printf("%20s  %?s   %<u>%15s %15s%</u>\n", "",
6187c478bd9Sstevel@tonic-gate 			    "log", "CLASS NAME", "ACTION");
6197c478bd9Sstevel@tonic-gate 			first_time = B_FALSE;
6207c478bd9Sstevel@tonic-gate 		}
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 		lp = &(array[i]);
6237c478bd9Sstevel@tonic-gate 		aid2aname(lp->ippl_aid, buf);
6247c478bd9Sstevel@tonic-gate 		mdb_printf("%20s  %?p:  %15s %15s\n", "",
6257c478bd9Sstevel@tonic-gate 		    ptr + (i * sizeof (ipp_class_t)), lp->ippl_name, buf);
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	mdb_free(lp, sizeof (ipp_log_t) * nelt);
6297c478bd9Sstevel@tonic-gate }
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate static void
aid2aname(ipp_action_id_t aid,char * buf)6327c478bd9Sstevel@tonic-gate aid2aname(
6337c478bd9Sstevel@tonic-gate 	ipp_action_id_t	aid,
6347c478bd9Sstevel@tonic-gate 	char		*buf)
6357c478bd9Sstevel@tonic-gate {
6367c478bd9Sstevel@tonic-gate 	uintptr_t	addr;
6377c478bd9Sstevel@tonic-gate 	uintptr_t	ptr;
6387c478bd9Sstevel@tonic-gate 	ipp_action_t	*ap;
6397c478bd9Sstevel@tonic-gate 
6407c478bd9Sstevel@tonic-gate 	switch (aid) {
6417c478bd9Sstevel@tonic-gate 	case IPP_ACTION_INVAL:
6427c478bd9Sstevel@tonic-gate 		strcpy(buf, "invalid");
6437c478bd9Sstevel@tonic-gate 		break;
6447c478bd9Sstevel@tonic-gate 	case IPP_ACTION_CONT:
6457c478bd9Sstevel@tonic-gate 		strcpy(buf, "continue");
6467c478bd9Sstevel@tonic-gate 		break;
6477c478bd9Sstevel@tonic-gate 	case IPP_ACTION_DEFER:
6487c478bd9Sstevel@tonic-gate 		strcpy(buf, "defer");
6497c478bd9Sstevel@tonic-gate 		break;
6507c478bd9Sstevel@tonic-gate 	case IPP_ACTION_DROP:
6517c478bd9Sstevel@tonic-gate 		strcpy(buf, "drop");
6527c478bd9Sstevel@tonic-gate 		break;
6537c478bd9Sstevel@tonic-gate 	default:
6547c478bd9Sstevel@tonic-gate 		if (mdb_vread(&addr, sizeof (uintptr_t),
6557c478bd9Sstevel@tonic-gate 		    ipp_action_byid) == -1) {
6567c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read from address %p",
6577c478bd9Sstevel@tonic-gate 			    ipp_action_byid);
6587c478bd9Sstevel@tonic-gate 			strcpy(buf, "???");
6597c478bd9Sstevel@tonic-gate 			break;
6607c478bd9Sstevel@tonic-gate 		}
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 		addr += ((int32_t)aid * sizeof (void *));
6637c478bd9Sstevel@tonic-gate 		if (mdb_vread(&ptr, sizeof (uintptr_t), addr) == -1) {
6647c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read from address %p", addr);
6657c478bd9Sstevel@tonic-gate 			strcpy(buf, "???");
6667c478bd9Sstevel@tonic-gate 			break;
6677c478bd9Sstevel@tonic-gate 		}
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 		ap = mdb_alloc(sizeof (ipp_action_t), UM_SLEEP);
6707c478bd9Sstevel@tonic-gate 		if (mdb_vread(ap, sizeof (ipp_action_t), ptr) == -1) {
6717c478bd9Sstevel@tonic-gate 			mdb_warn("failed to read ipp_action_t at %p", ptr);
6727c478bd9Sstevel@tonic-gate 			mdb_free(ap, sizeof (ipp_action_t));
6737c478bd9Sstevel@tonic-gate 			strcpy(buf, "???");
6747c478bd9Sstevel@tonic-gate 			break;
6757c478bd9Sstevel@tonic-gate 		}
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 		if (ap->ippa_id != aid) {
6787c478bd9Sstevel@tonic-gate 			mdb_warn("corrupt action at %p", ptr);
6797c478bd9Sstevel@tonic-gate 			mdb_free(ap, sizeof (ipp_action_t));
6807c478bd9Sstevel@tonic-gate 			strcpy(buf, "???");
6817c478bd9Sstevel@tonic-gate 			break;
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 		strcpy(buf, ap->ippa_name);
6857c478bd9Sstevel@tonic-gate 	}
6867c478bd9Sstevel@tonic-gate }
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
6897c478bd9Sstevel@tonic-gate 	{ "ipp_action", "?[-v]",
6907c478bd9Sstevel@tonic-gate 	    "display ipp_action structure", action },
6917c478bd9Sstevel@tonic-gate 	{ "ipp_mod", "?[-v]",
6927c478bd9Sstevel@tonic-gate 	    "display ipp_mod structure", mod },
6937c478bd9Sstevel@tonic-gate 	{ "cfglock", ":",
6947c478bd9Sstevel@tonic-gate 	    "display cfglock structure", cfglock },
6957c478bd9Sstevel@tonic-gate 	{ "ippops", ":",
6967c478bd9Sstevel@tonic-gate 	    "display ipp_ops structure", ippops },
6977c478bd9Sstevel@tonic-gate 	{ "ipp_packet", ":",
6987c478bd9Sstevel@tonic-gate 	    "display ipp_packet structure", packet },
6997c478bd9Sstevel@tonic-gate 	{ NULL }
7007c478bd9Sstevel@tonic-gate };
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
7037c478bd9Sstevel@tonic-gate 	{ "ipp_byid", "walk byid array", byid_walk_init, byid_walk_step,
7047c478bd9Sstevel@tonic-gate 	    byid_walk_fini },
7057c478bd9Sstevel@tonic-gate 	{ "ipp_ref", "walk reference list", ref_walk_init, ref_walk_step,
7067c478bd9Sstevel@tonic-gate 	    ref_walk_fini },
7077c478bd9Sstevel@tonic-gate 	{ NULL }
7087c478bd9Sstevel@tonic-gate };
7097c478bd9Sstevel@tonic-gate 
7107c478bd9Sstevel@tonic-gate static const mdb_modinfo_t ipp_modinfo = { MDB_API_VERSION, dcmds, walkers };
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)7137c478bd9Sstevel@tonic-gate _mdb_init(void)
7147c478bd9Sstevel@tonic-gate {
7157c478bd9Sstevel@tonic-gate 	GElf_Sym sym;
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("ipp_action_byid", &sym) == -1) {
7187c478bd9Sstevel@tonic-gate 		mdb_warn("failed to lookup 'ipp_action_byid'");
7197c478bd9Sstevel@tonic-gate 		return (NULL);
7207c478bd9Sstevel@tonic-gate 	}
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 	ipp_action_byid = (uintptr_t)sym.st_value;
7237c478bd9Sstevel@tonic-gate 
7247c478bd9Sstevel@tonic-gate 	if (mdb_lookup_by_name("ipp_mod_byid", &sym) == -1) {
7257c478bd9Sstevel@tonic-gate 		mdb_warn("failed to lookup 'ipp_mod_byid'");
7267c478bd9Sstevel@tonic-gate 		return (NULL);
7277c478bd9Sstevel@tonic-gate 	}
7287c478bd9Sstevel@tonic-gate 
7297c478bd9Sstevel@tonic-gate 	ipp_mod_byid = (uintptr_t)sym.st_value;
7307c478bd9Sstevel@tonic-gate 
7317c478bd9Sstevel@tonic-gate 	return (&ipp_modinfo);
7327c478bd9Sstevel@tonic-gate }
733