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 54e968bc2Sgc * Common Development and Distribution License (the "License"). 64e968bc2Sgc * 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 /* 224e968bc2Sgc * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*993e3fafSRobert Mustacchi * 25*993e3fafSRobert Mustacchi * Copyright 2016 Joyent, Inc. 267c478bd9Sstevel@tonic-gate */ 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> 37*993e3fafSRobert Mustacchi #include <sys/usb/hubd/hub.h> 38*993e3fafSRobert Mustacchi #include <sys/usb/hubd/hubdvar.h> 397c478bd9Sstevel@tonic-gate #include <sys/file.h> 407c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 417c478bd9Sstevel@tonic-gate #include <unistd.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * Prototypes 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate /* usba.c */ 487c478bd9Sstevel@tonic-gate extern uintptr_t mdb_usba_get_usba_device(uintptr_t); 497c478bd9Sstevel@tonic-gate extern uintptr_t mdb_usba_hcdi_get_hcdi(struct dev_info *); 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * Defines 537c478bd9Sstevel@tonic-gate */ 547c478bd9Sstevel@tonic-gate /* dcmd options */ 557c478bd9Sstevel@tonic-gate #define USB_DUMP_VERBOSE 0x01 567c478bd9Sstevel@tonic-gate #define USB_DUMP_ACTIVE_PIPES 0x02 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* Hardcoded slop factor designed into debug buf logic */ 597c478bd9Sstevel@tonic-gate #define USB_DEBUG_SIZE_EXTRA_ALLOC 8 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * Callback arg struct for find_dip (callback func used in usba_device2devinfo). 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate typedef struct usba_device2devinfo_data { 667c478bd9Sstevel@tonic-gate uintptr_t u2d_target_usb_dev_p; /* one we're looking for */ 677c478bd9Sstevel@tonic-gate uintptr_t *u2d_dip_addr; /* Where to store result */ 687c478bd9Sstevel@tonic-gate boolean_t u2d_found; /* Match found */ 697c478bd9Sstevel@tonic-gate } usba_device2devinfo_cbdata_t; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * Callback for usba_device2dip. 747c478bd9Sstevel@tonic-gate * Callback called from the devinfo_children walk invoked in usba_device2dip. 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * For the current dip, get the (potential) pointer to its usba_device_t 777c478bd9Sstevel@tonic-gate * struct. 787c478bd9Sstevel@tonic-gate * See if this pointer matches the address of the usba_device_t we're looking 797c478bd9Sstevel@tonic-gate * for (passed in as usb_dev_p). If so, stuff its value in u2d_dip_addr, 807c478bd9Sstevel@tonic-gate * and terminate the walk. 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * - dip_addr is the address in core of the dip currently being processed by the 837c478bd9Sstevel@tonic-gate * walk 847c478bd9Sstevel@tonic-gate * - local_dip is a pointer to a copy of the struct dev_info in local memory 857c478bd9Sstevel@tonic-gate * - cb_data is the addr of the callback arg the walker was invoked with 867c478bd9Sstevel@tonic-gate * (passed through transparently from walk invoker). 877c478bd9Sstevel@tonic-gate * 887c478bd9Sstevel@tonic-gate * Returns: 897c478bd9Sstevel@tonic-gate * - WALK_NEXT on success (match not found yet) 907c478bd9Sstevel@tonic-gate * - WALK_ERR on errors. 917c478bd9Sstevel@tonic-gate * - WALK_DONE is returned, cb_data.found is set to TRUE, and 927c478bd9Sstevel@tonic-gate * *cb_data.u2d_dip_addr is set to the matched dip addr if a dip corresponding 937c478bd9Sstevel@tonic-gate * to the desired usba_device_t* is found. 947c478bd9Sstevel@tonic-gate */ 957c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 967c478bd9Sstevel@tonic-gate static int 977c478bd9Sstevel@tonic-gate find_dip(uintptr_t dip_addr, const void *local_dip, void *cb_arg) 987c478bd9Sstevel@tonic-gate { 997c478bd9Sstevel@tonic-gate uintptr_t cur_usb_dev; 1007c478bd9Sstevel@tonic-gate usba_device2devinfo_cbdata_t *cb_data = 101*993e3fafSRobert Mustacchi (usba_device2devinfo_cbdata_t *)cb_arg; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate if ((cur_usb_dev = mdb_usba_get_usba_device(dip_addr)) == NULL) { 1047c478bd9Sstevel@tonic-gate /* 1057c478bd9Sstevel@tonic-gate * If there's no corresponding usba_device_t, this dip isn't 1067c478bd9Sstevel@tonic-gate * a usb node. Might be an sd node. Ignore it. 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate if (cur_usb_dev == cb_data->u2d_target_usb_dev_p) { 1137c478bd9Sstevel@tonic-gate *cb_data->u2d_dip_addr = dip_addr; 1147c478bd9Sstevel@tonic-gate cb_data->u2d_found = TRUE; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate return (WALK_DONE); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * Given a usba_device pointer, figure out which dip is associated with it. 1257c478bd9Sstevel@tonic-gate * Relies on usba_device.usb_root_hub_dip being accurate. 1267c478bd9Sstevel@tonic-gate * 1277c478bd9Sstevel@tonic-gate * - usb_dev_addr is a pointer to a usba_device_t in core. 1287c478bd9Sstevel@tonic-gate * - dip_addr is the address of a uintptr_t to receive the address in core 1297c478bd9Sstevel@tonic-gate * of the found dip (if any). 1307c478bd9Sstevel@tonic-gate * 1317c478bd9Sstevel@tonic-gate * Returns: 1327c478bd9Sstevel@tonic-gate * 0 on success (no match found) 1337c478bd9Sstevel@tonic-gate * 1 on success (match found) 1347c478bd9Sstevel@tonic-gate * -1 on errors. 1357c478bd9Sstevel@tonic-gate */ 1367c478bd9Sstevel@tonic-gate static int 1377c478bd9Sstevel@tonic-gate usba_device2dip(uintptr_t usb_dev_addr, uintptr_t *dip_addr) 1387c478bd9Sstevel@tonic-gate { 1397c478bd9Sstevel@tonic-gate usba_device_t usb_dev; 1407c478bd9Sstevel@tonic-gate usba_device2devinfo_cbdata_t cb_data; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate /* 1437c478bd9Sstevel@tonic-gate * Walk all USB children of the root hub devinfo. 1447c478bd9Sstevel@tonic-gate * The callback func looks for a match on the usba_device address. 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate cb_data.u2d_target_usb_dev_p = usb_dev_addr; 1477c478bd9Sstevel@tonic-gate cb_data.u2d_dip_addr = dip_addr; 1487c478bd9Sstevel@tonic-gate cb_data.u2d_found = FALSE; 1497c478bd9Sstevel@tonic-gate 1504610e4a0Sfrits if (mdb_vread(&usb_dev, sizeof (usba_device_t), 1517c478bd9Sstevel@tonic-gate usb_dev_addr) == -1) { 1527c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_device struct"); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate return (-1); 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * Walk devinfo children starting with the root hub node, 1597c478bd9Sstevel@tonic-gate * looking for a match on the usba_device pointer (which is what 1607c478bd9Sstevel@tonic-gate * find_dip does). 1617c478bd9Sstevel@tonic-gate * Result is placed in cb_data.dip_addr. 1627c478bd9Sstevel@tonic-gate */ 1634610e4a0Sfrits if (mdb_pwalk("devinfo_children", find_dip, &cb_data, 1647c478bd9Sstevel@tonic-gate (uintptr_t)usb_dev.usb_root_hub_dip) != 0) { 1657c478bd9Sstevel@tonic-gate mdb_warn("failed to walk devinfo_children"); 1667c478bd9Sstevel@tonic-gate 1677c478bd9Sstevel@tonic-gate return (-1); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate if (cb_data.u2d_found == TRUE) { 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate return (1); 1737c478bd9Sstevel@tonic-gate } 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate return (0); 1767c478bd9Sstevel@tonic-gate } 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate /* 1807c478bd9Sstevel@tonic-gate * Generic walker usba_list_entry_t walker. 1817c478bd9Sstevel@tonic-gate * Works for any usba_list_entry_t list. 1827c478bd9Sstevel@tonic-gate */ 1837c478bd9Sstevel@tonic-gate int 1847c478bd9Sstevel@tonic-gate usba_list_walk_init(mdb_walk_state_t *wsp) 1857c478bd9Sstevel@tonic-gate { 1867c478bd9Sstevel@tonic-gate /* Must have a start addr. */ 1877c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 1887c478bd9Sstevel@tonic-gate mdb_warn("not a global walk. Starting address required\n"); 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate return (WALK_ERR); 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate return (WALK_NEXT); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* 1987c478bd9Sstevel@tonic-gate * Generic list walker step routine. 1997c478bd9Sstevel@tonic-gate * NOTE: multiple walkers share this routine. 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate int 2027c478bd9Sstevel@tonic-gate usba_list_walk_step(mdb_walk_state_t *wsp) 2037c478bd9Sstevel@tonic-gate { 2047c478bd9Sstevel@tonic-gate int status; 2057c478bd9Sstevel@tonic-gate usba_list_entry_t list_entry; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate if (mdb_vread(&list_entry, sizeof (usba_list_entry_t), 2087c478bd9Sstevel@tonic-gate (uintptr_t)wsp->walk_addr) == -1) { 2097c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_list_entry_t at %p", 2107c478bd9Sstevel@tonic-gate wsp->walk_addr); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate return (WALK_ERR); 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate status = wsp->walk_callback(wsp->walk_addr, &list_entry, 2167c478bd9Sstevel@tonic-gate wsp->walk_cbdata); 2177c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)list_entry.next; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate /* Check if we're at the last element */ 2207c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate return (WALK_DONE); 2237c478bd9Sstevel@tonic-gate } 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate return (status); 2267c478bd9Sstevel@tonic-gate } 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * usb_pipe_handle walker 2317c478bd9Sstevel@tonic-gate * Given a pointer to a usba_device_t, walk the array of endpoint 2327c478bd9Sstevel@tonic-gate * pipe_handle lists. 2337c478bd9Sstevel@tonic-gate * For each list, traverse the list, invoking the callback on each element. 2347c478bd9Sstevel@tonic-gate * 2357c478bd9Sstevel@tonic-gate * Note this function takes the address of a usba_device struct (which is 2367c478bd9Sstevel@tonic-gate * easily obtainable), but actually traverses a sub-portion of the struct 2377c478bd9Sstevel@tonic-gate * (which address is not so easily obtainable). 2387c478bd9Sstevel@tonic-gate */ 2397c478bd9Sstevel@tonic-gate int 2407c478bd9Sstevel@tonic-gate usb_pipe_handle_walk_init(mdb_walk_state_t *wsp) 2417c478bd9Sstevel@tonic-gate { 2427c478bd9Sstevel@tonic-gate if (wsp->walk_addr == NULL) { 2437c478bd9Sstevel@tonic-gate mdb_warn("not a global walk; usba_device_t required\n"); 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate return (WALK_ERR); 2467c478bd9Sstevel@tonic-gate } 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate wsp->walk_data = mdb_alloc((sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS, 249*993e3fafSRobert Mustacchi UM_SLEEP | UM_GC); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * Read the usb_ph_list array into local memory. 2537c478bd9Sstevel@tonic-gate * Set start address to first element/endpoint in usb_pipehandle_list 2547c478bd9Sstevel@tonic-gate */ 2554610e4a0Sfrits if (mdb_vread(wsp->walk_data, 2567c478bd9Sstevel@tonic-gate (sizeof (usba_ph_impl_t)) * USBA_N_ENDPOINTS, 2577c478bd9Sstevel@tonic-gate (uintptr_t)((size_t)(wsp->walk_addr) + 2587c478bd9Sstevel@tonic-gate offsetof(usba_device_t, usb_ph_list))) == -1) { 2597c478bd9Sstevel@tonic-gate mdb_warn("failed to read usb_pipehandle_list at %p", 2607c478bd9Sstevel@tonic-gate wsp->walk_addr); 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate return (WALK_ERR); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate wsp->walk_arg = 0; 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate return (WALK_NEXT); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate int 2727c478bd9Sstevel@tonic-gate usb_pipe_handle_walk_step(mdb_walk_state_t *wsp) 2737c478bd9Sstevel@tonic-gate { 2747c478bd9Sstevel@tonic-gate int status; 2757c478bd9Sstevel@tonic-gate usba_ph_impl_t *impl_list = (usba_ph_impl_t *)(wsp->walk_data); 2767c478bd9Sstevel@tonic-gate intptr_t index = (intptr_t)wsp->walk_arg; 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* Find the first valid endpoint, starting from where we left off. */ 2797c478bd9Sstevel@tonic-gate while ((index < USBA_N_ENDPOINTS) && 2807c478bd9Sstevel@tonic-gate (impl_list[index].usba_ph_data == NULL)) { 2817c478bd9Sstevel@tonic-gate index++; 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate /* No more valid endpoints. */ 2857c478bd9Sstevel@tonic-gate if (index >= USBA_N_ENDPOINTS) { 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate return (WALK_DONE); 2887c478bd9Sstevel@tonic-gate } 2897c478bd9Sstevel@tonic-gate 2907c478bd9Sstevel@tonic-gate status = wsp->walk_callback((uintptr_t)impl_list[index].usba_ph_data, 291*993e3fafSRobert Mustacchi wsp->walk_data, wsp->walk_cbdata); 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* Set up to start at next pipe handle next time. */ 2947c478bd9Sstevel@tonic-gate wsp->walk_arg = (void *)(index + 1); 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate return (status); 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * Given the address of a usba_pipe_handle_data_t, dump summary info. 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3047c478bd9Sstevel@tonic-gate int 3057c478bd9Sstevel@tonic-gate usb_pipe_handle(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 3067c478bd9Sstevel@tonic-gate { 3077c478bd9Sstevel@tonic-gate char *dir, *type, *state; 3087c478bd9Sstevel@tonic-gate usb_ep_descr_t ept_descr; 3097c478bd9Sstevel@tonic-gate usba_pipe_handle_data_t pipe_handle; 3107c478bd9Sstevel@tonic-gate usba_ph_impl_t ph_impl; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate if (mdb_vread(&pipe_handle, 3187c478bd9Sstevel@tonic-gate sizeof (usba_pipe_handle_data_t), addr) == -1) { 3197c478bd9Sstevel@tonic-gate mdb_warn("failed to read pipe handle at %p", addr); 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate return (DCMD_ERR); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate if (mdb_vread(&ph_impl, sizeof (usba_ph_impl_t), 3257c478bd9Sstevel@tonic-gate (uintptr_t)pipe_handle.p_ph_impl) == -1) { 3267c478bd9Sstevel@tonic-gate state = "*******"; 3277c478bd9Sstevel@tonic-gate } else { 3287c478bd9Sstevel@tonic-gate switch (ph_impl.usba_ph_state) { 3297c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_CLOSED: 3307c478bd9Sstevel@tonic-gate state = "CLOSED "; 3317c478bd9Sstevel@tonic-gate break; 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_IDLE: 3347c478bd9Sstevel@tonic-gate state = "IDLE "; 3357c478bd9Sstevel@tonic-gate break; 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_ACTIVE: 3387c478bd9Sstevel@tonic-gate state = "ACTIVE "; 3397c478bd9Sstevel@tonic-gate break; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_ERROR: 3427c478bd9Sstevel@tonic-gate state = "ERROR "; 3437c478bd9Sstevel@tonic-gate break; 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate case USB_PIPE_STATE_CLOSING: 3467c478bd9Sstevel@tonic-gate state = "CLOSING"; 3477c478bd9Sstevel@tonic-gate break; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate default: 3507c478bd9Sstevel@tonic-gate state = "ILLEGAL"; 3517c478bd9Sstevel@tonic-gate break; 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate } 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate bcopy(&pipe_handle.p_ep, &ept_descr, sizeof (usb_ep_descr_t)); 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 3587c478bd9Sstevel@tonic-gate mdb_printf("\n %<u>%-3s %5s %3s %7s %-?s %-?s %-?s%</u>\n", 3597c478bd9Sstevel@tonic-gate "EP", "TYPE ", "DIR", "STATE ", "P_HANDLE", "P_POLICY", 3607c478bd9Sstevel@tonic-gate "EP DESCR"); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate dir = ((ept_descr.bEndpointAddress & USB_EP_DIR_MASK) & 3647c478bd9Sstevel@tonic-gate USB_EP_DIR_IN) ? "In " : "Out"; 3657c478bd9Sstevel@tonic-gate switch (ept_descr.bmAttributes & USB_EP_ATTR_MASK) { 3667c478bd9Sstevel@tonic-gate case USB_EP_ATTR_CONTROL: 3677c478bd9Sstevel@tonic-gate type = "Cntrl"; 3687c478bd9Sstevel@tonic-gate break; 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate case USB_EP_ATTR_ISOCH: 3717c478bd9Sstevel@tonic-gate type = "Isoch"; 3727c478bd9Sstevel@tonic-gate break; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate case USB_EP_ATTR_BULK: 3757c478bd9Sstevel@tonic-gate type = "Bulk "; 3767c478bd9Sstevel@tonic-gate break; 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate case USB_EP_ATTR_INTR: 3797c478bd9Sstevel@tonic-gate type = "Intr "; 3807c478bd9Sstevel@tonic-gate break; 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate default: 3837c478bd9Sstevel@tonic-gate type = "*****"; 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate 3877c478bd9Sstevel@tonic-gate mdb_printf(" %3d %5s %3s %7s %-?p %-?p %-?p\n", 3887c478bd9Sstevel@tonic-gate ept_descr.bEndpointAddress & USB_EP_NUM_MASK, type, dir, state, 3897c478bd9Sstevel@tonic-gate addr, addr + offsetof(usba_pipe_handle_data_t, p_policy), 3907c478bd9Sstevel@tonic-gate addr + offsetof(usba_pipe_handle_data_t, p_ep)); 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate return (DCMD_OK); 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate 3967c478bd9Sstevel@tonic-gate /* 3977c478bd9Sstevel@tonic-gate * usba_device walker: 3987c478bd9Sstevel@tonic-gate * 3997c478bd9Sstevel@tonic-gate * walks the chain of usba_device structs headed by usba_device_list in usba.c 4007c478bd9Sstevel@tonic-gate * NOTE: It uses the generic list walk step routine usba_list_walk_step. 4017c478bd9Sstevel@tonic-gate * No walk_fini routine is needed. 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate int 4047c478bd9Sstevel@tonic-gate usba_device_walk_init(mdb_walk_state_t *wsp) 4057c478bd9Sstevel@tonic-gate { 4067c478bd9Sstevel@tonic-gate usba_list_entry_t list_entry; 4077c478bd9Sstevel@tonic-gate 4087c478bd9Sstevel@tonic-gate if (wsp->walk_addr != NULL) { 4097c478bd9Sstevel@tonic-gate mdb_warn( 4107c478bd9Sstevel@tonic-gate "global walk only. Must be invoked without an address\n"); 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate return (WALK_ERR); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate 4154610e4a0Sfrits if (mdb_readvar(&list_entry, "usba_device_list") == -1) { 4167c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_device_list"); 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate return (WALK_ERR); 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate /* List head is not part of usba_device_t, get first usba_device_t */ 4227c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)list_entry.next; 4237c478bd9Sstevel@tonic-gate 4247c478bd9Sstevel@tonic-gate return (WALK_NEXT); 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate 427*993e3fafSRobert Mustacchi int 428*993e3fafSRobert Mustacchi usba_hubd_walk_init(mdb_walk_state_t *wsp) 429*993e3fafSRobert Mustacchi { 430*993e3fafSRobert Mustacchi if (wsp->walk_addr != 0) { 431*993e3fafSRobert Mustacchi mdb_warn("hubd only supports global walks.\n"); 432*993e3fafSRobert Mustacchi return (WALK_ERR); 433*993e3fafSRobert Mustacchi } 434*993e3fafSRobert Mustacchi 435*993e3fafSRobert Mustacchi if (mdb_layered_walk("usba_device", wsp) == -1) { 436*993e3fafSRobert Mustacchi mdb_warn("couldn't walk 'usba_device'"); 437*993e3fafSRobert Mustacchi return (WALK_ERR); 438*993e3fafSRobert Mustacchi } 439*993e3fafSRobert Mustacchi 440*993e3fafSRobert Mustacchi return (WALK_NEXT); 441*993e3fafSRobert Mustacchi } 442*993e3fafSRobert Mustacchi 443*993e3fafSRobert Mustacchi /* 444*993e3fafSRobert Mustacchi * Getting the hub state is annoying. The root hubs are stored on dev_info_t 445*993e3fafSRobert Mustacchi * while the normal hubs are stored as soft state. 446*993e3fafSRobert Mustacchi */ 447*993e3fafSRobert Mustacchi int 448*993e3fafSRobert Mustacchi usba_hubd_walk_step(mdb_walk_state_t *wsp) 449*993e3fafSRobert Mustacchi { 450*993e3fafSRobert Mustacchi usba_device_t ud; 451*993e3fafSRobert Mustacchi hubd_t hubd; 452*993e3fafSRobert Mustacchi struct dev_info dev_info; 453*993e3fafSRobert Mustacchi uintptr_t state_addr; 454*993e3fafSRobert Mustacchi 455*993e3fafSRobert Mustacchi if (mdb_vread(&ud, sizeof (ud), wsp->walk_addr) != sizeof (ud)) { 456*993e3fafSRobert Mustacchi mdb_warn("failed to read usba_device_t at %p", wsp->walk_addr); 457*993e3fafSRobert Mustacchi return (WALK_ERR); 458*993e3fafSRobert Mustacchi } 459*993e3fafSRobert Mustacchi 460*993e3fafSRobert Mustacchi if (ud.usb_root_hubd != NULL) { 461*993e3fafSRobert Mustacchi if (mdb_vread(&hubd, sizeof (hubd), 462*993e3fafSRobert Mustacchi (uintptr_t)ud.usb_root_hubd) != sizeof (hubd)) { 463*993e3fafSRobert Mustacchi mdb_warn("failed to read hubd at %p", ud.usb_root_hubd); 464*993e3fafSRobert Mustacchi return (WALK_ERR); 465*993e3fafSRobert Mustacchi } 466*993e3fafSRobert Mustacchi return (wsp->walk_callback((uintptr_t)ud.usb_root_hubd, &hubd, 467*993e3fafSRobert Mustacchi wsp->walk_cbdata)); 468*993e3fafSRobert Mustacchi } 469*993e3fafSRobert Mustacchi 470*993e3fafSRobert Mustacchi if (ud.usb_hubdi == NULL) 471*993e3fafSRobert Mustacchi return (WALK_NEXT); 472*993e3fafSRobert Mustacchi 473*993e3fafSRobert Mustacchi /* 474*993e3fafSRobert Mustacchi * For non-root hubs, the hubd_t is stored in the soft state. Figure out 475*993e3fafSRobert Mustacchi * the instance from the dev_info_t and then get its soft state. 476*993e3fafSRobert Mustacchi */ 477*993e3fafSRobert Mustacchi if (mdb_vread(&dev_info, sizeof (struct dev_info), 478*993e3fafSRobert Mustacchi (uintptr_t)ud.usb_dip) != sizeof (struct dev_info)) { 479*993e3fafSRobert Mustacchi mdb_warn("failed to read dev_info_t for device %p at %p", 480*993e3fafSRobert Mustacchi wsp->walk_addr, ud.usb_dip); 481*993e3fafSRobert Mustacchi return (WALK_ERR); 482*993e3fafSRobert Mustacchi } 483*993e3fafSRobert Mustacchi 484*993e3fafSRobert Mustacchi if (mdb_get_soft_state_byname("hubd_statep", dev_info.devi_instance, 485*993e3fafSRobert Mustacchi &state_addr, &hubd, sizeof (hubd)) == -1) { 486*993e3fafSRobert Mustacchi mdb_warn("failed to read hubd soft state for instance %d from " 487*993e3fafSRobert Mustacchi "usb device %p", dev_info.devi_instance, wsp->walk_addr); 488*993e3fafSRobert Mustacchi return (WALK_ERR); 489*993e3fafSRobert Mustacchi } 490*993e3fafSRobert Mustacchi 491*993e3fafSRobert Mustacchi return (wsp->walk_callback(state_addr, &hubd, wsp->walk_cbdata)); 492*993e3fafSRobert Mustacchi } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * usba_device dcmd 4967c478bd9Sstevel@tonic-gate * Given the address of a usba_device struct, dump summary info 4977c478bd9Sstevel@tonic-gate * -v: Print more (verbose) info 4987c478bd9Sstevel@tonic-gate * -p: Walk/dump all open pipes for this usba_device 4997c478bd9Sstevel@tonic-gate */ 5007c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5017c478bd9Sstevel@tonic-gate int 5027c478bd9Sstevel@tonic-gate usba_device(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 5037c478bd9Sstevel@tonic-gate { 5047c478bd9Sstevel@tonic-gate int status; 5057c478bd9Sstevel@tonic-gate char pathname[MAXNAMELEN]; 5067c478bd9Sstevel@tonic-gate char dname[MODMAXNAMELEN + 1] = "<unatt>"; /* Driver name */ 5077c478bd9Sstevel@tonic-gate char drv_statep[MODMAXNAMELEN+ 10]; 5087c478bd9Sstevel@tonic-gate uint_t usb_flag = NULL; 5097c478bd9Sstevel@tonic-gate boolean_t no_driver_attached = FALSE; 5107c478bd9Sstevel@tonic-gate uintptr_t dip_addr; 5117c478bd9Sstevel@tonic-gate struct dev_info devinfo; 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate if (!(flags & DCMD_ADDRSPEC)) { 5147c478bd9Sstevel@tonic-gate /* Global walk */ 5157c478bd9Sstevel@tonic-gate if (mdb_walk_dcmd("usba_device", "usba_device", argc, 5167c478bd9Sstevel@tonic-gate argv) == -1) { 5177c478bd9Sstevel@tonic-gate mdb_warn("failed to walk usba_device"); 5187c478bd9Sstevel@tonic-gate 5197c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate return (DCMD_OK); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate if (mdb_getopts(argc, argv, 5267c478bd9Sstevel@tonic-gate 'p', MDB_OPT_SETBITS, USB_DUMP_ACTIVE_PIPES, &usb_flag, 5277c478bd9Sstevel@tonic-gate 'v', MDB_OPT_SETBITS, USB_DUMP_VERBOSE, &usb_flag, NULL) != argc) { 5287c478bd9Sstevel@tonic-gate 5297c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 5307c478bd9Sstevel@tonic-gate } 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate if (usb_flag && !(DCMD_HDRSPEC(flags))) { 5337c478bd9Sstevel@tonic-gate mdb_printf("\n"); 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags)) { 5377c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-15s %4s %-?s %-42s%</u>\n", 5387c478bd9Sstevel@tonic-gate "NAME", "INST", "DIP", "PATH "); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate status = usba_device2dip(addr, &dip_addr); 5427c478bd9Sstevel@tonic-gate /* 5437c478bd9Sstevel@tonic-gate * -1 = error 5447c478bd9Sstevel@tonic-gate * 0 = no error, no match 5457c478bd9Sstevel@tonic-gate * 1 = no error, match 5467c478bd9Sstevel@tonic-gate */ 5477c478bd9Sstevel@tonic-gate if (status != 1) { 5487c478bd9Sstevel@tonic-gate if (status == -1) { 5497c478bd9Sstevel@tonic-gate mdb_warn("error looking for dip for usba_device %p", 5507c478bd9Sstevel@tonic-gate addr); 5517c478bd9Sstevel@tonic-gate } else { 5527c478bd9Sstevel@tonic-gate mdb_warn("failed to find dip for usba_device %p\n", 5537c478bd9Sstevel@tonic-gate addr); 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate mdb_warn("dip and statep unobtainable\n"); 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate /* Figure out what driver (name) is attached to this node. */ 5617c478bd9Sstevel@tonic-gate (void) mdb_devinfo2driver(dip_addr, (char *)dname, sizeof (dname)); 5627c478bd9Sstevel@tonic-gate 5634610e4a0Sfrits if (mdb_vread(&devinfo, sizeof (struct dev_info), 5647c478bd9Sstevel@tonic-gate dip_addr) == -1) { 5657c478bd9Sstevel@tonic-gate mdb_warn("failed to read devinfo"); 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate if (!(DDI_CF2(&devinfo))) { 5717c478bd9Sstevel@tonic-gate no_driver_attached = TRUE; 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate (void) mdb_ddi_pathname(dip_addr, pathname, sizeof (pathname)); 5757c478bd9Sstevel@tonic-gate mdb_printf("%-15s %2d %-?p %s\n", dname, devinfo.devi_instance, 5767c478bd9Sstevel@tonic-gate dip_addr, pathname); 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate if (usb_flag & USB_DUMP_VERBOSE) { 5797c478bd9Sstevel@tonic-gate int i; 5807c478bd9Sstevel@tonic-gate uintptr_t statep = NULL; 5817c478bd9Sstevel@tonic-gate char *string_descr; 5827c478bd9Sstevel@tonic-gate char **config_cloud, **conf_str_descr; 5837c478bd9Sstevel@tonic-gate usb_dev_descr_t usb_dev_descr; 5847c478bd9Sstevel@tonic-gate usba_device_t usba_device_struct; 5857c478bd9Sstevel@tonic-gate 5864610e4a0Sfrits if (mdb_vread(&usba_device_struct, 5877c478bd9Sstevel@tonic-gate sizeof (usba_device_t), addr) == -1) { 5887c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_device struct"); 5897c478bd9Sstevel@tonic-gate 5907c478bd9Sstevel@tonic-gate return (DCMD_ERR); 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate mdb_printf(" usba_device: %-16p\n\n", (usba_device_t *)addr); 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate if (mdb_vread(&usb_dev_descr, sizeof (usb_dev_descr), 5967c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_dev_descr) == -1) { 5977c478bd9Sstevel@tonic-gate mdb_warn("failed to read usb_dev_descr_t struct"); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate return (DCMD_ERR); 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate mdb_printf("\n idVendor: 0x%04x idProduct: 0x%04x " 6037c478bd9Sstevel@tonic-gate "usb_addr: 0x%02x\n", usb_dev_descr.idVendor, 6047c478bd9Sstevel@tonic-gate usb_dev_descr.idProduct, usba_device_struct.usb_addr); 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate /* Get the string descriptor string into local space. */ 6077c478bd9Sstevel@tonic-gate string_descr = (char *)mdb_alloc(USB_MAXSTRINGLEN, UM_GC); 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate if (usba_device_struct.usb_mfg_str == NULL) { 6107c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "<No Manufacturer String>"); 6117c478bd9Sstevel@tonic-gate } else { 6127c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, USB_MAXSTRINGLEN, 6137c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_mfg_str) == -1) { 6147c478bd9Sstevel@tonic-gate mdb_warn("failed to read manufacturer " 6157c478bd9Sstevel@tonic-gate "string descriptor"); 6167c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "???"); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate mdb_printf("\n Manufacturer String:\t%s\n", string_descr); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate if (usba_device_struct.usb_product_str == NULL) { 6227c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "<No Product String>"); 6237c478bd9Sstevel@tonic-gate } else { 6247c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, USB_MAXSTRINGLEN, 6257c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_product_str) == 6267c478bd9Sstevel@tonic-gate -1) { 6277c478bd9Sstevel@tonic-gate mdb_warn("failed to read product string " 6287c478bd9Sstevel@tonic-gate "descriptor"); 6297c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "???"); 6307c478bd9Sstevel@tonic-gate } 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate mdb_printf(" Product String:\t\t%s\n", string_descr); 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate if (usba_device_struct.usb_serialno_str == NULL) { 6357c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "<No SerialNumber String>"); 6367c478bd9Sstevel@tonic-gate } else { 6377c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, USB_MAXSTRINGLEN, 6387c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_serialno_str) == 6397c478bd9Sstevel@tonic-gate -1) { 6407c478bd9Sstevel@tonic-gate mdb_warn("failed to read serial number string " 6417c478bd9Sstevel@tonic-gate "descriptor"); 6427c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, "???"); 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate } 6457c478bd9Sstevel@tonic-gate mdb_printf(" SerialNumber String:\t%s\n", string_descr); 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate if (no_driver_attached) { 6487c478bd9Sstevel@tonic-gate mdb_printf("\n"); 6497c478bd9Sstevel@tonic-gate } else { 6507c478bd9Sstevel@tonic-gate mdb_printf(" state_p: "); 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate /* 6537c478bd9Sstevel@tonic-gate * Given the dip, find the associated statep. The 6547c478bd9Sstevel@tonic-gate * convention to generate this soft state anchor is: 6557c478bd9Sstevel@tonic-gate * <driver_name>_statep 6567c478bd9Sstevel@tonic-gate */ 6577c478bd9Sstevel@tonic-gate (void) mdb_snprintf(drv_statep, sizeof (drv_statep), 6587c478bd9Sstevel@tonic-gate "%s_statep", dname); 6597c478bd9Sstevel@tonic-gate if (mdb_devinfo2statep(dip_addr, drv_statep, 6607c478bd9Sstevel@tonic-gate &statep) == -1) { 6617c478bd9Sstevel@tonic-gate mdb_warn("failed to find %s state struct for " 6627c478bd9Sstevel@tonic-gate "dip %p", drv_statep, dip_addr); 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate return (DCMD_ERR); 6657c478bd9Sstevel@tonic-gate } 6667c478bd9Sstevel@tonic-gate mdb_printf("%-?p\n", statep); 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate config_cloud = (char **)mdb_alloc(sizeof (void *) * 6707c478bd9Sstevel@tonic-gate usba_device_struct.usb_n_cfgs, UM_GC); 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate conf_str_descr = (char **)mdb_alloc(sizeof (void *) * 6737c478bd9Sstevel@tonic-gate usba_device_struct.usb_n_cfgs, UM_GC); 6747c478bd9Sstevel@tonic-gate 6757c478bd9Sstevel@tonic-gate if ((usba_device_struct.usb_cfg_array) && 6767c478bd9Sstevel@tonic-gate (usba_device_struct.usb_cfg_str_descr)) { 6777c478bd9Sstevel@tonic-gate if ((mdb_vread(config_cloud, sizeof (void *) * 6787c478bd9Sstevel@tonic-gate usba_device_struct.usb_n_cfgs, 6797c478bd9Sstevel@tonic-gate (uintptr_t)usba_device_struct.usb_cfg_array) == 6807c478bd9Sstevel@tonic-gate -1) || (mdb_vread(conf_str_descr, sizeof (void *) 6817c478bd9Sstevel@tonic-gate * usba_device_struct.usb_n_cfgs, (uintptr_t) 6827c478bd9Sstevel@tonic-gate usba_device_struct.usb_cfg_str_descr)) == -1) { 6837c478bd9Sstevel@tonic-gate 684*993e3fafSRobert Mustacchi mdb_warn("failed to read config cloud " 685*993e3fafSRobert Mustacchi "pointers"); 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate } else { 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate mdb_printf("\n Device Config Clouds:\n" 6907c478bd9Sstevel@tonic-gate " Index\tConfig\t\tConfiguration " 6917c478bd9Sstevel@tonic-gate "String\n" 6927c478bd9Sstevel@tonic-gate " -----\t------\t\t" 6937c478bd9Sstevel@tonic-gate "--------------------\n"); 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate for (i = 0; i < usba_device_struct.usb_n_cfgs; 6967c478bd9Sstevel@tonic-gate i++) { 6977c478bd9Sstevel@tonic-gate if (mdb_readstr(string_descr, 6987c478bd9Sstevel@tonic-gate USB_MAXSTRINGLEN, 6997c478bd9Sstevel@tonic-gate (uintptr_t)conf_str_descr[i]) == 7007c478bd9Sstevel@tonic-gate -1) { 7017c478bd9Sstevel@tonic-gate (void) strcpy(string_descr, 7027c478bd9Sstevel@tonic-gate "<No Configuration " 7037c478bd9Sstevel@tonic-gate "String>"); 7047c478bd9Sstevel@tonic-gate } 7057c478bd9Sstevel@tonic-gate mdb_printf(" %4d\t0x%p\t%s\n", i, 7067c478bd9Sstevel@tonic-gate config_cloud[i], string_descr); 7077c478bd9Sstevel@tonic-gate } 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate mdb_printf("\n Active configuration index: %d\n", 7127c478bd9Sstevel@tonic-gate usba_device_struct.usb_active_cfg_ndx); 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate if (usb_flag & USB_DUMP_ACTIVE_PIPES) { 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate if (mdb_pwalk_dcmd("usb_pipe_handle", "usb_pipe_handle", 7187c478bd9Sstevel@tonic-gate 0, NULL, addr) == -1) { 7197c478bd9Sstevel@tonic-gate mdb_warn("failed to walk usb_pipe_handle"); 7207c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7217c478bd9Sstevel@tonic-gate } 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate return (DCMD_OK); 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate /* 7297c478bd9Sstevel@tonic-gate * Dump the contents of the usba_debug_buf, from the oldest to newest, 7307c478bd9Sstevel@tonic-gate * wrapping around if necessary. 7317c478bd9Sstevel@tonic-gate */ 7327c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7337c478bd9Sstevel@tonic-gate int 7347c478bd9Sstevel@tonic-gate usba_debug_buf(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 7357c478bd9Sstevel@tonic-gate { 7367c478bd9Sstevel@tonic-gate char *debug_buf_addr; /* addr in core */ 7377c478bd9Sstevel@tonic-gate char *local_debug_buf; /* local copy of buf */ 7387c478bd9Sstevel@tonic-gate int debug_buf_size; 7397c478bd9Sstevel@tonic-gate char *term_p; 7407c478bd9Sstevel@tonic-gate int being_cleared; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate if (flags & DCMD_ADDRSPEC) { 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate return (DCMD_USAGE); 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate 7474610e4a0Sfrits if (mdb_readvar(&being_cleared, "usba_clear_debug_buf_flag") == 7487c478bd9Sstevel@tonic-gate -1) { 7497c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_clear_debug_buf_flag"); 7507c478bd9Sstevel@tonic-gate 7517c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate if (being_cleared) { 7547c478bd9Sstevel@tonic-gate 7557c478bd9Sstevel@tonic-gate return (DCMD_OK); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate 7584610e4a0Sfrits if (mdb_readvar(&debug_buf_addr, "usba_debug_buf") == -1) { 7597c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_debug_buf"); 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7627c478bd9Sstevel@tonic-gate } 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate if (debug_buf_addr == NULL) { 7657c478bd9Sstevel@tonic-gate mdb_warn("usba_debug_buf not allocated\n"); 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate return (DCMD_OK); 7687c478bd9Sstevel@tonic-gate } 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate 7714610e4a0Sfrits if (mdb_readvar(&debug_buf_size, "usba_debug_buf_size") == -1) { 7727c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_debug_buf_size"); 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate 7777c478bd9Sstevel@tonic-gate debug_buf_size += USB_DEBUG_SIZE_EXTRA_ALLOC; 7787c478bd9Sstevel@tonic-gate local_debug_buf = (char *)mdb_alloc(debug_buf_size, UM_SLEEP | UM_GC); 7797c478bd9Sstevel@tonic-gate 7804610e4a0Sfrits if ((mdb_vread(local_debug_buf, debug_buf_size, 7817c478bd9Sstevel@tonic-gate (uintptr_t)debug_buf_addr)) == -1) { 7827c478bd9Sstevel@tonic-gate mdb_warn("failed to read usba_debug_buf at %p", 7837c478bd9Sstevel@tonic-gate local_debug_buf); 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7867c478bd9Sstevel@tonic-gate } 7877c478bd9Sstevel@tonic-gate local_debug_buf[debug_buf_size - 1] = '\0'; 7887c478bd9Sstevel@tonic-gate 7897c478bd9Sstevel@tonic-gate if (strlen(local_debug_buf) == NULL) { 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate return (DCMD_OK); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate if ((term_p = strstr(local_debug_buf, ">>>>")) == NULL) { 7957c478bd9Sstevel@tonic-gate mdb_warn("failed to find terminator \">>>>\"\n"); 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate return (DCMD_ERR); 7987c478bd9Sstevel@tonic-gate } 7997c478bd9Sstevel@tonic-gate 8007c478bd9Sstevel@tonic-gate /* 8017c478bd9Sstevel@tonic-gate * Print the chunk of buffer from the terminator to the end. 8027c478bd9Sstevel@tonic-gate * This will print a null string if no wrap has occurred yet. 8037c478bd9Sstevel@tonic-gate */ 8047c478bd9Sstevel@tonic-gate mdb_printf("%s", term_p+5); /* after >>>>\0 to end of buf */ 8057c478bd9Sstevel@tonic-gate mdb_printf("%s\n", local_debug_buf); /* beg of buf to >>>>\0 */ 8067c478bd9Sstevel@tonic-gate 8077c478bd9Sstevel@tonic-gate return (DCMD_OK); 8087c478bd9Sstevel@tonic-gate } 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8117c478bd9Sstevel@tonic-gate int 8127c478bd9Sstevel@tonic-gate usba_clear_debug_buf( 8137c478bd9Sstevel@tonic-gate uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv) 8147c478bd9Sstevel@tonic-gate { 8157c478bd9Sstevel@tonic-gate int clear = 1; 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate /* stop the tracing */ 8187c478bd9Sstevel@tonic-gate if (mdb_writevar((void*)&clear, "usba_clear_debug_buf_flag") == -1) { 8197c478bd9Sstevel@tonic-gate mdb_warn("failed to set usba_clear_debug_buf_flag"); 8207c478bd9Sstevel@tonic-gate 8217c478bd9Sstevel@tonic-gate return (DCMD_ERR); 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate 8247c478bd9Sstevel@tonic-gate return (DCMD_OK); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8274e968bc2Sgc /* prtusb entries */ 8284e968bc2Sgc extern int prtusb(uintptr_t, uint_t, int, const mdb_arg_t *); 8294e968bc2Sgc 8304e968bc2Sgc extern void prt_usb_usage(void); 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate /* 8337c478bd9Sstevel@tonic-gate * MDB module linkage information: 8347c478bd9Sstevel@tonic-gate * 8357c478bd9Sstevel@tonic-gate * We declare a list of structures describing our dcmds, and a function 8367c478bd9Sstevel@tonic-gate * named _mdb_init to return a pointer to our module information. 8377c478bd9Sstevel@tonic-gate */ 8387c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = { 8397c478bd9Sstevel@tonic-gate { "usb_pipe_handle", ":", 8407c478bd9Sstevel@tonic-gate "print a usb_pipe_handle struct", usb_pipe_handle, NULL}, 8417c478bd9Sstevel@tonic-gate { "usba_device", ": [-pv]", 8427c478bd9Sstevel@tonic-gate "print summary info for a usba_device_t struct", usba_device, NULL}, 8437c478bd9Sstevel@tonic-gate { "usba_debug_buf", NULL, 8447c478bd9Sstevel@tonic-gate "print usba_debug_buf", usba_debug_buf, NULL}, 8457c478bd9Sstevel@tonic-gate { "usba_clear_debug_buf", NULL, 8467c478bd9Sstevel@tonic-gate "clear usba_debug_buf", usba_clear_debug_buf, NULL}, 847eae66f16Sgc { "prtusb", "?[-t] [-v] [-i index]", 848eae66f16Sgc "print trees and descriptors for usba_device_t", 849eae66f16Sgc prtusb, prt_usb_usage}, 8507c478bd9Sstevel@tonic-gate { NULL } 8517c478bd9Sstevel@tonic-gate }; 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = { 8547c478bd9Sstevel@tonic-gate /* Generic list walker. */ 8557c478bd9Sstevel@tonic-gate { "usba_list_entry", "walk list of usba_list_entry_t structures", 8567c478bd9Sstevel@tonic-gate usba_list_walk_init, usba_list_walk_step, NULL, NULL }, 8577c478bd9Sstevel@tonic-gate { "usb_pipe_handle", "walk USB pipe handles, given a usba_device_t ptr", 8587c478bd9Sstevel@tonic-gate usb_pipe_handle_walk_init, usb_pipe_handle_walk_step, NULL, NULL }, 8597c478bd9Sstevel@tonic-gate { "usba_device", "walk global list of usba_device_t structures", 8607c478bd9Sstevel@tonic-gate usba_device_walk_init, usba_list_walk_step, NULL, NULL }, 861*993e3fafSRobert Mustacchi { "hubd", "walk hubd instances", usba_hubd_walk_init, 862*993e3fafSRobert Mustacchi usba_hubd_walk_step, NULL, NULL }, 8637c478bd9Sstevel@tonic-gate { NULL } 8647c478bd9Sstevel@tonic-gate }; 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = { 8677c478bd9Sstevel@tonic-gate MDB_API_VERSION, dcmds, walkers 8687c478bd9Sstevel@tonic-gate }; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate const mdb_modinfo_t * 8717c478bd9Sstevel@tonic-gate _mdb_init(void) 8727c478bd9Sstevel@tonic-gate { 8737c478bd9Sstevel@tonic-gate return (&modinfo); 8747c478bd9Sstevel@tonic-gate } 875