xref: /titanic_51/usr/src/cmd/mdb/common/modules/crypto/impl.c (revision 9b009fc1b553084f6003dcd46b171890049de0ff)
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
56a1073f8Skrishna  * Common Development and Distribution License (the "License").
66a1073f8Skrishna  * 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 /*
22*9b009fc1SValerie Bubb Fenwick  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
267c478bd9Sstevel@tonic-gate  * mdb dcmds for selected structures from
277c478bd9Sstevel@tonic-gate  * usr/src/uts/common/sys/crypto/impl.h
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate #include <stdio.h>
307c478bd9Sstevel@tonic-gate #include <sys/mdb_modapi.h>
317c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/crypto/api.h>
347c478bd9Sstevel@tonic-gate #include <sys/crypto/common.h>
357c478bd9Sstevel@tonic-gate #include <sys/crypto/impl.h>
367c478bd9Sstevel@tonic-gate #include "crypto_cmds.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate static const char *prov_states[] = {
397c478bd9Sstevel@tonic-gate 	"none",
407c478bd9Sstevel@tonic-gate 	"KCF_PROV_ALLOCATED",
417c478bd9Sstevel@tonic-gate 	"KCF_PROV_UNVERIFIED",
42fe2f7468Skrishna 	"KCF_PROV_VERIFICATION_FAILED",
437c478bd9Sstevel@tonic-gate 	"KCF_PROV_READY",
447c478bd9Sstevel@tonic-gate 	"KCF_PROV_BUSY",
457c478bd9Sstevel@tonic-gate 	"KCF_PROV_FAILED",
467c478bd9Sstevel@tonic-gate 	"KCF_PROV_DISABLED",
47ef56a3c5SKrishna Yenduri 	"KCF_PROV_UNREGISTERING",
48ef56a3c5SKrishna Yenduri 	"KCF_PROV_UNREGISTERED"
497c478bd9Sstevel@tonic-gate };
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*ARGSUSED*/
527c478bd9Sstevel@tonic-gate int
537c478bd9Sstevel@tonic-gate kcf_provider_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
547c478bd9Sstevel@tonic-gate {
557c478bd9Sstevel@tonic-gate 	kcf_provider_desc_t desc;
567c478bd9Sstevel@tonic-gate 	kcf_provider_desc_t *ptr;
577c478bd9Sstevel@tonic-gate 	char string[MAXNAMELEN + 1];
587c478bd9Sstevel@tonic-gate 	int i, j;
597c478bd9Sstevel@tonic-gate 	crypto_mech_info_t *mech_pointer;
60ef56a3c5SKrishna Yenduri 	kcf_prov_cpu_t stats;
61ef56a3c5SKrishna Yenduri 	uint64_t dtotal, ftotal, btotal;
62ef56a3c5SKrishna Yenduri 	int holdcnt, jobcnt;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC)
657c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
667c478bd9Sstevel@tonic-gate 	ptr = (kcf_provider_desc_t *)addr;
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifdef DEBUG
697c478bd9Sstevel@tonic-gate 	mdb_printf("DEBUG: reading kcf_provider_desc at %p\n", ptr);
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	if (mdb_vread(&desc, sizeof (kcf_provider_desc_t), (uintptr_t)ptr)
737c478bd9Sstevel@tonic-gate 	    == -1) {
747c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read at address %p", (uintptr_t)ptr);
757c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
767c478bd9Sstevel@tonic-gate 	}
777c478bd9Sstevel@tonic-gate 	mdb_printf("%<b>kcf_provider_desc at %p%</b>\n", ptr);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	switch (desc.pd_prov_type) {
807c478bd9Sstevel@tonic-gate 	case CRYPTO_HW_PROVIDER:
817c478bd9Sstevel@tonic-gate 		mdb_printf("pd_prov_type:\t\tCRYPTO_HW_PROVIDER\n");
827c478bd9Sstevel@tonic-gate 		break;
837c478bd9Sstevel@tonic-gate 	case CRYPTO_SW_PROVIDER:
847c478bd9Sstevel@tonic-gate 		mdb_printf("pd_prov_type:\t\tCRYPTO_SW_PROVIDER\n");
857c478bd9Sstevel@tonic-gate 		break;
867c478bd9Sstevel@tonic-gate 	case CRYPTO_LOGICAL_PROVIDER:
877c478bd9Sstevel@tonic-gate 		mdb_printf("pd_prov_type:\t\tCRYPTO_LOGICAL_PROVIDER\n");
887c478bd9Sstevel@tonic-gate 		break;
897c478bd9Sstevel@tonic-gate 	default:
907c478bd9Sstevel@tonic-gate 		mdb_printf("bad pd_prov_type:\t%d\n", desc.pd_prov_type);
917c478bd9Sstevel@tonic-gate 	}
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	mdb_printf("pd_prov_id:\t\t%u\n", desc.pd_prov_id);
947c478bd9Sstevel@tonic-gate 	if (desc.pd_description == NULL)
957c478bd9Sstevel@tonic-gate 		mdb_printf("pd_description:\t\tNULL\n");
967c478bd9Sstevel@tonic-gate 	else if (mdb_readstr(string, MAXNAMELEN + 1,
977c478bd9Sstevel@tonic-gate 	    (uintptr_t)desc.pd_description) == -1) {
987c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read %p", desc.pd_description);
997c478bd9Sstevel@tonic-gate 	} else
1007c478bd9Sstevel@tonic-gate 		mdb_printf("pd_description:\t\t%s\n", string);
1017c478bd9Sstevel@tonic-gate 
102ef56a3c5SKrishna Yenduri 	mdb_printf("pd_sid:\t\t\t%u\n", desc.pd_sid);
103ef56a3c5SKrishna Yenduri 	mdb_printf("pd_taskq:\t\t%p\n", desc.pd_taskq);
104ef56a3c5SKrishna Yenduri 	mdb_printf("pd_nbins:\t\t%u\n", desc.pd_nbins);
105ef56a3c5SKrishna Yenduri 	mdb_printf("pd_percpu_bins:\t\t%p\n", desc.pd_percpu_bins);
106ef56a3c5SKrishna Yenduri 
107ef56a3c5SKrishna Yenduri 	dtotal = ftotal = btotal = 0;
108ef56a3c5SKrishna Yenduri 	holdcnt = jobcnt = 0;
109ef56a3c5SKrishna Yenduri 	for (i = 0; i < desc.pd_nbins; i++) {
110ef56a3c5SKrishna Yenduri 		if (mdb_vread(&stats, sizeof (kcf_prov_cpu_t),
111ef56a3c5SKrishna Yenduri 		    (uintptr_t)(desc.pd_percpu_bins + i)) == -1) {
112ef56a3c5SKrishna Yenduri 			mdb_warn("cannot read addr %p",
113ef56a3c5SKrishna Yenduri 			    desc.pd_percpu_bins + i);
114ef56a3c5SKrishna Yenduri 			return (DCMD_ERR);
115ef56a3c5SKrishna Yenduri 		}
116ef56a3c5SKrishna Yenduri 
117ef56a3c5SKrishna Yenduri 		holdcnt += stats.kp_holdcnt;
118ef56a3c5SKrishna Yenduri 		jobcnt += stats.kp_jobcnt;
119ef56a3c5SKrishna Yenduri 		dtotal += stats.kp_ndispatches;
120ef56a3c5SKrishna Yenduri 		ftotal += stats.kp_nfails;
121ef56a3c5SKrishna Yenduri 		btotal += stats.kp_nbusy_rval;
122ef56a3c5SKrishna Yenduri 	}
123ef56a3c5SKrishna Yenduri 	mdb_inc_indent(4);
124ef56a3c5SKrishna Yenduri 	mdb_printf("total kp_holdcnt:\t\t%d\n", holdcnt);
125ef56a3c5SKrishna Yenduri 	mdb_printf("total kp_jobcnt:\t\t%u\n", jobcnt);
126ef56a3c5SKrishna Yenduri 	mdb_printf("total kp_ndispatches:\t%llu\n", dtotal);
127ef56a3c5SKrishna Yenduri 	mdb_printf("total kp_nfails:\t\t%llu\n", ftotal);
128ef56a3c5SKrishna Yenduri 	mdb_printf("total kp_nbusy_rval:\t%llu\n", btotal);
129ef56a3c5SKrishna Yenduri 	mdb_dec_indent(4);
130ef56a3c5SKrishna Yenduri 
131ef56a3c5SKrishna Yenduri 	mdb_printf("pd_prov_handle:\t\t%p\n", desc.pd_prov_handle);
132ef56a3c5SKrishna Yenduri 	mdb_printf("pd_kcf_prov_handle:\t%u\n", desc.pd_kcf_prov_handle);
133ef56a3c5SKrishna Yenduri 
1347c478bd9Sstevel@tonic-gate 	mdb_printf("pd_ops_vector:\t\t%p\n", desc.pd_ops_vector);
1357c478bd9Sstevel@tonic-gate 	mdb_printf("pd_mech_list_count:\t%u\n", desc.pd_mech_list_count);
1367c478bd9Sstevel@tonic-gate 	/* mechanisms */
1377c478bd9Sstevel@tonic-gate 	mdb_inc_indent(4);
1387c478bd9Sstevel@tonic-gate 	for (i = 0; i < desc.pd_mech_list_count; i++) {
1397c478bd9Sstevel@tonic-gate 		mech_pointer = desc.pd_mechanisms + i;
1407c478bd9Sstevel@tonic-gate 		mdb_call_dcmd("crypto_mech_info",
1417c478bd9Sstevel@tonic-gate 		    (uintptr_t)mech_pointer, DCMD_ADDRSPEC, 0, NULL);
1427c478bd9Sstevel@tonic-gate 	}
1437c478bd9Sstevel@tonic-gate 	mdb_dec_indent(4);
1446a1073f8Skrishna 	mdb_printf("pd_mech_indx:\n");
1457c478bd9Sstevel@tonic-gate 	mdb_inc_indent(8);
1467c478bd9Sstevel@tonic-gate 	for (i = 0; i < KCF_OPS_CLASSSIZE; i++) {
1477c478bd9Sstevel@tonic-gate 		for (j = 0; j < KCF_MAXMECHTAB; j++) {
1486a1073f8Skrishna 			if (desc.pd_mech_indx[i][j] == KCF_INVALID_INDX)
1496a1073f8Skrishna 				mdb_printf("N ");
1506a1073f8Skrishna 			else
1516a1073f8Skrishna 				mdb_printf("%u ", desc.pd_mech_indx[i][j]);
1527c478bd9Sstevel@tonic-gate 		}
1537c478bd9Sstevel@tonic-gate 		mdb_printf("\n");
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 	mdb_dec_indent(8);
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	if (desc.pd_name == NULL)
1587c478bd9Sstevel@tonic-gate 		mdb_printf("pd_name:\t\t NULL\n");
1597c478bd9Sstevel@tonic-gate 	else if (mdb_readstr(string, MAXNAMELEN + 1, (uintptr_t)desc.pd_name)
1607c478bd9Sstevel@tonic-gate 	    == -1)
1617c478bd9Sstevel@tonic-gate 		mdb_warn("could not read pd_name from %X\n", desc.pd_name);
1627c478bd9Sstevel@tonic-gate 	else
1637c478bd9Sstevel@tonic-gate 		mdb_printf("pd_name:\t\t%s\n", string);
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	mdb_printf("pd_instance:\t\t%u\n", desc.pd_instance);
1667c478bd9Sstevel@tonic-gate 	mdb_printf("pd_module_id:\t\t%d\n", desc.pd_module_id);
1677c478bd9Sstevel@tonic-gate 	mdb_printf("pd_mctlp:\t\t%p\n", desc.pd_mctlp);
1687c478bd9Sstevel@tonic-gate 	mdb_printf("pd_lock:\t\t%p\n", desc.pd_lock);
1697c478bd9Sstevel@tonic-gate 	if (desc.pd_state < KCF_PROV_ALLOCATED ||
170ef56a3c5SKrishna Yenduri 	    desc.pd_state > KCF_PROV_UNREGISTERED)
1717c478bd9Sstevel@tonic-gate 		mdb_printf("pd_state is invalid:\t%d\n", desc.pd_state);
1727c478bd9Sstevel@tonic-gate 	else
1737c478bd9Sstevel@tonic-gate 		mdb_printf("pd_state:\t%s\n", prov_states[desc.pd_state]);
174ef56a3c5SKrishna Yenduri 	mdb_printf("pd_provider_list:\t%p\n", desc.pd_provider_list);
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	mdb_printf("pd_resume_cv:\t\t%hd\n", desc.pd_resume_cv._opaque);
177*9b009fc1SValerie Bubb Fenwick 	mdb_printf("pd_flags:\t\t%s %s %s %s %s\n",
1786a1073f8Skrishna 	    (desc.pd_flags & CRYPTO_HIDE_PROVIDER) ?
1796a1073f8Skrishna 	    "CRYPTO_HIDE_PROVIDER" : " ",
180ba5f469cSkrishna 	    (desc.pd_flags & CRYPTO_HASH_NO_UPDATE) ?
181ba5f469cSkrishna 	    "CRYPTO_HASH_NO_UPDATE" : " ",
1824df55fdeSJanie Lu 	    (desc.pd_flags & CRYPTO_HMAC_NO_UPDATE) ?
1834df55fdeSJanie Lu 	    "CRYPTO_HMAC_NO_UPDATE" : " ",
184c1591d22SKrishna Yenduri 	    (desc.pd_flags & CRYPTO_SYNCHRONOUS) ?
185c1591d22SKrishna Yenduri 	    "CRYPTO_SYNCHRONOUS" : " ",
1866a1073f8Skrishna 	    (desc.pd_flags & KCF_LPROV_MEMBER) ?
187*9b009fc1SValerie Bubb Fenwick 	    "KCF_LPROV_MEMBER" : " ");
188ba5f469cSkrishna 	if (desc.pd_flags & CRYPTO_HASH_NO_UPDATE)
189ba5f469cSkrishna 		mdb_printf("pd_hash_limit:\t\t%u\n", desc.pd_hash_limit);
1904df55fdeSJanie Lu 	if (desc.pd_flags & CRYPTO_HMAC_NO_UPDATE)
1914df55fdeSJanie Lu 		mdb_printf("pd_hmac_limit:\t\t%u\n", desc.pd_hmac_limit);
192ef56a3c5SKrishna Yenduri 
193ef56a3c5SKrishna Yenduri 	mdb_printf("pd_kstat:\t\t%p\n", desc.pd_kstat);
194ef56a3c5SKrishna Yenduri 
1957c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate #define	GOT_NONE	(-2)
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2017c478bd9Sstevel@tonic-gate int
2027c478bd9Sstevel@tonic-gate prov_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2037c478bd9Sstevel@tonic-gate {
2047c478bd9Sstevel@tonic-gate 	kcf_provider_desc_t **tab;
2057c478bd9Sstevel@tonic-gate 	kcf_provider_desc_t desc;
2067c478bd9Sstevel@tonic-gate 	kcf_provider_desc_t *ptr;
2077c478bd9Sstevel@tonic-gate 	uint_t prov_tab_max;
2087c478bd9Sstevel@tonic-gate 	int i;
2097c478bd9Sstevel@tonic-gate 	int gotzero = GOT_NONE;
2107c478bd9Sstevel@tonic-gate 	char string[MAXNAMELEN + 1];
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) {
2137c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
2147c478bd9Sstevel@tonic-gate 	} else if (mdb_readsym(&ptr, sizeof (void *), "prov_tab")
2157c478bd9Sstevel@tonic-gate 	    == -1) {
2167c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read prov_tab");
2177c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	} else if (mdb_readvar(&prov_tab_max, "prov_tab_max") == -1) {
2207c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read prov_tab_max");
2217c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2227c478bd9Sstevel@tonic-gate 	}
2237c478bd9Sstevel@tonic-gate 	mdb_printf("%<b>prov_tab = %p%</b>\n", ptr);
2247c478bd9Sstevel@tonic-gate 	tab = mdb_zalloc(prov_tab_max * sizeof (kcf_provider_desc_t *),
2257c478bd9Sstevel@tonic-gate 	    UM_SLEEP| UM_GC);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate #ifdef DEBUG
2287c478bd9Sstevel@tonic-gate 	mdb_printf("DEBUG: tab = %p, prov_tab_max = %d\n", tab, prov_tab_max);
2297c478bd9Sstevel@tonic-gate #endif
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate 	if (mdb_vread(tab, prov_tab_max * sizeof (kcf_provider_desc_t *),
2327c478bd9Sstevel@tonic-gate 	    (uintptr_t)ptr) == -1) {
2337c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read prov_tab");
2347c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2357c478bd9Sstevel@tonic-gate 	}
2367c478bd9Sstevel@tonic-gate #ifdef DEBUG
2377c478bd9Sstevel@tonic-gate 	mdb_printf("DEBUG: got past mdb_vread of tab\n");
2387c478bd9Sstevel@tonic-gate 	mdb_printf("DEBUG: *tab = %p\n", *tab);
2397c478bd9Sstevel@tonic-gate #endif
2407c478bd9Sstevel@tonic-gate 	for (i = 0;  i <  prov_tab_max; i++) {
2417c478bd9Sstevel@tonic-gate 		/* save space, only print range for long list of nulls */
2427c478bd9Sstevel@tonic-gate 		if (tab[i] == NULL) {
2437c478bd9Sstevel@tonic-gate 			if (gotzero == GOT_NONE) {
2447c478bd9Sstevel@tonic-gate 				mdb_printf("prov_tab[%d", i);
2457c478bd9Sstevel@tonic-gate 				gotzero = i;
2467c478bd9Sstevel@tonic-gate 			}
2477c478bd9Sstevel@tonic-gate 		} else {
2487c478bd9Sstevel@tonic-gate 			/* first non-null in awhile, print index of prev null */
2497c478bd9Sstevel@tonic-gate 			if (gotzero != GOT_NONE) {
2507c478bd9Sstevel@tonic-gate 				if (gotzero == (i - 1))
2517c478bd9Sstevel@tonic-gate 					mdb_printf("] = NULL\n", i - 1);
2527c478bd9Sstevel@tonic-gate 				else
2537c478bd9Sstevel@tonic-gate 					mdb_printf(" - %d] = NULL\n", i - 1);
2547c478bd9Sstevel@tonic-gate 				gotzero = GOT_NONE;
2557c478bd9Sstevel@tonic-gate 			}
2567c478bd9Sstevel@tonic-gate 			/* interesting value, print it */
2577c478bd9Sstevel@tonic-gate 			mdb_printf("prov_tab[%d] = %p ", i, tab[i]);
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 			if (mdb_vread(&desc, sizeof (kcf_provider_desc_t),
2607c478bd9Sstevel@tonic-gate 			    (uintptr_t)tab[i]) == -1) {
2617c478bd9Sstevel@tonic-gate 				mdb_warn("cannot read at address %p",
2627c478bd9Sstevel@tonic-gate 				    (uintptr_t)tab[i]);
2637c478bd9Sstevel@tonic-gate 				return (DCMD_ERR);
2647c478bd9Sstevel@tonic-gate 			}
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 			(void) mdb_readstr(string, MAXNAMELEN + 1,
2677c478bd9Sstevel@tonic-gate 			    (uintptr_t)desc.pd_name);
2687c478bd9Sstevel@tonic-gate 			mdb_printf("(%s\t%s)\n", string,
2697c478bd9Sstevel@tonic-gate 			    prov_states[desc.pd_state]);
2707c478bd9Sstevel@tonic-gate 		}
2717c478bd9Sstevel@tonic-gate 	}
2727c478bd9Sstevel@tonic-gate 	/* if we've printed the first of many nulls but left the brace open */
2737c478bd9Sstevel@tonic-gate 	if ((i > 0) && (tab[i-1] == NULL)) {
2747c478bd9Sstevel@tonic-gate 		if (gotzero == GOT_NONE)
2757c478bd9Sstevel@tonic-gate 			mdb_printf("] = NULL\n");
2767c478bd9Sstevel@tonic-gate 		else
2777c478bd9Sstevel@tonic-gate 			mdb_printf(" - %d] = NULL\n", i - 1);
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
2817c478bd9Sstevel@tonic-gate }
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2847c478bd9Sstevel@tonic-gate int
2857c478bd9Sstevel@tonic-gate policy_tab(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate 	kcf_policy_desc_t **tab;
2887c478bd9Sstevel@tonic-gate 	kcf_policy_desc_t *ptr;
2897c478bd9Sstevel@tonic-gate 	uint_t policy_tab_max;
2907c478bd9Sstevel@tonic-gate 	int num, i;
2917c478bd9Sstevel@tonic-gate 	int gotzero = GOT_NONE;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) {
2947c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
2957c478bd9Sstevel@tonic-gate 	} else if (mdb_readsym(&ptr, sizeof (void *), "policy_tab")
2967c478bd9Sstevel@tonic-gate 	    == -1) {
2977c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read policy_tab");
2987c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
2997c478bd9Sstevel@tonic-gate 
3007c478bd9Sstevel@tonic-gate 	} else if (mdb_readvar(&policy_tab_max, "policy_tab_max") == -1) {
3017c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read policy_tab_max");
3027c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3037c478bd9Sstevel@tonic-gate 	}
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	/* get the current number of descriptors in the table */
3067c478bd9Sstevel@tonic-gate 	if (mdb_readvar(&num, "policy_tab_num") == -1) {
3077c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read policy_tab_num");
3087c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 	mdb_printf("%<b>policy_tab = %p%</b> \tpolicy_tab_num = %d\n",
3117c478bd9Sstevel@tonic-gate 	    ptr, num);
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	tab = mdb_zalloc(policy_tab_max * sizeof (kcf_policy_desc_t *),
3147c478bd9Sstevel@tonic-gate 	    UM_SLEEP| UM_GC);
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate 	if (mdb_vread(tab, policy_tab_max * sizeof (kcf_policy_desc_t *),
3177c478bd9Sstevel@tonic-gate 	    (uintptr_t)ptr) == -1) {
3187c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read policy_tab");
3197c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
3207c478bd9Sstevel@tonic-gate 	}
3217c478bd9Sstevel@tonic-gate #ifdef DEBUG
3227c478bd9Sstevel@tonic-gate 	mdb_printf("DEBUG: got past mdb_vread of tab\n");
3237c478bd9Sstevel@tonic-gate 	mdb_printf("DEBUG: *tab = %p\n", *tab);
3247c478bd9Sstevel@tonic-gate #endif
3257c478bd9Sstevel@tonic-gate 	for (i = 0;  i < policy_tab_max; i++) {
3267c478bd9Sstevel@tonic-gate 		/* save space, only print range for long list of nulls */
3277c478bd9Sstevel@tonic-gate 		if (tab[i] == NULL) {
3287c478bd9Sstevel@tonic-gate 			if (gotzero == GOT_NONE) {
3297c478bd9Sstevel@tonic-gate 				mdb_printf("policy_tab[%d", i);
3307c478bd9Sstevel@tonic-gate 				gotzero = i;
3317c478bd9Sstevel@tonic-gate 			}
3327c478bd9Sstevel@tonic-gate 		} else {
3337c478bd9Sstevel@tonic-gate 			/* first non-null in awhile, print index of prev null */
3347c478bd9Sstevel@tonic-gate 			if (gotzero != GOT_NONE) {
3357c478bd9Sstevel@tonic-gate 				if (gotzero == (i - 1))
3367c478bd9Sstevel@tonic-gate 					mdb_printf("] = NULL\n", i - 1);
3377c478bd9Sstevel@tonic-gate 				else
3387c478bd9Sstevel@tonic-gate 					mdb_printf(" - %d] = NULL\n", i - 1);
3397c478bd9Sstevel@tonic-gate 				gotzero = GOT_NONE;
3407c478bd9Sstevel@tonic-gate 			}
3417c478bd9Sstevel@tonic-gate 			/* interesting value, print it */
3427c478bd9Sstevel@tonic-gate 			mdb_printf("policy_tab[%d] = %p\n", i, tab[i]);
3437c478bd9Sstevel@tonic-gate 		}
3447c478bd9Sstevel@tonic-gate 	}
3457c478bd9Sstevel@tonic-gate 	/* if we've printed the first of many nulls but left the brace open */
3467c478bd9Sstevel@tonic-gate 	if ((i > 0) && (tab[i-1] == NULL)) {
3477c478bd9Sstevel@tonic-gate 		if (gotzero == GOT_NONE)
3487c478bd9Sstevel@tonic-gate 			mdb_printf("] = NULL\n");
3497c478bd9Sstevel@tonic-gate 		else
3507c478bd9Sstevel@tonic-gate 			mdb_printf(" - %d] = NULL\n", i - 1);
3517c478bd9Sstevel@tonic-gate 	}
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate static void
3577c478bd9Sstevel@tonic-gate prt_mechs(int count, crypto_mech_name_t *mechs)
3587c478bd9Sstevel@tonic-gate {
3597c478bd9Sstevel@tonic-gate 	int i;
3607c478bd9Sstevel@tonic-gate 	char name[CRYPTO_MAX_MECH_NAME + 1];
3617c478bd9Sstevel@tonic-gate 	char name2[CRYPTO_MAX_MECH_NAME + 3];
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	for (i = 0; i < count; i++) {
3647c478bd9Sstevel@tonic-gate 		if (mdb_readstr(name, CRYPTO_MAX_MECH_NAME,
3657c478bd9Sstevel@tonic-gate 		    (uintptr_t)((char *)mechs)) == -1)
3667c478bd9Sstevel@tonic-gate 			continue;
3677c478bd9Sstevel@tonic-gate 		/* put in quotes */
3687c478bd9Sstevel@tonic-gate 		(void) mdb_snprintf(name2, sizeof (name2), "\"%s\"", name);
3697c478bd9Sstevel@tonic-gate 		/* yes, length is 32, but then it will wrap */
3707c478bd9Sstevel@tonic-gate 		/* this shorter size formats nicely for most cases */
3717c478bd9Sstevel@tonic-gate 		mdb_printf("mechs[%d]=%-28s", i, name2);
3727c478bd9Sstevel@tonic-gate 		mdb_printf("%s", i%2 ? "\n" : "  "); /* 2-columns */
3737c478bd9Sstevel@tonic-gate 		mechs++;
3747c478bd9Sstevel@tonic-gate 	}
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate 
3777c478bd9Sstevel@tonic-gate /* ARGSUSED2 */
3787c478bd9Sstevel@tonic-gate static int
3797c478bd9Sstevel@tonic-gate prt_soft_conf_entry(kcf_soft_conf_entry_t *addr, kcf_soft_conf_entry_t *entry,
3807c478bd9Sstevel@tonic-gate     void *cbdata)
3817c478bd9Sstevel@tonic-gate {
3827c478bd9Sstevel@tonic-gate 	char name[MAXNAMELEN + 1];
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	mdb_printf("\n%<b>kcf_soft_conf_entry_t at %p:%</b>\n", addr);
3857c478bd9Sstevel@tonic-gate 	mdb_printf("ce_next: %p", entry->ce_next);
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate 	if (entry->ce_name == NULL)
3887c478bd9Sstevel@tonic-gate 		mdb_printf("\tce_name: NULL\n");
3897c478bd9Sstevel@tonic-gate 	else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)entry->ce_name)
3907c478bd9Sstevel@tonic-gate 	    == -1)
3917c478bd9Sstevel@tonic-gate 		mdb_printf("could not read ce_name from %p\n",
3927c478bd9Sstevel@tonic-gate 		    entry->ce_name);
3937c478bd9Sstevel@tonic-gate 	else
3947c478bd9Sstevel@tonic-gate 		mdb_printf("\tce_name: %s\n", name);
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	mdb_printf("ce_count: %d\n", entry->ce_count);
3977c478bd9Sstevel@tonic-gate 	prt_mechs(entry->ce_count, entry->ce_mechs);
3987c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate int
4027c478bd9Sstevel@tonic-gate soft_conf_walk_init(mdb_walk_state_t *wsp)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate 	uintptr_t *soft;
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	if (mdb_readsym(&soft, sizeof (kcf_soft_conf_entry_t *),
4077c478bd9Sstevel@tonic-gate 	    "soft_config_list") == -1) {
4087c478bd9Sstevel@tonic-gate 		mdb_warn("failed to find 'soft_config_list'");
4097c478bd9Sstevel@tonic-gate 		return (WALK_ERR);
4107c478bd9Sstevel@tonic-gate 	}
4117c478bd9Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)soft;
4127c478bd9Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc(sizeof (kcf_soft_conf_entry_t), UM_SLEEP);
4137c478bd9Sstevel@tonic-gate 	wsp->walk_callback = (mdb_walk_cb_t)prt_soft_conf_entry;
4147c478bd9Sstevel@tonic-gate 	return (WALK_NEXT);
4157c478bd9Sstevel@tonic-gate }
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate  * At each step, read a kcf_soft_conf_entry_t into our private storage, then
4197c478bd9Sstevel@tonic-gate  * invoke the callback function.  We terminate when we reach a NULL ce_next
4207c478bd9Sstevel@tonic-gate  * pointer.
4217c478bd9Sstevel@tonic-gate  */
4227c478bd9Sstevel@tonic-gate int
4237c478bd9Sstevel@tonic-gate soft_conf_walk_step(mdb_walk_state_t *wsp)
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	int status;
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	if (wsp->walk_addr == NULL)	/* then we're done */
4287c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
4297c478bd9Sstevel@tonic-gate #ifdef DEBUG
4307c478bd9Sstevel@tonic-gate 	else
4317c478bd9Sstevel@tonic-gate 		mdb_printf("DEBUG: wsp->walk_addr == %p\n", wsp->walk_addr);
4327c478bd9Sstevel@tonic-gate #endif
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 	if (mdb_vread(wsp->walk_data, sizeof (kcf_soft_conf_entry_t),
4357c478bd9Sstevel@tonic-gate 	    wsp->walk_addr) == -1) {
4367c478bd9Sstevel@tonic-gate 		mdb_warn("failed to read kcf_soft_conf_entry at %p",
4377c478bd9Sstevel@tonic-gate 		    wsp->walk_addr);
4387c478bd9Sstevel@tonic-gate 		return (WALK_DONE);
4397c478bd9Sstevel@tonic-gate 	}
4407c478bd9Sstevel@tonic-gate 
4417c478bd9Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
4427c478bd9Sstevel@tonic-gate 	    wsp->walk_cbdata);
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	wsp->walk_addr =
4457c478bd9Sstevel@tonic-gate 	    (uintptr_t)(((kcf_soft_conf_entry_t *)wsp->walk_data)->ce_next);
4467c478bd9Sstevel@tonic-gate 	return (status);
4477c478bd9Sstevel@tonic-gate }
4487c478bd9Sstevel@tonic-gate 
4497c478bd9Sstevel@tonic-gate /*
4507c478bd9Sstevel@tonic-gate  * The walker's fini function is invoked at the end of each walk.  Since we
4517c478bd9Sstevel@tonic-gate  * dynamically allocated a kcf_soft_conf_entry_t in soft_conf_walk_init,
4527c478bd9Sstevel@tonic-gate  * we must free it now.
4537c478bd9Sstevel@tonic-gate  */
4547c478bd9Sstevel@tonic-gate void
4557c478bd9Sstevel@tonic-gate soft_conf_walk_fini(mdb_walk_state_t *wsp)
4567c478bd9Sstevel@tonic-gate {
4577c478bd9Sstevel@tonic-gate #ifdef	DEBUG
4587c478bd9Sstevel@tonic-gate 	mdb_printf("...end of kcf_soft_conf_entry walk\n");
4597c478bd9Sstevel@tonic-gate #endif
4607c478bd9Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (kcf_soft_conf_entry_t));
4617c478bd9Sstevel@tonic-gate }
4627c478bd9Sstevel@tonic-gate /* ARGSUSED2 */
4637c478bd9Sstevel@tonic-gate int
4647c478bd9Sstevel@tonic-gate kcf_soft_conf_entry(uintptr_t addr, uint_t flags, int argc,
4657c478bd9Sstevel@tonic-gate     const mdb_arg_t *argv)
4667c478bd9Sstevel@tonic-gate {
4677c478bd9Sstevel@tonic-gate 	kcf_soft_conf_entry_t entry;
4687c478bd9Sstevel@tonic-gate 	kcf_soft_conf_entry_t *ptr;
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) == DCMD_ADDRSPEC) {
4717c478bd9Sstevel@tonic-gate 		if (addr == NULL) 	/* not allowed with DCMD_ADDRSPEC */
4727c478bd9Sstevel@tonic-gate 			return (DCMD_USAGE);
4737c478bd9Sstevel@tonic-gate 		else
4747c478bd9Sstevel@tonic-gate 			ptr = (kcf_soft_conf_entry_t *)addr;
4757c478bd9Sstevel@tonic-gate 	} else if (mdb_readsym(&ptr, sizeof (void *), "soft_config_list")
4767c478bd9Sstevel@tonic-gate 	    == -1) {
4777c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read soft_config_list");
4787c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4797c478bd9Sstevel@tonic-gate 	} else
4807c478bd9Sstevel@tonic-gate 		mdb_printf("soft_config_list = %p\n", ptr);
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	if (ptr == NULL)
4837c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	if (mdb_vread(&entry, sizeof (kcf_soft_conf_entry_t), (uintptr_t)ptr)
4867c478bd9Sstevel@tonic-gate 	    == -1) {
4877c478bd9Sstevel@tonic-gate 		mdb_warn("cannot read at address %p", (uintptr_t)ptr);
4887c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
4897c478bd9Sstevel@tonic-gate 	}
4907c478bd9Sstevel@tonic-gate 
4917c478bd9Sstevel@tonic-gate 	/* this could change in the future to have more than one ret val */
4927c478bd9Sstevel@tonic-gate 	if (prt_soft_conf_entry(ptr, &entry, NULL) != WALK_ERR)
4937c478bd9Sstevel@tonic-gate 		return (DCMD_OK);
4947c478bd9Sstevel@tonic-gate 	return (DCMD_ERR);
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate /* ARGSUSED1 */
4987c478bd9Sstevel@tonic-gate int
4997c478bd9Sstevel@tonic-gate kcf_policy_desc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
5007c478bd9Sstevel@tonic-gate {
5017c478bd9Sstevel@tonic-gate 	kcf_policy_desc_t  desc;
5027c478bd9Sstevel@tonic-gate 	char name[MAXNAMELEN + 1];
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC) != DCMD_ADDRSPEC)
5067c478bd9Sstevel@tonic-gate 		return (DCMD_USAGE);
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate 	if (mdb_vread(&desc, sizeof (kcf_policy_desc_t), (uintptr_t)addr)
5097c478bd9Sstevel@tonic-gate 	    == -1) {
5107c478bd9Sstevel@tonic-gate 		mdb_warn("Could not read kcf_policy_desc_t at %p\n", addr);
5117c478bd9Sstevel@tonic-gate 		return (DCMD_ERR);
5127c478bd9Sstevel@tonic-gate 	}
5137c478bd9Sstevel@tonic-gate 	mdb_printf("pd_prov_type:  %s",
514c1591d22SKrishna Yenduri 	    desc.pd_prov_type == CRYPTO_HW_PROVIDER ? "CRYPTO_HW_PROVIDER" :
515c1591d22SKrishna Yenduri 	    "CRYPTO_SW_PROVIDER");
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate 	if (desc.pd_name == NULL)
5187c478bd9Sstevel@tonic-gate 		mdb_printf("\tpd_name: NULL\n");
5197c478bd9Sstevel@tonic-gate 	else if (mdb_readstr(name, MAXNAMELEN, (uintptr_t)desc.pd_name)
5207c478bd9Sstevel@tonic-gate 	    == -1)
5217c478bd9Sstevel@tonic-gate 		mdb_printf("could not read pd_name from %p\n",
5227c478bd9Sstevel@tonic-gate 		    desc.pd_name);
5237c478bd9Sstevel@tonic-gate 	else
5247c478bd9Sstevel@tonic-gate 		mdb_printf("\tpd_name: %s\n", name);
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	mdb_printf("pd_instance: %d ", desc.pd_instance);
5277c478bd9Sstevel@tonic-gate 	mdb_printf("\t\tpd_refcnt: %d\n", desc.pd_refcnt);
5287c478bd9Sstevel@tonic-gate 	mdb_printf("pd_mutex: %p", desc.pd_mutex);
5297c478bd9Sstevel@tonic-gate 	mdb_printf("\t\tpd_disabled_count: %d", desc.pd_disabled_count);
5307c478bd9Sstevel@tonic-gate 	mdb_printf("\npd_disabled_mechs:\n");
5317c478bd9Sstevel@tonic-gate 	mdb_inc_indent(4);
5327c478bd9Sstevel@tonic-gate 	prt_mechs(desc.pd_disabled_count, desc.pd_disabled_mechs);
5337c478bd9Sstevel@tonic-gate 	mdb_dec_indent(4);
5347c478bd9Sstevel@tonic-gate 	return (DCMD_OK);
5357c478bd9Sstevel@tonic-gate }
536