xref: /titanic_51/usr/src/cmd/mdb/common/modules/rdc/rdc.c (revision fcf3ce441efd61da9bb2884968af01cb7c1452cc)
1*fcf3ce44SJohn Forte /*
2*fcf3ce44SJohn Forte  * CDDL HEADER START
3*fcf3ce44SJohn Forte  *
4*fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5*fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6*fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7*fcf3ce44SJohn Forte  *
8*fcf3ce44SJohn Forte  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fcf3ce44SJohn Forte  * or http://www.opensolaris.org/os/licensing.
10*fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11*fcf3ce44SJohn Forte  * and limitations under the License.
12*fcf3ce44SJohn Forte  *
13*fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14*fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16*fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17*fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fcf3ce44SJohn Forte  *
19*fcf3ce44SJohn Forte  * CDDL HEADER END
20*fcf3ce44SJohn Forte  */
21*fcf3ce44SJohn Forte /*
22*fcf3ce44SJohn Forte  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*fcf3ce44SJohn Forte  * Use is subject to license terms.
24*fcf3ce44SJohn Forte  */
25*fcf3ce44SJohn Forte 
26*fcf3ce44SJohn Forte #include <sys/types.h>
27*fcf3ce44SJohn Forte #include <sys/mdb_modapi.h>
28*fcf3ce44SJohn Forte 
29*fcf3ce44SJohn Forte #include <sys/nsctl/nsctl.h>
30*fcf3ce44SJohn Forte #include <sys/unistat/spcs_s.h>
31*fcf3ce44SJohn Forte #include <sys/unistat/spcs_s_k.h>
32*fcf3ce44SJohn Forte 
33*fcf3ce44SJohn Forte #include <rpc/auth.h>
34*fcf3ce44SJohn Forte #include <rpc/auth_unix.h>
35*fcf3ce44SJohn Forte #include <rpc/auth_des.h>
36*fcf3ce44SJohn Forte #include <rpc/svc.h>
37*fcf3ce44SJohn Forte #include <rpc/xdr.h>
38*fcf3ce44SJohn Forte #include <rpc/svc_soc.h>
39*fcf3ce44SJohn Forte 
40*fcf3ce44SJohn Forte /* HACK HACK  so we can bring in rdc_io.h and friends */
41*fcf3ce44SJohn Forte #define	nstset_t	char
42*fcf3ce44SJohn Forte 
43*fcf3ce44SJohn Forte #include <sys/nsctl/rdc.h>
44*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_prot.h>
45*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_ioctl.h>
46*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_io.h>
47*fcf3ce44SJohn Forte #include <sys/nsctl/rdc_bitmap.h>
48*fcf3ce44SJohn Forte 
49*fcf3ce44SJohn Forte #include <sys/nsctl/nsvers.h>
50*fcf3ce44SJohn Forte 
51*fcf3ce44SJohn Forte 
52*fcf3ce44SJohn Forte /*
53*fcf3ce44SJohn Forte  * Walker for an array of rdc_k_info_t structures.
54*fcf3ce44SJohn Forte  * A global walk is assumed to start at rdc_k_info.
55*fcf3ce44SJohn Forte  */
56*fcf3ce44SJohn Forte 
57*fcf3ce44SJohn Forte struct rdc_kinfo_winfo {
58*fcf3ce44SJohn Forte 	uintptr_t start;
59*fcf3ce44SJohn Forte 	uintptr_t end;
60*fcf3ce44SJohn Forte };
61*fcf3ce44SJohn Forte 
62*fcf3ce44SJohn Forte char bitstr[33] = { '0' };
63*fcf3ce44SJohn Forte 
64*fcf3ce44SJohn Forte static int
65*fcf3ce44SJohn Forte rdc_k_info_winit(mdb_walk_state_t *wsp)
66*fcf3ce44SJohn Forte {
67*fcf3ce44SJohn Forte 	struct rdc_kinfo_winfo *winfo;
68*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info;
69*fcf3ce44SJohn Forte 	int rdc_max_sets;
70*fcf3ce44SJohn Forte 
71*fcf3ce44SJohn Forte 	winfo = mdb_zalloc(sizeof (struct rdc_kinfo_winfo), UM_SLEEP);
72*fcf3ce44SJohn Forte 
73*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
74*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
75*fcf3ce44SJohn Forte 		mdb_free(winfo,  sizeof (struct rdc_kinfo_winfo));
76*fcf3ce44SJohn Forte 		return (WALK_ERR);
77*fcf3ce44SJohn Forte 	}
78*fcf3ce44SJohn Forte 
79*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_max_sets, "rdc_max_sets") == -1) {
80*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_max_sets'");
81*fcf3ce44SJohn Forte 		mdb_free(winfo, sizeof (struct rdc_kinfo_winfo));
82*fcf3ce44SJohn Forte 		return (WALK_ERR);
83*fcf3ce44SJohn Forte 	}
84*fcf3ce44SJohn Forte 
85*fcf3ce44SJohn Forte 	winfo->start = (uintptr_t)rdc_k_info;
86*fcf3ce44SJohn Forte 	winfo->end = (uintptr_t)(rdc_k_info + rdc_max_sets);
87*fcf3ce44SJohn Forte 
88*fcf3ce44SJohn Forte 	if (wsp->walk_addr == NULL)
89*fcf3ce44SJohn Forte 		wsp->walk_addr = winfo->start;
90*fcf3ce44SJohn Forte 
91*fcf3ce44SJohn Forte 	wsp->walk_data = winfo;
92*fcf3ce44SJohn Forte 	return (WALK_NEXT);
93*fcf3ce44SJohn Forte }
94*fcf3ce44SJohn Forte 
95*fcf3ce44SJohn Forte 
96*fcf3ce44SJohn Forte static int
97*fcf3ce44SJohn Forte rdc_k_info_wstep(mdb_walk_state_t *wsp)
98*fcf3ce44SJohn Forte {
99*fcf3ce44SJohn Forte 	struct rdc_kinfo_winfo *winfo = wsp->walk_data;
100*fcf3ce44SJohn Forte 	int status;
101*fcf3ce44SJohn Forte 
102*fcf3ce44SJohn Forte 	if (wsp->walk_addr == NULL)
103*fcf3ce44SJohn Forte 		return (WALK_DONE);
104*fcf3ce44SJohn Forte 
105*fcf3ce44SJohn Forte 	if (wsp->walk_addr >= winfo->end)
106*fcf3ce44SJohn Forte 		return (WALK_DONE);
107*fcf3ce44SJohn Forte 
108*fcf3ce44SJohn Forte 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
109*fcf3ce44SJohn Forte 	    wsp->walk_cbdata);
110*fcf3ce44SJohn Forte 
111*fcf3ce44SJohn Forte 	wsp->walk_addr += sizeof (rdc_k_info_t);
112*fcf3ce44SJohn Forte 	return (status);
113*fcf3ce44SJohn Forte }
114*fcf3ce44SJohn Forte 
115*fcf3ce44SJohn Forte 
116*fcf3ce44SJohn Forte static void
117*fcf3ce44SJohn Forte rdc_k_info_wfini(mdb_walk_state_t *wsp)
118*fcf3ce44SJohn Forte {
119*fcf3ce44SJohn Forte 	mdb_free(wsp->walk_data, sizeof (struct rdc_kinfo_winfo));
120*fcf3ce44SJohn Forte }
121*fcf3ce44SJohn Forte 
122*fcf3ce44SJohn Forte /*
123*fcf3ce44SJohn Forte  * Walker for an array of rdc_u_info_t structures.
124*fcf3ce44SJohn Forte  * A global walk is assumed to start at rdc_u_info.
125*fcf3ce44SJohn Forte  */
126*fcf3ce44SJohn Forte 
127*fcf3ce44SJohn Forte struct rdc_uinfo_winfo {
128*fcf3ce44SJohn Forte 	uintptr_t start;
129*fcf3ce44SJohn Forte 	uintptr_t end;
130*fcf3ce44SJohn Forte };
131*fcf3ce44SJohn Forte 
132*fcf3ce44SJohn Forte 
133*fcf3ce44SJohn Forte static int
134*fcf3ce44SJohn Forte rdc_u_info_winit(mdb_walk_state_t *wsp)
135*fcf3ce44SJohn Forte {
136*fcf3ce44SJohn Forte 	struct rdc_uinfo_winfo *winfo;
137*fcf3ce44SJohn Forte 	rdc_u_info_t *rdc_u_info;
138*fcf3ce44SJohn Forte 	int rdc_max_sets;
139*fcf3ce44SJohn Forte 
140*fcf3ce44SJohn Forte 	winfo = mdb_zalloc(sizeof (struct rdc_uinfo_winfo), UM_SLEEP);
141*fcf3ce44SJohn Forte 
142*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_u_info, "rdc_u_info") == -1) {
143*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_u_info'");
144*fcf3ce44SJohn Forte 		mdb_free(winfo,  sizeof (struct rdc_uinfo_winfo));
145*fcf3ce44SJohn Forte 		return (WALK_ERR);
146*fcf3ce44SJohn Forte 	}
147*fcf3ce44SJohn Forte 
148*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_max_sets, "rdc_max_sets") == -1) {
149*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_max_sets'");
150*fcf3ce44SJohn Forte 		mdb_free(winfo, sizeof (struct rdc_uinfo_winfo));
151*fcf3ce44SJohn Forte 		return (WALK_ERR);
152*fcf3ce44SJohn Forte 	}
153*fcf3ce44SJohn Forte 
154*fcf3ce44SJohn Forte 	winfo->start = (uintptr_t)rdc_u_info;
155*fcf3ce44SJohn Forte 	winfo->end = (uintptr_t)(rdc_u_info + rdc_max_sets);
156*fcf3ce44SJohn Forte 
157*fcf3ce44SJohn Forte 	if (wsp->walk_addr == NULL)
158*fcf3ce44SJohn Forte 		wsp->walk_addr = winfo->start;
159*fcf3ce44SJohn Forte 
160*fcf3ce44SJohn Forte 	wsp->walk_data = winfo;
161*fcf3ce44SJohn Forte 	return (WALK_NEXT);
162*fcf3ce44SJohn Forte }
163*fcf3ce44SJohn Forte 
164*fcf3ce44SJohn Forte 
165*fcf3ce44SJohn Forte static int
166*fcf3ce44SJohn Forte rdc_u_info_wstep(mdb_walk_state_t *wsp)
167*fcf3ce44SJohn Forte {
168*fcf3ce44SJohn Forte 	struct rdc_uinfo_winfo *winfo = wsp->walk_data;
169*fcf3ce44SJohn Forte 	int status;
170*fcf3ce44SJohn Forte 
171*fcf3ce44SJohn Forte 	if (wsp->walk_addr == NULL)
172*fcf3ce44SJohn Forte 		return (WALK_DONE);
173*fcf3ce44SJohn Forte 
174*fcf3ce44SJohn Forte 	if (wsp->walk_addr >= winfo->end)
175*fcf3ce44SJohn Forte 		return (WALK_DONE);
176*fcf3ce44SJohn Forte 
177*fcf3ce44SJohn Forte 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
178*fcf3ce44SJohn Forte 	    wsp->walk_cbdata);
179*fcf3ce44SJohn Forte 
180*fcf3ce44SJohn Forte 	wsp->walk_addr += sizeof (rdc_u_info_t);
181*fcf3ce44SJohn Forte 	return (status);
182*fcf3ce44SJohn Forte }
183*fcf3ce44SJohn Forte 
184*fcf3ce44SJohn Forte 
185*fcf3ce44SJohn Forte static void
186*fcf3ce44SJohn Forte rdc_u_info_wfini(mdb_walk_state_t *wsp)
187*fcf3ce44SJohn Forte {
188*fcf3ce44SJohn Forte 	mdb_free(wsp->walk_data, sizeof (struct rdc_uinfo_winfo));
189*fcf3ce44SJohn Forte }
190*fcf3ce44SJohn Forte 
191*fcf3ce44SJohn Forte /*
192*fcf3ce44SJohn Forte  * Walker for the rdc_if chain.
193*fcf3ce44SJohn Forte  * A global walk is assumed to start at rdc_if_top.
194*fcf3ce44SJohn Forte  */
195*fcf3ce44SJohn Forte 
196*fcf3ce44SJohn Forte static int
197*fcf3ce44SJohn Forte rdc_if_winit(mdb_walk_state_t *wsp)
198*fcf3ce44SJohn Forte {
199*fcf3ce44SJohn Forte 	if (wsp->walk_addr == NULL &&
200*fcf3ce44SJohn Forte 	    mdb_readvar(&wsp->walk_addr, "rdc_if_top") == -1) {
201*fcf3ce44SJohn Forte 		mdb_warn("unable to read 'rdc_if_top'");
202*fcf3ce44SJohn Forte 		return (WALK_ERR);
203*fcf3ce44SJohn Forte 	}
204*fcf3ce44SJohn Forte 
205*fcf3ce44SJohn Forte 	wsp->walk_data = mdb_zalloc(sizeof (rdc_if_t), UM_SLEEP);
206*fcf3ce44SJohn Forte 
207*fcf3ce44SJohn Forte 	return (WALK_NEXT);
208*fcf3ce44SJohn Forte }
209*fcf3ce44SJohn Forte 
210*fcf3ce44SJohn Forte 
211*fcf3ce44SJohn Forte static int
212*fcf3ce44SJohn Forte rdc_if_wstep(mdb_walk_state_t *wsp)
213*fcf3ce44SJohn Forte {
214*fcf3ce44SJohn Forte 	int status;
215*fcf3ce44SJohn Forte 
216*fcf3ce44SJohn Forte 	if (wsp->walk_addr == NULL)
217*fcf3ce44SJohn Forte 		return (WALK_DONE);
218*fcf3ce44SJohn Forte 
219*fcf3ce44SJohn Forte 	if (mdb_vread(wsp->walk_data,
220*fcf3ce44SJohn Forte 	    sizeof (rdc_if_t), wsp->walk_addr) == -1) {
221*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_if at %p", wsp->walk_addr);
222*fcf3ce44SJohn Forte 		return (WALK_DONE);
223*fcf3ce44SJohn Forte 	}
224*fcf3ce44SJohn Forte 
225*fcf3ce44SJohn Forte 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
226*fcf3ce44SJohn Forte 	    wsp->walk_cbdata);
227*fcf3ce44SJohn Forte 
228*fcf3ce44SJohn Forte 	wsp->walk_addr = (uintptr_t)(((rdc_if_t *)wsp->walk_data)->next);
229*fcf3ce44SJohn Forte 	return (status);
230*fcf3ce44SJohn Forte }
231*fcf3ce44SJohn Forte 
232*fcf3ce44SJohn Forte 
233*fcf3ce44SJohn Forte static void
234*fcf3ce44SJohn Forte rdc_if_wfini(mdb_walk_state_t *wsp)
235*fcf3ce44SJohn Forte {
236*fcf3ce44SJohn Forte 	mdb_free(wsp->walk_data, sizeof (rdc_if_t));
237*fcf3ce44SJohn Forte }
238*fcf3ce44SJohn Forte 
239*fcf3ce44SJohn Forte /*
240*fcf3ce44SJohn Forte  * Displays the asynchronous sleep q on the server.
241*fcf3ce44SJohn Forte  */
242*fcf3ce44SJohn Forte /*ARGSUSED*/
243*fcf3ce44SJohn Forte static int
244*fcf3ce44SJohn Forte rdc_sleepq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
245*fcf3ce44SJohn Forte {
246*fcf3ce44SJohn Forte 	rdc_sleepq_t sq;
247*fcf3ce44SJohn Forte 
248*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
249*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
250*fcf3ce44SJohn Forte 	while (addr) {
251*fcf3ce44SJohn Forte 		if (mdb_vread(&sq, sizeof (sq), addr) != sizeof (sq)) {
252*fcf3ce44SJohn Forte 			mdb_warn("failed to read rdc_sleepq at %p", addr);
253*fcf3ce44SJohn Forte 			return (DCMD_ERR);
254*fcf3ce44SJohn Forte 		}
255*fcf3ce44SJohn Forte 		mdb_printf("sequence number %u  qpos %d \n", sq.seq, sq.qpos);
256*fcf3ce44SJohn Forte 		addr = (uintptr_t)sq.next;
257*fcf3ce44SJohn Forte 	}
258*fcf3ce44SJohn Forte 	return (DCMD_OK);
259*fcf3ce44SJohn Forte }
260*fcf3ce44SJohn Forte 
261*fcf3ce44SJohn Forte /*
262*fcf3ce44SJohn Forte  * display the header info for the pending diskq requests
263*fcf3ce44SJohn Forte  */
264*fcf3ce44SJohn Forte /*ARGSUSED*/
265*fcf3ce44SJohn Forte static int
266*fcf3ce44SJohn Forte rdc_iohdr(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
267*fcf3ce44SJohn Forte {
268*fcf3ce44SJohn Forte 	io_hdr hdr;
269*fcf3ce44SJohn Forte 
270*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
271*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
272*fcf3ce44SJohn Forte 
273*fcf3ce44SJohn Forte 	while (addr) {
274*fcf3ce44SJohn Forte 		if (mdb_vread(&hdr, sizeof (io_hdr), addr) != sizeof (io_hdr)) {
275*fcf3ce44SJohn Forte 			mdb_warn("failed to read io_hdr at %p", addr);
276*fcf3ce44SJohn Forte 			return (DCMD_ERR);
277*fcf3ce44SJohn Forte 		}
278*fcf3ce44SJohn Forte 		mdb_printf("iohdr: type %d pos %d qpos %d len %d flag 0x%x"
279*fcf3ce44SJohn Forte 		" iostatus %x setid %d next %p\n", hdr.dat.type, hdr.dat.pos,
280*fcf3ce44SJohn Forte 		hdr.dat.qpos, hdr.dat.len, hdr.dat.flag, hdr.dat.iostatus,
281*fcf3ce44SJohn Forte 		hdr.dat.setid, hdr.dat.next);
282*fcf3ce44SJohn Forte 
283*fcf3ce44SJohn Forte 		addr = (uintptr_t)hdr.dat.next;
284*fcf3ce44SJohn Forte 	}
285*fcf3ce44SJohn Forte 	return (DCMD_OK);
286*fcf3ce44SJohn Forte }
287*fcf3ce44SJohn Forte 
288*fcf3ce44SJohn Forte /*
289*fcf3ce44SJohn Forte  * Display a krdc->group.
290*fcf3ce44SJohn Forte  * Requires an address.
291*fcf3ce44SJohn Forte  */
292*fcf3ce44SJohn Forte /*ARGSUSED*/
293*fcf3ce44SJohn Forte static int
294*fcf3ce44SJohn Forte rdc_group(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
295*fcf3ce44SJohn Forte {
296*fcf3ce44SJohn Forte 	struct rdc_group *group;
297*fcf3ce44SJohn Forte 	disk_queue	*dq;
298*fcf3ce44SJohn Forte 
299*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
300*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
301*fcf3ce44SJohn Forte 
302*fcf3ce44SJohn Forte 
303*fcf3ce44SJohn Forte 	group = mdb_zalloc(sizeof (*group), UM_GC);
304*fcf3ce44SJohn Forte 
305*fcf3ce44SJohn Forte 	if (mdb_vread(group, sizeof (*group), addr) != sizeof (*group)) {
306*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_group at %p", addr);
307*fcf3ce44SJohn Forte 		return (DCMD_ERR);
308*fcf3ce44SJohn Forte 	}
309*fcf3ce44SJohn Forte #ifdef XXXJET
310*fcf3ce44SJohn Forte 	if (DCMD_HDRSPEC(flags)) {
311*fcf3ce44SJohn Forte 		mdb_printf("%-?s  %8T%-8s  %8T%s\n", "ADDR", "MAJOR", "INUSE");
312*fcf3ce44SJohn Forte 	}
313*fcf3ce44SJohn Forte #endif
314*fcf3ce44SJohn Forte 	mdb_printf("count: %d  %8Twriter: %d  %8T flags: %d\n",
315*fcf3ce44SJohn Forte 	    group->count, group->rdc_writer, group->flags);
316*fcf3ce44SJohn Forte 	mdb_printf("thread num %d\n", group->rdc_thrnum);
317*fcf3ce44SJohn Forte 
318*fcf3ce44SJohn Forte 	dq = &group->diskq;
319*fcf3ce44SJohn Forte 	if (RDC_IS_MEMQ(group)) {
320*fcf3ce44SJohn Forte 		mdb_printf("queue type: Memory based\n");
321*fcf3ce44SJohn Forte 	} else if (RDC_IS_DISKQ(group)) {
322*fcf3ce44SJohn Forte 		mdb_printf("queue type: Disk based  %8Tqstate 0x%x\n",
323*fcf3ce44SJohn Forte 		    QSTATE(dq));
324*fcf3ce44SJohn Forte 	}
325*fcf3ce44SJohn Forte 	mdb_printf("ra_queue head: 0x%p  %8Ttail 0x%p\n",
326*fcf3ce44SJohn Forte 	    group->ra_queue.net_qhead, group->ra_queue.net_qtail);
327*fcf3ce44SJohn Forte 	mdb_printf("ra_queue blocks: %d  %8Titems %d\n",
328*fcf3ce44SJohn Forte 	    group->ra_queue.blocks, group->ra_queue.nitems);
329*fcf3ce44SJohn Forte 	mdb_printf("ra_queue blockhwm: %d itemhwm: %d\n",
330*fcf3ce44SJohn Forte 	    group->ra_queue.blocks_hwm, group->ra_queue.nitems_hwm);
331*fcf3ce44SJohn Forte 	mdb_printf("ra_queue hwmhit: %d qfillsleep: %d\n",
332*fcf3ce44SJohn Forte 	    group->ra_queue.hwmhit, group->ra_queue.qfill_sleeping);
333*fcf3ce44SJohn Forte 	mdb_printf("ra_queue throttle: %ld\n",
334*fcf3ce44SJohn Forte 	    group->ra_queue.throttle_delay);
335*fcf3ce44SJohn Forte 
336*fcf3ce44SJohn Forte 	if (RDC_IS_DISKQ(group)) {
337*fcf3ce44SJohn Forte 		mdb_printf("head: %d %8Tnxtio: %d  %8Ttail %d %8Tlastail: %d\n",
338*fcf3ce44SJohn Forte 		    QHEAD(dq), QNXTIO(dq), QTAIL(dq), LASTQTAIL(dq));
339*fcf3ce44SJohn Forte 		mdb_printf("coalbounds: %d %8Tqwrap: %d\n", QCOALBOUNDS(dq),
340*fcf3ce44SJohn Forte 		    QWRAP(dq));
341*fcf3ce44SJohn Forte 		mdb_printf("blocks: %d  %8Titems %d qfflags 0x%x \n",
342*fcf3ce44SJohn Forte 		    QBLOCKS(dq), QNITEMS(dq), group->ra_queue.qfflags);
343*fcf3ce44SJohn Forte 		mdb_printf("diskq throttle: %ld %8Tflags: %x\n",
344*fcf3ce44SJohn Forte 		    dq->throttle_delay, group->flags);
345*fcf3ce44SJohn Forte 		mdb_printf("disk queue nitems_hwm: %d %8Tblocks_hwm: %d\n",
346*fcf3ce44SJohn Forte 		    dq->nitems_hwm, dq->blocks_hwm);
347*fcf3ce44SJohn Forte 		mdb_printf("diskqfd:   0x%p %8Tdisqrsrv: %d lastio: 0x%p\n",
348*fcf3ce44SJohn Forte 		    group->diskqfd, group->diskqrsrv, dq->lastio);
349*fcf3ce44SJohn Forte 		mdb_printf("outstanding req %d iohdrs 0x%p iohdrs_last 0x%p\n",
350*fcf3ce44SJohn Forte 		    dq->hdrcnt, dq->iohdrs, dq->hdr_last);
351*fcf3ce44SJohn Forte 	}
352*fcf3ce44SJohn Forte 	mdb_printf("seq: %u\n", group->seq);
353*fcf3ce44SJohn Forte 	mdb_printf("seqack: %u\n", group->seqack);
354*fcf3ce44SJohn Forte 	mdb_printf("sleepq: 0x%p\n", group->sleepq);
355*fcf3ce44SJohn Forte 	mdb_printf("asyncstall %d\n", group->asyncstall);
356*fcf3ce44SJohn Forte 	mdb_printf("asyncdis %d\n", group->asyncdis);
357*fcf3ce44SJohn Forte 
358*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
359*fcf3ce44SJohn Forte 	if (group->sleepq) {
360*fcf3ce44SJohn Forte 		rdc_sleepq((uintptr_t)group->sleepq, DCMD_ADDRSPEC,
361*fcf3ce44SJohn Forte 		    0, 0);
362*fcf3ce44SJohn Forte 	}
363*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
364*fcf3ce44SJohn Forte 
365*fcf3ce44SJohn Forte 	return (DCMD_OK);
366*fcf3ce44SJohn Forte }
367*fcf3ce44SJohn Forte 
368*fcf3ce44SJohn Forte 
369*fcf3ce44SJohn Forte /*
370*fcf3ce44SJohn Forte  * Display a krdc->lsrv.
371*fcf3ce44SJohn Forte  * Requires an address.
372*fcf3ce44SJohn Forte  */
373*fcf3ce44SJohn Forte /*ARGSUSED*/
374*fcf3ce44SJohn Forte static int
375*fcf3ce44SJohn Forte rdc_srv(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
376*fcf3ce44SJohn Forte {
377*fcf3ce44SJohn Forte 	rdc_srv_t *lsrv;
378*fcf3ce44SJohn Forte 	char name[MAX_RDC_HOST_SIZE];
379*fcf3ce44SJohn Forte 
380*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
381*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
382*fcf3ce44SJohn Forte 
383*fcf3ce44SJohn Forte 
384*fcf3ce44SJohn Forte 	lsrv = mdb_zalloc(sizeof (*lsrv), UM_GC);
385*fcf3ce44SJohn Forte 
386*fcf3ce44SJohn Forte 	if (mdb_vread(lsrv, sizeof (*lsrv), addr) != sizeof (*lsrv)) {
387*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_srv at %p", addr);
388*fcf3ce44SJohn Forte 		return (DCMD_ERR);
389*fcf3ce44SJohn Forte 	}
390*fcf3ce44SJohn Forte 
391*fcf3ce44SJohn Forte 	if (mdb_readstr(name, sizeof (name),
392*fcf3ce44SJohn Forte 		(uintptr_t)lsrv->ri_hostname) == -1) {
393*fcf3ce44SJohn Forte 		mdb_warn("failed to read ri_hostname name at %p", addr);
394*fcf3ce44SJohn Forte 		return (DCMD_ERR);
395*fcf3ce44SJohn Forte 	}
396*fcf3ce44SJohn Forte 
397*fcf3ce44SJohn Forte 	mdb_printf("host: %s  %16Tri_knconf 0x%p\n", name, lsrv->ri_knconf);
398*fcf3ce44SJohn Forte 
399*fcf3ce44SJohn Forte 	mdb_printf("ri_addr: 0x%p  %8Tsecdata 0x%p\n",
400*fcf3ce44SJohn Forte 	    addr + OFFSETOF(rdc_srv_t, ri_addr), lsrv->ri_secdata);
401*fcf3ce44SJohn Forte 
402*fcf3ce44SJohn Forte 	return (DCMD_OK);
403*fcf3ce44SJohn Forte }
404*fcf3ce44SJohn Forte 
405*fcf3ce44SJohn Forte /*
406*fcf3ce44SJohn Forte  * Display a rdc_if_t.
407*fcf3ce44SJohn Forte  * Requires an address.
408*fcf3ce44SJohn Forte  */
409*fcf3ce44SJohn Forte static int
410*fcf3ce44SJohn Forte rdc_if(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
411*fcf3ce44SJohn Forte {
412*fcf3ce44SJohn Forte 	rdc_if_t *ifp;
413*fcf3ce44SJohn Forte 
414*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC)) {
415*fcf3ce44SJohn Forte 		/*
416*fcf3ce44SJohn Forte 		 * paranoid mode on: qualify walker name with module name
417*fcf3ce44SJohn Forte 		 * using '`' syntax.
418*fcf3ce44SJohn Forte 		 */
419*fcf3ce44SJohn Forte 		if (mdb_walk_dcmd("rdc`rdc_if",
420*fcf3ce44SJohn Forte 			"rdc`rdc_if", argc, argv) == -1) {
421*fcf3ce44SJohn Forte 			mdb_warn("failed to walk 'rdc_if'");
422*fcf3ce44SJohn Forte 			return (DCMD_ERR);
423*fcf3ce44SJohn Forte 		}
424*fcf3ce44SJohn Forte 		return (DCMD_OK);
425*fcf3ce44SJohn Forte 	}
426*fcf3ce44SJohn Forte 
427*fcf3ce44SJohn Forte 	ifp = mdb_zalloc(sizeof (*ifp), UM_GC);
428*fcf3ce44SJohn Forte 
429*fcf3ce44SJohn Forte 	if (mdb_vread(ifp, sizeof (*ifp), addr) != sizeof (*ifp)) {
430*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_srv at %p", addr);
431*fcf3ce44SJohn Forte 		return (DCMD_ERR);
432*fcf3ce44SJohn Forte 	}
433*fcf3ce44SJohn Forte 
434*fcf3ce44SJohn Forte 	mdb_printf("next: 0x%p  %8Tsrv 0x%p\n", ifp->next, ifp->srv);
435*fcf3ce44SJohn Forte 	mdb_printf("if_addr: 0x%p  %8Tr_ifaddr 0x%p\n",
436*fcf3ce44SJohn Forte 	    addr + OFFSETOF(rdc_if_t, ifaddr),
437*fcf3ce44SJohn Forte 	    addr + OFFSETOF(rdc_if_t, r_ifaddr));
438*fcf3ce44SJohn Forte 	mdb_printf("if_down: %d  %8Tprimary %d  %8Tsecondary  %d\n",
439*fcf3ce44SJohn Forte 		ifp->if_down, ifp->isprimary, ifp->issecondary);
440*fcf3ce44SJohn Forte 	mdb_printf("version %d  %8Tnoping  %d\n", ifp->rpc_version,
441*fcf3ce44SJohn Forte 		ifp->no_ping);
442*fcf3ce44SJohn Forte 	mdb_printf("\n");
443*fcf3ce44SJohn Forte 
444*fcf3ce44SJohn Forte 	return (DCMD_OK);
445*fcf3ce44SJohn Forte }
446*fcf3ce44SJohn Forte 
447*fcf3ce44SJohn Forte 
448*fcf3ce44SJohn Forte /*
449*fcf3ce44SJohn Forte  * Display a rdc_buf_t
450*fcf3ce44SJohn Forte  * Requires an address.
451*fcf3ce44SJohn Forte  */
452*fcf3ce44SJohn Forte /*ARGSUSED*/
453*fcf3ce44SJohn Forte static int
454*fcf3ce44SJohn Forte rdc_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
455*fcf3ce44SJohn Forte {
456*fcf3ce44SJohn Forte 	rdc_buf_t *buf;
457*fcf3ce44SJohn Forte 
458*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
459*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
460*fcf3ce44SJohn Forte 
461*fcf3ce44SJohn Forte 
462*fcf3ce44SJohn Forte 	buf = mdb_zalloc(sizeof (*buf), UM_GC);
463*fcf3ce44SJohn Forte 
464*fcf3ce44SJohn Forte 	if (mdb_vread(buf, sizeof (*buf), addr) != sizeof (*buf)) {
465*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_buf at %p", addr);
466*fcf3ce44SJohn Forte 		return (DCMD_ERR);
467*fcf3ce44SJohn Forte 	}
468*fcf3ce44SJohn Forte 
469*fcf3ce44SJohn Forte 	mdb_printf("nsc_buf fd: 0x%p  %8Tvec 0x%p\n",
470*fcf3ce44SJohn Forte 	    buf->rdc_bufh.sb_fd, buf->rdc_bufh.sb_vec);
471*fcf3ce44SJohn Forte 
472*fcf3ce44SJohn Forte 	mdb_printf("nsc_buf pos: %d  %8Tlen %d\n",
473*fcf3ce44SJohn Forte 	    buf->rdc_bufh.sb_pos, buf->rdc_bufh.sb_len);
474*fcf3ce44SJohn Forte 
475*fcf3ce44SJohn Forte 	mdb_printf("nsc_buf flag: 0x%x  %8Terror %d\n",
476*fcf3ce44SJohn Forte 	    buf->rdc_bufh.sb_flag, buf->rdc_bufh.sb_error);
477*fcf3ce44SJohn Forte 
478*fcf3ce44SJohn Forte 	mdb_printf("anon_buf : 0x%p  %8Tfd 0x%p  %8Tbufp  0x%p\n",
479*fcf3ce44SJohn Forte 	    buf->rdc_anon, buf->rdc_fd, buf->rdc_bufp);
480*fcf3ce44SJohn Forte 
481*fcf3ce44SJohn Forte 	mdb_printf("vsize: %d  %8Tflags 0x%x\n",
482*fcf3ce44SJohn Forte 	    buf->rdc_vsize, buf->rdc_flags);
483*fcf3ce44SJohn Forte 
484*fcf3ce44SJohn Forte 	return (DCMD_OK);
485*fcf3ce44SJohn Forte }
486*fcf3ce44SJohn Forte 
487*fcf3ce44SJohn Forte /*ARGSUSED*/
488*fcf3ce44SJohn Forte static int
489*fcf3ce44SJohn Forte rdc_aio(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
490*fcf3ce44SJohn Forte {
491*fcf3ce44SJohn Forte 	rdc_aio_t *aio;
492*fcf3ce44SJohn Forte 
493*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
494*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
495*fcf3ce44SJohn Forte 
496*fcf3ce44SJohn Forte 	aio = mdb_zalloc(sizeof (*aio), UM_GC);
497*fcf3ce44SJohn Forte 
498*fcf3ce44SJohn Forte 	if (mdb_vread(aio, sizeof (*aio), addr) != sizeof (*aio)) {
499*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_aio at %p", addr);
500*fcf3ce44SJohn Forte 		return (DCMD_ERR);
501*fcf3ce44SJohn Forte 	}
502*fcf3ce44SJohn Forte 	mdb_printf("rdc_aio next: %p %8T nsc_buf: %p %8T nsc_qbuf %p\n",
503*fcf3ce44SJohn Forte 	    aio->next, aio->handle, aio->qhandle);
504*fcf3ce44SJohn Forte 	mdb_printf("pos: %d len: %d qpos: %d flag: %x iostatus: %d index: %d"
505*fcf3ce44SJohn Forte 	    " seq: %d\n", aio->pos, aio->len, aio->qpos, aio->flag,
506*fcf3ce44SJohn Forte 	    aio->iostatus, aio->index, aio->seq);
507*fcf3ce44SJohn Forte 	return (DCMD_OK);
508*fcf3ce44SJohn Forte }
509*fcf3ce44SJohn Forte 
510*fcf3ce44SJohn Forte /*ARGSUSED*/
511*fcf3ce44SJohn Forte static int
512*fcf3ce44SJohn Forte rdc_dset(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
513*fcf3ce44SJohn Forte {
514*fcf3ce44SJohn Forte 	rdc_net_dataset_t *dset;
515*fcf3ce44SJohn Forte 
516*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
517*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
518*fcf3ce44SJohn Forte 
519*fcf3ce44SJohn Forte 	dset = mdb_zalloc(sizeof (*dset), UM_GC);
520*fcf3ce44SJohn Forte 
521*fcf3ce44SJohn Forte 	if (mdb_vread(dset, sizeof (*dset), addr) != sizeof (*dset)) {
522*fcf3ce44SJohn Forte 		mdb_warn("failed to read dset at %p", addr);
523*fcf3ce44SJohn Forte 		return (DCMD_ERR);
524*fcf3ce44SJohn Forte 	}
525*fcf3ce44SJohn Forte 	mdb_printf("dset id: %d %8T dset inuse: %d %8T dset delpend: %d\n",
526*fcf3ce44SJohn Forte 	    dset->id, dset->inuse, dset->delpend);
527*fcf3ce44SJohn Forte 	mdb_printf("dset items: %d %8T dset head %p %8T dset tail %p \n",
528*fcf3ce44SJohn Forte 	    dset->nitems, dset->head, dset->tail);
529*fcf3ce44SJohn Forte 	mdb_printf("dset pos %d %8T dset len %d\n", dset->pos, dset->fbalen);
530*fcf3ce44SJohn Forte 
531*fcf3ce44SJohn Forte 	return (DCMD_OK);
532*fcf3ce44SJohn Forte }
533*fcf3ce44SJohn Forte /*
534*fcf3ce44SJohn Forte  * Display a single rdc_k_info structure.
535*fcf3ce44SJohn Forte  * If called with no address, performs a global walk of all rdc_k_info.
536*fcf3ce44SJohn Forte  * -a : all (i.e. display all devices, even if disabled
537*fcf3ce44SJohn Forte  * -v : verbose
538*fcf3ce44SJohn Forte  */
539*fcf3ce44SJohn Forte 
540*fcf3ce44SJohn Forte const mdb_bitmask_t sv_flag_bits[] = {
541*fcf3ce44SJohn Forte 	{ "NSC_DEVICE", NSC_DEVICE, NSC_DEVICE },
542*fcf3ce44SJohn Forte 	{ "NSC_CACHE", NSC_CACHE, NSC_CACHE },
543*fcf3ce44SJohn Forte 	{ NULL, 0, 0 }
544*fcf3ce44SJohn Forte };
545*fcf3ce44SJohn Forte 
546*fcf3ce44SJohn Forte static int
547*fcf3ce44SJohn Forte rdc_kinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
548*fcf3ce44SJohn Forte {
549*fcf3ce44SJohn Forte 	rdc_k_info_t *krdc;
550*fcf3ce44SJohn Forte 	rdc_u_info_t *rdc_u_info, *urdc;
551*fcf3ce44SJohn Forte 	int a_opt, v_opt;
552*fcf3ce44SJohn Forte 	int dev_t_chars;
553*fcf3ce44SJohn Forte 
554*fcf3ce44SJohn Forte 	a_opt = v_opt = FALSE;
555*fcf3ce44SJohn Forte 	dev_t_chars = sizeof (dev_t) * 2;	/* # chars to display dev_t */
556*fcf3ce44SJohn Forte 
557*fcf3ce44SJohn Forte 	if (mdb_getopts(argc, argv,
558*fcf3ce44SJohn Forte 	    'a', MDB_OPT_SETBITS, TRUE, &a_opt,
559*fcf3ce44SJohn Forte 	    'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
560*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
561*fcf3ce44SJohn Forte 
562*fcf3ce44SJohn Forte 	krdc = mdb_zalloc(sizeof (*krdc), UM_GC);
563*fcf3ce44SJohn Forte 	urdc = mdb_zalloc(sizeof (*urdc), UM_GC);
564*fcf3ce44SJohn Forte 
565*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC)) {
566*fcf3ce44SJohn Forte 		/*
567*fcf3ce44SJohn Forte 		 * paranoid mode on: qualify walker name with module name
568*fcf3ce44SJohn Forte 		 * using '`' syntax.
569*fcf3ce44SJohn Forte 		 */
570*fcf3ce44SJohn Forte 		if (mdb_walk_dcmd("rdc`rdc_kinfo",
571*fcf3ce44SJohn Forte 			"rdc`rdc_kinfo", argc, argv) == -1) {
572*fcf3ce44SJohn Forte 			mdb_warn("failed to walk 'rdc_kinfo'");
573*fcf3ce44SJohn Forte 			return (DCMD_ERR);
574*fcf3ce44SJohn Forte 		}
575*fcf3ce44SJohn Forte 		return (DCMD_OK);
576*fcf3ce44SJohn Forte 	}
577*fcf3ce44SJohn Forte 	if (DCMD_HDRSPEC(flags)) {
578*fcf3ce44SJohn Forte 		mdb_printf("%-?s  %8T%-*s  %8T%s\n", "ADDR",
579*fcf3ce44SJohn Forte 		    dev_t_chars, "TFLAG", "STATE");
580*fcf3ce44SJohn Forte 	}
581*fcf3ce44SJohn Forte 
582*fcf3ce44SJohn Forte 	if (mdb_vread(krdc, sizeof (*krdc), addr) != sizeof (*krdc)) {
583*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_k_info at %p", addr);
584*fcf3ce44SJohn Forte 		return (DCMD_ERR);
585*fcf3ce44SJohn Forte 	}
586*fcf3ce44SJohn Forte 
587*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_u_info, "rdc_u_info") == -1) {
588*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_u_info'");
589*fcf3ce44SJohn Forte 		return (DCMD_ERR);
590*fcf3ce44SJohn Forte 	}
591*fcf3ce44SJohn Forte 
592*fcf3ce44SJohn Forte 	urdc = &rdc_u_info[krdc->index];
593*fcf3ce44SJohn Forte 
594*fcf3ce44SJohn Forte 	if (!a_opt && ((krdc->type_flag & RDC_CONFIGURED) == 0))
595*fcf3ce44SJohn Forte 		return (DCMD_OK);
596*fcf3ce44SJohn Forte 
597*fcf3ce44SJohn Forte 	mdb_printf("%?p  %8T%0*lx  %8T", addr, dev_t_chars, krdc->type_flag);
598*fcf3ce44SJohn Forte 
599*fcf3ce44SJohn Forte 
600*fcf3ce44SJohn Forte 	if (krdc->type_flag & RDC_DISABLEPEND)
601*fcf3ce44SJohn Forte 		mdb_printf(" disable pending");
602*fcf3ce44SJohn Forte 	if (krdc->type_flag &  RDC_ASYNCMODE)
603*fcf3ce44SJohn Forte 		mdb_printf(" async");
604*fcf3ce44SJohn Forte 	if (krdc->type_flag & RDC_RESUMEPEND)
605*fcf3ce44SJohn Forte 		mdb_printf(" resume pending");
606*fcf3ce44SJohn Forte 	if (krdc->type_flag & RDC_BUSYWAIT)
607*fcf3ce44SJohn Forte 		mdb_printf(" busywait");
608*fcf3ce44SJohn Forte #ifdef RDC_SMALLIO
609*fcf3ce44SJohn Forte 	if (krdc->type_flag & RDC_SMALLIO)
610*fcf3ce44SJohn Forte 		mdb_printf(" smallio");
611*fcf3ce44SJohn Forte #endif
612*fcf3ce44SJohn Forte 
613*fcf3ce44SJohn Forte 	mdb_printf("\n");
614*fcf3ce44SJohn Forte 
615*fcf3ce44SJohn Forte 	if (!v_opt)
616*fcf3ce44SJohn Forte 		return (DCMD_OK);
617*fcf3ce44SJohn Forte 
618*fcf3ce44SJohn Forte 	/*
619*fcf3ce44SJohn Forte 	 * verbose - print the rest of the structure as well.
620*fcf3ce44SJohn Forte 	 */
621*fcf3ce44SJohn Forte 
622*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
623*fcf3ce44SJohn Forte 
624*fcf3ce44SJohn Forte 	mdb_printf("index: %d  %8Trindex: %d  %8Tbusyc: %d  %8Tmaxfbas:  %d\n",
625*fcf3ce44SJohn Forte 	    krdc->index, krdc->remote_index, krdc->busy_count, krdc->maxfbas);
626*fcf3ce44SJohn Forte 
627*fcf3ce44SJohn Forte 	mdb_printf("info_dev:  0x%p %8Tiodev: 0x%p  %8T %8T vers %d\n",
628*fcf3ce44SJohn Forte 	krdc->devices, krdc->iodev, krdc->rpc_version);
629*fcf3ce44SJohn Forte 
630*fcf3ce44SJohn Forte 	mdb_printf("iokstats:  0x%p\n", krdc->io_kstats);
631*fcf3ce44SJohn Forte 	mdb_printf("group:  0x%p %8Tgroup_next:  0x%p\n",
632*fcf3ce44SJohn Forte 		krdc->group, krdc->group_next);
633*fcf3ce44SJohn Forte 	mdb_printf("group lock: 0x%p aux_state: %d\n",
634*fcf3ce44SJohn Forte 	    &krdc->group->lock, krdc->aux_state);
635*fcf3ce44SJohn Forte 
636*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
637*fcf3ce44SJohn Forte 	if (krdc->type_flag & RDC_ASYNCMODE) {
638*fcf3ce44SJohn Forte 		rdc_group((uintptr_t)krdc->group, DCMD_ADDRSPEC, 0, 0);
639*fcf3ce44SJohn Forte 	}
640*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
641*fcf3ce44SJohn Forte 
642*fcf3ce44SJohn Forte 	mdb_printf("servinfo:  0x%p %8Tintf:  0x%p\nbitmap: 0x%p  %8T"
643*fcf3ce44SJohn Forte 	    "bitmap_ref:  0x%p\n",
644*fcf3ce44SJohn Forte 	    krdc->lsrv, krdc->intf, krdc->dcio_bitmap, krdc->bitmap_ref);
645*fcf3ce44SJohn Forte 
646*fcf3ce44SJohn Forte 	mdb_printf("bmap_size:  %d %8Tbmaprsrv: %d%8T bmap_write:  %d\n",
647*fcf3ce44SJohn Forte 	    krdc->bitmap_size, krdc->bmaprsrv, krdc->bitmap_write);
648*fcf3ce44SJohn Forte 
649*fcf3ce44SJohn Forte 	mdb_printf("bitmapfd:  0x%p %8Tremote_fd: 0x%p  %8T\n", krdc->bitmapfd,
650*fcf3ce44SJohn Forte 	    krdc->remote_fd);
651*fcf3ce44SJohn Forte 
652*fcf3ce44SJohn Forte 	mdb_printf("net_dataset:  0x%p %8Tdisk_status: %d  %8T\n",
653*fcf3ce44SJohn Forte 	    krdc->net_dataset, krdc->disk_status);
654*fcf3ce44SJohn Forte 
655*fcf3ce44SJohn Forte 	mdb_printf("many:  0x%p %8Tmulti: 0x%p  %8T\n", krdc->many_next,
656*fcf3ce44SJohn Forte 	    krdc->multi_next);
657*fcf3ce44SJohn Forte 
658*fcf3ce44SJohn Forte 	mdb_printf("rdc_uinfo: 0x%p\n\n", urdc);
659*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
660*fcf3ce44SJohn Forte 	return (DCMD_OK);
661*fcf3ce44SJohn Forte }
662*fcf3ce44SJohn Forte 
663*fcf3ce44SJohn Forte 
664*fcf3ce44SJohn Forte static int
665*fcf3ce44SJohn Forte rdc_uinfo(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
666*fcf3ce44SJohn Forte {
667*fcf3ce44SJohn Forte 	rdc_u_info_t *urdc;
668*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info, *krdc, krdc1;
669*fcf3ce44SJohn Forte 	rdc_group_t grp;
670*fcf3ce44SJohn Forte 	disk_queue *dqp = NULL;
671*fcf3ce44SJohn Forte 	int a_opt, v_opt;
672*fcf3ce44SJohn Forte 	int dev_t_chars;
673*fcf3ce44SJohn Forte 	int rdcflags;
674*fcf3ce44SJohn Forte 
675*fcf3ce44SJohn Forte 	a_opt = v_opt = FALSE;
676*fcf3ce44SJohn Forte 	dev_t_chars = sizeof (dev_t) * 2;	/* # chars to display dev_t */
677*fcf3ce44SJohn Forte 
678*fcf3ce44SJohn Forte 	if (mdb_getopts(argc, argv,
679*fcf3ce44SJohn Forte 	    'a', MDB_OPT_SETBITS, TRUE, &a_opt,
680*fcf3ce44SJohn Forte 	    'v', MDB_OPT_SETBITS, TRUE, &v_opt) != argc)
681*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
682*fcf3ce44SJohn Forte 
683*fcf3ce44SJohn Forte 	urdc = mdb_zalloc(sizeof (*urdc), UM_GC);
684*fcf3ce44SJohn Forte 	krdc = mdb_zalloc(sizeof (*krdc), UM_GC);
685*fcf3ce44SJohn Forte 
686*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC)) {
687*fcf3ce44SJohn Forte 		/*
688*fcf3ce44SJohn Forte 		 * paranoid mode on: qualify walker name with module name
689*fcf3ce44SJohn Forte 		 * using '`' syntax.
690*fcf3ce44SJohn Forte 		 */
691*fcf3ce44SJohn Forte 		if (mdb_walk_dcmd("rdc`rdc_uinfo",
692*fcf3ce44SJohn Forte 			"rdc`rdc_uinfo", argc, argv) == -1) {
693*fcf3ce44SJohn Forte 			mdb_warn("failed to walk 'rdc_uinfo'");
694*fcf3ce44SJohn Forte 			return (DCMD_ERR);
695*fcf3ce44SJohn Forte 		}
696*fcf3ce44SJohn Forte 		return (DCMD_OK);
697*fcf3ce44SJohn Forte 	}
698*fcf3ce44SJohn Forte 	if (DCMD_HDRSPEC(flags)) {
699*fcf3ce44SJohn Forte 		mdb_printf("%-?s  %8T%-*s  %8T%s\n", "ADDR",
700*fcf3ce44SJohn Forte 		    dev_t_chars, "FLAG", "STATE");
701*fcf3ce44SJohn Forte 	}
702*fcf3ce44SJohn Forte 
703*fcf3ce44SJohn Forte 	if (mdb_vread(urdc, sizeof (*urdc), addr) != sizeof (*urdc)) {
704*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_u_info at %p", addr);
705*fcf3ce44SJohn Forte 		return (DCMD_ERR);
706*fcf3ce44SJohn Forte 	}
707*fcf3ce44SJohn Forte 
708*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
709*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
710*fcf3ce44SJohn Forte 		return (DCMD_ERR);
711*fcf3ce44SJohn Forte 	}
712*fcf3ce44SJohn Forte 
713*fcf3ce44SJohn Forte 	krdc = &rdc_k_info[urdc->index];
714*fcf3ce44SJohn Forte 
715*fcf3ce44SJohn Forte 	if (!a_opt && ((urdc->flags & RDC_ENABLED) == 0))
716*fcf3ce44SJohn Forte 		return (DCMD_OK);
717*fcf3ce44SJohn Forte 
718*fcf3ce44SJohn Forte 
719*fcf3ce44SJohn Forte 	if (mdb_vread(&krdc1, sizeof (krdc1),
720*fcf3ce44SJohn Forte 	    (uintptr_t)krdc) != sizeof (krdc1)) {
721*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info1'");
722*fcf3ce44SJohn Forte 		return (DCMD_ERR);
723*fcf3ce44SJohn Forte 	}
724*fcf3ce44SJohn Forte 
725*fcf3ce44SJohn Forte 	if (krdc1.group) {
726*fcf3ce44SJohn Forte 		if (mdb_vread(&grp, sizeof (grp),
727*fcf3ce44SJohn Forte 		    (uintptr_t)krdc1.group) != sizeof (grp)) {
728*fcf3ce44SJohn Forte 			mdb_warn("failed to read group info ");
729*fcf3ce44SJohn Forte 			return (DCMD_ERR);
730*fcf3ce44SJohn Forte 		}
731*fcf3ce44SJohn Forte 		dqp = &grp.diskq;
732*fcf3ce44SJohn Forte 	}
733*fcf3ce44SJohn Forte 
734*fcf3ce44SJohn Forte 	rdcflags = (urdc->flags | urdc->sync_flags | urdc->bmap_flags);
735*fcf3ce44SJohn Forte 	mdb_printf("%?p  %8T%0*lx  %8T", addr, dev_t_chars, rdcflags);
736*fcf3ce44SJohn Forte 
737*fcf3ce44SJohn Forte 
738*fcf3ce44SJohn Forte 	if (rdcflags & RDC_PRIMARY)
739*fcf3ce44SJohn Forte 		mdb_printf(" primary");
740*fcf3ce44SJohn Forte 	if (rdcflags &  RDC_SLAVE)
741*fcf3ce44SJohn Forte 		mdb_printf(" slave");
742*fcf3ce44SJohn Forte 	if (rdcflags &  RDC_SYNCING)
743*fcf3ce44SJohn Forte 		mdb_printf(" syncing");
744*fcf3ce44SJohn Forte 	if (rdcflags &  RDC_SYNC_NEEDED)
745*fcf3ce44SJohn Forte 		mdb_printf(" sync_need");
746*fcf3ce44SJohn Forte 	if (rdcflags &  RDC_RSYNC_NEEDED)
747*fcf3ce44SJohn Forte 		mdb_printf(" rsync_need");
748*fcf3ce44SJohn Forte 	if (rdcflags & RDC_LOGGING)
749*fcf3ce44SJohn Forte 		mdb_printf(" logging");
750*fcf3ce44SJohn Forte 	if (rdcflags & RDC_QUEUING)
751*fcf3ce44SJohn Forte 		mdb_printf(" queuing");
752*fcf3ce44SJohn Forte 	if (rdcflags & RDC_DISKQ_FAILED)
753*fcf3ce44SJohn Forte 		mdb_printf(" diskq failed");
754*fcf3ce44SJohn Forte 	if (rdcflags & RDC_VOL_FAILED)
755*fcf3ce44SJohn Forte 		mdb_printf(" vol failed");
756*fcf3ce44SJohn Forte 	if (rdcflags & RDC_BMP_FAILED)
757*fcf3ce44SJohn Forte 		mdb_printf(" bmp failed");
758*fcf3ce44SJohn Forte 	if (rdcflags & RDC_ASYNC)
759*fcf3ce44SJohn Forte 		mdb_printf(" async");
760*fcf3ce44SJohn Forte 	if (rdcflags & RDC_CLR_AFTERSYNC)
761*fcf3ce44SJohn Forte 		mdb_printf(" clr_bitmap_aftersync");
762*fcf3ce44SJohn Forte 	if (dqp) {
763*fcf3ce44SJohn Forte 		if (IS_QSTATE(dqp, RDC_QNOBLOCK))
764*fcf3ce44SJohn Forte 			mdb_printf(" noblock");
765*fcf3ce44SJohn Forte 	}
766*fcf3ce44SJohn Forte #ifdef RDC_SMALLIO
767*fcf3ce44SJohn Forte 	if (rdcflags & RDC_SMALLIO)
768*fcf3ce44SJohn Forte 		mdb_printf(" smallio");
769*fcf3ce44SJohn Forte #endif
770*fcf3ce44SJohn Forte 
771*fcf3ce44SJohn Forte 	mdb_printf("\n");
772*fcf3ce44SJohn Forte 
773*fcf3ce44SJohn Forte 	if (!v_opt)
774*fcf3ce44SJohn Forte 		return (DCMD_OK);
775*fcf3ce44SJohn Forte 
776*fcf3ce44SJohn Forte 	/*
777*fcf3ce44SJohn Forte 	 * verbose - print the rest of the structure as well.
778*fcf3ce44SJohn Forte 	 */
779*fcf3ce44SJohn Forte 
780*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
781*fcf3ce44SJohn Forte 	mdb_printf("\n");
782*fcf3ce44SJohn Forte 
783*fcf3ce44SJohn Forte 	mdb_printf("primary: %s  %8Tfile: %s  \nbitmap: %s  ",
784*fcf3ce44SJohn Forte 	    urdc->primary.intf, urdc->primary.file, urdc->primary.bitmap);
785*fcf3ce44SJohn Forte 	mdb_printf("netbuf: 0x%p\n", addr + OFFSETOF(rdc_set_t, primary));
786*fcf3ce44SJohn Forte 	mdb_printf("secondary: %s  %8Tfile: %s  \nbitmap: %s  ",
787*fcf3ce44SJohn Forte 	    urdc->secondary.intf, urdc->secondary.file, urdc->secondary.bitmap);
788*fcf3ce44SJohn Forte 	mdb_printf("netbuf: 0x%p\n", addr + OFFSETOF(rdc_set_t, secondary));
789*fcf3ce44SJohn Forte 
790*fcf3ce44SJohn Forte 	mdb_printf("sflags:  %d %8Tbflags: %d%8T mflags:  %d\n",
791*fcf3ce44SJohn Forte 		urdc->sync_flags, urdc->bmap_flags, urdc->mflags);
792*fcf3ce44SJohn Forte 	mdb_printf("index:  %d %8Tsync_pos: %d%8T vsize:  %d\n",
793*fcf3ce44SJohn Forte 		urdc->index, urdc->sync_pos, urdc->volume_size);
794*fcf3ce44SJohn Forte 	mdb_printf("setid:  %d %8Tbits set:  %d %8Tautosync: %d\n",
795*fcf3ce44SJohn Forte 		urdc->setid, urdc->bits_set, urdc->autosync);
796*fcf3ce44SJohn Forte 	mdb_printf("maxqfbas:  %d %8Tmaxqitems: %d\n",
797*fcf3ce44SJohn Forte 		urdc->maxqfbas, urdc->maxqitems);
798*fcf3ce44SJohn Forte 	mdb_printf("netconfig:  %p\n", urdc->netconfig);
799*fcf3ce44SJohn Forte 	mdb_printf("group:  %s %8TdirectIO: %s\n",
800*fcf3ce44SJohn Forte 		urdc->group_name, urdc->direct_file);
801*fcf3ce44SJohn Forte 	mdb_printf("diskqueue: %s ", urdc->disk_queue);
802*fcf3ce44SJohn Forte 	if (dqp) {
803*fcf3ce44SJohn Forte 		mdb_printf("diskqsize: %d\n", QSIZE(dqp));
804*fcf3ce44SJohn Forte 	} else {
805*fcf3ce44SJohn Forte 		mdb_printf("\n");
806*fcf3ce44SJohn Forte 	}
807*fcf3ce44SJohn Forte 	mdb_printf("rdc_k_info: 0x%p\n", krdc);
808*fcf3ce44SJohn Forte 	mdb_printf("\n");
809*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
810*fcf3ce44SJohn Forte 
811*fcf3ce44SJohn Forte 	mdb_printf("\n");
812*fcf3ce44SJohn Forte 	return (DCMD_OK);
813*fcf3ce44SJohn Forte }
814*fcf3ce44SJohn Forte 
815*fcf3ce44SJohn Forte /*ARGSUSED*/
816*fcf3ce44SJohn Forte static int
817*fcf3ce44SJohn Forte rdc_infodev(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
818*fcf3ce44SJohn Forte {
819*fcf3ce44SJohn Forte 	rdc_info_dev_t *infodev;
820*fcf3ce44SJohn Forte 	_rdc_info_dev_t *infp;
821*fcf3ce44SJohn Forte 
822*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
823*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
824*fcf3ce44SJohn Forte 
825*fcf3ce44SJohn Forte 	infodev = mdb_zalloc(sizeof (*infodev), UM_GC);
826*fcf3ce44SJohn Forte 	infp = mdb_zalloc(sizeof (*infp), UM_GC);
827*fcf3ce44SJohn Forte 
828*fcf3ce44SJohn Forte 	if (mdb_vread(infodev, sizeof (*infodev), addr) != sizeof (*infodev)) {
829*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_infodev at 0x%p\n", addr);
830*fcf3ce44SJohn Forte 		return (DCMD_ERR);
831*fcf3ce44SJohn Forte 	}
832*fcf3ce44SJohn Forte 
833*fcf3ce44SJohn Forte 	infp = &infodev->id_cache_dev;
834*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
835*fcf3ce44SJohn Forte 
836*fcf3ce44SJohn Forte 	mdb_printf("id_next: 0x%p\n", infodev->id_next);
837*fcf3ce44SJohn Forte 	mdb_printf("id_cache_dev:\n");
838*fcf3ce44SJohn Forte 
839*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
840*fcf3ce44SJohn Forte 	mdb_printf("bi_fd: 0x%p %8Tbi_iodev: 0x%p %8Tbi_krdc 0x%p\n",
841*fcf3ce44SJohn Forte 	    infp->bi_fd, infp->bi_iodev, infp->bi_krdc);
842*fcf3ce44SJohn Forte 	mdb_printf("bi_rsrv: %d %8Tbi_orsrv: %d %8Tbi_failed: %d %8T\n"
843*fcf3ce44SJohn Forte 	    "bi_ofailed: %d %8Tbi_flag: %d\n", infp->bi_rsrv, infp->bi_orsrv,
844*fcf3ce44SJohn Forte 	    infp->bi_failed, infp->bi_ofailed, infp->bi_flag);
845*fcf3ce44SJohn Forte 
846*fcf3ce44SJohn Forte 	infp = &infodev->id_raw_dev;
847*fcf3ce44SJohn Forte 
848*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
849*fcf3ce44SJohn Forte 	mdb_printf("id_cache_dev:\n");
850*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
851*fcf3ce44SJohn Forte 
852*fcf3ce44SJohn Forte 	mdb_printf("bi_fd: 0x%p %8Tbi_iodev: 0x%p %8Tbi_krdc 0x%p\n",
853*fcf3ce44SJohn Forte 	    infp->bi_fd, infp->bi_iodev, infp->bi_krdc);
854*fcf3ce44SJohn Forte 	mdb_printf("bi_rsrv: %d %8Tbi_orsrv: %d %8Tbi_failed: %d %8T\n"
855*fcf3ce44SJohn Forte 	    "bi_ofailed: %d %8Tbi_flag: %d\n", infp->bi_rsrv, infp->bi_orsrv,
856*fcf3ce44SJohn Forte 	    infp->bi_failed, infp->bi_ofailed, infp->bi_flag);
857*fcf3ce44SJohn Forte 
858*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
859*fcf3ce44SJohn Forte 
860*fcf3ce44SJohn Forte 	mdb_printf("id_sets: %d %8Tid_release: %d %8Tid_flag %d",
861*fcf3ce44SJohn Forte 	    infodev->id_sets, infodev->id_release, infodev->id_flag);
862*fcf3ce44SJohn Forte 
863*fcf3ce44SJohn Forte 	if (infodev->id_flag & RDC_ID_CLOSING) {
864*fcf3ce44SJohn Forte 		mdb_printf("closing");
865*fcf3ce44SJohn Forte 	}
866*fcf3ce44SJohn Forte 	mdb_printf("\n");
867*fcf3ce44SJohn Forte 
868*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
869*fcf3ce44SJohn Forte 	return (DCMD_OK);
870*fcf3ce44SJohn Forte }
871*fcf3ce44SJohn Forte 
872*fcf3ce44SJohn Forte /*
873*fcf3ce44SJohn Forte  * Display general sv module information.
874*fcf3ce44SJohn Forte  */
875*fcf3ce44SJohn Forte 
876*fcf3ce44SJohn Forte #define	rdc_get_print(kvar, str, fmt, val)		\
877*fcf3ce44SJohn Forte 	if (mdb_readvar(&(val), #kvar) == -1) {		\
878*fcf3ce44SJohn Forte 		mdb_dec_indent(4);			\
879*fcf3ce44SJohn Forte 		mdb_warn("unable to read '" #kvar "'");	\
880*fcf3ce44SJohn Forte 		return (DCMD_ERR);			\
881*fcf3ce44SJohn Forte 	}						\
882*fcf3ce44SJohn Forte 	mdb_printf("%-20s" fmt "\n", str ":", val)
883*fcf3ce44SJohn Forte 
884*fcf3ce44SJohn Forte /*ARGSUSED*/
885*fcf3ce44SJohn Forte static int
886*fcf3ce44SJohn Forte rdc(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
887*fcf3ce44SJohn Forte {
888*fcf3ce44SJohn Forte 	int maj, min, mic, baseline, i;
889*fcf3ce44SJohn Forte 
890*fcf3ce44SJohn Forte 	if (argc != 0)
891*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
892*fcf3ce44SJohn Forte 
893*fcf3ce44SJohn Forte 	if (mdb_readvar(&maj, "sndr_major_rev") == -1) {
894*fcf3ce44SJohn Forte 		mdb_warn("unable to read 'sndr_major_rev'");
895*fcf3ce44SJohn Forte 		return (DCMD_ERR);
896*fcf3ce44SJohn Forte 	}
897*fcf3ce44SJohn Forte 
898*fcf3ce44SJohn Forte 	if (mdb_readvar(&min, "sndr_minor_rev") == -1) {
899*fcf3ce44SJohn Forte 		mdb_warn("unable to read 'sndr_minor_rev'");
900*fcf3ce44SJohn Forte 		return (DCMD_ERR);
901*fcf3ce44SJohn Forte 	}
902*fcf3ce44SJohn Forte 
903*fcf3ce44SJohn Forte 	if (mdb_readvar(&mic, "sndr_micro_rev") == -1) {
904*fcf3ce44SJohn Forte 		mdb_warn("unable to read 'sndr_micro_rev'");
905*fcf3ce44SJohn Forte 		return (DCMD_ERR);
906*fcf3ce44SJohn Forte 	}
907*fcf3ce44SJohn Forte 
908*fcf3ce44SJohn Forte 	if (mdb_readvar(&baseline, "sndr_baseline_rev") == -1) {
909*fcf3ce44SJohn Forte 		mdb_warn("unable to read 'sndr_baseline_rev'");
910*fcf3ce44SJohn Forte 		return (DCMD_ERR);
911*fcf3ce44SJohn Forte 	}
912*fcf3ce44SJohn Forte 
913*fcf3ce44SJohn Forte 	mdb_printf("Remote Mirror module version: kernel %d.%d.%d.%d; "
914*fcf3ce44SJohn Forte 		    "mdb %d.%d.%d.%d\n", maj, min, mic, baseline,
915*fcf3ce44SJohn Forte 	    ISS_VERSION_MAJ, ISS_VERSION_MIN, ISS_VERSION_MIC, ISS_VERSION_NUM);
916*fcf3ce44SJohn Forte 	mdb_inc_indent(4);
917*fcf3ce44SJohn Forte 
918*fcf3ce44SJohn Forte 	rdc_get_print(rdc_debug, "debug", "%d", i);
919*fcf3ce44SJohn Forte 	rdc_get_print(rdc_bitmap_mode, "bitmap mode", "%d", i);
920*fcf3ce44SJohn Forte 	rdc_get_print(rdc_max_sets, "max sndr devices", "%d", i);
921*fcf3ce44SJohn Forte 	rdc_get_print(rdc_rpc_tmout, "client RPC timeout", "%d", i);
922*fcf3ce44SJohn Forte 	rdc_get_print(rdc_health_thres, "health threshold", "%d", i);
923*fcf3ce44SJohn Forte 	rdc_get_print(MAX_RDC_FBAS, "max trans fba", "%d", i);
924*fcf3ce44SJohn Forte 
925*fcf3ce44SJohn Forte 	mdb_dec_indent(4);
926*fcf3ce44SJohn Forte 	return (DCMD_OK);
927*fcf3ce44SJohn Forte }
928*fcf3ce44SJohn Forte 
929*fcf3ce44SJohn Forte static int
930*fcf3ce44SJohn Forte rdc_k2u(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
931*fcf3ce44SJohn Forte {
932*fcf3ce44SJohn Forte 	rdc_k_info_t *krdc;
933*fcf3ce44SJohn Forte 	rdc_u_info_t *rdc_u_info, *urdc;
934*fcf3ce44SJohn Forte 	int rc;
935*fcf3ce44SJohn Forte 
936*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
937*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
938*fcf3ce44SJohn Forte 
939*fcf3ce44SJohn Forte 	krdc = mdb_zalloc(sizeof (*krdc), UM_GC);
940*fcf3ce44SJohn Forte 	urdc = mdb_zalloc(sizeof (*urdc), UM_GC);
941*fcf3ce44SJohn Forte 
942*fcf3ce44SJohn Forte 	if (mdb_vread(krdc, sizeof (*krdc), addr) != sizeof (*krdc)) {
943*fcf3ce44SJohn Forte 		mdb_warn("failed to read krdc at %p", addr);
944*fcf3ce44SJohn Forte 		return (DCMD_ERR);
945*fcf3ce44SJohn Forte 	}
946*fcf3ce44SJohn Forte 
947*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_u_info, "rdc_u_info") == -1) {
948*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_u_info'");
949*fcf3ce44SJohn Forte 		return (DCMD_ERR);
950*fcf3ce44SJohn Forte 	}
951*fcf3ce44SJohn Forte 
952*fcf3ce44SJohn Forte 	urdc = &rdc_u_info[krdc->index];
953*fcf3ce44SJohn Forte 
954*fcf3ce44SJohn Forte 	rc = rdc_uinfo((uintptr_t)urdc, DCMD_ADDRSPEC, argc, argv);
955*fcf3ce44SJohn Forte 	return (rc);
956*fcf3ce44SJohn Forte }
957*fcf3ce44SJohn Forte 
958*fcf3ce44SJohn Forte static int
959*fcf3ce44SJohn Forte rdc_u2k(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
960*fcf3ce44SJohn Forte {
961*fcf3ce44SJohn Forte 	rdc_u_info_t *urdc;
962*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info, *krdc;
963*fcf3ce44SJohn Forte 	int rc;
964*fcf3ce44SJohn Forte 
965*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
966*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
967*fcf3ce44SJohn Forte 
968*fcf3ce44SJohn Forte 	urdc = mdb_zalloc(sizeof (*urdc), UM_GC);
969*fcf3ce44SJohn Forte 	krdc = mdb_zalloc(sizeof (*krdc), UM_GC);
970*fcf3ce44SJohn Forte 
971*fcf3ce44SJohn Forte 	if (mdb_vread(urdc, sizeof (*urdc), addr) != sizeof (*urdc)) {
972*fcf3ce44SJohn Forte 		mdb_warn("failed to read urdc at %p\n", addr);
973*fcf3ce44SJohn Forte 		return (DCMD_ERR);
974*fcf3ce44SJohn Forte 	}
975*fcf3ce44SJohn Forte 
976*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
977*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
978*fcf3ce44SJohn Forte 		return (DCMD_ERR);
979*fcf3ce44SJohn Forte 	}
980*fcf3ce44SJohn Forte 
981*fcf3ce44SJohn Forte 	krdc = &rdc_k_info[urdc->index];
982*fcf3ce44SJohn Forte 
983*fcf3ce44SJohn Forte 	rc = rdc_kinfo((uintptr_t)krdc, DCMD_ADDRSPEC, argc, argv);
984*fcf3ce44SJohn Forte 	return (rc);
985*fcf3ce44SJohn Forte }
986*fcf3ce44SJohn Forte 
987*fcf3ce44SJohn Forte #ifdef DEBUG
988*fcf3ce44SJohn Forte /*
989*fcf3ce44SJohn Forte  * This routine is used to set the seq field in the rdc_kinfo->group
990*fcf3ce44SJohn Forte  * structure. Used to test that the queue code handles the integer
991*fcf3ce44SJohn Forte  * overflow correctly.
992*fcf3ce44SJohn Forte  * Takes two arguments index and value.
993*fcf3ce44SJohn Forte  * The index is the index into the kinfo structure array and
994*fcf3ce44SJohn Forte  * the value is the new value to set into the seq field.
995*fcf3ce44SJohn Forte  */
996*fcf3ce44SJohn Forte /*ARGSUSED*/
997*fcf3ce44SJohn Forte static int
998*fcf3ce44SJohn Forte rdc_setseq(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
999*fcf3ce44SJohn Forte {
1000*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info;
1001*fcf3ce44SJohn Forte 	rdc_group_t *group;
1002*fcf3ce44SJohn Forte 	int index;
1003*fcf3ce44SJohn Forte 	uint_t val;
1004*fcf3ce44SJohn Forte 	uintptr_t pokeaddr;
1005*fcf3ce44SJohn Forte 
1006*fcf3ce44SJohn Forte 	if (argc != 2) {
1007*fcf3ce44SJohn Forte 		mdb_warn("must have two arguments, index and value\n");
1008*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1009*fcf3ce44SJohn Forte 	}
1010*fcf3ce44SJohn Forte 
1011*fcf3ce44SJohn Forte 	index = (int)mdb_strtoull(argv[0].a_un.a_str);
1012*fcf3ce44SJohn Forte 	val = (uint_t)mdb_strtoull(argv[1].a_un.a_str);
1013*fcf3ce44SJohn Forte 
1014*fcf3ce44SJohn Forte 	/*
1015*fcf3ce44SJohn Forte 	 * Find out where in memory the seq field.
1016*fcf3ce44SJohn Forte 	 * The structure offset first.
1017*fcf3ce44SJohn Forte 	 */
1018*fcf3ce44SJohn Forte 
1019*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
1020*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
1021*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1022*fcf3ce44SJohn Forte 	}
1023*fcf3ce44SJohn Forte 	pokeaddr = (uintptr_t)&rdc_k_info[index].group;
1024*fcf3ce44SJohn Forte 	if (mdb_vread(&group, sizeof (rdc_group_t *), pokeaddr) !=
1025*fcf3ce44SJohn Forte 	    sizeof (rdc_group_t *)) {
1026*fcf3ce44SJohn Forte 		mdb_warn("failed to fetch the group structure for set %d\n",
1027*fcf3ce44SJohn Forte 		    index);
1028*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1029*fcf3ce44SJohn Forte 	}
1030*fcf3ce44SJohn Forte 	pokeaddr = (uintptr_t)(&group->seq);
1031*fcf3ce44SJohn Forte 	if (mdb_vwrite(&val, sizeof (val), pokeaddr) != sizeof (val)) {
1032*fcf3ce44SJohn Forte 		mdb_warn("failed to write seq at %p\n", pokeaddr);
1033*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1034*fcf3ce44SJohn Forte 	}
1035*fcf3ce44SJohn Forte 
1036*fcf3ce44SJohn Forte 	return (DCMD_OK);
1037*fcf3ce44SJohn Forte }
1038*fcf3ce44SJohn Forte 
1039*fcf3ce44SJohn Forte 
1040*fcf3ce44SJohn Forte /*
1041*fcf3ce44SJohn Forte  * This routine is used to set the seqack field in the rdc_kinfo->group
1042*fcf3ce44SJohn Forte  * structure. Used to test that the queue code handles the integer
1043*fcf3ce44SJohn Forte  * overflow correctly.
1044*fcf3ce44SJohn Forte  * Takes two arguments index and value.
1045*fcf3ce44SJohn Forte  * The index is the index into the kinfo structure array and
1046*fcf3ce44SJohn Forte  * the value is the new value to set into the seqack field.
1047*fcf3ce44SJohn Forte  */
1048*fcf3ce44SJohn Forte /*ARGSUSED*/
1049*fcf3ce44SJohn Forte static int
1050*fcf3ce44SJohn Forte rdc_setseqack(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1051*fcf3ce44SJohn Forte {
1052*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info;
1053*fcf3ce44SJohn Forte 	rdc_group_t *group;
1054*fcf3ce44SJohn Forte 	int index;
1055*fcf3ce44SJohn Forte 	uint_t val;
1056*fcf3ce44SJohn Forte 	uintptr_t pokeaddr;
1057*fcf3ce44SJohn Forte 
1058*fcf3ce44SJohn Forte 	if (argc != 2) {
1059*fcf3ce44SJohn Forte 		mdb_warn("must have two arguments, index and value\n");
1060*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1061*fcf3ce44SJohn Forte 	}
1062*fcf3ce44SJohn Forte 
1063*fcf3ce44SJohn Forte 	index = (int)mdb_strtoull(argv[0].a_un.a_str);
1064*fcf3ce44SJohn Forte 	val = (uint_t)mdb_strtoull(argv[1].a_un.a_str);
1065*fcf3ce44SJohn Forte 
1066*fcf3ce44SJohn Forte 	/*
1067*fcf3ce44SJohn Forte 	 * Find out where in memory the seqack field.
1068*fcf3ce44SJohn Forte 	 * The structure offset first.
1069*fcf3ce44SJohn Forte 	 */
1070*fcf3ce44SJohn Forte 
1071*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
1072*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
1073*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1074*fcf3ce44SJohn Forte 	}
1075*fcf3ce44SJohn Forte 	pokeaddr = (uintptr_t)&rdc_k_info[index].group;
1076*fcf3ce44SJohn Forte 	if (mdb_vread(&group, sizeof (rdc_group_t *), pokeaddr) !=
1077*fcf3ce44SJohn Forte 	    sizeof (rdc_group_t *)) {
1078*fcf3ce44SJohn Forte 		mdb_warn("failed to fetch the group structure for set %d\n",
1079*fcf3ce44SJohn Forte 		    index);
1080*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1081*fcf3ce44SJohn Forte 	}
1082*fcf3ce44SJohn Forte 	pokeaddr = (uintptr_t)(&group->seqack);
1083*fcf3ce44SJohn Forte 	if (mdb_vwrite(&val, sizeof (val), pokeaddr) != sizeof (val)) {
1084*fcf3ce44SJohn Forte 		mdb_warn("failed to write seqack at %p\n", pokeaddr);
1085*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1086*fcf3ce44SJohn Forte 	}
1087*fcf3ce44SJohn Forte 
1088*fcf3ce44SJohn Forte 	return (DCMD_OK);
1089*fcf3ce44SJohn Forte }
1090*fcf3ce44SJohn Forte 
1091*fcf3ce44SJohn Forte /*
1092*fcf3ce44SJohn Forte  * random define printing stuff, just does the define, and print the result
1093*fcf3ce44SJohn Forte  */
1094*fcf3ce44SJohn Forte /*ARGSUSED*/
1095*fcf3ce44SJohn Forte static int
1096*fcf3ce44SJohn Forte fba_to_log_num(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1097*fcf3ce44SJohn Forte {
1098*fcf3ce44SJohn Forte 	int num;
1099*fcf3ce44SJohn Forte 	if (argc < 1) {
1100*fcf3ce44SJohn Forte 		mdb_warn("must have an argument\n");
1101*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1102*fcf3ce44SJohn Forte 	}
1103*fcf3ce44SJohn Forte 	num = (int)mdb_strtoull(argv[0].a_un.a_str);
1104*fcf3ce44SJohn Forte 	num = FBA_TO_LOG_NUM(num);
1105*fcf3ce44SJohn Forte 	mdb_printf("LOG NUM: %d (0x%x)", num, num);
1106*fcf3ce44SJohn Forte 
1107*fcf3ce44SJohn Forte 	return (DCMD_OK);
1108*fcf3ce44SJohn Forte }
1109*fcf3ce44SJohn Forte 
1110*fcf3ce44SJohn Forte /*ARGSUSED*/
1111*fcf3ce44SJohn Forte static int
1112*fcf3ce44SJohn Forte log_to_fba_num(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1113*fcf3ce44SJohn Forte {
1114*fcf3ce44SJohn Forte 	int num;
1115*fcf3ce44SJohn Forte 	if (argc < 1) {
1116*fcf3ce44SJohn Forte 		mdb_warn("must have an argument\n");
1117*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1118*fcf3ce44SJohn Forte 	}
1119*fcf3ce44SJohn Forte 	num = (int)mdb_strtoull(argv[0].a_un.a_str);
1120*fcf3ce44SJohn Forte 	num = LOG_TO_FBA_NUM(num);
1121*fcf3ce44SJohn Forte 	mdb_printf("LOG NUM: %d (0x%x)", num, num);
1122*fcf3ce44SJohn Forte 
1123*fcf3ce44SJohn Forte 	return (DCMD_OK);
1124*fcf3ce44SJohn Forte }
1125*fcf3ce44SJohn Forte 
1126*fcf3ce44SJohn Forte static int
1127*fcf3ce44SJohn Forte bmap_bit_isset(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1128*fcf3ce44SJohn Forte {
1129*fcf3ce44SJohn Forte 	int st;
1130*fcf3ce44SJohn Forte 	int i, num;
1131*fcf3ce44SJohn Forte 	rdc_k_info_t *krdc;
1132*fcf3ce44SJohn Forte 	unsigned char *bmap;
1133*fcf3ce44SJohn Forte 	unsigned char *bmaddr;
1134*fcf3ce44SJohn Forte 	int bmsize;
1135*fcf3ce44SJohn Forte 
1136*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
1137*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
1138*fcf3ce44SJohn Forte 
1139*fcf3ce44SJohn Forte 	if (argc < 1) {
1140*fcf3ce44SJohn Forte 		mdb_warn("must have an argument\n");
1141*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1142*fcf3ce44SJohn Forte 	}
1143*fcf3ce44SJohn Forte 	krdc = mdb_zalloc(sizeof (*krdc), UM_GC);
1144*fcf3ce44SJohn Forte 
1145*fcf3ce44SJohn Forte 	if (mdb_vread(krdc, sizeof (*krdc), addr) != sizeof (*krdc)) {
1146*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_k_info at %p", addr);
1147*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1148*fcf3ce44SJohn Forte 	}
1149*fcf3ce44SJohn Forte 
1150*fcf3ce44SJohn Forte 	bmaddr = krdc->dcio_bitmap;
1151*fcf3ce44SJohn Forte 	bmsize = krdc->bitmap_size;
1152*fcf3ce44SJohn Forte 	bmap = mdb_zalloc(bmsize, UM_GC);
1153*fcf3ce44SJohn Forte 	if (mdb_vread(bmap, bmsize, (uintptr_t)bmaddr) != bmsize) {
1154*fcf3ce44SJohn Forte 		mdb_warn("failed to read bitmap");
1155*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1156*fcf3ce44SJohn Forte 	}
1157*fcf3ce44SJohn Forte 
1158*fcf3ce44SJohn Forte 	num = (int)mdb_strtoull(argv[0].a_un.a_str);
1159*fcf3ce44SJohn Forte 	st = FBA_TO_LOG_NUM(num);
1160*fcf3ce44SJohn Forte 	i = BMAP_BIT_ISSET(bmap, st);
1161*fcf3ce44SJohn Forte 	mdb_printf(" BIT (%d) for %x %s set (%02x)", st, num, i?"IS":"IS NOT",
1162*fcf3ce44SJohn Forte 	    bmap[IND_BYTE(st)] & 0xff);
1163*fcf3ce44SJohn Forte 
1164*fcf3ce44SJohn Forte 	return (DCMD_OK);
1165*fcf3ce44SJohn Forte }
1166*fcf3ce44SJohn Forte 
1167*fcf3ce44SJohn Forte static int
1168*fcf3ce44SJohn Forte bmap_bitref_isset(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1169*fcf3ce44SJohn Forte {
1170*fcf3ce44SJohn Forte 	int num, st, i;
1171*fcf3ce44SJohn Forte 	rdc_k_info_t *krdc;
1172*fcf3ce44SJohn Forte 	unsigned char *brefbyte;
1173*fcf3ce44SJohn Forte 	unsigned int *brefint;
1174*fcf3ce44SJohn Forte 	void *bradder;
1175*fcf3ce44SJohn Forte 	int brsize;
1176*fcf3ce44SJohn Forte 	size_t refcntsize = sizeof (unsigned char);
1177*fcf3ce44SJohn Forte 	struct bm_ref_ops *refops;
1178*fcf3ce44SJohn Forte 
1179*fcf3ce44SJohn Forte 	if (!(flags & DCMD_ADDRSPEC))
1180*fcf3ce44SJohn Forte 		return (DCMD_USAGE);
1181*fcf3ce44SJohn Forte 
1182*fcf3ce44SJohn Forte 	if (argc < 1) {
1183*fcf3ce44SJohn Forte 		mdb_warn("must have an argument\n");
1184*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1185*fcf3ce44SJohn Forte 	}
1186*fcf3ce44SJohn Forte 
1187*fcf3ce44SJohn Forte 	krdc = mdb_zalloc(sizeof (*krdc), UM_GC);
1188*fcf3ce44SJohn Forte 
1189*fcf3ce44SJohn Forte 	if (mdb_vread(krdc, sizeof (*krdc), addr) != sizeof (*krdc)) {
1190*fcf3ce44SJohn Forte 		mdb_warn("failed to read rdc_k_info at %p", addr);
1191*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1192*fcf3ce44SJohn Forte 	}
1193*fcf3ce44SJohn Forte 
1194*fcf3ce44SJohn Forte 	bradder = krdc->bitmap_ref;
1195*fcf3ce44SJohn Forte 	refops = mdb_zalloc(sizeof (*refops), UM_GC);
1196*fcf3ce44SJohn Forte 	if (mdb_vread(refops, sizeof (*refops), (uintptr_t)krdc->bm_refs) !=
1197*fcf3ce44SJohn Forte 	    sizeof (*refops)) {
1198*fcf3ce44SJohn Forte 		mdb_warn("failed to read bm_refops at %p", krdc->bm_refs);
1199*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1200*fcf3ce44SJohn Forte 	}
1201*fcf3ce44SJohn Forte 	refcntsize = refops->bmap_ref_size;
1202*fcf3ce44SJohn Forte 	brsize = krdc->bitmap_size * BITS_IN_BYTE * refcntsize;
1203*fcf3ce44SJohn Forte 	if (refcntsize == sizeof (unsigned char)) {
1204*fcf3ce44SJohn Forte 		brefbyte = mdb_zalloc(brsize, UM_GC);
1205*fcf3ce44SJohn Forte 		if (mdb_vread(brefbyte, brsize, (uintptr_t)bradder) != brsize) {
1206*fcf3ce44SJohn Forte 			mdb_warn("failed to read bitmap");
1207*fcf3ce44SJohn Forte 			return (DCMD_ERR);
1208*fcf3ce44SJohn Forte 		}
1209*fcf3ce44SJohn Forte 	} else {
1210*fcf3ce44SJohn Forte 		brefint = mdb_zalloc(brsize, UM_GC);
1211*fcf3ce44SJohn Forte 		if (mdb_vread(brefint, brsize, (uintptr_t)bradder) != brsize) {
1212*fcf3ce44SJohn Forte 			mdb_warn("failed to read bitmap");
1213*fcf3ce44SJohn Forte 			return (DCMD_ERR);
1214*fcf3ce44SJohn Forte 		}
1215*fcf3ce44SJohn Forte 	}
1216*fcf3ce44SJohn Forte 
1217*fcf3ce44SJohn Forte 	num = (int)mdb_strtoull(argv[0].a_un.a_str);
1218*fcf3ce44SJohn Forte 	st = FBA_TO_LOG_NUM(num);
1219*fcf3ce44SJohn Forte 	if (refcntsize == sizeof (unsigned char))
1220*fcf3ce44SJohn Forte 		i = brefbyte[st];
1221*fcf3ce44SJohn Forte 	else
1222*fcf3ce44SJohn Forte 		i = brefint[st];
1223*fcf3ce44SJohn Forte 
1224*fcf3ce44SJohn Forte 	mdb_printf("BITREF (%d) for %x %s set (%02x)", st, num, i?"IS":"IS NOT",
1225*fcf3ce44SJohn Forte 	    i);
1226*fcf3ce44SJohn Forte 
1227*fcf3ce44SJohn Forte 	return (DCMD_OK);
1228*fcf3ce44SJohn Forte }
1229*fcf3ce44SJohn Forte 
1230*fcf3ce44SJohn Forte /*ARGSUSED*/
1231*fcf3ce44SJohn Forte static int
1232*fcf3ce44SJohn Forte ind_byte(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1233*fcf3ce44SJohn Forte {
1234*fcf3ce44SJohn Forte 	int num;
1235*fcf3ce44SJohn Forte 
1236*fcf3ce44SJohn Forte 	if (argc < 1) {
1237*fcf3ce44SJohn Forte 		mdb_warn("must have an argument\n");
1238*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1239*fcf3ce44SJohn Forte 	}
1240*fcf3ce44SJohn Forte 	num = FBA_TO_LOG_NUM((int)mdb_strtoull(argv[0].a_un.a_str));
1241*fcf3ce44SJohn Forte 	mdb_printf("IND_BYTE: %d", IND_BYTE(num));
1242*fcf3ce44SJohn Forte 
1243*fcf3ce44SJohn Forte 	return (DCMD_OK);
1244*fcf3ce44SJohn Forte }
1245*fcf3ce44SJohn Forte 
1246*fcf3ce44SJohn Forte /*ARGSUSED*/
1247*fcf3ce44SJohn Forte static int
1248*fcf3ce44SJohn Forte ind_bit(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1249*fcf3ce44SJohn Forte {
1250*fcf3ce44SJohn Forte 	int num;
1251*fcf3ce44SJohn Forte 
1252*fcf3ce44SJohn Forte 	if (argc < 1) {
1253*fcf3ce44SJohn Forte 		mdb_warn("must have an argument\n");
1254*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1255*fcf3ce44SJohn Forte 	}
1256*fcf3ce44SJohn Forte 	num = FBA_TO_LOG_NUM((int)mdb_strtoull(argv[0].a_un.a_str));
1257*fcf3ce44SJohn Forte 	mdb_printf("IND_BIT: %d 0x%x", IND_BIT(num), IND_BIT(num));
1258*fcf3ce44SJohn Forte 
1259*fcf3ce44SJohn Forte 	return (DCMD_OK);
1260*fcf3ce44SJohn Forte }
1261*fcf3ce44SJohn Forte 
1262*fcf3ce44SJohn Forte static char *
1263*fcf3ce44SJohn Forte print_bit(uint_t bitmask)
1264*fcf3ce44SJohn Forte {
1265*fcf3ce44SJohn Forte 	int bitval = 1;
1266*fcf3ce44SJohn Forte 	int i;
1267*fcf3ce44SJohn Forte 
1268*fcf3ce44SJohn Forte 	bitstr[32] = '\0';
1269*fcf3ce44SJohn Forte 
1270*fcf3ce44SJohn Forte 	for (i = 31; i >= 0; i--) {
1271*fcf3ce44SJohn Forte 		if (bitmask & bitval) {
1272*fcf3ce44SJohn Forte 			bitstr[i] = '1';
1273*fcf3ce44SJohn Forte 		} else {
1274*fcf3ce44SJohn Forte 			bitstr[i] = '0';
1275*fcf3ce44SJohn Forte 		}
1276*fcf3ce44SJohn Forte 		bitval *= 2;
1277*fcf3ce44SJohn Forte 	}
1278*fcf3ce44SJohn Forte 	return (bitstr);
1279*fcf3ce44SJohn Forte }
1280*fcf3ce44SJohn Forte 
1281*fcf3ce44SJohn Forte /*ARGSUSED*/
1282*fcf3ce44SJohn Forte static int
1283*fcf3ce44SJohn Forte rdc_bitmask(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1284*fcf3ce44SJohn Forte {
1285*fcf3ce44SJohn Forte 	uint_t bitmask = 0;
1286*fcf3ce44SJohn Forte 	int first, st, en, pos, len;
1287*fcf3ce44SJohn Forte 
1288*fcf3ce44SJohn Forte 	if (argc < 2) {
1289*fcf3ce44SJohn Forte 		mdb_warn("must have 2 args (pos, len)\n");
1290*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1291*fcf3ce44SJohn Forte 	}
1292*fcf3ce44SJohn Forte 	pos = (int)mdb_strtoull(argv[0].a_un.a_str);
1293*fcf3ce44SJohn Forte 	len = (int)mdb_strtoull(argv[1].a_un.a_str);
1294*fcf3ce44SJohn Forte 
1295*fcf3ce44SJohn Forte 	if (len <= 0) {
1296*fcf3ce44SJohn Forte 		mdb_printf("non positive len specified");
1297*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1298*fcf3ce44SJohn Forte 	}
1299*fcf3ce44SJohn Forte 
1300*fcf3ce44SJohn Forte 	if ((len - pos) > 2048) {
1301*fcf3ce44SJohn Forte 		mdb_printf("len out of range, 32 bit bitmask");
1302*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1303*fcf3ce44SJohn Forte 	}
1304*fcf3ce44SJohn Forte 
1305*fcf3ce44SJohn Forte 	first = st = FBA_TO_LOG_NUM(pos);
1306*fcf3ce44SJohn Forte 	en = FBA_TO_LOG_NUM(pos + len - 1);
1307*fcf3ce44SJohn Forte 	while (st <= en) {
1308*fcf3ce44SJohn Forte 		BMAP_BIT_SET((uchar_t *)&bitmask, st - first);
1309*fcf3ce44SJohn Forte 		st++;
1310*fcf3ce44SJohn Forte 	}
1311*fcf3ce44SJohn Forte 
1312*fcf3ce44SJohn Forte 	mdb_printf("bitmask for POS: %d LEN: %d : 0x%08x (%s)", pos, len,
1313*fcf3ce44SJohn Forte 	    bitmask & 0xffffffff, print_bit(bitmask));
1314*fcf3ce44SJohn Forte 	return (DCMD_OK);
1315*fcf3ce44SJohn Forte 
1316*fcf3ce44SJohn Forte }
1317*fcf3ce44SJohn Forte 
1318*fcf3ce44SJohn Forte /*
1319*fcf3ce44SJohn Forte  * Dump the bitmap of the krdc structure indicated by the index
1320*fcf3ce44SJohn Forte  * argument. Used by the ZatoIchi tests.
1321*fcf3ce44SJohn Forte  */
1322*fcf3ce44SJohn Forte /*ARGSUSED*/
1323*fcf3ce44SJohn Forte static int
1324*fcf3ce44SJohn Forte rdc_bmapdump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1325*fcf3ce44SJohn Forte {
1326*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info;
1327*fcf3ce44SJohn Forte 	int index;
1328*fcf3ce44SJohn Forte 	uintptr_t bmapaddr;
1329*fcf3ce44SJohn Forte 	uintptr_t bmapdata;
1330*fcf3ce44SJohn Forte 	unsigned char *data;
1331*fcf3ce44SJohn Forte 	int bmapsize;
1332*fcf3ce44SJohn Forte 	int i;
1333*fcf3ce44SJohn Forte 	int st = 0;
1334*fcf3ce44SJohn Forte 	int en = 0;
1335*fcf3ce44SJohn Forte 
1336*fcf3ce44SJohn Forte 	if (argc < 1) {
1337*fcf3ce44SJohn Forte 		mdb_warn("must have index argument\n");
1338*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1339*fcf3ce44SJohn Forte 	}
1340*fcf3ce44SJohn Forte 
1341*fcf3ce44SJohn Forte 	i = argc;
1342*fcf3ce44SJohn Forte 	if (i == 3) {
1343*fcf3ce44SJohn Forte 		en = (int)mdb_strtoull(argv[2].a_un.a_str);
1344*fcf3ce44SJohn Forte 		en = FBA_TO_LOG_NUM(en);
1345*fcf3ce44SJohn Forte 		i--;
1346*fcf3ce44SJohn Forte 	}
1347*fcf3ce44SJohn Forte 	if (i == 2) {
1348*fcf3ce44SJohn Forte 		st = (int)mdb_strtoull(argv[1].a_un.a_str);
1349*fcf3ce44SJohn Forte 		st = FBA_TO_LOG_NUM(st);
1350*fcf3ce44SJohn Forte 	}
1351*fcf3ce44SJohn Forte 
1352*fcf3ce44SJohn Forte 	index = (int)mdb_strtoull(argv[0].a_un.a_str);
1353*fcf3ce44SJohn Forte 	/*
1354*fcf3ce44SJohn Forte 	 * Find out where in memory the rdc_k_kinfo array starts
1355*fcf3ce44SJohn Forte 	 */
1356*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
1357*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
1358*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1359*fcf3ce44SJohn Forte 	}
1360*fcf3ce44SJohn Forte 	bmapaddr = (uintptr_t)(&rdc_k_info[index].bitmap_size);
1361*fcf3ce44SJohn Forte 	if (mdb_vread(&bmapsize, sizeof (bmapsize), bmapaddr)
1362*fcf3ce44SJohn Forte 	    != sizeof (bmapsize)) {
1363*fcf3ce44SJohn Forte 		mdb_warn("failed to read dcio_bitmap at %p\n", bmapaddr);
1364*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1365*fcf3ce44SJohn Forte 	}
1366*fcf3ce44SJohn Forte 
1367*fcf3ce44SJohn Forte 	bmapaddr = (uintptr_t)(&rdc_k_info[index].dcio_bitmap);
1368*fcf3ce44SJohn Forte 	if (mdb_vread(&bmapdata, sizeof (bmapdata), bmapaddr)
1369*fcf3ce44SJohn Forte 	    != sizeof (bmapdata)) {
1370*fcf3ce44SJohn Forte 		mdb_warn("failed to read dcio_bitmap at %p\n", bmapaddr);
1371*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1372*fcf3ce44SJohn Forte 	}
1373*fcf3ce44SJohn Forte 	data = mdb_zalloc(bmapsize, UM_SLEEP);
1374*fcf3ce44SJohn Forte 
1375*fcf3ce44SJohn Forte 	if (mdb_vread(data, bmapsize, bmapdata) != bmapsize) {
1376*fcf3ce44SJohn Forte 		mdb_warn("failed to read the bitmap data\n");
1377*fcf3ce44SJohn Forte 		mdb_free(data, bmapsize);
1378*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1379*fcf3ce44SJohn Forte 	}
1380*fcf3ce44SJohn Forte 	mdb_printf("bitmap data address 0x%p bitmap size %d\n"
1381*fcf3ce44SJohn Forte 	    "kinfo 0x%p\n", bmapdata, bmapsize, &rdc_k_info[index]);
1382*fcf3ce44SJohn Forte 
1383*fcf3ce44SJohn Forte 	if ((st < 0) || ((st/8) > bmapsize) || (en < 0)) {
1384*fcf3ce44SJohn Forte 		mdb_warn("offset is out of range st %d bms %d en %d",
1385*fcf3ce44SJohn Forte 		    st, bmapsize, en);
1386*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1387*fcf3ce44SJohn Forte 	}
1388*fcf3ce44SJohn Forte 	if (((en/8) > bmapsize) || (en == 0))
1389*fcf3ce44SJohn Forte 		en = bmapsize * 8;
1390*fcf3ce44SJohn Forte 
1391*fcf3ce44SJohn Forte 	mdb_printf("bit start pos: %d bit end pos: %d\n\n", st, en);
1392*fcf3ce44SJohn Forte 	st /= 8;
1393*fcf3ce44SJohn Forte 	en /= 8;
1394*fcf3ce44SJohn Forte 	for (i = st; i < en; i++) {
1395*fcf3ce44SJohn Forte 		mdb_printf("%02x ", data[i] & 0xff);
1396*fcf3ce44SJohn Forte 		if ((i % 16) == 15) {
1397*fcf3ce44SJohn Forte 			int s = LOG_TO_FBA_NUM((i-15)*8);
1398*fcf3ce44SJohn Forte 			int e = LOG_TO_FBA_NUM(((i+1)*8)) - 1;
1399*fcf3ce44SJohn Forte 			mdb_printf(" fbas: %x - %x\n", s, e);
1400*fcf3ce44SJohn Forte 		}
1401*fcf3ce44SJohn Forte 	}
1402*fcf3ce44SJohn Forte 	mdb_printf("\n");
1403*fcf3ce44SJohn Forte 	mdb_free(data, bmapsize);
1404*fcf3ce44SJohn Forte 	return (DCMD_OK);
1405*fcf3ce44SJohn Forte }
1406*fcf3ce44SJohn Forte 
1407*fcf3ce44SJohn Forte /*
1408*fcf3ce44SJohn Forte  * dump the bitmap reference count
1409*fcf3ce44SJohn Forte  */
1410*fcf3ce44SJohn Forte /*ARGSUSED*/
1411*fcf3ce44SJohn Forte static int
1412*fcf3ce44SJohn Forte rdc_brefdump(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1413*fcf3ce44SJohn Forte {
1414*fcf3ce44SJohn Forte 	rdc_k_info_t *rdc_k_info;
1415*fcf3ce44SJohn Forte 	int index;
1416*fcf3ce44SJohn Forte 	uintptr_t bmapaddr;
1417*fcf3ce44SJohn Forte 	uintptr_t bmapdata;
1418*fcf3ce44SJohn Forte 	unsigned char *data;
1419*fcf3ce44SJohn Forte 	int bmapsize;
1420*fcf3ce44SJohn Forte 	int i;
1421*fcf3ce44SJohn Forte 	int st = 0;
1422*fcf3ce44SJohn Forte 	int en = 0;
1423*fcf3ce44SJohn Forte 
1424*fcf3ce44SJohn Forte 	if (argc < 1) {
1425*fcf3ce44SJohn Forte 		mdb_warn("must have index argument\n");
1426*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1427*fcf3ce44SJohn Forte 	}
1428*fcf3ce44SJohn Forte 	index = (int)mdb_strtoull(argv[0].a_un.a_str);
1429*fcf3ce44SJohn Forte 
1430*fcf3ce44SJohn Forte 	i = argc;
1431*fcf3ce44SJohn Forte 	if (i == 3) {
1432*fcf3ce44SJohn Forte 		en = (int)mdb_strtoull(argv[2].a_un.a_str);
1433*fcf3ce44SJohn Forte 		en = FBA_TO_LOG_NUM(en);
1434*fcf3ce44SJohn Forte 		i--;
1435*fcf3ce44SJohn Forte 
1436*fcf3ce44SJohn Forte 	}
1437*fcf3ce44SJohn Forte 	if (i == 2) {
1438*fcf3ce44SJohn Forte 		st = (int)mdb_strtoull(argv[1].a_un.a_str);
1439*fcf3ce44SJohn Forte 		st = FBA_TO_LOG_NUM(st);
1440*fcf3ce44SJohn Forte 	}
1441*fcf3ce44SJohn Forte 
1442*fcf3ce44SJohn Forte 	/*
1443*fcf3ce44SJohn Forte 	 * Find out where in memory the rdc_k_kinfo array starts
1444*fcf3ce44SJohn Forte 	 */
1445*fcf3ce44SJohn Forte 	if (mdb_readvar(&rdc_k_info, "rdc_k_info") == -1) {
1446*fcf3ce44SJohn Forte 		mdb_warn("failed to read 'rdc_k_info'");
1447*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1448*fcf3ce44SJohn Forte 	}
1449*fcf3ce44SJohn Forte 	bmapaddr = (uintptr_t)(&rdc_k_info[index].bitmap_size);
1450*fcf3ce44SJohn Forte 
1451*fcf3ce44SJohn Forte 	if (mdb_vread(&bmapsize, sizeof (bmapsize), bmapaddr)
1452*fcf3ce44SJohn Forte 	    != sizeof (bmapsize)) {
1453*fcf3ce44SJohn Forte 		mdb_warn("failed to read dcio_bitmap at %p\n", bmapaddr);
1454*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1455*fcf3ce44SJohn Forte 	}
1456*fcf3ce44SJohn Forte 
1457*fcf3ce44SJohn Forte 	bmapsize *= 8;
1458*fcf3ce44SJohn Forte 	bmapaddr = (uintptr_t)(&rdc_k_info[index].bitmap_ref);
1459*fcf3ce44SJohn Forte 
1460*fcf3ce44SJohn Forte 	if (mdb_vread(&bmapdata, sizeof (bmapdata), bmapaddr)
1461*fcf3ce44SJohn Forte 	    != sizeof (bmapdata)) {
1462*fcf3ce44SJohn Forte 		mdb_warn("failed to read dcio_bitmap at %p\n", bmapaddr);
1463*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1464*fcf3ce44SJohn Forte 	}
1465*fcf3ce44SJohn Forte 	data = mdb_zalloc(bmapsize, UM_SLEEP);
1466*fcf3ce44SJohn Forte 
1467*fcf3ce44SJohn Forte 	if (mdb_vread(data, bmapsize, bmapdata) != bmapsize) {
1468*fcf3ce44SJohn Forte 		mdb_warn("failed to read the bitmap data\n");
1469*fcf3ce44SJohn Forte 		mdb_free(data, bmapsize);
1470*fcf3ce44SJohn Forte 		return (DCMD_ERR);
1471*fcf3ce44SJohn Forte 	}
1472*fcf3ce44SJohn Forte 	mdb_printf("bitmap data address 0x%p bitmap size %d\n"
1473*fcf3ce44SJohn Forte 	    "kinfo 0x%p\n", bmapdata, bmapsize, &rdc_k_info[index]);
1474*fcf3ce44SJohn Forte 
1475*fcf3ce44SJohn Forte 	if ((st < 0) || (st > bmapsize) || (en < 0)) {
1476*fcf3ce44SJohn Forte 		mdb_warn("offset is out of range");
1477*fcf3ce44SJohn Forte 	}
1478*fcf3ce44SJohn Forte 	if ((en > bmapsize) || (en == 0))
1479*fcf3ce44SJohn Forte 		en = bmapsize;
1480*fcf3ce44SJohn Forte 
1481*fcf3ce44SJohn Forte 	mdb_printf("bit start pos: %d bit end pos: %d\n\n", st, en);
1482*fcf3ce44SJohn Forte 
1483*fcf3ce44SJohn Forte 	for (i = st; i < en; i++) {
1484*fcf3ce44SJohn Forte 		mdb_printf("%02x ", data[i] & 0xff);
1485*fcf3ce44SJohn Forte 		if ((i % 16) == 15) {
1486*fcf3ce44SJohn Forte 			int s = LOG_TO_FBA_NUM(i-15);
1487*fcf3ce44SJohn Forte 			int e = LOG_TO_FBA_NUM(i+1) - 1;
1488*fcf3ce44SJohn Forte 			mdb_printf(" fbas: 0x%x - 0x%x \n", s, e);
1489*fcf3ce44SJohn Forte 		}
1490*fcf3ce44SJohn Forte 	}
1491*fcf3ce44SJohn Forte 	mdb_printf("\n");
1492*fcf3ce44SJohn Forte 	mdb_free(data, bmapsize);
1493*fcf3ce44SJohn Forte 	return (DCMD_OK);
1494*fcf3ce44SJohn Forte }
1495*fcf3ce44SJohn Forte 
1496*fcf3ce44SJohn Forte static int
1497*fcf3ce44SJohn Forte rdc_bmapnref(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
1498*fcf3ce44SJohn Forte {
1499*fcf3ce44SJohn Forte 	mdb_printf("\nRDC bitmap info\n");
1500*fcf3ce44SJohn Forte 	rdc_bmapdump(addr, flags, argc, argv);
1501*fcf3ce44SJohn Forte 	mdb_printf("RDC bitmap reference count info\n");
1502*fcf3ce44SJohn Forte 	rdc_brefdump(addr, flags, argc, argv);
1503*fcf3ce44SJohn Forte 	return (DCMD_OK);
1504*fcf3ce44SJohn Forte }
1505*fcf3ce44SJohn Forte 
1506*fcf3ce44SJohn Forte #endif
1507*fcf3ce44SJohn Forte /*
1508*fcf3ce44SJohn Forte  * MDB module linkage information:
1509*fcf3ce44SJohn Forte  */
1510*fcf3ce44SJohn Forte 
1511*fcf3ce44SJohn Forte static const mdb_dcmd_t dcmds[] = {
1512*fcf3ce44SJohn Forte 	{ "rdc", NULL, "display sndr module info", rdc },
1513*fcf3ce44SJohn Forte 	{ "rdc_buf", "?[-v]", "rdc_buf structure", rdc_buf },
1514*fcf3ce44SJohn Forte 	{ "rdc_kinfo", "?[-av]", "rdc_k_info structure", rdc_kinfo },
1515*fcf3ce44SJohn Forte 	{ "rdc_uinfo", "?[-av]", "rdc_u_info structure", rdc_uinfo },
1516*fcf3ce44SJohn Forte 	{ "rdc_group", "?", "rdc group structure", rdc_group },
1517*fcf3ce44SJohn Forte 	{ "rdc_srv", "?", "rdc_srv structure", rdc_srv },
1518*fcf3ce44SJohn Forte 	{ "rdc_if", "?", "rdc_if structure", rdc_if },
1519*fcf3ce44SJohn Forte 	{ "rdc_infodev", "?", "rdc_info_dev structure", rdc_infodev },
1520*fcf3ce44SJohn Forte 	{ "rdc_k2u", "?", "rdc_kinfo to rdc_uinfo", rdc_k2u },
1521*fcf3ce44SJohn Forte 	{ "rdc_u2k", "?", "rdc_uinfo to rdc_kinfo", rdc_u2k },
1522*fcf3ce44SJohn Forte 	{ "rdc_aio", "?", "rdc_aio structure", rdc_aio},
1523*fcf3ce44SJohn Forte 	{ "rdc_iohdr", "?", "rdc_iohdr structure", rdc_iohdr},
1524*fcf3ce44SJohn Forte #ifdef DEBUG
1525*fcf3ce44SJohn Forte 	{ "rdc_setseq", "?", "Write seq field in group", rdc_setseq },
1526*fcf3ce44SJohn Forte 	{ "rdc_setseqack", "?", "Write seqack field in group", rdc_setseqack },
1527*fcf3ce44SJohn Forte 	{ "rdc_dset", "?", "Dump dset info", rdc_dset },
1528*fcf3ce44SJohn Forte 	{ "rdc_bmapdump", "?", "Dump bitmap", rdc_bmapdump },
1529*fcf3ce44SJohn Forte 	{ "rdc_brefdump", "?", "Dump bitmap reference count", rdc_brefdump },
1530*fcf3ce44SJohn Forte 	{ "rdc_bmapnref", "?", "Dump bitmap and ref count", rdc_bmapnref },
1531*fcf3ce44SJohn Forte 	{ "rdc_fba2log", "?", "fba to log num", fba_to_log_num },
1532*fcf3ce44SJohn Forte 	{ "rdc_log2fba", "?", "log to fba num", log_to_fba_num },
1533*fcf3ce44SJohn Forte 	{ "rdc_bitisset", "?", "check bit set", bmap_bit_isset },
1534*fcf3ce44SJohn Forte 	{ "rdc_brefisset", "?", "check bit ref set", bmap_bitref_isset },
1535*fcf3ce44SJohn Forte 	{ "rdc_indbyte", "?", "print indbyte", ind_byte },
1536*fcf3ce44SJohn Forte 	{ "rdc_indbit", "?", "print indbit", ind_bit },
1537*fcf3ce44SJohn Forte 	{ "rdc_bitmask", "?", "print bitmask for pos->len", rdc_bitmask },
1538*fcf3ce44SJohn Forte #endif
1539*fcf3ce44SJohn Forte 	{ NULL }
1540*fcf3ce44SJohn Forte };
1541*fcf3ce44SJohn Forte 
1542*fcf3ce44SJohn Forte 
1543*fcf3ce44SJohn Forte static const mdb_walker_t walkers[] = {
1544*fcf3ce44SJohn Forte 	{ "rdc_kinfo", "walk the rdc_k_info array",
1545*fcf3ce44SJohn Forte 	    rdc_k_info_winit, rdc_k_info_wstep, rdc_k_info_wfini },
1546*fcf3ce44SJohn Forte 	{ "rdc_uinfo", "walk the rdc_u_info array",
1547*fcf3ce44SJohn Forte 	    rdc_u_info_winit, rdc_u_info_wstep, rdc_u_info_wfini },
1548*fcf3ce44SJohn Forte 	{ "rdc_if", "walk rdc_if chain",
1549*fcf3ce44SJohn Forte 	    rdc_if_winit, rdc_if_wstep, rdc_if_wfini },
1550*fcf3ce44SJohn Forte 	{ NULL }
1551*fcf3ce44SJohn Forte };
1552*fcf3ce44SJohn Forte 
1553*fcf3ce44SJohn Forte 
1554*fcf3ce44SJohn Forte static const mdb_modinfo_t modinfo = {
1555*fcf3ce44SJohn Forte 	MDB_API_VERSION, dcmds, walkers
1556*fcf3ce44SJohn Forte };
1557*fcf3ce44SJohn Forte 
1558*fcf3ce44SJohn Forte 
1559*fcf3ce44SJohn Forte const mdb_modinfo_t *
1560*fcf3ce44SJohn Forte _mdb_init(void)
1561*fcf3ce44SJohn Forte {
1562*fcf3ce44SJohn Forte 	return (&modinfo);
1563*fcf3ce44SJohn Forte }
1564