xref: /onnv-gate/usr/src/cmd/mdb/common/modules/usba/usb.c (revision 3926:1dfa4fd577c0)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53519Sgc161489  * Common Development and Distribution License (the "License").
63519Sgc161489  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
223519Sgc161489  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stddef.h>
290Sstevel@tonic-gate #include <sys/mdb_modapi.h>
300Sstevel@tonic-gate #include <mdb/mdb_ks.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <sys/usb/usba.h>
330Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
340Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
350Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
360Sstevel@tonic-gate #include <sys/usb/usba/hcdi_impl.h>
370Sstevel@tonic-gate #include <sys/file.h>
380Sstevel@tonic-gate #include <sys/sunndi.h>
390Sstevel@tonic-gate #include <unistd.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * Prototypes
440Sstevel@tonic-gate  */
450Sstevel@tonic-gate /* usba.c */
460Sstevel@tonic-gate extern uintptr_t mdb_usba_get_usba_device(uintptr_t);
470Sstevel@tonic-gate extern uintptr_t mdb_usba_hcdi_get_hcdi(struct dev_info *);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * Defines
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate /* dcmd options */
530Sstevel@tonic-gate #define	USB_DUMP_VERBOSE	0x01
540Sstevel@tonic-gate #define	USB_DUMP_ACTIVE_PIPES	0x02
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /* Hardcoded slop factor designed into debug buf logic */
570Sstevel@tonic-gate #define	USB_DEBUG_SIZE_EXTRA_ALLOC 8
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate  * Callback arg struct for find_dip (callback func used in usba_device2devinfo).
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate typedef struct usba_device2devinfo_data {
640Sstevel@tonic-gate 	uintptr_t	u2d_target_usb_dev_p;	/* one we're looking for */
650Sstevel@tonic-gate 	uintptr_t	*u2d_dip_addr;		/* Where to store result */
660Sstevel@tonic-gate 	boolean_t	u2d_found;		/* Match found */
670Sstevel@tonic-gate } usba_device2devinfo_cbdata_t;
680Sstevel@tonic-gate 
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate  * Callback for usba_device2dip.
720Sstevel@tonic-gate  * Callback called from the devinfo_children walk invoked in usba_device2dip.
730Sstevel@tonic-gate  *
740Sstevel@tonic-gate  * For the current dip, get the (potential) pointer to its usba_device_t
750Sstevel@tonic-gate  * struct.
760Sstevel@tonic-gate  * See if this pointer matches the address of the usba_device_t we're looking
770Sstevel@tonic-gate  * for (passed in as usb_dev_p).  If so, stuff its value in u2d_dip_addr,
780Sstevel@tonic-gate  * and terminate the walk.
790Sstevel@tonic-gate  *
800Sstevel@tonic-gate  * - dip_addr is the address in core of the dip currently being processed by the
810Sstevel@tonic-gate  * walk
820Sstevel@tonic-gate  * - local_dip is a pointer to a copy of the struct dev_info in local memory
830Sstevel@tonic-gate  * - cb_data is the addr of the callback arg the walker was invoked with
840Sstevel@tonic-gate  * (passed through transparently from walk invoker).
850Sstevel@tonic-gate  *
860Sstevel@tonic-gate  * Returns:
870Sstevel@tonic-gate  * - WALK_NEXT on success (match not found yet)
880Sstevel@tonic-gate  * - WALK_ERR on errors.
890Sstevel@tonic-gate  * - WALK_DONE is returned, cb_data.found is set to TRUE, and
900Sstevel@tonic-gate  * *cb_data.u2d_dip_addr is set to the matched dip addr if a dip corresponding
910Sstevel@tonic-gate  * to the desired usba_device_t* is found.
920Sstevel@tonic-gate  */
930Sstevel@tonic-gate /*ARGSUSED*/
940Sstevel@tonic-gate static int
find_dip(uintptr_t dip_addr,const void * local_dip,void * cb_arg)950Sstevel@tonic-gate find_dip(uintptr_t dip_addr, const void *local_dip, void *cb_arg)
960Sstevel@tonic-gate {
970Sstevel@tonic-gate 	uintptr_t			cur_usb_dev;
980Sstevel@tonic-gate 	usba_device2devinfo_cbdata_t	*cb_data =
990Sstevel@tonic-gate 			    (usba_device2devinfo_cbdata_t *)cb_arg;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	if ((cur_usb_dev = mdb_usba_get_usba_device(dip_addr)) == NULL) {
1020Sstevel@tonic-gate 		/*
1030Sstevel@tonic-gate 		 * If there's no corresponding usba_device_t, this dip isn't
1040Sstevel@tonic-gate 		 * a usb node.  Might be an sd node.  Ignore it.
1050Sstevel@tonic-gate 		 */
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 		return (WALK_NEXT);
1080Sstevel@tonic-gate 	}
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 	if (cur_usb_dev == cb_data->u2d_target_usb_dev_p) {
1110Sstevel@tonic-gate 		*cb_data->u2d_dip_addr = dip_addr;
1120Sstevel@tonic-gate 		cb_data->u2d_found = TRUE;
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate 		return (WALK_DONE);
1150Sstevel@tonic-gate 	}
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate 	return (WALK_NEXT);
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /*
1220Sstevel@tonic-gate  * Given a usba_device pointer, figure out which dip is associated with it.
1230Sstevel@tonic-gate  * Relies on usba_device.usb_root_hub_dip being accurate.
1240Sstevel@tonic-gate  *
1250Sstevel@tonic-gate  * - usb_dev_addr is a pointer to a usba_device_t in core.
1260Sstevel@tonic-gate  * - dip_addr is the address of a uintptr_t to receive the address in core
1270Sstevel@tonic-gate  * of the found dip (if any).
1280Sstevel@tonic-gate  *
1290Sstevel@tonic-gate  * Returns:
1300Sstevel@tonic-gate  *  0 on success (no match found)
1310Sstevel@tonic-gate  *  1 on success (match found)
1320Sstevel@tonic-gate  * -1 on errors.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate static int
usba_device2dip(uintptr_t usb_dev_addr,uintptr_t * dip_addr)1350Sstevel@tonic-gate usba_device2dip(uintptr_t usb_dev_addr, uintptr_t *dip_addr)
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate 	usba_device_t			usb_dev;
1380Sstevel@tonic-gate 	usba_device2devinfo_cbdata_t	cb_data;
1390Sstevel@tonic-gate 
1400Sstevel@tonic-gate 	/*
1410Sstevel@tonic-gate 	 * Walk all USB children of the root hub devinfo.
1420Sstevel@tonic-gate 	 * The callback func looks for a match on the usba_device address.
1430Sstevel@tonic-gate 	 */
1440Sstevel@tonic-gate 	cb_data.u2d_target_usb_dev_p = usb_dev_addr;
1450Sstevel@tonic-gate 	cb_data.u2d_dip_addr = dip_addr;
1460Sstevel@tonic-gate 	cb_data.u2d_found = FALSE;
1470Sstevel@tonic-gate 
148880Sfrits 	if (mdb_vread(&usb_dev, sizeof (usba_device_t),
1490Sstevel@tonic-gate 	    usb_dev_addr) == -1) {
1500Sstevel@tonic-gate 		mdb_warn("failed to read usba_device struct");
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 		return (-1);
1530Sstevel@tonic-gate 	}
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	/*
1560Sstevel@tonic-gate 	 * Walk devinfo children starting with the root hub node,
1570Sstevel@tonic-gate 	 * looking for a match on the usba_device pointer (which is what
1580Sstevel@tonic-gate 	 * find_dip does).
1590Sstevel@tonic-gate 	 * Result is placed in cb_data.dip_addr.
1600Sstevel@tonic-gate 	 */
161880Sfrits 	if (mdb_pwalk("devinfo_children", find_dip, &cb_data,
1620Sstevel@tonic-gate 	    (uintptr_t)usb_dev.usb_root_hub_dip) != 0) {
1630Sstevel@tonic-gate 		mdb_warn("failed to walk devinfo_children");
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 		return (-1);
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	if (cb_data.u2d_found == TRUE) {
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 		return (1);
1710Sstevel@tonic-gate 	}
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 	return (0);
1740Sstevel@tonic-gate }
1750Sstevel@tonic-gate 
1760Sstevel@tonic-gate 
1770Sstevel@tonic-gate /*
1780Sstevel@tonic-gate  * Generic walker usba_list_entry_t walker.
1790Sstevel@tonic-gate  * Works for any usba_list_entry_t list.
1800Sstevel@tonic-gate  */
1810Sstevel@tonic-gate int
usba_list_walk_init(mdb_walk_state_t * wsp)1820Sstevel@tonic-gate usba_list_walk_init(mdb_walk_state_t *wsp)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate 	/* Must have a start addr.  */
1850Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
1860Sstevel@tonic-gate 		mdb_warn("not a global walk.  Starting address required\n");
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 		return (WALK_ERR);
1890Sstevel@tonic-gate 	}
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	return (WALK_NEXT);
1920Sstevel@tonic-gate }
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate /*
1960Sstevel@tonic-gate  * Generic list walker step routine.
1970Sstevel@tonic-gate  * NOTE: multiple walkers share this routine.
1980Sstevel@tonic-gate  */
1990Sstevel@tonic-gate int
usba_list_walk_step(mdb_walk_state_t * wsp)2000Sstevel@tonic-gate usba_list_walk_step(mdb_walk_state_t *wsp)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate 	int			status;
2030Sstevel@tonic-gate 	usba_list_entry_t	list_entry;
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	if (mdb_vread(&list_entry, sizeof (usba_list_entry_t),
2060Sstevel@tonic-gate 	    (uintptr_t)wsp->walk_addr) == -1) {
2070Sstevel@tonic-gate 		mdb_warn("failed to read usba_list_entry_t at %p",
2080Sstevel@tonic-gate 		    wsp->walk_addr);
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 		return (WALK_ERR);
2110Sstevel@tonic-gate 	}
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	status = wsp->walk_callback(wsp->walk_addr, &list_entry,
2140Sstevel@tonic-gate 	    wsp->walk_cbdata);
2150Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)list_entry.next;
2160Sstevel@tonic-gate 
2170Sstevel@tonic-gate 	/* Check if we're at the last element */
2180Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 		return (WALK_DONE);
2210Sstevel@tonic-gate 	}
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate 	return (status);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 
2270Sstevel@tonic-gate /*
2280Sstevel@tonic-gate  * usb_pipe_handle walker
2290Sstevel@tonic-gate  * Given a pointer to a usba_device_t, walk the array of endpoint
2300Sstevel@tonic-gate  * pipe_handle lists.
2310Sstevel@tonic-gate  * For each list, traverse the list, invoking the callback on each element.
2320Sstevel@tonic-gate  *
2330Sstevel@tonic-gate  * Note this function takes the address of a usba_device struct (which is
2340Sstevel@tonic-gate  * easily obtainable), but actually traverses a sub-portion of the struct
2350Sstevel@tonic-gate  * (which address is not so easily obtainable).
2360Sstevel@tonic-gate  */
2370Sstevel@tonic-gate int
usb_pipe_handle_walk_init(mdb_walk_state_t * wsp)2380Sstevel@tonic-gate usb_pipe_handle_walk_init(mdb_walk_state_t *wsp)
2390Sstevel@tonic-gate {
2400Sstevel@tonic-gate 	if (wsp->walk_addr == NULL) {
2410Sstevel@tonic-gate 		mdb_warn("not a global walk; usba_device_t required\n");
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 		return (WALK_ERR);
2440Sstevel@tonic-gate 	}
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate 	wsp->walk_data = mdb_alloc((sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS,
2470Sstevel@tonic-gate 					UM_SLEEP | UM_GC);
2480Sstevel@tonic-gate 
2490Sstevel@tonic-gate 	/*
2500Sstevel@tonic-gate 	 * Read the usb_ph_list array into local memory.
2510Sstevel@tonic-gate 	 * Set start address to first element/endpoint in usb_pipehandle_list
2520Sstevel@tonic-gate 	 */
253880Sfrits 	if (mdb_vread(wsp->walk_data,
2540Sstevel@tonic-gate 	    (sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS,
2550Sstevel@tonic-gate 	    (uintptr_t)((size_t)(wsp->walk_addr) +
2560Sstevel@tonic-gate 	    offsetof(usba_device_t, usb_ph_list))) == -1) {
2570Sstevel@tonic-gate 		mdb_warn("failed to read usb_pipehandle_list at %p",
2580Sstevel@tonic-gate 		    wsp->walk_addr);
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 		return (WALK_ERR);
2610Sstevel@tonic-gate 	}
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	wsp->walk_arg = 0;
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	return (WALK_NEXT);
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate int
usb_pipe_handle_walk_step(mdb_walk_state_t * wsp)2700Sstevel@tonic-gate usb_pipe_handle_walk_step(mdb_walk_state_t *wsp)
2710Sstevel@tonic-gate {
2720Sstevel@tonic-gate 	int status;
2730Sstevel@tonic-gate 	usba_ph_impl_t *impl_list = (usba_ph_impl_t *)(wsp->walk_data);
2740Sstevel@tonic-gate 	intptr_t index = (intptr_t)wsp->walk_arg;
2750Sstevel@tonic-gate 
2760Sstevel@tonic-gate 	/* Find the first valid endpoint, starting from where we left off. */
2770Sstevel@tonic-gate 	while ((index < USBA_N_ENDPOINTS) &&
2780Sstevel@tonic-gate 	    (impl_list[index].usba_ph_data == NULL)) {
2790Sstevel@tonic-gate 		index++;
2800Sstevel@tonic-gate 	}
2810Sstevel@tonic-gate 
2820Sstevel@tonic-gate 	/* No more valid endpoints. */
2830Sstevel@tonic-gate 	if (index >= USBA_N_ENDPOINTS) {
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 		return (WALK_DONE);
2860Sstevel@tonic-gate 	}
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	status = wsp->walk_callback((uintptr_t)impl_list[index].usba_ph_data,
2890Sstevel@tonic-gate 					wsp->walk_data, wsp->walk_cbdata);
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate 	/* Set up to start at next pipe handle next time. */
2920Sstevel@tonic-gate 	wsp->walk_arg = (void *)(index + 1);
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate 	return (status);
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate /*
2990Sstevel@tonic-gate  * Given the address of a usba_pipe_handle_data_t, dump summary info.
3000Sstevel@tonic-gate  */
3010Sstevel@tonic-gate /*ARGSUSED*/
3020Sstevel@tonic-gate int
usb_pipe_handle(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3030Sstevel@tonic-gate usb_pipe_handle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3040Sstevel@tonic-gate {
3050Sstevel@tonic-gate 	char			*dir, *type, *state;
3060Sstevel@tonic-gate 	usb_ep_descr_t		ept_descr;
3070Sstevel@tonic-gate 	usba_pipe_handle_data_t	pipe_handle;
3080Sstevel@tonic-gate 	usba_ph_impl_t		ph_impl;
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 		return (DCMD_USAGE);
3130Sstevel@tonic-gate 	}
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate 	if (mdb_vread(&pipe_handle,
3160Sstevel@tonic-gate 	    sizeof (usba_pipe_handle_data_t), addr) == -1) {
3170Sstevel@tonic-gate 		mdb_warn("failed to read pipe handle at %p", addr);
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 		return (DCMD_ERR);
3200Sstevel@tonic-gate 	}
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 	if (mdb_vread(&ph_impl, sizeof (usba_ph_impl_t),
3230Sstevel@tonic-gate 	    (uintptr_t)pipe_handle.p_ph_impl) == -1) {
3240Sstevel@tonic-gate 		state = "*******";
3250Sstevel@tonic-gate 	} else {
3260Sstevel@tonic-gate 		switch (ph_impl.usba_ph_state) {
3270Sstevel@tonic-gate 		case USB_PIPE_STATE_CLOSED:
3280Sstevel@tonic-gate 			state = "CLOSED ";
3290Sstevel@tonic-gate 			break;
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 		case USB_PIPE_STATE_IDLE:
3320Sstevel@tonic-gate 			state = "IDLE   ";
3330Sstevel@tonic-gate 			break;
3340Sstevel@tonic-gate 
3350Sstevel@tonic-gate 		case USB_PIPE_STATE_ACTIVE:
3360Sstevel@tonic-gate 			state = "ACTIVE ";
3370Sstevel@tonic-gate 			break;
3380Sstevel@tonic-gate 
3390Sstevel@tonic-gate 		case USB_PIPE_STATE_ERROR:
3400Sstevel@tonic-gate 			state = "ERROR  ";
3410Sstevel@tonic-gate 			break;
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 		case USB_PIPE_STATE_CLOSING:
3440Sstevel@tonic-gate 			state = "CLOSING";
3450Sstevel@tonic-gate 			break;
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 		default:
3480Sstevel@tonic-gate 			state = "ILLEGAL";
3490Sstevel@tonic-gate 			break;
3500Sstevel@tonic-gate 		}
3510Sstevel@tonic-gate 	}
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate 	bcopy(&pipe_handle.p_ep, &ept_descr, sizeof (usb_ep_descr_t));
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
3560Sstevel@tonic-gate 		mdb_printf("\n    %<u>%-3s %5s %3s %7s %-?s %-?s %-?s%</u>\n",
3570Sstevel@tonic-gate 		    "EP", "TYPE ", "DIR", "STATE  ", "P_HANDLE", "P_POLICY",
3580Sstevel@tonic-gate 		    "EP DESCR");
3590Sstevel@tonic-gate 	}
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 	dir = ((ept_descr.bEndpointAddress & USB_EP_DIR_MASK) &
3620Sstevel@tonic-gate 	    USB_EP_DIR_IN) ? "In " : "Out";
3630Sstevel@tonic-gate 	switch (ept_descr.bmAttributes & USB_EP_ATTR_MASK) {
3640Sstevel@tonic-gate 	case USB_EP_ATTR_CONTROL:
3650Sstevel@tonic-gate 		type = "Cntrl";
3660Sstevel@tonic-gate 		break;
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate 	case USB_EP_ATTR_ISOCH:
3690Sstevel@tonic-gate 		type = "Isoch";
3700Sstevel@tonic-gate 		break;
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	case USB_EP_ATTR_BULK:
3730Sstevel@tonic-gate 		type = "Bulk ";
3740Sstevel@tonic-gate 		break;
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	case USB_EP_ATTR_INTR:
3770Sstevel@tonic-gate 		type = "Intr ";
3780Sstevel@tonic-gate 		break;
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	default:
3810Sstevel@tonic-gate 		type = "*****";
3820Sstevel@tonic-gate 		break;
3830Sstevel@tonic-gate 	}
3840Sstevel@tonic-gate 
3850Sstevel@tonic-gate 	mdb_printf("    %3d %5s %3s %7s %-?p %-?p %-?p\n",
3860Sstevel@tonic-gate 	    ept_descr.bEndpointAddress & USB_EP_NUM_MASK, type, dir, state,
3870Sstevel@tonic-gate 	    addr, addr + offsetof(usba_pipe_handle_data_t, p_policy),
3880Sstevel@tonic-gate 	    addr + offsetof(usba_pipe_handle_data_t, p_ep));
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	return (DCMD_OK);
3910Sstevel@tonic-gate }
3920Sstevel@tonic-gate 
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate /*
3950Sstevel@tonic-gate  * usba_device walker:
3960Sstevel@tonic-gate  *
3970Sstevel@tonic-gate  * walks the chain of usba_device structs headed by usba_device_list in usba.c
3980Sstevel@tonic-gate  * NOTE: It uses the generic list walk step routine usba_list_walk_step.
3990Sstevel@tonic-gate  * No walk_fini routine is needed.
4000Sstevel@tonic-gate  */
4010Sstevel@tonic-gate int
usba_device_walk_init(mdb_walk_state_t * wsp)4020Sstevel@tonic-gate usba_device_walk_init(mdb_walk_state_t *wsp)
4030Sstevel@tonic-gate {
4040Sstevel@tonic-gate 	usba_list_entry_t	list_entry;
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	if (wsp->walk_addr != NULL) {
4070Sstevel@tonic-gate 		mdb_warn(
4080Sstevel@tonic-gate 		    "global walk only.  Must be invoked without an address\n");
4090Sstevel@tonic-gate 
4100Sstevel@tonic-gate 		return (WALK_ERR);
4110Sstevel@tonic-gate 	}
4120Sstevel@tonic-gate 
413880Sfrits 	if (mdb_readvar(&list_entry, "usba_device_list") == -1) {
4140Sstevel@tonic-gate 		mdb_warn("failed to read usba_device_list");
4150Sstevel@tonic-gate 
4160Sstevel@tonic-gate 		return (WALK_ERR);
4170Sstevel@tonic-gate 	}
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate 	/* List head is not part of usba_device_t, get first usba_device_t */
4200Sstevel@tonic-gate 	wsp->walk_addr = (uintptr_t)list_entry.next;
4210Sstevel@tonic-gate 
4220Sstevel@tonic-gate 	return (WALK_NEXT);
4230Sstevel@tonic-gate }
4240Sstevel@tonic-gate 
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate /*
4270Sstevel@tonic-gate  * usba_device dcmd
4280Sstevel@tonic-gate  *	Given the address of a usba_device struct, dump summary info
4290Sstevel@tonic-gate  *	-v:	Print more (verbose) info
4300Sstevel@tonic-gate  *	-p:	Walk/dump all open pipes for this usba_device
4310Sstevel@tonic-gate  */
4320Sstevel@tonic-gate /*ARGSUSED*/
4330Sstevel@tonic-gate int
usba_device(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4340Sstevel@tonic-gate usba_device(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4350Sstevel@tonic-gate {
4360Sstevel@tonic-gate 	int		status;
4370Sstevel@tonic-gate 	char		pathname[MAXNAMELEN];
4380Sstevel@tonic-gate 	char		dname[MODMAXNAMELEN + 1] = "<unatt>"; /* Driver name */
4390Sstevel@tonic-gate 	char		drv_statep[MODMAXNAMELEN+ 10];
4400Sstevel@tonic-gate 	uint_t		usb_flag  = NULL;
4410Sstevel@tonic-gate 	boolean_t	no_driver_attached = FALSE;
4420Sstevel@tonic-gate 	uintptr_t	dip_addr;
4430Sstevel@tonic-gate 	struct dev_info	devinfo;
4440Sstevel@tonic-gate 
4450Sstevel@tonic-gate 	if (!(flags & DCMD_ADDRSPEC)) {
4460Sstevel@tonic-gate 		/* Global walk */
4470Sstevel@tonic-gate 		if (mdb_walk_dcmd("usba_device", "usba_device", argc,
4480Sstevel@tonic-gate 		    argv) == -1) {
4490Sstevel@tonic-gate 			mdb_warn("failed to walk usba_device");
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 			return (DCMD_ERR);
4520Sstevel@tonic-gate 		}
4530Sstevel@tonic-gate 
4540Sstevel@tonic-gate 		return (DCMD_OK);
4550Sstevel@tonic-gate 	}
4560Sstevel@tonic-gate 
4570Sstevel@tonic-gate 	if (mdb_getopts(argc, argv,
4580Sstevel@tonic-gate 	    'p', MDB_OPT_SETBITS, USB_DUMP_ACTIVE_PIPES, &usb_flag,
4590Sstevel@tonic-gate 	    'v', MDB_OPT_SETBITS, USB_DUMP_VERBOSE, &usb_flag, NULL) != argc) {
4600Sstevel@tonic-gate 
4610Sstevel@tonic-gate 		return (DCMD_USAGE);
4620Sstevel@tonic-gate 	}
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	if (usb_flag && !(DCMD_HDRSPEC(flags))) {
4650Sstevel@tonic-gate 		mdb_printf("\n");
4660Sstevel@tonic-gate 	}
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	if (DCMD_HDRSPEC(flags)) {
4690Sstevel@tonic-gate 		mdb_printf("%<u>%-15s %4s %-?s %-42s%</u>\n",
4700Sstevel@tonic-gate 		    "NAME", "INST", "DIP", "PATH                             ");
4710Sstevel@tonic-gate 	}
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate 	status = usba_device2dip(addr, &dip_addr);
4740Sstevel@tonic-gate 	/*
4750Sstevel@tonic-gate 	 * -1 = error
4760Sstevel@tonic-gate 	 * 0 = no error, no match
4770Sstevel@tonic-gate 	 * 1 = no error, match
4780Sstevel@tonic-gate 	 */
4790Sstevel@tonic-gate 	if (status != 1) {
4800Sstevel@tonic-gate 		if (status == -1) {
4810Sstevel@tonic-gate 			mdb_warn("error looking for dip for usba_device %p",
4820Sstevel@tonic-gate 			    addr);
4830Sstevel@tonic-gate 		} else {
4840Sstevel@tonic-gate 			mdb_warn("failed to find dip for usba_device %p\n",
4850Sstevel@tonic-gate 			    addr);
4860Sstevel@tonic-gate 		}
4870Sstevel@tonic-gate 		mdb_warn("dip and statep unobtainable\n");
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate 		return (DCMD_ERR);
4900Sstevel@tonic-gate 	}
4910Sstevel@tonic-gate 
4920Sstevel@tonic-gate 	/* Figure out what driver (name) is attached to this node. */
4930Sstevel@tonic-gate 	(void) mdb_devinfo2driver(dip_addr, (char *)dname, sizeof (dname));
4940Sstevel@tonic-gate 
495880Sfrits 	if (mdb_vread(&devinfo, sizeof (struct dev_info),
4960Sstevel@tonic-gate 	    dip_addr) == -1) {
4970Sstevel@tonic-gate 		mdb_warn("failed to read devinfo");
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 		return (DCMD_ERR);
5000Sstevel@tonic-gate 	}
5010Sstevel@tonic-gate 
5020Sstevel@tonic-gate 	if (!(DDI_CF2(&devinfo))) {
5030Sstevel@tonic-gate 		no_driver_attached = TRUE;
5040Sstevel@tonic-gate 	}
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate 	(void) mdb_ddi_pathname(dip_addr, pathname, sizeof (pathname));
5070Sstevel@tonic-gate 	mdb_printf("%-15s %2d   %-?p %s\n", dname, devinfo.devi_instance,
5080Sstevel@tonic-gate 	    dip_addr, pathname);
5090Sstevel@tonic-gate 
5100Sstevel@tonic-gate 	if (usb_flag & USB_DUMP_VERBOSE) {
5110Sstevel@tonic-gate 		int		i;
5120Sstevel@tonic-gate 		uintptr_t	statep = NULL;
5130Sstevel@tonic-gate 		char		*string_descr;
5140Sstevel@tonic-gate 		char		**config_cloud, **conf_str_descr;
5150Sstevel@tonic-gate 		usb_dev_descr_t	usb_dev_descr;
5160Sstevel@tonic-gate 		usba_device_t	usba_device_struct;
5170Sstevel@tonic-gate 
518880Sfrits 		if (mdb_vread(&usba_device_struct,
5190Sstevel@tonic-gate 		    sizeof (usba_device_t), addr) == -1) {
5200Sstevel@tonic-gate 			mdb_warn("failed to read usba_device struct");
5210Sstevel@tonic-gate 
5220Sstevel@tonic-gate 			return (DCMD_ERR);
5230Sstevel@tonic-gate 		}
5240Sstevel@tonic-gate 
5250Sstevel@tonic-gate 		mdb_printf("    usba_device: %-16p\n\n", (usba_device_t *)addr);
5260Sstevel@tonic-gate 
5270Sstevel@tonic-gate 		if (mdb_vread(&usb_dev_descr, sizeof (usb_dev_descr),
5280Sstevel@tonic-gate 		    (uintptr_t)usba_device_struct.usb_dev_descr) == -1) {
5290Sstevel@tonic-gate 			mdb_warn("failed to read usb_dev_descr_t struct");
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate 			return (DCMD_ERR);
5320Sstevel@tonic-gate 		}
5330Sstevel@tonic-gate 
5340Sstevel@tonic-gate 		mdb_printf("\n    idVendor: 0x%04x idProduct: 0x%04x "
5350Sstevel@tonic-gate 		    "usb_addr: 0x%02x\n", usb_dev_descr.idVendor,
5360Sstevel@tonic-gate 		    usb_dev_descr.idProduct, usba_device_struct.usb_addr);
5370Sstevel@tonic-gate 
5380Sstevel@tonic-gate 		/* Get the string descriptor string into local space. */
5390Sstevel@tonic-gate 		string_descr = (char *)mdb_alloc(USB_MAXSTRINGLEN, UM_GC);
5400Sstevel@tonic-gate 
5410Sstevel@tonic-gate 		if (usba_device_struct.usb_mfg_str == NULL) {
5420Sstevel@tonic-gate 			(void) strcpy(string_descr, "<No Manufacturer String>");
5430Sstevel@tonic-gate 		} else {
5440Sstevel@tonic-gate 			if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
5450Sstevel@tonic-gate 			    (uintptr_t)usba_device_struct.usb_mfg_str) == -1) {
5460Sstevel@tonic-gate 				mdb_warn("failed to read manufacturer "
5470Sstevel@tonic-gate 				    "string descriptor");
5480Sstevel@tonic-gate 				(void) strcpy(string_descr, "???");
5490Sstevel@tonic-gate 			}
5500Sstevel@tonic-gate 		}
5510Sstevel@tonic-gate 		mdb_printf("\n    Manufacturer String:\t%s\n", string_descr);
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate 		if (usba_device_struct.usb_product_str == NULL) {
5540Sstevel@tonic-gate 			(void) strcpy(string_descr, "<No Product String>");
5550Sstevel@tonic-gate 		} else {
5560Sstevel@tonic-gate 			if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
5570Sstevel@tonic-gate 			    (uintptr_t)usba_device_struct.usb_product_str) ==
5580Sstevel@tonic-gate 			    -1) {
5590Sstevel@tonic-gate 				mdb_warn("failed to read product string "
5600Sstevel@tonic-gate 				    "descriptor");
5610Sstevel@tonic-gate 				(void) strcpy(string_descr, "???");
5620Sstevel@tonic-gate 			}
5630Sstevel@tonic-gate 		}
5640Sstevel@tonic-gate 		mdb_printf("    Product String:\t\t%s\n", string_descr);
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 		if (usba_device_struct.usb_serialno_str == NULL) {
5670Sstevel@tonic-gate 			(void) strcpy(string_descr, "<No SerialNumber String>");
5680Sstevel@tonic-gate 		} else {
5690Sstevel@tonic-gate 			if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
5700Sstevel@tonic-gate 			    (uintptr_t)usba_device_struct.usb_serialno_str) ==
5710Sstevel@tonic-gate 			    -1) {
5720Sstevel@tonic-gate 				mdb_warn("failed to read serial number string "
5730Sstevel@tonic-gate 				    "descriptor");
5740Sstevel@tonic-gate 				(void) strcpy(string_descr, "???");
5750Sstevel@tonic-gate 			}
5760Sstevel@tonic-gate 		}
5770Sstevel@tonic-gate 		mdb_printf("    SerialNumber String:\t%s\n", string_descr);
5780Sstevel@tonic-gate 
5790Sstevel@tonic-gate 		if (no_driver_attached) {
5800Sstevel@tonic-gate 			mdb_printf("\n");
5810Sstevel@tonic-gate 		} else {
5820Sstevel@tonic-gate 			mdb_printf("      state_p: ");
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate 			/*
5850Sstevel@tonic-gate 			 * Given the dip, find the associated statep. The
5860Sstevel@tonic-gate 			 * convention to generate this soft state anchor is:
5870Sstevel@tonic-gate 			 *	<driver_name>_statep
5880Sstevel@tonic-gate 			 */
5890Sstevel@tonic-gate 			(void) mdb_snprintf(drv_statep, sizeof (drv_statep),
5900Sstevel@tonic-gate 			    "%s_statep", dname);
5910Sstevel@tonic-gate 			if (mdb_devinfo2statep(dip_addr, drv_statep,
5920Sstevel@tonic-gate 			    &statep) == -1) {
5930Sstevel@tonic-gate 				mdb_warn("failed to find %s state struct for "
5940Sstevel@tonic-gate 				    "dip %p", drv_statep, dip_addr);
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate 				return (DCMD_ERR);
5970Sstevel@tonic-gate 			}
5980Sstevel@tonic-gate 			mdb_printf("%-?p\n", statep);
5990Sstevel@tonic-gate 		}
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate 		config_cloud = (char **)mdb_alloc(sizeof (void *) *
6020Sstevel@tonic-gate 		    usba_device_struct.usb_n_cfgs, UM_GC);
6030Sstevel@tonic-gate 
6040Sstevel@tonic-gate 		conf_str_descr = (char **)mdb_alloc(sizeof (void *) *
6050Sstevel@tonic-gate 		    usba_device_struct.usb_n_cfgs, UM_GC);
6060Sstevel@tonic-gate 
6070Sstevel@tonic-gate 		if ((usba_device_struct.usb_cfg_array) &&
6080Sstevel@tonic-gate 		    (usba_device_struct.usb_cfg_str_descr)) {
6090Sstevel@tonic-gate 			if ((mdb_vread(config_cloud,  sizeof (void *) *
6100Sstevel@tonic-gate 			    usba_device_struct.usb_n_cfgs,
6110Sstevel@tonic-gate 			    (uintptr_t)usba_device_struct.usb_cfg_array) ==
6120Sstevel@tonic-gate 			    -1) || (mdb_vread(conf_str_descr, sizeof (void *)
6130Sstevel@tonic-gate 			    * usba_device_struct.usb_n_cfgs, (uintptr_t)
6140Sstevel@tonic-gate 			    usba_device_struct.usb_cfg_str_descr)) == -1) {
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate 			    mdb_warn("failed to read config cloud pointers");
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate 			} else {
6190Sstevel@tonic-gate 
6200Sstevel@tonic-gate 				mdb_printf("\n    Device Config Clouds:\n"
6210Sstevel@tonic-gate 				    "    Index\tConfig\t\tConfiguration "
6220Sstevel@tonic-gate 				    "String\n"
6230Sstevel@tonic-gate 				    "    -----\t------\t\t"
6240Sstevel@tonic-gate 				    "--------------------\n");
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 				for (i = 0; i < usba_device_struct.usb_n_cfgs;
6270Sstevel@tonic-gate 				    i++) {
6280Sstevel@tonic-gate 					if (mdb_readstr(string_descr,
6290Sstevel@tonic-gate 					    USB_MAXSTRINGLEN,
6300Sstevel@tonic-gate 					    (uintptr_t)conf_str_descr[i]) ==
6310Sstevel@tonic-gate 					    -1) {
6320Sstevel@tonic-gate 						(void) strcpy(string_descr,
6330Sstevel@tonic-gate 						    "<No Configuration "
6340Sstevel@tonic-gate 						    "String>");
6350Sstevel@tonic-gate 					}
6360Sstevel@tonic-gate 					mdb_printf("    %4d\t0x%p\t%s\n", i,
6370Sstevel@tonic-gate 					    config_cloud[i], string_descr);
6380Sstevel@tonic-gate 				}
6390Sstevel@tonic-gate 			}
6400Sstevel@tonic-gate 		}
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate 		mdb_printf("\n    Active configuration index: %d\n",
6430Sstevel@tonic-gate 		    usba_device_struct.usb_active_cfg_ndx);
6440Sstevel@tonic-gate 	}
6450Sstevel@tonic-gate 
6460Sstevel@tonic-gate 	if (usb_flag & USB_DUMP_ACTIVE_PIPES) {
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate 		if (mdb_pwalk_dcmd("usb_pipe_handle", "usb_pipe_handle",
6490Sstevel@tonic-gate 		    0, NULL, addr) == -1) {
6500Sstevel@tonic-gate 			mdb_warn("failed to walk usb_pipe_handle");
6510Sstevel@tonic-gate 			return (DCMD_ERR);
6520Sstevel@tonic-gate 		}
6530Sstevel@tonic-gate 	}
6540Sstevel@tonic-gate 
6550Sstevel@tonic-gate 	return (DCMD_OK);
6560Sstevel@tonic-gate }
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate 
6590Sstevel@tonic-gate /*
6600Sstevel@tonic-gate  * Dump the contents of the usba_debug_buf, from the oldest to newest,
6610Sstevel@tonic-gate  * wrapping around if necessary.
6620Sstevel@tonic-gate  */
6630Sstevel@tonic-gate /*ARGSUSED*/
6640Sstevel@tonic-gate int
usba_debug_buf(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)6650Sstevel@tonic-gate usba_debug_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
6660Sstevel@tonic-gate {
6670Sstevel@tonic-gate 	char	*debug_buf_addr;	/* addr in core */
6680Sstevel@tonic-gate 	char	*local_debug_buf;	/* local copy of buf */
6690Sstevel@tonic-gate 	int	debug_buf_size;
6700Sstevel@tonic-gate 	char	*term_p;
6710Sstevel@tonic-gate 	int	being_cleared;
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 	if (flags & DCMD_ADDRSPEC) {
6740Sstevel@tonic-gate 
6750Sstevel@tonic-gate 		return (DCMD_USAGE);
6760Sstevel@tonic-gate 	}
6770Sstevel@tonic-gate 
678880Sfrits 	if (mdb_readvar(&being_cleared, "usba_clear_debug_buf_flag") ==
6790Sstevel@tonic-gate 	    -1) {
6800Sstevel@tonic-gate 		mdb_warn("failed to read usba_clear_debug_buf_flag");
6810Sstevel@tonic-gate 
6820Sstevel@tonic-gate 		return (DCMD_ERR);
6830Sstevel@tonic-gate 	}
6840Sstevel@tonic-gate 	if (being_cleared) {
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate 		return (DCMD_OK);
6870Sstevel@tonic-gate 	}
6880Sstevel@tonic-gate 
689880Sfrits 	if (mdb_readvar(&debug_buf_addr, "usba_debug_buf") == -1) {
6900Sstevel@tonic-gate 		mdb_warn("failed to read usba_debug_buf");
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 		return (DCMD_ERR);
6930Sstevel@tonic-gate 	}
6940Sstevel@tonic-gate 
6950Sstevel@tonic-gate 	if (debug_buf_addr == NULL) {
6960Sstevel@tonic-gate 		mdb_warn("usba_debug_buf not allocated\n");
6970Sstevel@tonic-gate 
6980Sstevel@tonic-gate 		return (DCMD_OK);
6990Sstevel@tonic-gate 	}
7000Sstevel@tonic-gate 
7010Sstevel@tonic-gate 
702880Sfrits 	if (mdb_readvar(&debug_buf_size, "usba_debug_buf_size") == -1) {
7030Sstevel@tonic-gate 		mdb_warn("failed to read usba_debug_buf_size");
7040Sstevel@tonic-gate 
7050Sstevel@tonic-gate 		return (DCMD_ERR);
7060Sstevel@tonic-gate 	}
7070Sstevel@tonic-gate 
7080Sstevel@tonic-gate 	debug_buf_size += USB_DEBUG_SIZE_EXTRA_ALLOC;
7090Sstevel@tonic-gate 	local_debug_buf = (char *)mdb_alloc(debug_buf_size, UM_SLEEP | UM_GC);
7100Sstevel@tonic-gate 
711880Sfrits 	if ((mdb_vread(local_debug_buf, debug_buf_size,
7120Sstevel@tonic-gate 	    (uintptr_t)debug_buf_addr)) == -1) {
7130Sstevel@tonic-gate 		mdb_warn("failed to read usba_debug_buf at %p",
7140Sstevel@tonic-gate 		    local_debug_buf);
7150Sstevel@tonic-gate 
7160Sstevel@tonic-gate 		return (DCMD_ERR);
7170Sstevel@tonic-gate 	}
7180Sstevel@tonic-gate 	local_debug_buf[debug_buf_size - 1] = '\0';
7190Sstevel@tonic-gate 
7200Sstevel@tonic-gate 	if (strlen(local_debug_buf) == NULL) {
7210Sstevel@tonic-gate 
7220Sstevel@tonic-gate 		return (DCMD_OK);
7230Sstevel@tonic-gate 	}
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate 	if ((term_p = strstr(local_debug_buf, ">>>>")) == NULL) {
7260Sstevel@tonic-gate 		mdb_warn("failed to find terminator \">>>>\"\n");
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate 		return (DCMD_ERR);
7290Sstevel@tonic-gate 	}
7300Sstevel@tonic-gate 
7310Sstevel@tonic-gate 	/*
7320Sstevel@tonic-gate 	 * Print the chunk of buffer from the terminator to the end.
7330Sstevel@tonic-gate 	 * This will print a null string if no wrap has occurred yet.
7340Sstevel@tonic-gate 	 */
7350Sstevel@tonic-gate 	mdb_printf("%s", term_p+5);	/* after >>>>\0 to end of buf */
7360Sstevel@tonic-gate 	mdb_printf("%s\n", local_debug_buf);	/* beg of buf to >>>>\0 */
7370Sstevel@tonic-gate 
7380Sstevel@tonic-gate 	return (DCMD_OK);
7390Sstevel@tonic-gate }
7400Sstevel@tonic-gate 
7410Sstevel@tonic-gate /*ARGSUSED*/
7420Sstevel@tonic-gate int
usba_clear_debug_buf(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)7430Sstevel@tonic-gate usba_clear_debug_buf(
7440Sstevel@tonic-gate 	uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7450Sstevel@tonic-gate {
7460Sstevel@tonic-gate 	int clear = 1;
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate 	/* stop the tracing */
7490Sstevel@tonic-gate 	if (mdb_writevar((void*)&clear, "usba_clear_debug_buf_flag") == -1) {
7500Sstevel@tonic-gate 		mdb_warn("failed to set usba_clear_debug_buf_flag");
7510Sstevel@tonic-gate 
7520Sstevel@tonic-gate 		return (DCMD_ERR);
7530Sstevel@tonic-gate 	}
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate 	return (DCMD_OK);
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate 
7583519Sgc161489 /* prtusb entries */
7593519Sgc161489 extern int prtusb(uintptr_t, uint_t, int, const mdb_arg_t *);
7603519Sgc161489 
7613519Sgc161489 extern void prt_usb_usage(void);
7620Sstevel@tonic-gate 
7630Sstevel@tonic-gate /*
7640Sstevel@tonic-gate  * MDB module linkage information:
7650Sstevel@tonic-gate  *
7660Sstevel@tonic-gate  * We declare a list of structures describing our dcmds, and a function
7670Sstevel@tonic-gate  * named _mdb_init to return a pointer to our module information.
7680Sstevel@tonic-gate  */
7690Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
7700Sstevel@tonic-gate 	{ "usb_pipe_handle", ":",
7710Sstevel@tonic-gate 	    "print a usb_pipe_handle struct", usb_pipe_handle, NULL},
7720Sstevel@tonic-gate 	{ "usba_device", ": [-pv]",
7730Sstevel@tonic-gate 	    "print summary info for a usba_device_t struct", usba_device, NULL},
7740Sstevel@tonic-gate 	{ "usba_debug_buf", NULL,
7750Sstevel@tonic-gate 	    "print usba_debug_buf", usba_debug_buf, NULL},
7760Sstevel@tonic-gate 	{ "usba_clear_debug_buf", NULL,
7770Sstevel@tonic-gate 	    "clear usba_debug_buf", usba_clear_debug_buf, NULL},
778*3926Sgc161489 	{ "prtusb", "?[-t] [-v] [-i index]",
779*3926Sgc161489 	    "print trees and descriptors for usba_device_t",
780*3926Sgc161489 	    prtusb, prt_usb_usage},
7810Sstevel@tonic-gate 	{ NULL }
7820Sstevel@tonic-gate };
7830Sstevel@tonic-gate 
7840Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
7850Sstevel@tonic-gate 	/* Generic list walker. */
7860Sstevel@tonic-gate 	{ "usba_list_entry", "walk list of usba_list_entry_t structures",
7870Sstevel@tonic-gate 	    usba_list_walk_init, usba_list_walk_step, NULL, NULL },
7880Sstevel@tonic-gate 	{ "usb_pipe_handle", "walk USB pipe handles, given a usba_device_t ptr",
7890Sstevel@tonic-gate 	    usb_pipe_handle_walk_init, usb_pipe_handle_walk_step, NULL, NULL },
7900Sstevel@tonic-gate 	{ "usba_device", "walk global list of usba_device_t structures",
7910Sstevel@tonic-gate 	    usba_device_walk_init, usba_list_walk_step, NULL, NULL },
7920Sstevel@tonic-gate 	{ NULL }
7930Sstevel@tonic-gate };
7940Sstevel@tonic-gate 
7950Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
7960Sstevel@tonic-gate 	MDB_API_VERSION, dcmds, walkers
7970Sstevel@tonic-gate };
7980Sstevel@tonic-gate 
7990Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)8000Sstevel@tonic-gate _mdb_init(void)
8010Sstevel@tonic-gate {
8020Sstevel@tonic-gate 	return (&modinfo);
8030Sstevel@tonic-gate }
804