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 2702ac6454SAndrew Thompson #include <dev/usb/usb.h> 2802ac6454SAndrew Thompson 2902ac6454SAndrew Thompson #include <dev/usb/usb_core.h> 3002ac6454SAndrew Thompson #include <dev/usb/usb_debug.h> 3102ac6454SAndrew Thompson #include <dev/usb/usb_process.h> 3202ac6454SAndrew Thompson #include <dev/usb/usb_device.h> 3302ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h> 3402ac6454SAndrew Thompson #include <dev/usb/usb_transfer.h> 3502ac6454SAndrew Thompson 3602ac6454SAndrew Thompson /* 3702ac6454SAndrew Thompson * Define this unconditionally in case a kernel module is loaded that 3802ac6454SAndrew Thompson * has been compiled with debugging options. 3902ac6454SAndrew Thompson */ 4002ac6454SAndrew Thompson int usb2_debug = 0; 4102ac6454SAndrew Thompson 429360ae40SAndrew Thompson SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW, 0, "USB debugging"); 439360ae40SAndrew Thompson SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RW, 4402ac6454SAndrew Thompson &usb2_debug, 0, "Debug level"); 4502ac6454SAndrew Thompson 4602ac6454SAndrew Thompson /*------------------------------------------------------------------------* 4702ac6454SAndrew Thompson * usb2_dump_iface 4802ac6454SAndrew Thompson * 4902ac6454SAndrew Thompson * This function dumps information about an USB interface. 5002ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 5102ac6454SAndrew Thompson void 52760bc48eSAndrew Thompson usb2_dump_iface(struct usb_interface *iface) 5302ac6454SAndrew Thompson { 5402ac6454SAndrew Thompson printf("usb2_dump_iface: iface=%p\n", iface); 5502ac6454SAndrew Thompson if (iface == NULL) { 5602ac6454SAndrew Thompson return; 5702ac6454SAndrew Thompson } 5802ac6454SAndrew Thompson printf(" iface=%p idesc=%p altindex=%d\n", 5902ac6454SAndrew Thompson iface, iface->idesc, iface->alt_index); 6002ac6454SAndrew Thompson } 6102ac6454SAndrew Thompson 6202ac6454SAndrew Thompson /*------------------------------------------------------------------------* 6302ac6454SAndrew Thompson * usb2_dump_device 6402ac6454SAndrew Thompson * 6502ac6454SAndrew Thompson * This function dumps information about an USB device. 6602ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 6702ac6454SAndrew Thompson void 68760bc48eSAndrew Thompson usb2_dump_device(struct usb_device *udev) 6902ac6454SAndrew Thompson { 7002ac6454SAndrew Thompson printf("usb2_dump_device: dev=%p\n", udev); 7102ac6454SAndrew Thompson if (udev == NULL) { 7202ac6454SAndrew Thompson return; 7302ac6454SAndrew Thompson } 7402ac6454SAndrew Thompson printf(" bus=%p \n" 7502ac6454SAndrew Thompson " address=%d config=%d depth=%d speed=%d self_powered=%d\n" 7602ac6454SAndrew Thompson " power=%d langid=%d\n", 7702ac6454SAndrew Thompson udev->bus, 7802ac6454SAndrew Thompson udev->address, udev->curr_config_no, udev->depth, udev->speed, 7902ac6454SAndrew Thompson udev->flags.self_powered, udev->power, udev->langid); 8002ac6454SAndrew Thompson } 8102ac6454SAndrew Thompson 8202ac6454SAndrew Thompson /*------------------------------------------------------------------------* 8302ac6454SAndrew Thompson * usb2_dump_queue 8402ac6454SAndrew Thompson * 85ae60fdfbSAndrew Thompson * This function dumps the USB transfer that are queued up on an USB endpoint. 8602ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 8702ac6454SAndrew Thompson void 88ae60fdfbSAndrew Thompson usb2_dump_queue(struct usb_endpoint *ep) 8902ac6454SAndrew Thompson { 90760bc48eSAndrew Thompson struct usb_xfer *xfer; 9102ac6454SAndrew Thompson 92ae60fdfbSAndrew Thompson printf("usb2_dump_queue: endpoint=%p xfer: ", ep); 93ae60fdfbSAndrew Thompson TAILQ_FOREACH(xfer, &ep->endpoint_q.head, wait_entry) { 9402ac6454SAndrew Thompson printf(" %p", xfer); 9502ac6454SAndrew Thompson } 9602ac6454SAndrew Thompson printf("\n"); 9702ac6454SAndrew Thompson } 9802ac6454SAndrew Thompson 9902ac6454SAndrew Thompson /*------------------------------------------------------------------------* 100ae60fdfbSAndrew Thompson * usb2_dump_endpoint 10102ac6454SAndrew Thompson * 102ae60fdfbSAndrew Thompson * This function dumps information about an USB endpoint. 10302ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 10402ac6454SAndrew Thompson void 105ae60fdfbSAndrew Thompson usb2_dump_endpoint(struct usb_endpoint *ep) 10602ac6454SAndrew Thompson { 107ae60fdfbSAndrew Thompson if (ep) { 108ae60fdfbSAndrew Thompson printf("usb2_dump_endpoint: endpoint=%p", ep); 10902ac6454SAndrew Thompson 11002ac6454SAndrew Thompson printf(" edesc=%p isoc_next=%d toggle_next=%d", 111ae60fdfbSAndrew Thompson ep->edesc, ep->isoc_next, ep->toggle_next); 11202ac6454SAndrew Thompson 113ae60fdfbSAndrew Thompson if (ep->edesc) { 11402ac6454SAndrew Thompson printf(" bEndpointAddress=0x%02x", 115ae60fdfbSAndrew Thompson ep->edesc->bEndpointAddress); 11602ac6454SAndrew Thompson } 11702ac6454SAndrew Thompson printf("\n"); 118ae60fdfbSAndrew Thompson usb2_dump_queue(ep); 11902ac6454SAndrew Thompson } else { 120ae60fdfbSAndrew Thompson printf("usb2_dump_endpoint: endpoint=NULL\n"); 12102ac6454SAndrew Thompson } 12202ac6454SAndrew Thompson } 12302ac6454SAndrew Thompson 12402ac6454SAndrew Thompson /*------------------------------------------------------------------------* 12502ac6454SAndrew Thompson * usb2_dump_xfer 12602ac6454SAndrew Thompson * 12702ac6454SAndrew Thompson * This function dumps information about an USB transfer. 12802ac6454SAndrew Thompson *------------------------------------------------------------------------*/ 12902ac6454SAndrew Thompson void 130760bc48eSAndrew Thompson usb2_dump_xfer(struct usb_xfer *xfer) 13102ac6454SAndrew Thompson { 132760bc48eSAndrew Thompson struct usb_device *udev; 13302ac6454SAndrew Thompson printf("usb2_dump_xfer: xfer=%p\n", xfer); 13402ac6454SAndrew Thompson if (xfer == NULL) { 13502ac6454SAndrew Thompson return; 13602ac6454SAndrew Thompson } 137ae60fdfbSAndrew Thompson if (xfer->endpoint == NULL) { 138ae60fdfbSAndrew Thompson printf("xfer %p: endpoint=NULL\n", 13902ac6454SAndrew Thompson xfer); 14002ac6454SAndrew Thompson return; 14102ac6454SAndrew Thompson } 14202ac6454SAndrew Thompson udev = xfer->xroot->udev; 14302ac6454SAndrew Thompson printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d " 144ae60fdfbSAndrew Thompson "endpoint=%p ep=0x%02x attr=0x%02x\n", 14502ac6454SAndrew Thompson xfer, udev, 14602ac6454SAndrew Thompson UGETW(udev->ddesc.idVendor), 14702ac6454SAndrew Thompson UGETW(udev->ddesc.idProduct), 148ae60fdfbSAndrew Thompson udev->address, xfer->endpoint, 149ae60fdfbSAndrew Thompson xfer->endpoint->edesc->bEndpointAddress, 150ae60fdfbSAndrew Thompson xfer->endpoint->edesc->bmAttributes); 15102ac6454SAndrew Thompson } 152