102ac6454SAndrew Thompson /* $FreeBSD$ */ 202ac6454SAndrew Thompson /*- 302ac6454SAndrew Thompson * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 402ac6454SAndrew Thompson * 502ac6454SAndrew Thompson * Redistribution and use in source and binary forms, with or without 602ac6454SAndrew Thompson * modification, are permitted provided that the following conditions 702ac6454SAndrew Thompson * are met: 802ac6454SAndrew Thompson * 1. Redistributions of source code must retain the above copyright 902ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer. 1002ac6454SAndrew Thompson * 2. Redistributions in binary form must reproduce the above copyright 1102ac6454SAndrew Thompson * notice, this list of conditions and the following disclaimer in the 1202ac6454SAndrew Thompson * documentation and/or other materials provided with the distribution. 1302ac6454SAndrew Thompson * 1402ac6454SAndrew Thompson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1502ac6454SAndrew Thompson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1602ac6454SAndrew Thompson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1702ac6454SAndrew Thompson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1802ac6454SAndrew Thompson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1902ac6454SAndrew Thompson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2002ac6454SAndrew Thompson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2102ac6454SAndrew Thompson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2202ac6454SAndrew Thompson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2302ac6454SAndrew Thompson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2402ac6454SAndrew Thompson * SUCH DAMAGE. 2502ac6454SAndrew Thompson */ 2602ac6454SAndrew Thompson 27ed6d949aSAndrew Thompson #include <sys/stdint.h> 28ed6d949aSAndrew Thompson #include <sys/stddef.h> 29ed6d949aSAndrew Thompson #include <sys/param.h> 30ed6d949aSAndrew Thompson #include <sys/queue.h> 31ed6d949aSAndrew Thompson #include <sys/types.h> 32ed6d949aSAndrew Thompson #include <sys/systm.h> 33ed6d949aSAndrew Thompson #include <sys/kernel.h> 34ed6d949aSAndrew Thompson #include <sys/bus.h> 35ed6d949aSAndrew Thompson #include <sys/linker_set.h> 36ed6d949aSAndrew Thompson #include <sys/module.h> 37ed6d949aSAndrew Thompson #include <sys/lock.h> 38ed6d949aSAndrew Thompson #include <sys/mutex.h> 39ed6d949aSAndrew Thompson #include <sys/condvar.h> 40ed6d949aSAndrew Thompson #include <sys/sysctl.h> 41ed6d949aSAndrew Thompson #include <sys/sx.h> 42ed6d949aSAndrew Thompson #include <sys/unistd.h> 43ed6d949aSAndrew Thompson #include <sys/callout.h> 44ed6d949aSAndrew Thompson #include <sys/malloc.h> 45ed6d949aSAndrew Thompson #include <sys/priv.h> 46ed6d949aSAndrew Thompson 4702ac6454SAndrew Thompson #include <dev/usb/usb.h> 48ed6d949aSAndrew Thompson #include <dev/usb/usbdi.h> 4902ac6454SAndrew Thompson 5002ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 5102ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 5202ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 5302ac6454SAndrew Thompson #include <dev/usb/usb_device.h> 5402ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h> 5502ac6454SAndrew Thompson #include <dev/usb/usb_transfer.h> 5602ac6454SAndrew Thompson 57ed6d949aSAndrew Thompson #include <ddb/ddb.h> 58ed6d949aSAndrew Thompson #include <ddb/db_sym.h> 59ed6d949aSAndrew Thompson 6002ac6454SAndrew Thompson /* 6102ac6454SAndrew Thompson * Define this unconditionally in case a kernel module is loaded that 6202ac6454SAndrew Thompson * has been compiled with debugging options. 6302ac6454SAndrew Thompson */ 64a593f6b8SAndrew Thompson int usb_debug = 0; 6502ac6454SAndrew Thompson 669360ae40SAndrew Thompson SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW, 0, "USB debugging"); 679360ae40SAndrew Thompson SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RW, 68a593f6b8SAndrew Thompson &usb_debug, 0, "Debug level"); 6902ac6454SAndrew Thompson 70c13fd8d4SAndrew Thompson TUNABLE_INT("hw.usb.debug", &usb_debug); 71c13fd8d4SAndrew Thompson 7202ac6454SAndrew Thompson /*------------------------------------------------------------------------* 73a593f6b8SAndrew Thompson * usb_dump_iface 7402ac6454SAndrew Thompson * 7502ac6454SAndrew Thompson * This function dumps information about an USB interface. 7602ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 7702ac6454SAndrew Thompson void 78a593f6b8SAndrew Thompson usb_dump_iface(struct usb_interface *iface) 7902ac6454SAndrew Thompson { 80a593f6b8SAndrew Thompson printf("usb_dump_iface: iface=%p\n", iface); 8102ac6454SAndrew Thompson if (iface == NULL) { 8202ac6454SAndrew Thompson return; 8302ac6454SAndrew Thompson } 8402ac6454SAndrew Thompson printf(" iface=%p idesc=%p altindex=%d\n", 8502ac6454SAndrew Thompson iface, iface->idesc, iface->alt_index); 8602ac6454SAndrew Thompson } 8702ac6454SAndrew Thompson 8802ac6454SAndrew Thompson /*------------------------------------------------------------------------* 89a593f6b8SAndrew Thompson * usb_dump_device 9002ac6454SAndrew Thompson * 9102ac6454SAndrew Thompson * This function dumps information about an USB device. 9202ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 9302ac6454SAndrew Thompson void 94a593f6b8SAndrew Thompson usb_dump_device(struct usb_device *udev) 9502ac6454SAndrew Thompson { 96a593f6b8SAndrew Thompson printf("usb_dump_device: dev=%p\n", udev); 9702ac6454SAndrew Thompson if (udev == NULL) { 9802ac6454SAndrew Thompson return; 9902ac6454SAndrew Thompson } 10002ac6454SAndrew Thompson printf(" bus=%p \n" 10102ac6454SAndrew Thompson " address=%d config=%d depth=%d speed=%d self_powered=%d\n" 10202ac6454SAndrew Thompson " power=%d langid=%d\n", 10302ac6454SAndrew Thompson udev->bus, 10402ac6454SAndrew Thompson udev->address, udev->curr_config_no, udev->depth, udev->speed, 10502ac6454SAndrew Thompson udev->flags.self_powered, udev->power, udev->langid); 10602ac6454SAndrew Thompson } 10702ac6454SAndrew Thompson 10802ac6454SAndrew Thompson /*------------------------------------------------------------------------* 109a593f6b8SAndrew Thompson * usb_dump_queue 11002ac6454SAndrew Thompson * 111ae60fdfbSAndrew Thompson * This function dumps the USB transfer that are queued up on an USB endpoint. 11202ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 11302ac6454SAndrew Thompson void 114a593f6b8SAndrew Thompson usb_dump_queue(struct usb_endpoint *ep) 11502ac6454SAndrew Thompson { 116760bc48eSAndrew Thompson struct usb_xfer *xfer; 11702ac6454SAndrew Thompson 118a593f6b8SAndrew Thompson printf("usb_dump_queue: endpoint=%p xfer: ", ep); 119ae60fdfbSAndrew Thompson TAILQ_FOREACH(xfer, &ep->endpoint_q.head, wait_entry) { 12002ac6454SAndrew Thompson printf(" %p", xfer); 12102ac6454SAndrew Thompson } 12202ac6454SAndrew Thompson printf("\n"); 12302ac6454SAndrew Thompson } 12402ac6454SAndrew Thompson 12502ac6454SAndrew Thompson /*------------------------------------------------------------------------* 126a593f6b8SAndrew Thompson * usb_dump_endpoint 12702ac6454SAndrew Thompson * 128ae60fdfbSAndrew Thompson * This function dumps information about an USB endpoint. 12902ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 13002ac6454SAndrew Thompson void 131a593f6b8SAndrew Thompson usb_dump_endpoint(struct usb_endpoint *ep) 13202ac6454SAndrew Thompson { 133ae60fdfbSAndrew Thompson if (ep) { 134a593f6b8SAndrew Thompson printf("usb_dump_endpoint: endpoint=%p", ep); 13502ac6454SAndrew Thompson 13602ac6454SAndrew Thompson printf(" edesc=%p isoc_next=%d toggle_next=%d", 137ae60fdfbSAndrew Thompson ep->edesc, ep->isoc_next, ep->toggle_next); 13802ac6454SAndrew Thompson 139ae60fdfbSAndrew Thompson if (ep->edesc) { 14002ac6454SAndrew Thompson printf(" bEndpointAddress=0x%02x", 141ae60fdfbSAndrew Thompson ep->edesc->bEndpointAddress); 14202ac6454SAndrew Thompson } 14302ac6454SAndrew Thompson printf("\n"); 144a593f6b8SAndrew Thompson usb_dump_queue(ep); 14502ac6454SAndrew Thompson } else { 146a593f6b8SAndrew Thompson printf("usb_dump_endpoint: endpoint=NULL\n"); 14702ac6454SAndrew Thompson } 14802ac6454SAndrew Thompson } 14902ac6454SAndrew Thompson 15002ac6454SAndrew Thompson /*------------------------------------------------------------------------* 151a593f6b8SAndrew Thompson * usb_dump_xfer 15202ac6454SAndrew Thompson * 15302ac6454SAndrew Thompson * This function dumps information about an USB transfer. 15402ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 15502ac6454SAndrew Thompson void 156a593f6b8SAndrew Thompson usb_dump_xfer(struct usb_xfer *xfer) 15702ac6454SAndrew Thompson { 158760bc48eSAndrew Thompson struct usb_device *udev; 159a593f6b8SAndrew Thompson printf("usb_dump_xfer: xfer=%p\n", xfer); 16002ac6454SAndrew Thompson if (xfer == NULL) { 16102ac6454SAndrew Thompson return; 16202ac6454SAndrew Thompson } 163ae60fdfbSAndrew Thompson if (xfer->endpoint == NULL) { 164ae60fdfbSAndrew Thompson printf("xfer %p: endpoint=NULL\n", 16502ac6454SAndrew Thompson xfer); 16602ac6454SAndrew Thompson return; 16702ac6454SAndrew Thompson } 16802ac6454SAndrew Thompson udev = xfer->xroot->udev; 16902ac6454SAndrew Thompson printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d " 170ae60fdfbSAndrew Thompson "endpoint=%p ep=0x%02x attr=0x%02x\n", 17102ac6454SAndrew Thompson xfer, udev, 17202ac6454SAndrew Thompson UGETW(udev->ddesc.idVendor), 17302ac6454SAndrew Thompson UGETW(udev->ddesc.idProduct), 174ae60fdfbSAndrew Thompson udev->address, xfer->endpoint, 175ae60fdfbSAndrew Thompson xfer->endpoint->edesc->bEndpointAddress, 176ae60fdfbSAndrew Thompson xfer->endpoint->edesc->bmAttributes); 17702ac6454SAndrew Thompson } 178