xref: /onnv-gate/usr/src/cmd/mdb/common/modules/sd/sd.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24*0Sstevel@tonic-gate  * Use is subject to license terms.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <sys/mdb_modapi.h>
30*0Sstevel@tonic-gate #include <sys/scsi/scsi.h>
31*0Sstevel@tonic-gate #include <sys/dkio.h>
32*0Sstevel@tonic-gate #include <sys/taskq.h>
33*0Sstevel@tonic-gate #include <sys/scsi/targets/sddef.h>
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate /* Represents global soft state data in walk_step, walk_init */
36*0Sstevel@tonic-gate #define	SD_DATA(param)	((sd_str_p)wsp->walk_data)->param
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate /* Represents global soft state data in callback and related routines */
39*0Sstevel@tonic-gate #define	SD_DATA_IN_CBACK(param)	((sd_str_p)walk_data)->param
40*0Sstevel@tonic-gate 
41*0Sstevel@tonic-gate #define	SUCCESS			WALK_NEXT
42*0Sstevel@tonic-gate #define	FAIL			WALK_ERR
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate /*
45*0Sstevel@tonic-gate  * Primary attribute struct for buf extensions.
46*0Sstevel@tonic-gate  */
47*0Sstevel@tonic-gate struct __ddi_xbuf_attr {
48*0Sstevel@tonic-gate 	kmutex_t	xa_mutex;
49*0Sstevel@tonic-gate 	size_t		xa_allocsize;
50*0Sstevel@tonic-gate 	uint32_t	xa_pending;	/* call to xbuf_iostart() is iminent */
51*0Sstevel@tonic-gate 	uint32_t	xa_active_limit;
52*0Sstevel@tonic-gate 	uint32_t	xa_active_count;
53*0Sstevel@tonic-gate 	uint32_t	xa_active_lowater;
54*0Sstevel@tonic-gate 	struct buf	*xa_headp;	/* FIFO buf queue head ptr */
55*0Sstevel@tonic-gate 	struct buf	*xa_tailp;	/* FIFO buf queue tail ptr */
56*0Sstevel@tonic-gate 	kmutex_t	xa_reserve_mutex;
57*0Sstevel@tonic-gate 	uint32_t	xa_reserve_limit;
58*0Sstevel@tonic-gate 	uint32_t	xa_reserve_count;
59*0Sstevel@tonic-gate 	void		*xa_reserve_headp;
60*0Sstevel@tonic-gate 	void		(*xa_strategy)(struct buf *, void *, void *);
61*0Sstevel@tonic-gate 	void		*xa_attr_arg;
62*0Sstevel@tonic-gate 	timeout_id_t	xa_timeid;
63*0Sstevel@tonic-gate 	taskq_t		*xa_tq;
64*0Sstevel@tonic-gate };
65*0Sstevel@tonic-gate 
66*0Sstevel@tonic-gate /*
67*0Sstevel@tonic-gate  * Provides soft state information like the number of elements, pointer
68*0Sstevel@tonic-gate  * to soft state elements etc
69*0Sstevel@tonic-gate  */
70*0Sstevel@tonic-gate typedef struct i_ddi_soft_state sd_state_str_t, *sd_state_str_ptr;
71*0Sstevel@tonic-gate 
72*0Sstevel@tonic-gate /* structure to store soft state statistics */
73*0Sstevel@tonic-gate typedef struct sd_str {
74*0Sstevel@tonic-gate 	void		*sd_state;
75*0Sstevel@tonic-gate 	uintptr_t 	current_root;
76*0Sstevel@tonic-gate 	int		current_list_count;
77*0Sstevel@tonic-gate 	int		valid_root_count;
78*0Sstevel@tonic-gate 	int		silent;
79*0Sstevel@tonic-gate 	sd_state_str_t	sd_state_data;
80*0Sstevel@tonic-gate } sd_str_t, *sd_str_p;
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate 
83*0Sstevel@tonic-gate /*
84*0Sstevel@tonic-gate  *    Function: buf_avforw_walk_init
85*0Sstevel@tonic-gate  *
86*0Sstevel@tonic-gate  * Description: MDB calls the init function to initiate the walk,
87*0Sstevel@tonic-gate  *		in response to mdb_walk() function called by the
88*0Sstevel@tonic-gate  *		dcmd 'buf_avforw' or when the user executes the
89*0Sstevel@tonic-gate  *		walk dcmd 'address::walk buf_avforw'.
90*0Sstevel@tonic-gate  *
91*0Sstevel@tonic-gate  *   Arguments: new mdb_walk_state_t structure. A new structure is
92*0Sstevel@tonic-gate  *		created for each walk, so that multiple instances of
93*0Sstevel@tonic-gate  *		the walker can be active simultaneously.
94*0Sstevel@tonic-gate  */
95*0Sstevel@tonic-gate static int
buf_avforw_walk_init(mdb_walk_state_t * wsp)96*0Sstevel@tonic-gate buf_avforw_walk_init(mdb_walk_state_t *wsp)
97*0Sstevel@tonic-gate {
98*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
99*0Sstevel@tonic-gate 		mdb_warn("buffer address required with the command\n");
100*0Sstevel@tonic-gate 		return (WALK_ERR);
101*0Sstevel@tonic-gate 	}
102*0Sstevel@tonic-gate 
103*0Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc(sizeof (buf_t), UM_SLEEP);
104*0Sstevel@tonic-gate 	return (WALK_NEXT);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate 
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate /*
109*0Sstevel@tonic-gate  *    Function: buf_avforw_walk_step
110*0Sstevel@tonic-gate  *
111*0Sstevel@tonic-gate  * Description: The step function is invoked by the walker during each
112*0Sstevel@tonic-gate  *		iteration. Its primary job is to determine the address
113*0Sstevel@tonic-gate  *		of the next 'buf_avforw' object, read in the local copy
114*0Sstevel@tonic-gate  *		of this object, call the callback 'buf_callback' function,
115*0Sstevel@tonic-gate  *		and return its status. The iteration is terminated when
116*0Sstevel@tonic-gate  *		the walker encounters a null queue pointer which signifies
117*0Sstevel@tonic-gate  *		end of queue.
118*0Sstevel@tonic-gate  *
119*0Sstevel@tonic-gate  *   Arguments: mdb_walk_state_t structure
120*0Sstevel@tonic-gate  */
121*0Sstevel@tonic-gate static int
buf_avforw_walk_step(mdb_walk_state_t * wsp)122*0Sstevel@tonic-gate buf_avforw_walk_step(mdb_walk_state_t *wsp)
123*0Sstevel@tonic-gate {
124*0Sstevel@tonic-gate 	int		status;
125*0Sstevel@tonic-gate 
126*0Sstevel@tonic-gate 	/*
127*0Sstevel@tonic-gate 	 * if walk_addr is null then it effectively means an end of all
128*0Sstevel@tonic-gate 	 * buf structures, hence end the iterations.
129*0Sstevel@tonic-gate 	 */
130*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
131*0Sstevel@tonic-gate 		return (WALK_DONE);
132*0Sstevel@tonic-gate 	}
133*0Sstevel@tonic-gate 
134*0Sstevel@tonic-gate 	/*
135*0Sstevel@tonic-gate 	 * Read the contents of the current object, invoke the callback
136*0Sstevel@tonic-gate 	 * and assign the next objects address to mdb_walk_state_t structure.
137*0Sstevel@tonic-gate 	 */
138*0Sstevel@tonic-gate 	if (mdb_vread(wsp->walk_data, sizeof (buf_t), wsp->walk_addr) == -1) {
139*0Sstevel@tonic-gate 		mdb_warn("failed to read buf at %p", wsp->walk_addr);
140*0Sstevel@tonic-gate 		return (WALK_DONE);
141*0Sstevel@tonic-gate 	}
142*0Sstevel@tonic-gate 
143*0Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, wsp->walk_data,
144*0Sstevel@tonic-gate 							    wsp->walk_cbdata);
145*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)(((buf_t *)wsp->walk_data)->av_forw);
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate 	return (status);
148*0Sstevel@tonic-gate }
149*0Sstevel@tonic-gate 
150*0Sstevel@tonic-gate /*
151*0Sstevel@tonic-gate  *    Function: buf_callback
152*0Sstevel@tonic-gate  *
153*0Sstevel@tonic-gate  * Description: This is the callback function called by the 'buf_avforw'
154*0Sstevel@tonic-gate  *		walker when 'buf_avforw' dcmd is invoked.
155*0Sstevel@tonic-gate  *		It is called during each walk step. It displays the contents
156*0Sstevel@tonic-gate  *		of the current object (addr) passed to it by the step
157*0Sstevel@tonic-gate  *		function. It also prints the header and footer during the
158*0Sstevel@tonic-gate  *		first and the last iteration of the walker.
159*0Sstevel@tonic-gate  *
160*0Sstevel@tonic-gate  *   Arguments: addr -> current buf_avforw objects address.
161*0Sstevel@tonic-gate  *		walk_data -> private storage for the walker.
162*0Sstevel@tonic-gate  *		buf_entries -> private data for the callback. It represents
163*0Sstevel@tonic-gate  *		the count of objects processed so far.
164*0Sstevel@tonic-gate  */
165*0Sstevel@tonic-gate static int
buf_callback(uintptr_t addr,const void * walk_data,void * buf_entries)166*0Sstevel@tonic-gate buf_callback(uintptr_t addr, const void *walk_data, void *buf_entries)
167*0Sstevel@tonic-gate {
168*0Sstevel@tonic-gate 	int	*count = (int *)buf_entries;
169*0Sstevel@tonic-gate 
170*0Sstevel@tonic-gate 	/*
171*0Sstevel@tonic-gate 	 * If this is the first invocation of the command, print a
172*0Sstevel@tonic-gate 	 * header line for the output that will follow.
173*0Sstevel@tonic-gate 	 */
174*0Sstevel@tonic-gate 	if (*count == 0) {
175*0Sstevel@tonic-gate 		mdb_printf("============================\n");
176*0Sstevel@tonic-gate 		mdb_printf("Walking buf list via av_forw\n");
177*0Sstevel@tonic-gate 		mdb_printf("============================\n");
178*0Sstevel@tonic-gate 	}
179*0Sstevel@tonic-gate 
180*0Sstevel@tonic-gate 	/*
181*0Sstevel@tonic-gate 	 * read the object and print the contents.
182*0Sstevel@tonic-gate 	 */
183*0Sstevel@tonic-gate 	mdb_set_dot(addr);
184*0Sstevel@tonic-gate 	mdb_eval("$<buf");
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate 	mdb_printf("---\n");
187*0Sstevel@tonic-gate 	(*count)++;
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate 	/* if this is the last entry and print the footer */
190*0Sstevel@tonic-gate 	if (((buf_t *)walk_data)->av_forw == NULL) {
191*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
192*0Sstevel@tonic-gate 		mdb_printf("Processed %d Buf entries\n", *count);
193*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
194*0Sstevel@tonic-gate 		return (WALK_DONE);
195*0Sstevel@tonic-gate 	}
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate 	return (WALK_NEXT);
198*0Sstevel@tonic-gate }
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate /*
201*0Sstevel@tonic-gate  *    Function: buf_avforw_walk_fini
202*0Sstevel@tonic-gate  *
203*0Sstevel@tonic-gate  * Description: The buf_avforw_walk_fini is called when the walk is terminated
204*0Sstevel@tonic-gate  *		in response to WALK_DONE in buf_avforw_walk_step. It frees
205*0Sstevel@tonic-gate  *		the walk_data structure.
206*0Sstevel@tonic-gate  *
207*0Sstevel@tonic-gate  *   Arguments: mdb_walk_state_t structure
208*0Sstevel@tonic-gate  */
209*0Sstevel@tonic-gate static void
buf_avforw_walk_fini(mdb_walk_state_t * wsp)210*0Sstevel@tonic-gate buf_avforw_walk_fini(mdb_walk_state_t *wsp)
211*0Sstevel@tonic-gate {
212*0Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (buf_t));
213*0Sstevel@tonic-gate }
214*0Sstevel@tonic-gate 
215*0Sstevel@tonic-gate /*
216*0Sstevel@tonic-gate  *    Function: dump_xbuf_attr
217*0Sstevel@tonic-gate  *
218*0Sstevel@tonic-gate  * Description: Prints the contents of Xbuf queue.
219*0Sstevel@tonic-gate  *
220*0Sstevel@tonic-gate  *   Arguments: object contents pointer and address.
221*0Sstevel@tonic-gate  */
222*0Sstevel@tonic-gate static void
dump_xbuf_attr(struct __ddi_xbuf_attr * xba_ptr,uintptr_t mem_addr)223*0Sstevel@tonic-gate dump_xbuf_attr(struct __ddi_xbuf_attr *xba_ptr, uintptr_t mem_addr)
224*0Sstevel@tonic-gate {
225*0Sstevel@tonic-gate 	mdb_printf("0x%8lx:\tmutex\t\tallocsize\tpending\n",
226*0Sstevel@tonic-gate 		mem_addr + offsetof(struct __ddi_xbuf_attr, xa_mutex));
227*0Sstevel@tonic-gate 
228*0Sstevel@tonic-gate 	mdb_printf("           \t%lx\t\t%d\t\t%d\n",
229*0Sstevel@tonic-gate 		xba_ptr->xa_mutex._opaque[0], xba_ptr->xa_allocsize,
230*0Sstevel@tonic-gate 							xba_ptr->xa_pending);
231*0Sstevel@tonic-gate 	mdb_printf("0x%8lx:\tactive_limit\tactive_count\tactive_lowater\n",
232*0Sstevel@tonic-gate 		mem_addr + offsetof(struct __ddi_xbuf_attr, xa_active_limit));
233*0Sstevel@tonic-gate 
234*0Sstevel@tonic-gate 	mdb_printf("           \t%lx\t\t%lx\t\t%lx\n",
235*0Sstevel@tonic-gate 		xba_ptr->xa_active_limit, xba_ptr->xa_active_count,
236*0Sstevel@tonic-gate 						xba_ptr->xa_active_lowater);
237*0Sstevel@tonic-gate 	mdb_printf("0x%8lx:\theadp\t\ttailp\n",
238*0Sstevel@tonic-gate 		mem_addr + offsetof(struct __ddi_xbuf_attr, xa_headp));
239*0Sstevel@tonic-gate 
240*0Sstevel@tonic-gate 	mdb_printf("           \t%lx%c\t%lx\n",
241*0Sstevel@tonic-gate 		xba_ptr->xa_headp, (xba_ptr->xa_headp == 0?'\t':' '),
242*0Sstevel@tonic-gate 							xba_ptr->xa_tailp);
243*0Sstevel@tonic-gate 	mdb_printf(
244*0Sstevel@tonic-gate 	"0x%8lx:\treserve_mutex\treserve_limit\treserve_count\treserve_headp\n",
245*0Sstevel@tonic-gate 		mem_addr + offsetof(struct __ddi_xbuf_attr, xa_reserve_mutex));
246*0Sstevel@tonic-gate 
247*0Sstevel@tonic-gate 	mdb_printf("           \t%lx\t\t%lx\t\t%lx\t\t%lx\n",
248*0Sstevel@tonic-gate 		xba_ptr->xa_reserve_mutex._opaque[0], xba_ptr->xa_reserve_limit,
249*0Sstevel@tonic-gate 		xba_ptr->xa_reserve_count, xba_ptr->xa_reserve_headp);
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate 	mdb_printf("0x%8lx:\ttimeid\t\ttq\n",
252*0Sstevel@tonic-gate 		mem_addr + offsetof(struct __ddi_xbuf_attr, xa_timeid));
253*0Sstevel@tonic-gate 
254*0Sstevel@tonic-gate 	mdb_printf("           \t%lx%c\t%lx\n",
255*0Sstevel@tonic-gate 		xba_ptr->xa_timeid, (xba_ptr->xa_timeid == 0?'\t':' '),
256*0Sstevel@tonic-gate 								xba_ptr->xa_tq);
257*0Sstevel@tonic-gate }
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate /*
260*0Sstevel@tonic-gate  *    Function: init_softstate_members
261*0Sstevel@tonic-gate  *
262*0Sstevel@tonic-gate  * Description: Initialize mdb_walk_state_t structure with either 'sd' or
263*0Sstevel@tonic-gate  *		'ssd' related information.
264*0Sstevel@tonic-gate  *
265*0Sstevel@tonic-gate  *   Arguments: new mdb_walk_state_t structure
266*0Sstevel@tonic-gate  */
267*0Sstevel@tonic-gate static int
init_softstate_members(mdb_walk_state_t * wsp)268*0Sstevel@tonic-gate init_softstate_members(mdb_walk_state_t *wsp)
269*0Sstevel@tonic-gate {
270*0Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc(sizeof (sd_str_t), UM_SLEEP);
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate 	/*
273*0Sstevel@tonic-gate 	 * store the soft state statistics variables like non-zero
274*0Sstevel@tonic-gate 	 * soft state entries, base address, actual count of soft state
275*0Sstevel@tonic-gate 	 * processed etc.
276*0Sstevel@tonic-gate 	 */
277*0Sstevel@tonic-gate 	SD_DATA(sd_state) = (sd_state_str_ptr)wsp->walk_addr;
278*0Sstevel@tonic-gate 
279*0Sstevel@tonic-gate 	SD_DATA(current_list_count) = 0;
280*0Sstevel@tonic-gate 	SD_DATA(valid_root_count) = 0;
281*0Sstevel@tonic-gate 
282*0Sstevel@tonic-gate 	if (mdb_vread((void *)&SD_DATA(sd_state_data),
283*0Sstevel@tonic-gate 			sizeof (sd_state_str_t), wsp->walk_addr) == -1) {
284*0Sstevel@tonic-gate 		mdb_warn("failed to sd_state at %p", wsp->walk_addr);
285*0Sstevel@tonic-gate 		return (WALK_ERR);
286*0Sstevel@tonic-gate 	}
287*0Sstevel@tonic-gate 
288*0Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)(SD_DATA(sd_state_data.array));
289*0Sstevel@tonic-gate 
290*0Sstevel@tonic-gate 	SD_DATA(current_root) = wsp->walk_addr;
291*0Sstevel@tonic-gate 	return (WALK_NEXT);
292*0Sstevel@tonic-gate }
293*0Sstevel@tonic-gate 
294*0Sstevel@tonic-gate #if (!defined(__fibre))
295*0Sstevel@tonic-gate /*
296*0Sstevel@tonic-gate  *    Function: sd_state_walk_init
297*0Sstevel@tonic-gate  *
298*0Sstevel@tonic-gate  * Description: MDB calls the init function to initiate the walk,
299*0Sstevel@tonic-gate  *		in response to mdb_walk() function called by the
300*0Sstevel@tonic-gate  *		dcmd 'sd_state' or when the user executes the
301*0Sstevel@tonic-gate  *		walk dcmd '::walk sd_state'.
302*0Sstevel@tonic-gate  *		The init function initializes the walker to either
303*0Sstevel@tonic-gate  *		the user specified address or the default kernel
304*0Sstevel@tonic-gate  *		'sd_state' pointer.
305*0Sstevel@tonic-gate  *
306*0Sstevel@tonic-gate  *   Arguments: new mdb_walk_state_t structure
307*0Sstevel@tonic-gate  */
308*0Sstevel@tonic-gate static int
sd_state_walk_init(mdb_walk_state_t * wsp)309*0Sstevel@tonic-gate sd_state_walk_init(mdb_walk_state_t *wsp)
310*0Sstevel@tonic-gate {
311*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL &&
312*0Sstevel@tonic-gate 	    mdb_readvar(&wsp->walk_addr, "sd_state") == -1) {
313*0Sstevel@tonic-gate 		mdb_warn("failed to read 'sd_state'");
314*0Sstevel@tonic-gate 		return (WALK_ERR);
315*0Sstevel@tonic-gate 	}
316*0Sstevel@tonic-gate 
317*0Sstevel@tonic-gate 	return (init_softstate_members(wsp));
318*0Sstevel@tonic-gate }
319*0Sstevel@tonic-gate 
320*0Sstevel@tonic-gate #else
321*0Sstevel@tonic-gate 
322*0Sstevel@tonic-gate /*
323*0Sstevel@tonic-gate  *    Function: ssd_state_walk_init
324*0Sstevel@tonic-gate  *
325*0Sstevel@tonic-gate  * Description: MDB calls the init function to initiate the walk,
326*0Sstevel@tonic-gate  *		in response to mdb_walk() function called by the
327*0Sstevel@tonic-gate  *		dcmd 'ssd_state' or when the user executes the
328*0Sstevel@tonic-gate  *		walk dcmd '::walk ssd_state'.
329*0Sstevel@tonic-gate  *		The init function initializes the walker to either
330*0Sstevel@tonic-gate  *		the user specified address or the default kernel
331*0Sstevel@tonic-gate  *		'ssd_state' pointer.
332*0Sstevel@tonic-gate  *
333*0Sstevel@tonic-gate  *   Arguments: new mdb_walk_state_t structure
334*0Sstevel@tonic-gate  */
335*0Sstevel@tonic-gate static int
ssd_state_walk_init(mdb_walk_state_t * wsp)336*0Sstevel@tonic-gate ssd_state_walk_init(mdb_walk_state_t *wsp)
337*0Sstevel@tonic-gate {
338*0Sstevel@tonic-gate 	if (wsp->walk_addr == NULL &&
339*0Sstevel@tonic-gate 	    mdb_readvar(&wsp->walk_addr, "ssd_state") == -1) {
340*0Sstevel@tonic-gate 		mdb_warn("failed to read 'ssd_state'");
341*0Sstevel@tonic-gate 		return (WALK_ERR);
342*0Sstevel@tonic-gate 	}
343*0Sstevel@tonic-gate 
344*0Sstevel@tonic-gate 	return (init_softstate_members(wsp));
345*0Sstevel@tonic-gate }
346*0Sstevel@tonic-gate #endif
347*0Sstevel@tonic-gate 
348*0Sstevel@tonic-gate 
349*0Sstevel@tonic-gate /*
350*0Sstevel@tonic-gate  *    Function: sd_state_walk_step
351*0Sstevel@tonic-gate  *
352*0Sstevel@tonic-gate  * Description: The step function is invoked by the walker during each
353*0Sstevel@tonic-gate  *		iteration. Its primary job is to determine the address
354*0Sstevel@tonic-gate  *		of the next 'soft state' object, read in the local copy
355*0Sstevel@tonic-gate  *		of this object, call the callback 'sd_callback' function,
356*0Sstevel@tonic-gate  *		and return its status. The iteration is terminated when
357*0Sstevel@tonic-gate  *		the soft state counter equals the total soft state count
358*0Sstevel@tonic-gate  *		obtained initially.
359*0Sstevel@tonic-gate  *
360*0Sstevel@tonic-gate  *   Arguments: mdb_walk_state_t structure
361*0Sstevel@tonic-gate  */
362*0Sstevel@tonic-gate static int
sd_state_walk_step(mdb_walk_state_t * wsp)363*0Sstevel@tonic-gate sd_state_walk_step(mdb_walk_state_t *wsp)
364*0Sstevel@tonic-gate {
365*0Sstevel@tonic-gate 	int		status;
366*0Sstevel@tonic-gate 	void		*tp;
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate 	/*
369*0Sstevel@tonic-gate 	 * If all the soft state entries have been processed then stop
370*0Sstevel@tonic-gate 	 * future iterations.
371*0Sstevel@tonic-gate 	 */
372*0Sstevel@tonic-gate 	if (SD_DATA(current_list_count) >= SD_DATA(sd_state_data.n_items)) {
373*0Sstevel@tonic-gate 		return (WALK_DONE);
374*0Sstevel@tonic-gate 	}
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	/*
377*0Sstevel@tonic-gate 	 * read the object contents, invoke the callback and set the
378*0Sstevel@tonic-gate 	 * mdb_walk_state_t structure to the next object.
379*0Sstevel@tonic-gate 	 */
380*0Sstevel@tonic-gate 	if (mdb_vread(&tp, sizeof (void *), wsp->walk_addr) == -1) {
381*0Sstevel@tonic-gate 		mdb_warn("failed to read at %p", wsp->walk_addr);
382*0Sstevel@tonic-gate 		return (WALK_ERR);
383*0Sstevel@tonic-gate 	}
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 	status = wsp->walk_callback((uintptr_t)tp, wsp->walk_data,
386*0Sstevel@tonic-gate 							wsp->walk_cbdata);
387*0Sstevel@tonic-gate 	if (tp != 0) {
388*0Sstevel@tonic-gate 		/* Count the number of non-zero un entries. */
389*0Sstevel@tonic-gate 		SD_DATA(valid_root_count++);
390*0Sstevel@tonic-gate 	}
391*0Sstevel@tonic-gate 
392*0Sstevel@tonic-gate 	wsp->walk_addr += sizeof (void *);
393*0Sstevel@tonic-gate 	SD_DATA(current_list_count++);
394*0Sstevel@tonic-gate 	return (status);
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate 
397*0Sstevel@tonic-gate 
398*0Sstevel@tonic-gate /*
399*0Sstevel@tonic-gate  *    Function: sd_state_walk_fini
400*0Sstevel@tonic-gate  *
401*0Sstevel@tonic-gate  * Description: The sd_state_walk_fini is called when the walk is terminated
402*0Sstevel@tonic-gate  *		in response to WALK_DONE in sd_state_walk_step. It frees
403*0Sstevel@tonic-gate  *		the walk_data structure.
404*0Sstevel@tonic-gate  *
405*0Sstevel@tonic-gate  *   Arguments: mdb_walk_state_t structure
406*0Sstevel@tonic-gate  */
407*0Sstevel@tonic-gate static void
sd_state_walk_fini(mdb_walk_state_t * wsp)408*0Sstevel@tonic-gate sd_state_walk_fini(mdb_walk_state_t *wsp)
409*0Sstevel@tonic-gate {
410*0Sstevel@tonic-gate 	mdb_free(wsp->walk_data, sizeof (sd_str_t));
411*0Sstevel@tonic-gate }
412*0Sstevel@tonic-gate 
413*0Sstevel@tonic-gate /*
414*0Sstevel@tonic-gate  *    Function: process_semo_sleepq
415*0Sstevel@tonic-gate  *
416*0Sstevel@tonic-gate  * Description: Iterate over the semoclose wait Q members of the soft state.
417*0Sstevel@tonic-gate  *		Print the contents of each member. In case of silent mode
418*0Sstevel@tonic-gate  *		the contents are avoided and only the address is printed.
419*0Sstevel@tonic-gate  *
420*0Sstevel@tonic-gate  *   Arguments: starting queue address, print mode.
421*0Sstevel@tonic-gate  */
422*0Sstevel@tonic-gate static int
process_semo_sleepq(uintptr_t walk_addr,int silent)423*0Sstevel@tonic-gate process_semo_sleepq(uintptr_t	walk_addr, int silent)
424*0Sstevel@tonic-gate {
425*0Sstevel@tonic-gate 	uintptr_t	rootBuf;
426*0Sstevel@tonic-gate 	buf_t		currentBuf;
427*0Sstevel@tonic-gate 	int		semo_sleepq_count = 0;
428*0Sstevel@tonic-gate 
429*0Sstevel@tonic-gate 	/* Set up to process the device's semoclose wait Q */
430*0Sstevel@tonic-gate 	rootBuf = walk_addr;
431*0Sstevel@tonic-gate 
432*0Sstevel@tonic-gate 	if (!silent) {
433*0Sstevel@tonic-gate 		mdb_printf("\nSEMOCLOSE SLEEP Q:\n");
434*0Sstevel@tonic-gate 		mdb_printf("----------\n");
435*0Sstevel@tonic-gate 	}
436*0Sstevel@tonic-gate 
437*0Sstevel@tonic-gate 	mdb_printf("SEMOCLOSE sleep Q head: %lx\n", rootBuf);
438*0Sstevel@tonic-gate 
439*0Sstevel@tonic-gate 	while (rootBuf) {
440*0Sstevel@tonic-gate 		/* Process the device's cmd. wait Q */
441*0Sstevel@tonic-gate 		if (!silent) {
442*0Sstevel@tonic-gate 			mdb_printf("SEMOCLOSE SLEEP Q list entry:\n");
443*0Sstevel@tonic-gate 			mdb_printf("------------------\n");
444*0Sstevel@tonic-gate 		}
445*0Sstevel@tonic-gate 
446*0Sstevel@tonic-gate 		if (mdb_vread((void *)&currentBuf, sizeof (buf_t),
447*0Sstevel@tonic-gate 							rootBuf) == -1) {
448*0Sstevel@tonic-gate 			mdb_warn("failed to read buf at %p", rootBuf);
449*0Sstevel@tonic-gate 			return (FAIL);
450*0Sstevel@tonic-gate 		}
451*0Sstevel@tonic-gate 
452*0Sstevel@tonic-gate 		if (!silent) {
453*0Sstevel@tonic-gate 			mdb_set_dot(rootBuf);
454*0Sstevel@tonic-gate 			mdb_eval("$<buf");
455*0Sstevel@tonic-gate 			mdb_printf("---\n");
456*0Sstevel@tonic-gate 		}
457*0Sstevel@tonic-gate 		++semo_sleepq_count;
458*0Sstevel@tonic-gate 		rootBuf = (uintptr_t)currentBuf.av_forw;
459*0Sstevel@tonic-gate 	}
460*0Sstevel@tonic-gate 
461*0Sstevel@tonic-gate 	if (rootBuf == NULL) {
462*0Sstevel@tonic-gate 		mdb_printf("------------------------------\n");
463*0Sstevel@tonic-gate 		mdb_printf("Processed %d SEMOCLOSE SLEEP Q entries\n",
464*0Sstevel@tonic-gate 							semo_sleepq_count);
465*0Sstevel@tonic-gate 		mdb_printf("------------------------------\n");
466*0Sstevel@tonic-gate 
467*0Sstevel@tonic-gate 	}
468*0Sstevel@tonic-gate 	return (SUCCESS);
469*0Sstevel@tonic-gate }
470*0Sstevel@tonic-gate 
471*0Sstevel@tonic-gate /*
472*0Sstevel@tonic-gate  *    Function: process_sdlun_waitq
473*0Sstevel@tonic-gate  *
474*0Sstevel@tonic-gate  * Description: Iterate over the wait Q members of the soft state.
475*0Sstevel@tonic-gate  *		Print the contents of each member. In case of silent mode
476*0Sstevel@tonic-gate  *		the contents are avoided and only the address is printed.
477*0Sstevel@tonic-gate  *
478*0Sstevel@tonic-gate  *   Arguments: starting queue address, print mode.
479*0Sstevel@tonic-gate  */
480*0Sstevel@tonic-gate static int
process_sdlun_waitq(uintptr_t walk_addr,int silent)481*0Sstevel@tonic-gate process_sdlun_waitq(uintptr_t walk_addr, int silent)
482*0Sstevel@tonic-gate {
483*0Sstevel@tonic-gate 	uintptr_t	rootBuf;
484*0Sstevel@tonic-gate 	buf_t		currentBuf;
485*0Sstevel@tonic-gate 	int		sdLunQ_count = 0;
486*0Sstevel@tonic-gate 
487*0Sstevel@tonic-gate 	rootBuf = walk_addr;
488*0Sstevel@tonic-gate 
489*0Sstevel@tonic-gate 	if (!silent) {
490*0Sstevel@tonic-gate 		mdb_printf("\nUN WAIT Q:\n");
491*0Sstevel@tonic-gate 		mdb_printf("----------\n");
492*0Sstevel@tonic-gate 	}
493*0Sstevel@tonic-gate 	mdb_printf("UN wait Q head: %lx\n", rootBuf);
494*0Sstevel@tonic-gate 
495*0Sstevel@tonic-gate 	while (rootBuf) {
496*0Sstevel@tonic-gate 		/* Process the device's cmd. wait Q */
497*0Sstevel@tonic-gate 		if (!silent) {
498*0Sstevel@tonic-gate 			mdb_printf("UN WAIT Q list entry:\n");
499*0Sstevel@tonic-gate 			mdb_printf("------------------\n");
500*0Sstevel@tonic-gate 		}
501*0Sstevel@tonic-gate 
502*0Sstevel@tonic-gate 		if (mdb_vread(&currentBuf, sizeof (buf_t),
503*0Sstevel@tonic-gate 						(uintptr_t)rootBuf) == -1) {
504*0Sstevel@tonic-gate 			mdb_warn("failed to read buf at %p",
505*0Sstevel@tonic-gate 							(uintptr_t)rootBuf);
506*0Sstevel@tonic-gate 			return (FAIL);
507*0Sstevel@tonic-gate 		}
508*0Sstevel@tonic-gate 
509*0Sstevel@tonic-gate 		if (!silent) {
510*0Sstevel@tonic-gate 			mdb_set_dot(rootBuf);
511*0Sstevel@tonic-gate 			mdb_eval("$<buf");
512*0Sstevel@tonic-gate 			mdb_printf("---\n");
513*0Sstevel@tonic-gate 		}
514*0Sstevel@tonic-gate 
515*0Sstevel@tonic-gate 		rootBuf = (uintptr_t)currentBuf.av_forw;
516*0Sstevel@tonic-gate 		++sdLunQ_count;
517*0Sstevel@tonic-gate 	}
518*0Sstevel@tonic-gate 
519*0Sstevel@tonic-gate 	if (rootBuf == NULL) {
520*0Sstevel@tonic-gate 		mdb_printf("------------------------------\n");
521*0Sstevel@tonic-gate 		mdb_printf("Processed %d UN WAIT Q entries\n", sdLunQ_count);
522*0Sstevel@tonic-gate 		mdb_printf("------------------------------\n");
523*0Sstevel@tonic-gate 	}
524*0Sstevel@tonic-gate 
525*0Sstevel@tonic-gate 	return (SUCCESS);
526*0Sstevel@tonic-gate }
527*0Sstevel@tonic-gate 
528*0Sstevel@tonic-gate /*
529*0Sstevel@tonic-gate  *    Function: process_xbuf
530*0Sstevel@tonic-gate  *
531*0Sstevel@tonic-gate  * Description: Iterate over the Xbuf Attr and Xbuf Attr wait Q of the soft
532*0Sstevel@tonic-gate  *		state.
533*0Sstevel@tonic-gate  *		Print the contents of each member. In case of silent mode
534*0Sstevel@tonic-gate  *		the contents are avoided and only the address is printed.
535*0Sstevel@tonic-gate  *
536*0Sstevel@tonic-gate  *   Arguments: starting xbuf address, print mode.
537*0Sstevel@tonic-gate  */
538*0Sstevel@tonic-gate static int
process_xbuf(uintptr_t xbuf_attr,int silent)539*0Sstevel@tonic-gate process_xbuf(uintptr_t xbuf_attr, int silent)
540*0Sstevel@tonic-gate {
541*0Sstevel@tonic-gate 	struct __ddi_xbuf_attr	xba;
542*0Sstevel@tonic-gate 	buf_t			xba_current;
543*0Sstevel@tonic-gate 	void			*xba_root;
544*0Sstevel@tonic-gate 	int			xbuf_q_count = 0;
545*0Sstevel@tonic-gate 
546*0Sstevel@tonic-gate 	if (xbuf_attr == NULL) {
547*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
548*0Sstevel@tonic-gate 		mdb_printf("No XBUF ATTR entry\n");
549*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
550*0Sstevel@tonic-gate 		return (SUCCESS);
551*0Sstevel@tonic-gate 	}
552*0Sstevel@tonic-gate 
553*0Sstevel@tonic-gate 	/* Process the Xbuf Attr struct for a device. */
554*0Sstevel@tonic-gate 	if (mdb_vread((void *)&xba, sizeof (struct __ddi_xbuf_attr),
555*0Sstevel@tonic-gate 							xbuf_attr) == -1) {
556*0Sstevel@tonic-gate 		mdb_warn("failed to read xbuf_attr at %p", xbuf_attr);
557*0Sstevel@tonic-gate 		return (FAIL);
558*0Sstevel@tonic-gate 	}
559*0Sstevel@tonic-gate 
560*0Sstevel@tonic-gate 	if (!silent) {
561*0Sstevel@tonic-gate 		mdb_printf("\nXBUF ATTR:\n");
562*0Sstevel@tonic-gate 		mdb_printf("----------\n");
563*0Sstevel@tonic-gate 
564*0Sstevel@tonic-gate 		dump_xbuf_attr(&xba, xbuf_attr);
565*0Sstevel@tonic-gate 		mdb_printf("---\n");
566*0Sstevel@tonic-gate 
567*0Sstevel@tonic-gate 		mdb_printf("\nXBUF Q:\n");
568*0Sstevel@tonic-gate 		mdb_printf("-------\n");
569*0Sstevel@tonic-gate 	}
570*0Sstevel@tonic-gate 
571*0Sstevel@tonic-gate 	mdb_printf("xbuf Q head: %lx\n", xba.xa_headp);
572*0Sstevel@tonic-gate 
573*0Sstevel@tonic-gate 	xba_root = (void *) xba.xa_headp;
574*0Sstevel@tonic-gate 
575*0Sstevel@tonic-gate 	/* Process the Xbuf Attr wait Q, if there are any entries. */
576*0Sstevel@tonic-gate 	while ((uintptr_t)xba_root) {
577*0Sstevel@tonic-gate 		if (!silent) {
578*0Sstevel@tonic-gate 			mdb_printf("XBUF_Q list entry:\n");
579*0Sstevel@tonic-gate 			mdb_printf("------------------\n");
580*0Sstevel@tonic-gate 		}
581*0Sstevel@tonic-gate 
582*0Sstevel@tonic-gate 		if (mdb_vread((void *)&xba_current, sizeof (buf_t),
583*0Sstevel@tonic-gate 						(uintptr_t)xba_root) == -1) {
584*0Sstevel@tonic-gate 			mdb_warn("failed to read buf at %p",
585*0Sstevel@tonic-gate 							(uintptr_t)xba_root);
586*0Sstevel@tonic-gate 			return (FAIL);
587*0Sstevel@tonic-gate 		}
588*0Sstevel@tonic-gate 		if (!silent) {
589*0Sstevel@tonic-gate 			mdb_set_dot((uintptr_t)xba_root);
590*0Sstevel@tonic-gate 			mdb_eval("$<buf");
591*0Sstevel@tonic-gate 			mdb_printf("---\n");
592*0Sstevel@tonic-gate 		}
593*0Sstevel@tonic-gate 		++xbuf_q_count;
594*0Sstevel@tonic-gate 
595*0Sstevel@tonic-gate 		xba_root = (void *)xba_current.av_forw;
596*0Sstevel@tonic-gate 	}
597*0Sstevel@tonic-gate 
598*0Sstevel@tonic-gate 	if (xba_root == NULL) {
599*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
600*0Sstevel@tonic-gate 		mdb_printf("Processed %d XBUF Q entries\n", xbuf_q_count);
601*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
602*0Sstevel@tonic-gate 	}
603*0Sstevel@tonic-gate 	return (SUCCESS);
604*0Sstevel@tonic-gate }
605*0Sstevel@tonic-gate 
606*0Sstevel@tonic-gate /*
607*0Sstevel@tonic-gate  *    Function: print_footer
608*0Sstevel@tonic-gate  *
609*0Sstevel@tonic-gate  * Description: Prints the footer if all the soft state entries are processed.
610*0Sstevel@tonic-gate  *
611*0Sstevel@tonic-gate  *   Arguments: private storage of the walker.
612*0Sstevel@tonic-gate  */
613*0Sstevel@tonic-gate static void
print_footer(const void * walk_data)614*0Sstevel@tonic-gate print_footer(const void *walk_data)
615*0Sstevel@tonic-gate {
616*0Sstevel@tonic-gate 	if (SD_DATA_IN_CBACK(current_list_count) >=
617*0Sstevel@tonic-gate 			(SD_DATA_IN_CBACK(sd_state_data.n_items) - 1)) {
618*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
619*0Sstevel@tonic-gate 		mdb_printf("Processed %d UN softstate entries\n",
620*0Sstevel@tonic-gate 					SD_DATA_IN_CBACK(valid_root_count));
621*0Sstevel@tonic-gate 		mdb_printf("---------------------------\n");
622*0Sstevel@tonic-gate 	}
623*0Sstevel@tonic-gate }
624*0Sstevel@tonic-gate 
625*0Sstevel@tonic-gate /*
626*0Sstevel@tonic-gate  *    Function: sd_callback
627*0Sstevel@tonic-gate  *
628*0Sstevel@tonic-gate  * Description: This is the callback function called by the
629*0Sstevel@tonic-gate  *		'sd_state/ssd_state' walker when 'sd_state/ssd_state' dcmd
630*0Sstevel@tonic-gate  *		invokes the walker.
631*0Sstevel@tonic-gate  *		It is called during each walk step. It displays the contents
632*0Sstevel@tonic-gate  *		of the current soft state object (addr) passed to it by the
633*0Sstevel@tonic-gate  * 		step function. It also prints the header and footer during the
634*0Sstevel@tonic-gate  *		first and the last step of the walker.
635*0Sstevel@tonic-gate  *		The contents of the soft state also includes various queues
636*0Sstevel@tonic-gate  *		it includes like Xbuf, semo_close, sdlun_waitq.
637*0Sstevel@tonic-gate  *
638*0Sstevel@tonic-gate  *   Arguments: addr -> current soft state objects address.
639*0Sstevel@tonic-gate  *		walk_data -> private storage for the walker.
640*0Sstevel@tonic-gate  *		flg_silent -> private data for the callback. It represents
641*0Sstevel@tonic-gate  *		the silent mode of operation.
642*0Sstevel@tonic-gate  */
643*0Sstevel@tonic-gate static int
sd_callback(uintptr_t addr,const void * walk_data,void * flg_silent)644*0Sstevel@tonic-gate sd_callback(uintptr_t addr, const void *walk_data, void *flg_silent)
645*0Sstevel@tonic-gate {
646*0Sstevel@tonic-gate 	struct sd_lun	sdLun;
647*0Sstevel@tonic-gate 	int		silent = *(int *)flg_silent;
648*0Sstevel@tonic-gate 
649*0Sstevel@tonic-gate 	/*
650*0Sstevel@tonic-gate 	 * If this is the first invocation of the command, print a
651*0Sstevel@tonic-gate 	 * header line for the output that will follow.
652*0Sstevel@tonic-gate 	 */
653*0Sstevel@tonic-gate 	if (SD_DATA_IN_CBACK(current_list_count) == 0) {
654*0Sstevel@tonic-gate 		mdb_printf("walk_addr = %lx\n", SD_DATA_IN_CBACK(sd_state));
655*0Sstevel@tonic-gate 		mdb_printf("walking sd_state units via ptr: %lx\n",
656*0Sstevel@tonic-gate 					SD_DATA_IN_CBACK(current_root));
657*0Sstevel@tonic-gate 		mdb_printf("%d entries in sd_state table\n",
658*0Sstevel@tonic-gate 				SD_DATA_IN_CBACK(sd_state_data.n_items));
659*0Sstevel@tonic-gate 	}
660*0Sstevel@tonic-gate 
661*0Sstevel@tonic-gate 	mdb_printf("\nun %d: %lx\n", SD_DATA_IN_CBACK(current_list_count),
662*0Sstevel@tonic-gate 									addr);
663*0Sstevel@tonic-gate 
664*0Sstevel@tonic-gate 	mdb_printf("--------------\n");
665*0Sstevel@tonic-gate 
666*0Sstevel@tonic-gate 	/* if null soft state iterate over to next one */
667*0Sstevel@tonic-gate 	if (addr == 0) {
668*0Sstevel@tonic-gate 		print_footer(walk_data);
669*0Sstevel@tonic-gate 		return (SUCCESS);
670*0Sstevel@tonic-gate 	}
671*0Sstevel@tonic-gate 	/*
672*0Sstevel@tonic-gate 	 * For each buf, we need to read the sd_lun struct,
673*0Sstevel@tonic-gate 	 * and then print out its contents, and get the next.
674*0Sstevel@tonic-gate 	 */
675*0Sstevel@tonic-gate 	else if (mdb_vread(&sdLun, sizeof (struct sd_lun), (uintptr_t)addr) ==
676*0Sstevel@tonic-gate 	    sizeof (sdLun)) {
677*0Sstevel@tonic-gate 		if (!silent) {
678*0Sstevel@tonic-gate 			mdb_set_dot(addr);
679*0Sstevel@tonic-gate 			mdb_eval("$<sd_lun");
680*0Sstevel@tonic-gate 			mdb_printf("---\n");
681*0Sstevel@tonic-gate 		}
682*0Sstevel@tonic-gate 	} else {
683*0Sstevel@tonic-gate 		mdb_warn("failed to read softstate at %p", addr);
684*0Sstevel@tonic-gate 		return (FAIL);
685*0Sstevel@tonic-gate 	}
686*0Sstevel@tonic-gate 
687*0Sstevel@tonic-gate 	/* process device Xbuf Attr struct and wait Q */
688*0Sstevel@tonic-gate 	process_xbuf((uintptr_t)sdLun.un_xbuf_attr, silent);
689*0Sstevel@tonic-gate 
690*0Sstevel@tonic-gate 	/* process device cmd wait Q */
691*0Sstevel@tonic-gate 	process_sdlun_waitq((uintptr_t)sdLun.un_waitq_headp, silent);
692*0Sstevel@tonic-gate 
693*0Sstevel@tonic-gate 	/* process device semoclose wait Q */
694*0Sstevel@tonic-gate 	if (sdLun.un_semoclose._opaque[1] == 0) {
695*0Sstevel@tonic-gate 		process_semo_sleepq((uintptr_t)sdLun.un_semoclose._opaque[0],
696*0Sstevel@tonic-gate 									silent);
697*0Sstevel@tonic-gate 	}
698*0Sstevel@tonic-gate 
699*0Sstevel@tonic-gate 	/* print the actual number of soft state processed */
700*0Sstevel@tonic-gate 	print_footer(walk_data);
701*0Sstevel@tonic-gate 	return (SUCCESS);
702*0Sstevel@tonic-gate }
703*0Sstevel@tonic-gate 
704*0Sstevel@tonic-gate #if (!defined(__fibre))
705*0Sstevel@tonic-gate /*
706*0Sstevel@tonic-gate  *    Function: dcmd_sd_state
707*0Sstevel@tonic-gate  *
708*0Sstevel@tonic-gate  * Description: Scans through the sd soft state entries and prints their
709*0Sstevel@tonic-gate  *		contents including of various queues it contains. It uses
710*0Sstevel@tonic-gate  *		'sd_state' walker to perform a global walk. If a particular
711*0Sstevel@tonic-gate  *		soft state address is specified than it performs the above job
712*0Sstevel@tonic-gate  *		itself (local walk).
713*0Sstevel@tonic-gate  *
714*0Sstevel@tonic-gate  *   Arguments: addr -> user specified address or NULL if no address is
715*0Sstevel@tonic-gate  *			specified.
716*0Sstevel@tonic-gate  *		flags -> integer reflecting whether an address was specified,
717*0Sstevel@tonic-gate  *			 or if it was invoked by the walker in a loop etc.
718*0Sstevel@tonic-gate  *		argc -> the number of arguments supplied to the dcmd.
719*0Sstevel@tonic-gate  *		argv -> the actual arguments supplied by the user.
720*0Sstevel@tonic-gate  */
721*0Sstevel@tonic-gate /*ARGSUSED*/
722*0Sstevel@tonic-gate static int
dcmd_sd_state(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)723*0Sstevel@tonic-gate dcmd_sd_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
724*0Sstevel@tonic-gate {
725*0Sstevel@tonic-gate 	struct sd_lun	sdLun;
726*0Sstevel@tonic-gate 	uint_t		silent = 0;
727*0Sstevel@tonic-gate 
728*0Sstevel@tonic-gate 	/* Enable the silent mode if '-s' option specified the user */
729*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 's', MDB_OPT_SETBITS, TRUE, &silent, NULL)
730*0Sstevel@tonic-gate 							!= argc) {
731*0Sstevel@tonic-gate 		return (DCMD_USAGE);
732*0Sstevel@tonic-gate 	}
733*0Sstevel@tonic-gate 
734*0Sstevel@tonic-gate 	/*
735*0Sstevel@tonic-gate 	 * If no address is specified on the command line, perform
736*0Sstevel@tonic-gate 	 * a global walk invoking 'sd_state' walker. If a particular address
737*0Sstevel@tonic-gate 	 * is specified then print the soft state and its queues.
738*0Sstevel@tonic-gate 	 */
739*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
740*0Sstevel@tonic-gate 		mdb_walk("sd_state", sd_callback, (void *)&silent);
741*0Sstevel@tonic-gate 		return (DCMD_OK);
742*0Sstevel@tonic-gate 	} else {
743*0Sstevel@tonic-gate 		mdb_printf("\nun: %lx\n", addr);
744*0Sstevel@tonic-gate 		mdb_printf("--------------\n");
745*0Sstevel@tonic-gate 
746*0Sstevel@tonic-gate 		/* read the sd_lun struct and print the contents */
747*0Sstevel@tonic-gate 		if (mdb_vread(&sdLun, sizeof (struct sd_lun),
748*0Sstevel@tonic-gate 		    (uintptr_t)addr) == sizeof (sdLun)) {
749*0Sstevel@tonic-gate 
750*0Sstevel@tonic-gate 			if (!silent) {
751*0Sstevel@tonic-gate 				mdb_set_dot(addr);
752*0Sstevel@tonic-gate 				mdb_eval("$<sd_lun");
753*0Sstevel@tonic-gate 				mdb_printf("---\n");
754*0Sstevel@tonic-gate 			}
755*0Sstevel@tonic-gate 		} else {
756*0Sstevel@tonic-gate 			mdb_warn("failed to read softstate at %p", addr);
757*0Sstevel@tonic-gate 			return (DCMD_OK);
758*0Sstevel@tonic-gate 		}
759*0Sstevel@tonic-gate 
760*0Sstevel@tonic-gate 		/* process Xbuf Attr struct and wait Q for the soft state */
761*0Sstevel@tonic-gate 		process_xbuf((uintptr_t)sdLun.un_xbuf_attr, silent);
762*0Sstevel@tonic-gate 
763*0Sstevel@tonic-gate 		/* process device' cmd wait Q */
764*0Sstevel@tonic-gate 		process_sdlun_waitq((uintptr_t)sdLun.un_waitq_headp, silent);
765*0Sstevel@tonic-gate 
766*0Sstevel@tonic-gate 		/* process device's semoclose wait Q */
767*0Sstevel@tonic-gate 		if (sdLun.un_semoclose._opaque[1] == 0) {
768*0Sstevel@tonic-gate 			process_semo_sleepq(
769*0Sstevel@tonic-gate 			(uintptr_t)sdLun.un_semoclose._opaque[0], silent);
770*0Sstevel@tonic-gate 		}
771*0Sstevel@tonic-gate 	}
772*0Sstevel@tonic-gate 	return (DCMD_OK);
773*0Sstevel@tonic-gate }
774*0Sstevel@tonic-gate 
775*0Sstevel@tonic-gate #else
776*0Sstevel@tonic-gate 
777*0Sstevel@tonic-gate /*
778*0Sstevel@tonic-gate  *    Function: dcmd_ssd_state
779*0Sstevel@tonic-gate  *
780*0Sstevel@tonic-gate  * Description: Scans through the ssd soft state entries and prints their
781*0Sstevel@tonic-gate  *		contents including of various queues it contains. It uses
782*0Sstevel@tonic-gate  *		'ssd_state' walker to perform a global walk. If a particular
783*0Sstevel@tonic-gate  *		soft state address is specified than it performs the above job
784*0Sstevel@tonic-gate  *		itself (local walk).
785*0Sstevel@tonic-gate  *
786*0Sstevel@tonic-gate  *   Arguments: addr -> user specified address or NULL if no address is
787*0Sstevel@tonic-gate  *			specified.
788*0Sstevel@tonic-gate  *		flags -> integer reflecting whether an address was specified,
789*0Sstevel@tonic-gate  *			 or if it was invoked by the walker in a loop etc.
790*0Sstevel@tonic-gate  *		argc -> the number of arguments supplied to the dcmd.
791*0Sstevel@tonic-gate  *		argv -> the actual arguments supplied by the user.
792*0Sstevel@tonic-gate  */
793*0Sstevel@tonic-gate /*ARGSUSED*/
794*0Sstevel@tonic-gate static int
dcmd_ssd_state(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)795*0Sstevel@tonic-gate dcmd_ssd_state(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
796*0Sstevel@tonic-gate {
797*0Sstevel@tonic-gate 	struct sd_lun	sdLun;
798*0Sstevel@tonic-gate 	uint_t		silent = 0;
799*0Sstevel@tonic-gate 
800*0Sstevel@tonic-gate 	/* Enable the silent mode if '-s' option specified the user */
801*0Sstevel@tonic-gate 	if (mdb_getopts(argc, argv, 's', MDB_OPT_SETBITS, TRUE, &silent, NULL)
802*0Sstevel@tonic-gate 							!= argc) {
803*0Sstevel@tonic-gate 		return (DCMD_USAGE);
804*0Sstevel@tonic-gate 	}
805*0Sstevel@tonic-gate 
806*0Sstevel@tonic-gate 	/*
807*0Sstevel@tonic-gate 	 * If no address is specified on the command line, perform
808*0Sstevel@tonic-gate 	 * a global walk invoking 'sd_state' walker. If a particular address
809*0Sstevel@tonic-gate 	 * is specified then print the soft state and its queues.
810*0Sstevel@tonic-gate 	 */
811*0Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
812*0Sstevel@tonic-gate 		mdb_walk("ssd_state", sd_callback, (void *)&silent);
813*0Sstevel@tonic-gate 		return (DCMD_OK);
814*0Sstevel@tonic-gate 	} else {
815*0Sstevel@tonic-gate 		mdb_printf("\nun: %lx\n", addr);
816*0Sstevel@tonic-gate 		mdb_printf("--------------\n");
817*0Sstevel@tonic-gate 
818*0Sstevel@tonic-gate 		/* read the sd_lun struct and print the contents */
819*0Sstevel@tonic-gate 		if (mdb_vread(&sdLun, sizeof (struct sd_lun),
820*0Sstevel@tonic-gate 		    (uintptr_t)addr) == sizeof (sdLun)) {
821*0Sstevel@tonic-gate 			if (!silent) {
822*0Sstevel@tonic-gate 				mdb_set_dot(addr);
823*0Sstevel@tonic-gate 				mdb_eval("$<sd_lun");
824*0Sstevel@tonic-gate 				mdb_printf("---\n");
825*0Sstevel@tonic-gate 			}
826*0Sstevel@tonic-gate 		} else {
827*0Sstevel@tonic-gate 			mdb_warn("failed to read softstate at %p", addr);
828*0Sstevel@tonic-gate 			return (DCMD_OK);
829*0Sstevel@tonic-gate 		}
830*0Sstevel@tonic-gate 
831*0Sstevel@tonic-gate 		/* process Xbuf Attr struct and wait Q for the soft state */
832*0Sstevel@tonic-gate 		process_xbuf((uintptr_t)sdLun.un_xbuf_attr, silent);
833*0Sstevel@tonic-gate 
834*0Sstevel@tonic-gate 		/* process device' cmd wait Q */
835*0Sstevel@tonic-gate 		process_sdlun_waitq((uintptr_t)sdLun.un_waitq_headp, silent);
836*0Sstevel@tonic-gate 
837*0Sstevel@tonic-gate 		/* process device's semoclose wait Q */
838*0Sstevel@tonic-gate 		if (sdLun.un_semoclose._opaque[1] == 0) {
839*0Sstevel@tonic-gate 			process_semo_sleepq(
840*0Sstevel@tonic-gate 			(uintptr_t)sdLun.un_semoclose._opaque[0], silent);
841*0Sstevel@tonic-gate 		}
842*0Sstevel@tonic-gate 	}
843*0Sstevel@tonic-gate 	return (DCMD_OK);
844*0Sstevel@tonic-gate }
845*0Sstevel@tonic-gate #endif
846*0Sstevel@tonic-gate 
847*0Sstevel@tonic-gate /*
848*0Sstevel@tonic-gate  *    Function: dcmd_buf_avforw
849*0Sstevel@tonic-gate  *
850*0Sstevel@tonic-gate  * Description: Scans through the buf list via av_forw and prints
851*0Sstevel@tonic-gate  *		their contents.
852*0Sstevel@tonic-gate  *		It uses the 'buf_avforw' walker to perform the walk.
853*0Sstevel@tonic-gate  *
854*0Sstevel@tonic-gate  *   Arguments: addr -> user specified address.
855*0Sstevel@tonic-gate  *		flags -> integer reflecting whether an address was specified,
856*0Sstevel@tonic-gate  *			 or if it was invoked by the walker in a loop etc.
857*0Sstevel@tonic-gate  *		argc -> the number of arguments supplied to the dcmd.
858*0Sstevel@tonic-gate  *		argv -> the actual arguments supplied by the user.
859*0Sstevel@tonic-gate  */
860*0Sstevel@tonic-gate /*ARGSUSED*/
861*0Sstevel@tonic-gate static int
dcmd_buf_avforw(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)862*0Sstevel@tonic-gate dcmd_buf_avforw(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
863*0Sstevel@tonic-gate {
864*0Sstevel@tonic-gate 	int	buf_entries = 0;
865*0Sstevel@tonic-gate 
866*0Sstevel@tonic-gate 	/* it does not take any arguments */
867*0Sstevel@tonic-gate 	if (argc != 0)
868*0Sstevel@tonic-gate 		return (DCMD_USAGE);
869*0Sstevel@tonic-gate 
870*0Sstevel@tonic-gate 	/*
871*0Sstevel@tonic-gate 	 * If no address was specified on the command line, print the
872*0Sstevel@tonic-gate 	 * error msg, else scan and
873*0Sstevel@tonic-gate 	 * print out all the buffers available by invoking buf_avforw walker.
874*0Sstevel@tonic-gate 	 */
875*0Sstevel@tonic-gate 	if ((flags & DCMD_ADDRSPEC)) {
876*0Sstevel@tonic-gate 		mdb_pwalk("buf_avforw", buf_callback, (void *)&buf_entries,
877*0Sstevel@tonic-gate 									addr);
878*0Sstevel@tonic-gate 		return (DCMD_OK);
879*0Sstevel@tonic-gate 	} else {
880*0Sstevel@tonic-gate 		mdb_printf("buffer address required with the command\n");
881*0Sstevel@tonic-gate 	}
882*0Sstevel@tonic-gate 
883*0Sstevel@tonic-gate 	return (DCMD_USAGE);
884*0Sstevel@tonic-gate }
885*0Sstevel@tonic-gate 
886*0Sstevel@tonic-gate /*
887*0Sstevel@tonic-gate  * MDB module linkage information:
888*0Sstevel@tonic-gate  *
889*0Sstevel@tonic-gate  * List of structures describing our dcmds, a list of structures
890*0Sstevel@tonic-gate  * describing our walkers, and a function named _mdb_init to return a pointer
891*0Sstevel@tonic-gate  * to our module information.
892*0Sstevel@tonic-gate  */
893*0Sstevel@tonic-gate 
894*0Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
895*0Sstevel@tonic-gate 	{ "buf_avforw", ":", "buf_t list via av_forw", dcmd_buf_avforw},
896*0Sstevel@tonic-gate #if (!defined(__fibre))
897*0Sstevel@tonic-gate 	{ "sd_state", "[-s]", "sd soft state list", dcmd_sd_state},
898*0Sstevel@tonic-gate #else
899*0Sstevel@tonic-gate 	{ "ssd_state", "[-s]", "ssd soft state list", dcmd_ssd_state},
900*0Sstevel@tonic-gate #endif
901*0Sstevel@tonic-gate 	{ NULL }
902*0Sstevel@tonic-gate };
903*0Sstevel@tonic-gate 
904*0Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
905*0Sstevel@tonic-gate 	{ "buf_avforw", "walk list of buf_t structures via av_forw",
906*0Sstevel@tonic-gate 	buf_avforw_walk_init, buf_avforw_walk_step, buf_avforw_walk_fini },
907*0Sstevel@tonic-gate #if (!defined(__fibre))
908*0Sstevel@tonic-gate 	{ "sd_state", "walk all sd soft state queues",
909*0Sstevel@tonic-gate 		sd_state_walk_init, sd_state_walk_step, sd_state_walk_fini },
910*0Sstevel@tonic-gate #else
911*0Sstevel@tonic-gate 	{ "ssd_state", "walk all ssd soft state queues",
912*0Sstevel@tonic-gate 		ssd_state_walk_init, sd_state_walk_step, sd_state_walk_fini },
913*0Sstevel@tonic-gate #endif
914*0Sstevel@tonic-gate 	{ NULL }
915*0Sstevel@tonic-gate };
916*0Sstevel@tonic-gate 
917*0Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
918*0Sstevel@tonic-gate 	MDB_API_VERSION, dcmds, walkers
919*0Sstevel@tonic-gate };
920*0Sstevel@tonic-gate 
921*0Sstevel@tonic-gate /*
922*0Sstevel@tonic-gate  *    Function: _mdb_init
923*0Sstevel@tonic-gate  *
924*0Sstevel@tonic-gate  * Description: Returns mdb_modinfo_t structure which provides linkage and
925*0Sstevel@tonic-gate  *		module identification information to the debugger.
926*0Sstevel@tonic-gate  *
927*0Sstevel@tonic-gate  *   Arguments: void
928*0Sstevel@tonic-gate  */
929*0Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)930*0Sstevel@tonic-gate _mdb_init(void)
931*0Sstevel@tonic-gate {
932*0Sstevel@tonic-gate 	return (&modinfo);
933*0Sstevel@tonic-gate }
934