17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
54e968bc2Sgc161489 * Common Development and Distribution License (the "License").
64e968bc2Sgc161489 * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
224e968bc2Sgc161489 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate #include <stddef.h>
297c478bd9Sstevel@tonic-gate #include <sys/mdb_modapi.h>
307c478bd9Sstevel@tonic-gate #include <mdb/mdb_ks.h>
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
337c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
347c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
357c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hcdi_impl.h>
377c478bd9Sstevel@tonic-gate #include <sys/file.h>
387c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
397c478bd9Sstevel@tonic-gate #include <unistd.h>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate * Prototypes
447c478bd9Sstevel@tonic-gate */
457c478bd9Sstevel@tonic-gate /* usba.c */
467c478bd9Sstevel@tonic-gate extern uintptr_t mdb_usba_get_usba_device(uintptr_t);
477c478bd9Sstevel@tonic-gate extern uintptr_t mdb_usba_hcdi_get_hcdi(struct dev_info *);
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate * Defines
517c478bd9Sstevel@tonic-gate */
527c478bd9Sstevel@tonic-gate /* dcmd options */
537c478bd9Sstevel@tonic-gate #define USB_DUMP_VERBOSE 0x01
547c478bd9Sstevel@tonic-gate #define USB_DUMP_ACTIVE_PIPES 0x02
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /* Hardcoded slop factor designed into debug buf logic */
577c478bd9Sstevel@tonic-gate #define USB_DEBUG_SIZE_EXTRA_ALLOC 8
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate * Callback arg struct for find_dip (callback func used in usba_device2devinfo).
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate typedef struct usba_device2devinfo_data {
647c478bd9Sstevel@tonic-gate uintptr_t u2d_target_usb_dev_p; /* one we're looking for */
657c478bd9Sstevel@tonic-gate uintptr_t *u2d_dip_addr; /* Where to store result */
667c478bd9Sstevel@tonic-gate boolean_t u2d_found; /* Match found */
677c478bd9Sstevel@tonic-gate } usba_device2devinfo_cbdata_t;
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate * Callback for usba_device2dip.
727c478bd9Sstevel@tonic-gate * Callback called from the devinfo_children walk invoked in usba_device2dip.
737c478bd9Sstevel@tonic-gate *
747c478bd9Sstevel@tonic-gate * For the current dip, get the (potential) pointer to its usba_device_t
757c478bd9Sstevel@tonic-gate * struct.
767c478bd9Sstevel@tonic-gate * See if this pointer matches the address of the usba_device_t we're looking
777c478bd9Sstevel@tonic-gate * for (passed in as usb_dev_p). If so, stuff its value in u2d_dip_addr,
787c478bd9Sstevel@tonic-gate * and terminate the walk.
797c478bd9Sstevel@tonic-gate *
807c478bd9Sstevel@tonic-gate * - dip_addr is the address in core of the dip currently being processed by the
817c478bd9Sstevel@tonic-gate * walk
827c478bd9Sstevel@tonic-gate * - local_dip is a pointer to a copy of the struct dev_info in local memory
837c478bd9Sstevel@tonic-gate * - cb_data is the addr of the callback arg the walker was invoked with
847c478bd9Sstevel@tonic-gate * (passed through transparently from walk invoker).
857c478bd9Sstevel@tonic-gate *
867c478bd9Sstevel@tonic-gate * Returns:
877c478bd9Sstevel@tonic-gate * - WALK_NEXT on success (match not found yet)
887c478bd9Sstevel@tonic-gate * - WALK_ERR on errors.
897c478bd9Sstevel@tonic-gate * - WALK_DONE is returned, cb_data.found is set to TRUE, and
907c478bd9Sstevel@tonic-gate * *cb_data.u2d_dip_addr is set to the matched dip addr if a dip corresponding
917c478bd9Sstevel@tonic-gate * to the desired usba_device_t* is found.
927c478bd9Sstevel@tonic-gate */
937c478bd9Sstevel@tonic-gate /*ARGSUSED*/
947c478bd9Sstevel@tonic-gate static int
find_dip(uintptr_t dip_addr,const void * local_dip,void * cb_arg)957c478bd9Sstevel@tonic-gate find_dip(uintptr_t dip_addr, const void *local_dip, void *cb_arg)
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate uintptr_t cur_usb_dev;
987c478bd9Sstevel@tonic-gate usba_device2devinfo_cbdata_t *cb_data =
997c478bd9Sstevel@tonic-gate (usba_device2devinfo_cbdata_t *)cb_arg;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate if ((cur_usb_dev = mdb_usba_get_usba_device(dip_addr)) == NULL) {
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate * If there's no corresponding usba_device_t, this dip isn't
1047c478bd9Sstevel@tonic-gate * a usb node. Might be an sd node. Ignore it.
1057c478bd9Sstevel@tonic-gate */
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate return (WALK_NEXT);
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate if (cur_usb_dev == cb_data->u2d_target_usb_dev_p) {
1117c478bd9Sstevel@tonic-gate *cb_data->u2d_dip_addr = dip_addr;
1127c478bd9Sstevel@tonic-gate cb_data->u2d_found = TRUE;
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate return (WALK_DONE);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate return (WALK_NEXT);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate * Given a usba_device pointer, figure out which dip is associated with it.
1237c478bd9Sstevel@tonic-gate * Relies on usba_device.usb_root_hub_dip being accurate.
1247c478bd9Sstevel@tonic-gate *
1257c478bd9Sstevel@tonic-gate * - usb_dev_addr is a pointer to a usba_device_t in core.
1267c478bd9Sstevel@tonic-gate * - dip_addr is the address of a uintptr_t to receive the address in core
1277c478bd9Sstevel@tonic-gate * of the found dip (if any).
1287c478bd9Sstevel@tonic-gate *
1297c478bd9Sstevel@tonic-gate * Returns:
1307c478bd9Sstevel@tonic-gate * 0 on success (no match found)
1317c478bd9Sstevel@tonic-gate * 1 on success (match found)
1327c478bd9Sstevel@tonic-gate * -1 on errors.
1337c478bd9Sstevel@tonic-gate */
1347c478bd9Sstevel@tonic-gate static int
usba_device2dip(uintptr_t usb_dev_addr,uintptr_t * dip_addr)1357c478bd9Sstevel@tonic-gate usba_device2dip(uintptr_t usb_dev_addr, uintptr_t *dip_addr)
1367c478bd9Sstevel@tonic-gate {
1377c478bd9Sstevel@tonic-gate usba_device_t usb_dev;
1387c478bd9Sstevel@tonic-gate usba_device2devinfo_cbdata_t cb_data;
1397c478bd9Sstevel@tonic-gate
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate * Walk all USB children of the root hub devinfo.
1427c478bd9Sstevel@tonic-gate * The callback func looks for a match on the usba_device address.
1437c478bd9Sstevel@tonic-gate */
1447c478bd9Sstevel@tonic-gate cb_data.u2d_target_usb_dev_p = usb_dev_addr;
1457c478bd9Sstevel@tonic-gate cb_data.u2d_dip_addr = dip_addr;
1467c478bd9Sstevel@tonic-gate cb_data.u2d_found = FALSE;
1477c478bd9Sstevel@tonic-gate
1484610e4a0Sfrits if (mdb_vread(&usb_dev, sizeof (usba_device_t),
1497c478bd9Sstevel@tonic-gate usb_dev_addr) == -1) {
1507c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_device struct");
1517c478bd9Sstevel@tonic-gate
1527c478bd9Sstevel@tonic-gate return (-1);
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate * Walk devinfo children starting with the root hub node,
1577c478bd9Sstevel@tonic-gate * looking for a match on the usba_device pointer (which is what
1587c478bd9Sstevel@tonic-gate * find_dip does).
1597c478bd9Sstevel@tonic-gate * Result is placed in cb_data.dip_addr.
1607c478bd9Sstevel@tonic-gate */
1614610e4a0Sfrits if (mdb_pwalk("devinfo_children", find_dip, &cb_data,
1627c478bd9Sstevel@tonic-gate (uintptr_t)usb_dev.usb_root_hub_dip) != 0) {
1637c478bd9Sstevel@tonic-gate mdb_warn("failed to walk devinfo_children");
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate return (-1);
1667c478bd9Sstevel@tonic-gate }
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gate if (cb_data.u2d_found == TRUE) {
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate return (1);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate return (0);
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gate /*
1787c478bd9Sstevel@tonic-gate * Generic walker usba_list_entry_t walker.
1797c478bd9Sstevel@tonic-gate * Works for any usba_list_entry_t list.
1807c478bd9Sstevel@tonic-gate */
1817c478bd9Sstevel@tonic-gate int
usba_list_walk_init(mdb_walk_state_t * wsp)1827c478bd9Sstevel@tonic-gate usba_list_walk_init(mdb_walk_state_t *wsp)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate /* Must have a start addr. */
1857c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
1867c478bd9Sstevel@tonic-gate mdb_warn("not a global walk. Starting address required\n");
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate return (WALK_ERR);
1897c478bd9Sstevel@tonic-gate }
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate return (WALK_NEXT);
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate /*
1967c478bd9Sstevel@tonic-gate * Generic list walker step routine.
1977c478bd9Sstevel@tonic-gate * NOTE: multiple walkers share this routine.
1987c478bd9Sstevel@tonic-gate */
1997c478bd9Sstevel@tonic-gate int
usba_list_walk_step(mdb_walk_state_t * wsp)2007c478bd9Sstevel@tonic-gate usba_list_walk_step(mdb_walk_state_t *wsp)
2017c478bd9Sstevel@tonic-gate {
2027c478bd9Sstevel@tonic-gate int status;
2037c478bd9Sstevel@tonic-gate usba_list_entry_t list_entry;
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate if (mdb_vread(&list_entry, sizeof (usba_list_entry_t),
2067c478bd9Sstevel@tonic-gate (uintptr_t)wsp->walk_addr) == -1) {
2077c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_list_entry_t at %p",
2087c478bd9Sstevel@tonic-gate wsp->walk_addr);
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate return (WALK_ERR);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &list_entry,
2147c478bd9Sstevel@tonic-gate wsp->walk_cbdata);
2157c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)list_entry.next;
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate /* Check if we're at the last element */
2187c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate return (WALK_DONE);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate
2237c478bd9Sstevel@tonic-gate return (status);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate * usb_pipe_handle walker
2297c478bd9Sstevel@tonic-gate * Given a pointer to a usba_device_t, walk the array of endpoint
2307c478bd9Sstevel@tonic-gate * pipe_handle lists.
2317c478bd9Sstevel@tonic-gate * For each list, traverse the list, invoking the callback on each element.
2327c478bd9Sstevel@tonic-gate *
2337c478bd9Sstevel@tonic-gate * Note this function takes the address of a usba_device struct (which is
2347c478bd9Sstevel@tonic-gate * easily obtainable), but actually traverses a sub-portion of the struct
2357c478bd9Sstevel@tonic-gate * (which address is not so easily obtainable).
2367c478bd9Sstevel@tonic-gate */
2377c478bd9Sstevel@tonic-gate int
usb_pipe_handle_walk_init(mdb_walk_state_t * wsp)2387c478bd9Sstevel@tonic-gate usb_pipe_handle_walk_init(mdb_walk_state_t *wsp)
2397c478bd9Sstevel@tonic-gate {
2407c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) {
2417c478bd9Sstevel@tonic-gate mdb_warn("not a global walk; usba_device_t required\n");
2427c478bd9Sstevel@tonic-gate
2437c478bd9Sstevel@tonic-gate return (WALK_ERR);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate wsp->walk_data = mdb_alloc((sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS,
2477c478bd9Sstevel@tonic-gate UM_SLEEP | UM_GC);
2487c478bd9Sstevel@tonic-gate
2497c478bd9Sstevel@tonic-gate /*
2507c478bd9Sstevel@tonic-gate * Read the usb_ph_list array into local memory.
2517c478bd9Sstevel@tonic-gate * Set start address to first element/endpoint in usb_pipehandle_list
2527c478bd9Sstevel@tonic-gate */
2534610e4a0Sfrits if (mdb_vread(wsp->walk_data,
2547c478bd9Sstevel@tonic-gate (sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS,
2557c478bd9Sstevel@tonic-gate (uintptr_t)((size_t)(wsp->walk_addr) +
2567c478bd9Sstevel@tonic-gate offsetof(usba_device_t, usb_ph_list))) == -1) {
2577c478bd9Sstevel@tonic-gate mdb_warn("failed to read usb_pipehandle_list at %p",
2587c478bd9Sstevel@tonic-gate wsp->walk_addr);
2597c478bd9Sstevel@tonic-gate
2607c478bd9Sstevel@tonic-gate return (WALK_ERR);
2617c478bd9Sstevel@tonic-gate }
2627c478bd9Sstevel@tonic-gate
2637c478bd9Sstevel@tonic-gate wsp->walk_arg = 0;
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate return (WALK_NEXT);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate int
usb_pipe_handle_walk_step(mdb_walk_state_t * wsp)2707c478bd9Sstevel@tonic-gate usb_pipe_handle_walk_step(mdb_walk_state_t *wsp)
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate int status;
2737c478bd9Sstevel@tonic-gate usba_ph_impl_t *impl_list = (usba_ph_impl_t *)(wsp->walk_data);
2747c478bd9Sstevel@tonic-gate intptr_t index = (intptr_t)wsp->walk_arg;
2757c478bd9Sstevel@tonic-gate
2767c478bd9Sstevel@tonic-gate /* Find the first valid endpoint, starting from where we left off. */
2777c478bd9Sstevel@tonic-gate while ((index < USBA_N_ENDPOINTS) &&
2787c478bd9Sstevel@tonic-gate (impl_list[index].usba_ph_data == NULL)) {
2797c478bd9Sstevel@tonic-gate index++;
2807c478bd9Sstevel@tonic-gate }
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate /* No more valid endpoints. */
2837c478bd9Sstevel@tonic-gate if (index >= USBA_N_ENDPOINTS) {
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate return (WALK_DONE);
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate status = wsp->walk_callback((uintptr_t)impl_list[index].usba_ph_data,
2897c478bd9Sstevel@tonic-gate wsp->walk_data, wsp->walk_cbdata);
2907c478bd9Sstevel@tonic-gate
2917c478bd9Sstevel@tonic-gate /* Set up to start at next pipe handle next time. */
2927c478bd9Sstevel@tonic-gate wsp->walk_arg = (void *)(index + 1);
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate return (status);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate
2987c478bd9Sstevel@tonic-gate /*
2997c478bd9Sstevel@tonic-gate * Given the address of a usba_pipe_handle_data_t, dump summary info.
3007c478bd9Sstevel@tonic-gate */
3017c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3027c478bd9Sstevel@tonic-gate int
usb_pipe_handle(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)3037c478bd9Sstevel@tonic-gate usb_pipe_handle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
3047c478bd9Sstevel@tonic-gate {
3057c478bd9Sstevel@tonic-gate char *dir, *type, *state;
3067c478bd9Sstevel@tonic-gate usb_ep_descr_t ept_descr;
3077c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t pipe_handle;
3087c478bd9Sstevel@tonic-gate usba_ph_impl_t ph_impl;
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate
3157c478bd9Sstevel@tonic-gate if (mdb_vread(&pipe_handle,
3167c478bd9Sstevel@tonic-gate sizeof (usba_pipe_handle_data_t), addr) == -1) {
3177c478bd9Sstevel@tonic-gate mdb_warn("failed to read pipe handle at %p", addr);
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate return (DCMD_ERR);
3207c478bd9Sstevel@tonic-gate }
3217c478bd9Sstevel@tonic-gate
3227c478bd9Sstevel@tonic-gate if (mdb_vread(&ph_impl, sizeof (usba_ph_impl_t),
3237c478bd9Sstevel@tonic-gate (uintptr_t)pipe_handle.p_ph_impl) == -1) {
3247c478bd9Sstevel@tonic-gate state = "*******";
3257c478bd9Sstevel@tonic-gate } else {
3267c478bd9Sstevel@tonic-gate switch (ph_impl.usba_ph_state) {
3277c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_CLOSED:
3287c478bd9Sstevel@tonic-gate state = "CLOSED ";
3297c478bd9Sstevel@tonic-gate break;
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_IDLE:
3327c478bd9Sstevel@tonic-gate state = "IDLE ";
3337c478bd9Sstevel@tonic-gate break;
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_ACTIVE:
3367c478bd9Sstevel@tonic-gate state = "ACTIVE ";
3377c478bd9Sstevel@tonic-gate break;
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_ERROR:
3407c478bd9Sstevel@tonic-gate state = "ERROR ";
3417c478bd9Sstevel@tonic-gate break;
3427c478bd9Sstevel@tonic-gate
3437c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_CLOSING:
3447c478bd9Sstevel@tonic-gate state = "CLOSING";
3457c478bd9Sstevel@tonic-gate break;
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate default:
3487c478bd9Sstevel@tonic-gate state = "ILLEGAL";
3497c478bd9Sstevel@tonic-gate break;
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate bcopy(&pipe_handle.p_ep, &ept_descr, sizeof (usb_ep_descr_t));
3547c478bd9Sstevel@tonic-gate
3557c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) {
3567c478bd9Sstevel@tonic-gate mdb_printf("\n %<u>%-3s %5s %3s %7s %-?s %-?s %-?s%</u>\n",
3577c478bd9Sstevel@tonic-gate "EP", "TYPE ", "DIR", "STATE ", "P_HANDLE", "P_POLICY",
3587c478bd9Sstevel@tonic-gate "EP DESCR");
3597c478bd9Sstevel@tonic-gate }
3607c478bd9Sstevel@tonic-gate
3617c478bd9Sstevel@tonic-gate dir = ((ept_descr.bEndpointAddress & USB_EP_DIR_MASK) &
3627c478bd9Sstevel@tonic-gate USB_EP_DIR_IN) ? "In " : "Out";
3637c478bd9Sstevel@tonic-gate switch (ept_descr.bmAttributes & USB_EP_ATTR_MASK) {
3647c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL:
3657c478bd9Sstevel@tonic-gate type = "Cntrl";
3667c478bd9Sstevel@tonic-gate break;
3677c478bd9Sstevel@tonic-gate
3687c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH:
3697c478bd9Sstevel@tonic-gate type = "Isoch";
3707c478bd9Sstevel@tonic-gate break;
3717c478bd9Sstevel@tonic-gate
3727c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK:
3737c478bd9Sstevel@tonic-gate type = "Bulk ";
3747c478bd9Sstevel@tonic-gate break;
3757c478bd9Sstevel@tonic-gate
3767c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR:
3777c478bd9Sstevel@tonic-gate type = "Intr ";
3787c478bd9Sstevel@tonic-gate break;
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate default:
3817c478bd9Sstevel@tonic-gate type = "*****";
3827c478bd9Sstevel@tonic-gate break;
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate
3857c478bd9Sstevel@tonic-gate mdb_printf(" %3d %5s %3s %7s %-?p %-?p %-?p\n",
3867c478bd9Sstevel@tonic-gate ept_descr.bEndpointAddress & USB_EP_NUM_MASK, type, dir, state,
3877c478bd9Sstevel@tonic-gate addr, addr + offsetof(usba_pipe_handle_data_t, p_policy),
3887c478bd9Sstevel@tonic-gate addr + offsetof(usba_pipe_handle_data_t, p_ep));
3897c478bd9Sstevel@tonic-gate
3907c478bd9Sstevel@tonic-gate return (DCMD_OK);
3917c478bd9Sstevel@tonic-gate }
3927c478bd9Sstevel@tonic-gate
3937c478bd9Sstevel@tonic-gate
3947c478bd9Sstevel@tonic-gate /*
3957c478bd9Sstevel@tonic-gate * usba_device walker:
3967c478bd9Sstevel@tonic-gate *
3977c478bd9Sstevel@tonic-gate * walks the chain of usba_device structs headed by usba_device_list in usba.c
3987c478bd9Sstevel@tonic-gate * NOTE: It uses the generic list walk step routine usba_list_walk_step.
3997c478bd9Sstevel@tonic-gate * No walk_fini routine is needed.
4007c478bd9Sstevel@tonic-gate */
4017c478bd9Sstevel@tonic-gate int
usba_device_walk_init(mdb_walk_state_t * wsp)4027c478bd9Sstevel@tonic-gate usba_device_walk_init(mdb_walk_state_t *wsp)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate usba_list_entry_t list_entry;
4057c478bd9Sstevel@tonic-gate
4067c478bd9Sstevel@tonic-gate if (wsp->walk_addr != NULL) {
4077c478bd9Sstevel@tonic-gate mdb_warn(
4087c478bd9Sstevel@tonic-gate "global walk only. Must be invoked without an address\n");
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate return (WALK_ERR);
4117c478bd9Sstevel@tonic-gate }
4127c478bd9Sstevel@tonic-gate
4134610e4a0Sfrits if (mdb_readvar(&list_entry, "usba_device_list") == -1) {
4147c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_device_list");
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate return (WALK_ERR);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate
4197c478bd9Sstevel@tonic-gate /* List head is not part of usba_device_t, get first usba_device_t */
4207c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)list_entry.next;
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate return (WALK_NEXT);
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate /*
4277c478bd9Sstevel@tonic-gate * usba_device dcmd
4287c478bd9Sstevel@tonic-gate * Given the address of a usba_device struct, dump summary info
4297c478bd9Sstevel@tonic-gate * -v: Print more (verbose) info
4307c478bd9Sstevel@tonic-gate * -p: Walk/dump all open pipes for this usba_device
4317c478bd9Sstevel@tonic-gate */
4327c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4337c478bd9Sstevel@tonic-gate int
usba_device(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)4347c478bd9Sstevel@tonic-gate usba_device(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate int status;
4377c478bd9Sstevel@tonic-gate char pathname[MAXNAMELEN];
4387c478bd9Sstevel@tonic-gate char dname[MODMAXNAMELEN + 1] = "<unatt>"; /* Driver name */
4397c478bd9Sstevel@tonic-gate char drv_statep[MODMAXNAMELEN+ 10];
4407c478bd9Sstevel@tonic-gate uint_t usb_flag = NULL;
4417c478bd9Sstevel@tonic-gate boolean_t no_driver_attached = FALSE;
4427c478bd9Sstevel@tonic-gate uintptr_t dip_addr;
4437c478bd9Sstevel@tonic-gate struct dev_info devinfo;
4447c478bd9Sstevel@tonic-gate
4457c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) {
4467c478bd9Sstevel@tonic-gate /* Global walk */
4477c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("usba_device", "usba_device", argc,
4487c478bd9Sstevel@tonic-gate argv) == -1) {
4497c478bd9Sstevel@tonic-gate mdb_warn("failed to walk usba_device");
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate return (DCMD_ERR);
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate
4547c478bd9Sstevel@tonic-gate return (DCMD_OK);
4557c478bd9Sstevel@tonic-gate }
4567c478bd9Sstevel@tonic-gate
4577c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv,
4587c478bd9Sstevel@tonic-gate 'p', MDB_OPT_SETBITS, USB_DUMP_ACTIVE_PIPES, &usb_flag,
4597c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, USB_DUMP_VERBOSE, &usb_flag, NULL) != argc) {
4607c478bd9Sstevel@tonic-gate
4617c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate
4647c478bd9Sstevel@tonic-gate if (usb_flag && !(DCMD_HDRSPEC(flags))) {
4657c478bd9Sstevel@tonic-gate mdb_printf("\n");
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) {
4697c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-15s %4s %-?s %-42s%</u>\n",
4707c478bd9Sstevel@tonic-gate "NAME", "INST", "DIP", "PATH ");
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate status = usba_device2dip(addr, &dip_addr);
4747c478bd9Sstevel@tonic-gate /*
4757c478bd9Sstevel@tonic-gate * -1 = error
4767c478bd9Sstevel@tonic-gate * 0 = no error, no match
4777c478bd9Sstevel@tonic-gate * 1 = no error, match
4787c478bd9Sstevel@tonic-gate */
4797c478bd9Sstevel@tonic-gate if (status != 1) {
4807c478bd9Sstevel@tonic-gate if (status == -1) {
4817c478bd9Sstevel@tonic-gate mdb_warn("error looking for dip for usba_device %p",
4827c478bd9Sstevel@tonic-gate addr);
4837c478bd9Sstevel@tonic-gate } else {
4847c478bd9Sstevel@tonic-gate mdb_warn("failed to find dip for usba_device %p\n",
4857c478bd9Sstevel@tonic-gate addr);
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate mdb_warn("dip and statep unobtainable\n");
4887c478bd9Sstevel@tonic-gate
4897c478bd9Sstevel@tonic-gate return (DCMD_ERR);
4907c478bd9Sstevel@tonic-gate }
4917c478bd9Sstevel@tonic-gate
4927c478bd9Sstevel@tonic-gate /* Figure out what driver (name) is attached to this node. */
4937c478bd9Sstevel@tonic-gate (void) mdb_devinfo2driver(dip_addr, (char *)dname, sizeof (dname));
4947c478bd9Sstevel@tonic-gate
4954610e4a0Sfrits if (mdb_vread(&devinfo, sizeof (struct dev_info),
4967c478bd9Sstevel@tonic-gate dip_addr) == -1) {
4977c478bd9Sstevel@tonic-gate mdb_warn("failed to read devinfo");
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate return (DCMD_ERR);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate if (!(DDI_CF2(&devinfo))) {
5037c478bd9Sstevel@tonic-gate no_driver_attached = TRUE;
5047c478bd9Sstevel@tonic-gate }
5057c478bd9Sstevel@tonic-gate
5067c478bd9Sstevel@tonic-gate (void) mdb_ddi_pathname(dip_addr, pathname, sizeof (pathname));
5077c478bd9Sstevel@tonic-gate mdb_printf("%-15s %2d %-?p %s\n", dname, devinfo.devi_instance,
5087c478bd9Sstevel@tonic-gate dip_addr, pathname);
5097c478bd9Sstevel@tonic-gate
5107c478bd9Sstevel@tonic-gate if (usb_flag & USB_DUMP_VERBOSE) {
5117c478bd9Sstevel@tonic-gate int i;
5127c478bd9Sstevel@tonic-gate uintptr_t statep = NULL;
5137c478bd9Sstevel@tonic-gate char *string_descr;
5147c478bd9Sstevel@tonic-gate char **config_cloud, **conf_str_descr;
5157c478bd9Sstevel@tonic-gate usb_dev_descr_t usb_dev_descr;
5167c478bd9Sstevel@tonic-gate usba_device_t usba_device_struct;
5177c478bd9Sstevel@tonic-gate
5184610e4a0Sfrits if (mdb_vread(&usba_device_struct,
5197c478bd9Sstevel@tonic-gate sizeof (usba_device_t), addr) == -1) {
5207c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_device struct");
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate return (DCMD_ERR);
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate
5257c478bd9Sstevel@tonic-gate mdb_printf(" usba_device: %-16p\n\n", (usba_device_t *)addr);
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate if (mdb_vread(&usb_dev_descr, sizeof (usb_dev_descr),
5287c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_dev_descr) == -1) {
5297c478bd9Sstevel@tonic-gate mdb_warn("failed to read usb_dev_descr_t struct");
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate return (DCMD_ERR);
5327c478bd9Sstevel@tonic-gate }
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate mdb_printf("\n idVendor: 0x%04x idProduct: 0x%04x "
5357c478bd9Sstevel@tonic-gate "usb_addr: 0x%02x\n", usb_dev_descr.idVendor,
5367c478bd9Sstevel@tonic-gate usb_dev_descr.idProduct, usba_device_struct.usb_addr);
5377c478bd9Sstevel@tonic-gate
5387c478bd9Sstevel@tonic-gate /* Get the string descriptor string into local space. */
5397c478bd9Sstevel@tonic-gate string_descr = (char *)mdb_alloc(USB_MAXSTRINGLEN, UM_GC);
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate if (usba_device_struct.usb_mfg_str == NULL) {
5427c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "<No Manufacturer String>");
5437c478bd9Sstevel@tonic-gate } else {
5447c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
5457c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_mfg_str) == -1) {
5467c478bd9Sstevel@tonic-gate mdb_warn("failed to read manufacturer "
5477c478bd9Sstevel@tonic-gate "string descriptor");
5487c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "???");
5497c478bd9Sstevel@tonic-gate }
5507c478bd9Sstevel@tonic-gate }
5517c478bd9Sstevel@tonic-gate mdb_printf("\n Manufacturer String:\t%s\n", string_descr);
5527c478bd9Sstevel@tonic-gate
5537c478bd9Sstevel@tonic-gate if (usba_device_struct.usb_product_str == NULL) {
5547c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "<No Product String>");
5557c478bd9Sstevel@tonic-gate } else {
5567c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
5577c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_product_str) ==
5587c478bd9Sstevel@tonic-gate -1) {
5597c478bd9Sstevel@tonic-gate mdb_warn("failed to read product string "
5607c478bd9Sstevel@tonic-gate "descriptor");
5617c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "???");
5627c478bd9Sstevel@tonic-gate }
5637c478bd9Sstevel@tonic-gate }
5647c478bd9Sstevel@tonic-gate mdb_printf(" Product String:\t\t%s\n", string_descr);
5657c478bd9Sstevel@tonic-gate
5667c478bd9Sstevel@tonic-gate if (usba_device_struct.usb_serialno_str == NULL) {
5677c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "<No SerialNumber String>");
5687c478bd9Sstevel@tonic-gate } else {
5697c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, USB_MAXSTRINGLEN,
5707c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_serialno_str) ==
5717c478bd9Sstevel@tonic-gate -1) {
5727c478bd9Sstevel@tonic-gate mdb_warn("failed to read serial number string "
5737c478bd9Sstevel@tonic-gate "descriptor");
5747c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "???");
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate }
5777c478bd9Sstevel@tonic-gate mdb_printf(" SerialNumber String:\t%s\n", string_descr);
5787c478bd9Sstevel@tonic-gate
5797c478bd9Sstevel@tonic-gate if (no_driver_attached) {
5807c478bd9Sstevel@tonic-gate mdb_printf("\n");
5817c478bd9Sstevel@tonic-gate } else {
5827c478bd9Sstevel@tonic-gate mdb_printf(" state_p: ");
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate * Given the dip, find the associated statep. The
5867c478bd9Sstevel@tonic-gate * convention to generate this soft state anchor is:
5877c478bd9Sstevel@tonic-gate * <driver_name>_statep
5887c478bd9Sstevel@tonic-gate */
5897c478bd9Sstevel@tonic-gate (void) mdb_snprintf(drv_statep, sizeof (drv_statep),
5907c478bd9Sstevel@tonic-gate "%s_statep", dname);
5917c478bd9Sstevel@tonic-gate if (mdb_devinfo2statep(dip_addr, drv_statep,
5927c478bd9Sstevel@tonic-gate &statep) == -1) {
5937c478bd9Sstevel@tonic-gate mdb_warn("failed to find %s state struct for "
5947c478bd9Sstevel@tonic-gate "dip %p", drv_statep, dip_addr);
5957c478bd9Sstevel@tonic-gate
5967c478bd9Sstevel@tonic-gate return (DCMD_ERR);
5977c478bd9Sstevel@tonic-gate }
5987c478bd9Sstevel@tonic-gate mdb_printf("%-?p\n", statep);
5997c478bd9Sstevel@tonic-gate }
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate config_cloud = (char **)mdb_alloc(sizeof (void *) *
6027c478bd9Sstevel@tonic-gate usba_device_struct.usb_n_cfgs, UM_GC);
6037c478bd9Sstevel@tonic-gate
6047c478bd9Sstevel@tonic-gate conf_str_descr = (char **)mdb_alloc(sizeof (void *) *
6057c478bd9Sstevel@tonic-gate usba_device_struct.usb_n_cfgs, UM_GC);
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate if ((usba_device_struct.usb_cfg_array) &&
6087c478bd9Sstevel@tonic-gate (usba_device_struct.usb_cfg_str_descr)) {
6097c478bd9Sstevel@tonic-gate if ((mdb_vread(config_cloud, sizeof (void *) *
6107c478bd9Sstevel@tonic-gate usba_device_struct.usb_n_cfgs,
6117c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_cfg_array) ==
6127c478bd9Sstevel@tonic-gate -1) || (mdb_vread(conf_str_descr, sizeof (void *)
6137c478bd9Sstevel@tonic-gate * usba_device_struct.usb_n_cfgs, (uintptr_t)
6147c478bd9Sstevel@tonic-gate usba_device_struct.usb_cfg_str_descr)) == -1) {
6157c478bd9Sstevel@tonic-gate
6167c478bd9Sstevel@tonic-gate mdb_warn("failed to read config cloud pointers");
6177c478bd9Sstevel@tonic-gate
6187c478bd9Sstevel@tonic-gate } else {
6197c478bd9Sstevel@tonic-gate
6207c478bd9Sstevel@tonic-gate mdb_printf("\n Device Config Clouds:\n"
6217c478bd9Sstevel@tonic-gate " Index\tConfig\t\tConfiguration "
6227c478bd9Sstevel@tonic-gate "String\n"
6237c478bd9Sstevel@tonic-gate " -----\t------\t\t"
6247c478bd9Sstevel@tonic-gate "--------------------\n");
6257c478bd9Sstevel@tonic-gate
6267c478bd9Sstevel@tonic-gate for (i = 0; i < usba_device_struct.usb_n_cfgs;
6277c478bd9Sstevel@tonic-gate i++) {
6287c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr,
6297c478bd9Sstevel@tonic-gate USB_MAXSTRINGLEN,
6307c478bd9Sstevel@tonic-gate (uintptr_t)conf_str_descr[i]) ==
6317c478bd9Sstevel@tonic-gate -1) {
6327c478bd9Sstevel@tonic-gate (void) strcpy(string_descr,
6337c478bd9Sstevel@tonic-gate "<No Configuration "
6347c478bd9Sstevel@tonic-gate "String>");
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate mdb_printf(" %4d\t0x%p\t%s\n", i,
6377c478bd9Sstevel@tonic-gate config_cloud[i], string_descr);
6387c478bd9Sstevel@tonic-gate }
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate }
6417c478bd9Sstevel@tonic-gate
6427c478bd9Sstevel@tonic-gate mdb_printf("\n Active configuration index: %d\n",
6437c478bd9Sstevel@tonic-gate usba_device_struct.usb_active_cfg_ndx);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate
6467c478bd9Sstevel@tonic-gate if (usb_flag & USB_DUMP_ACTIVE_PIPES) {
6477c478bd9Sstevel@tonic-gate
6487c478bd9Sstevel@tonic-gate if (mdb_pwalk_dcmd("usb_pipe_handle", "usb_pipe_handle",
6497c478bd9Sstevel@tonic-gate 0, NULL, addr) == -1) {
6507c478bd9Sstevel@tonic-gate mdb_warn("failed to walk usb_pipe_handle");
6517c478bd9Sstevel@tonic-gate return (DCMD_ERR);
6527c478bd9Sstevel@tonic-gate }
6537c478bd9Sstevel@tonic-gate }
6547c478bd9Sstevel@tonic-gate
6557c478bd9Sstevel@tonic-gate return (DCMD_OK);
6567c478bd9Sstevel@tonic-gate }
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate
6597c478bd9Sstevel@tonic-gate /*
6607c478bd9Sstevel@tonic-gate * Dump the contents of the usba_debug_buf, from the oldest to newest,
6617c478bd9Sstevel@tonic-gate * wrapping around if necessary.
6627c478bd9Sstevel@tonic-gate */
6637c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6647c478bd9Sstevel@tonic-gate int
usba_debug_buf(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)6657c478bd9Sstevel@tonic-gate usba_debug_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
6667c478bd9Sstevel@tonic-gate {
6677c478bd9Sstevel@tonic-gate char *debug_buf_addr; /* addr in core */
6687c478bd9Sstevel@tonic-gate char *local_debug_buf; /* local copy of buf */
6697c478bd9Sstevel@tonic-gate int debug_buf_size;
6707c478bd9Sstevel@tonic-gate char *term_p;
6717c478bd9Sstevel@tonic-gate int being_cleared;
6727c478bd9Sstevel@tonic-gate
6737c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) {
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
6767c478bd9Sstevel@tonic-gate }
6777c478bd9Sstevel@tonic-gate
6784610e4a0Sfrits if (mdb_readvar(&being_cleared, "usba_clear_debug_buf_flag") ==
6797c478bd9Sstevel@tonic-gate -1) {
6807c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_clear_debug_buf_flag");
6817c478bd9Sstevel@tonic-gate
6827c478bd9Sstevel@tonic-gate return (DCMD_ERR);
6837c478bd9Sstevel@tonic-gate }
6847c478bd9Sstevel@tonic-gate if (being_cleared) {
6857c478bd9Sstevel@tonic-gate
6867c478bd9Sstevel@tonic-gate return (DCMD_OK);
6877c478bd9Sstevel@tonic-gate }
6887c478bd9Sstevel@tonic-gate
6894610e4a0Sfrits if (mdb_readvar(&debug_buf_addr, "usba_debug_buf") == -1) {
6907c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_debug_buf");
6917c478bd9Sstevel@tonic-gate
6927c478bd9Sstevel@tonic-gate return (DCMD_ERR);
6937c478bd9Sstevel@tonic-gate }
6947c478bd9Sstevel@tonic-gate
6957c478bd9Sstevel@tonic-gate if (debug_buf_addr == NULL) {
6967c478bd9Sstevel@tonic-gate mdb_warn("usba_debug_buf not allocated\n");
6977c478bd9Sstevel@tonic-gate
6987c478bd9Sstevel@tonic-gate return (DCMD_OK);
6997c478bd9Sstevel@tonic-gate }
7007c478bd9Sstevel@tonic-gate
7017c478bd9Sstevel@tonic-gate
7024610e4a0Sfrits if (mdb_readvar(&debug_buf_size, "usba_debug_buf_size") == -1) {
7037c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_debug_buf_size");
7047c478bd9Sstevel@tonic-gate
7057c478bd9Sstevel@tonic-gate return (DCMD_ERR);
7067c478bd9Sstevel@tonic-gate }
7077c478bd9Sstevel@tonic-gate
7087c478bd9Sstevel@tonic-gate debug_buf_size += USB_DEBUG_SIZE_EXTRA_ALLOC;
7097c478bd9Sstevel@tonic-gate local_debug_buf = (char *)mdb_alloc(debug_buf_size, UM_SLEEP | UM_GC);
7107c478bd9Sstevel@tonic-gate
7114610e4a0Sfrits if ((mdb_vread(local_debug_buf, debug_buf_size,
7127c478bd9Sstevel@tonic-gate (uintptr_t)debug_buf_addr)) == -1) {
7137c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_debug_buf at %p",
7147c478bd9Sstevel@tonic-gate local_debug_buf);
7157c478bd9Sstevel@tonic-gate
7167c478bd9Sstevel@tonic-gate return (DCMD_ERR);
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate local_debug_buf[debug_buf_size - 1] = '\0';
7197c478bd9Sstevel@tonic-gate
7207c478bd9Sstevel@tonic-gate if (strlen(local_debug_buf) == NULL) {
7217c478bd9Sstevel@tonic-gate
7227c478bd9Sstevel@tonic-gate return (DCMD_OK);
7237c478bd9Sstevel@tonic-gate }
7247c478bd9Sstevel@tonic-gate
7257c478bd9Sstevel@tonic-gate if ((term_p = strstr(local_debug_buf, ">>>>")) == NULL) {
7267c478bd9Sstevel@tonic-gate mdb_warn("failed to find terminator \">>>>\"\n");
7277c478bd9Sstevel@tonic-gate
7287c478bd9Sstevel@tonic-gate return (DCMD_ERR);
7297c478bd9Sstevel@tonic-gate }
7307c478bd9Sstevel@tonic-gate
7317c478bd9Sstevel@tonic-gate /*
7327c478bd9Sstevel@tonic-gate * Print the chunk of buffer from the terminator to the end.
7337c478bd9Sstevel@tonic-gate * This will print a null string if no wrap has occurred yet.
7347c478bd9Sstevel@tonic-gate */
7357c478bd9Sstevel@tonic-gate mdb_printf("%s", term_p+5); /* after >>>>\0 to end of buf */
7367c478bd9Sstevel@tonic-gate mdb_printf("%s\n", local_debug_buf); /* beg of buf to >>>>\0 */
7377c478bd9Sstevel@tonic-gate
7387c478bd9Sstevel@tonic-gate return (DCMD_OK);
7397c478bd9Sstevel@tonic-gate }
7407c478bd9Sstevel@tonic-gate
7417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7427c478bd9Sstevel@tonic-gate int
usba_clear_debug_buf(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)7437c478bd9Sstevel@tonic-gate usba_clear_debug_buf(
7447c478bd9Sstevel@tonic-gate uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
7457c478bd9Sstevel@tonic-gate {
7467c478bd9Sstevel@tonic-gate int clear = 1;
7477c478bd9Sstevel@tonic-gate
7487c478bd9Sstevel@tonic-gate /* stop the tracing */
7497c478bd9Sstevel@tonic-gate if (mdb_writevar((void*)&clear, "usba_clear_debug_buf_flag") == -1) {
7507c478bd9Sstevel@tonic-gate mdb_warn("failed to set usba_clear_debug_buf_flag");
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate return (DCMD_ERR);
7537c478bd9Sstevel@tonic-gate }
7547c478bd9Sstevel@tonic-gate
7557c478bd9Sstevel@tonic-gate return (DCMD_OK);
7567c478bd9Sstevel@tonic-gate }
7577c478bd9Sstevel@tonic-gate
7584e968bc2Sgc161489 /* prtusb entries */
7594e968bc2Sgc161489 extern int prtusb(uintptr_t, uint_t, int, const mdb_arg_t *);
7604e968bc2Sgc161489
7614e968bc2Sgc161489 extern void prt_usb_usage(void);
7627c478bd9Sstevel@tonic-gate
7637c478bd9Sstevel@tonic-gate /*
7647c478bd9Sstevel@tonic-gate * MDB module linkage information:
7657c478bd9Sstevel@tonic-gate *
7667c478bd9Sstevel@tonic-gate * We declare a list of structures describing our dcmds, and a function
7677c478bd9Sstevel@tonic-gate * named _mdb_init to return a pointer to our module information.
7687c478bd9Sstevel@tonic-gate */
7697c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
7707c478bd9Sstevel@tonic-gate { "usb_pipe_handle", ":",
7717c478bd9Sstevel@tonic-gate "print a usb_pipe_handle struct", usb_pipe_handle, NULL},
7727c478bd9Sstevel@tonic-gate { "usba_device", ": [-pv]",
7737c478bd9Sstevel@tonic-gate "print summary info for a usba_device_t struct", usba_device, NULL},
7747c478bd9Sstevel@tonic-gate { "usba_debug_buf", NULL,
7757c478bd9Sstevel@tonic-gate "print usba_debug_buf", usba_debug_buf, NULL},
7767c478bd9Sstevel@tonic-gate { "usba_clear_debug_buf", NULL,
7777c478bd9Sstevel@tonic-gate "clear usba_debug_buf", usba_clear_debug_buf, NULL},
778*eae66f16Sgc161489 { "prtusb", "?[-t] [-v] [-i index]",
779*eae66f16Sgc161489 "print trees and descriptors for usba_device_t",
780*eae66f16Sgc161489 prtusb, prt_usb_usage},
7817c478bd9Sstevel@tonic-gate { NULL }
7827c478bd9Sstevel@tonic-gate };
7837c478bd9Sstevel@tonic-gate
7847c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
7857c478bd9Sstevel@tonic-gate /* Generic list walker. */
7867c478bd9Sstevel@tonic-gate { "usba_list_entry", "walk list of usba_list_entry_t structures",
7877c478bd9Sstevel@tonic-gate usba_list_walk_init, usba_list_walk_step, NULL, NULL },
7887c478bd9Sstevel@tonic-gate { "usb_pipe_handle", "walk USB pipe handles, given a usba_device_t ptr",
7897c478bd9Sstevel@tonic-gate usb_pipe_handle_walk_init, usb_pipe_handle_walk_step, NULL, NULL },
7907c478bd9Sstevel@tonic-gate { "usba_device", "walk global list of usba_device_t structures",
7917c478bd9Sstevel@tonic-gate usba_device_walk_init, usba_list_walk_step, NULL, NULL },
7927c478bd9Sstevel@tonic-gate { NULL }
7937c478bd9Sstevel@tonic-gate };
7947c478bd9Sstevel@tonic-gate
7957c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
7967c478bd9Sstevel@tonic-gate MDB_API_VERSION, dcmds, walkers
7977c478bd9Sstevel@tonic-gate };
7987c478bd9Sstevel@tonic-gate
7997c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)8007c478bd9Sstevel@tonic-gate _mdb_init(void)
8017c478bd9Sstevel@tonic-gate {
8027c478bd9Sstevel@tonic-gate return (&modinfo);
8037c478bd9Sstevel@tonic-gate }
804