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