1 /* $FreeBSD$ */ 2 /*- 3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/stdint.h> 28 #include <sys/stddef.h> 29 #include <sys/param.h> 30 #include <sys/queue.h> 31 #include <sys/types.h> 32 #include <sys/systm.h> 33 #include <sys/kernel.h> 34 #include <sys/bus.h> 35 #include <sys/linker_set.h> 36 #include <sys/module.h> 37 #include <sys/lock.h> 38 #include <sys/mutex.h> 39 #include <sys/condvar.h> 40 #include <sys/sysctl.h> 41 #include <sys/sx.h> 42 #include <sys/unistd.h> 43 #include <sys/callout.h> 44 #include <sys/malloc.h> 45 #include <sys/priv.h> 46 47 #include <dev/usb/usb.h> 48 #include <dev/usb/usbdi.h> 49 50 #include <dev/usb/usb_core.h> 51 #include <dev/usb/usb_debug.h> 52 #include <dev/usb/usb_process.h> 53 #include <dev/usb/usb_device.h> 54 #include <dev/usb/usb_busdma.h> 55 #include <dev/usb/usb_transfer.h> 56 57 #include <ddb/ddb.h> 58 #include <ddb/db_sym.h> 59 60 /* 61 * Define this unconditionally in case a kernel module is loaded that 62 * has been compiled with debugging options. 63 */ 64 int usb_debug = 0; 65 66 SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW, 0, "USB debugging"); 67 SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RW, 68 &usb_debug, 0, "Debug level"); 69 70 TUNABLE_INT("hw.usb.debug", &usb_debug); 71 72 /*------------------------------------------------------------------------* 73 * usb_dump_iface 74 * 75 * This function dumps information about an USB interface. 76 *------------------------------------------------------------------------*/ 77 void 78 usb_dump_iface(struct usb_interface *iface) 79 { 80 printf("usb_dump_iface: iface=%p\n", iface); 81 if (iface == NULL) { 82 return; 83 } 84 printf(" iface=%p idesc=%p altindex=%d\n", 85 iface, iface->idesc, iface->alt_index); 86 } 87 88 /*------------------------------------------------------------------------* 89 * usb_dump_device 90 * 91 * This function dumps information about an USB device. 92 *------------------------------------------------------------------------*/ 93 void 94 usb_dump_device(struct usb_device *udev) 95 { 96 printf("usb_dump_device: dev=%p\n", udev); 97 if (udev == NULL) { 98 return; 99 } 100 printf(" bus=%p \n" 101 " address=%d config=%d depth=%d speed=%d self_powered=%d\n" 102 " power=%d langid=%d\n", 103 udev->bus, 104 udev->address, udev->curr_config_no, udev->depth, udev->speed, 105 udev->flags.self_powered, udev->power, udev->langid); 106 } 107 108 /*------------------------------------------------------------------------* 109 * usb_dump_queue 110 * 111 * This function dumps the USB transfer that are queued up on an USB endpoint. 112 *------------------------------------------------------------------------*/ 113 void 114 usb_dump_queue(struct usb_endpoint *ep) 115 { 116 struct usb_xfer *xfer; 117 118 printf("usb_dump_queue: endpoint=%p xfer: ", ep); 119 TAILQ_FOREACH(xfer, &ep->endpoint_q.head, wait_entry) { 120 printf(" %p", xfer); 121 } 122 printf("\n"); 123 } 124 125 /*------------------------------------------------------------------------* 126 * usb_dump_endpoint 127 * 128 * This function dumps information about an USB endpoint. 129 *------------------------------------------------------------------------*/ 130 void 131 usb_dump_endpoint(struct usb_endpoint *ep) 132 { 133 if (ep) { 134 printf("usb_dump_endpoint: endpoint=%p", ep); 135 136 printf(" edesc=%p isoc_next=%d toggle_next=%d", 137 ep->edesc, ep->isoc_next, ep->toggle_next); 138 139 if (ep->edesc) { 140 printf(" bEndpointAddress=0x%02x", 141 ep->edesc->bEndpointAddress); 142 } 143 printf("\n"); 144 usb_dump_queue(ep); 145 } else { 146 printf("usb_dump_endpoint: endpoint=NULL\n"); 147 } 148 } 149 150 /*------------------------------------------------------------------------* 151 * usb_dump_xfer 152 * 153 * This function dumps information about an USB transfer. 154 *------------------------------------------------------------------------*/ 155 void 156 usb_dump_xfer(struct usb_xfer *xfer) 157 { 158 struct usb_device *udev; 159 printf("usb_dump_xfer: xfer=%p\n", xfer); 160 if (xfer == NULL) { 161 return; 162 } 163 if (xfer->endpoint == NULL) { 164 printf("xfer %p: endpoint=NULL\n", 165 xfer); 166 return; 167 } 168 udev = xfer->xroot->udev; 169 printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d " 170 "endpoint=%p ep=0x%02x attr=0x%02x\n", 171 xfer, udev, 172 UGETW(udev->ddesc.idVendor), 173 UGETW(udev->ddesc.idProduct), 174 udev->address, xfer->endpoint, 175 xfer->endpoint->edesc->bEndpointAddress, 176 xfer->endpoint->edesc->bmAttributes); 177 } 178