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 <dev/usb/usb.h> 28 #include <dev/usb/usb_defs.h> 29 30 #include <dev/usb/usb_core.h> 31 #include <dev/usb/usb_debug.h> 32 #include <dev/usb/usb_process.h> 33 #include <dev/usb/usb_device.h> 34 #include <dev/usb/usb_busdma.h> 35 #include <dev/usb/usb_transfer.h> 36 37 /* 38 * Define this unconditionally in case a kernel module is loaded that 39 * has been compiled with debugging options. 40 */ 41 int usb2_debug = 0; 42 43 SYSCTL_NODE(_hw, OID_AUTO, usb2, CTLFLAG_RW, 0, "USB debugging"); 44 SYSCTL_INT(_hw_usb2, OID_AUTO, debug, CTLFLAG_RW, 45 &usb2_debug, 0, "Debug level"); 46 47 /*------------------------------------------------------------------------* 48 * usb2_dump_iface 49 * 50 * This function dumps information about an USB interface. 51 *------------------------------------------------------------------------*/ 52 void 53 usb2_dump_iface(struct usb2_interface *iface) 54 { 55 printf("usb2_dump_iface: iface=%p\n", iface); 56 if (iface == NULL) { 57 return; 58 } 59 printf(" iface=%p idesc=%p altindex=%d\n", 60 iface, iface->idesc, iface->alt_index); 61 } 62 63 /*------------------------------------------------------------------------* 64 * usb2_dump_device 65 * 66 * This function dumps information about an USB device. 67 *------------------------------------------------------------------------*/ 68 void 69 usb2_dump_device(struct usb2_device *udev) 70 { 71 printf("usb2_dump_device: dev=%p\n", udev); 72 if (udev == NULL) { 73 return; 74 } 75 printf(" bus=%p \n" 76 " address=%d config=%d depth=%d speed=%d self_powered=%d\n" 77 " power=%d langid=%d\n", 78 udev->bus, 79 udev->address, udev->curr_config_no, udev->depth, udev->speed, 80 udev->flags.self_powered, udev->power, udev->langid); 81 } 82 83 /*------------------------------------------------------------------------* 84 * usb2_dump_queue 85 * 86 * This function dumps the USB transfer that are queued up on an USB pipe. 87 *------------------------------------------------------------------------*/ 88 void 89 usb2_dump_queue(struct usb2_pipe *pipe) 90 { 91 struct usb2_xfer *xfer; 92 93 printf("usb2_dump_queue: pipe=%p xfer: ", pipe); 94 TAILQ_FOREACH(xfer, &pipe->pipe_q.head, wait_entry) { 95 printf(" %p", xfer); 96 } 97 printf("\n"); 98 } 99 100 /*------------------------------------------------------------------------* 101 * usb2_dump_pipe 102 * 103 * This function dumps information about an USB pipe. 104 *------------------------------------------------------------------------*/ 105 void 106 usb2_dump_pipe(struct usb2_pipe *pipe) 107 { 108 if (pipe) { 109 printf("usb2_dump_pipe: pipe=%p", pipe); 110 111 printf(" edesc=%p isoc_next=%d toggle_next=%d", 112 pipe->edesc, pipe->isoc_next, pipe->toggle_next); 113 114 if (pipe->edesc) { 115 printf(" bEndpointAddress=0x%02x", 116 pipe->edesc->bEndpointAddress); 117 } 118 printf("\n"); 119 usb2_dump_queue(pipe); 120 } else { 121 printf("usb2_dump_pipe: pipe=NULL\n"); 122 } 123 } 124 125 /*------------------------------------------------------------------------* 126 * usb2_dump_xfer 127 * 128 * This function dumps information about an USB transfer. 129 *------------------------------------------------------------------------*/ 130 void 131 usb2_dump_xfer(struct usb2_xfer *xfer) 132 { 133 struct usb2_device *udev; 134 printf("usb2_dump_xfer: xfer=%p\n", xfer); 135 if (xfer == NULL) { 136 return; 137 } 138 if (xfer->pipe == NULL) { 139 printf("xfer %p: pipe=NULL\n", 140 xfer); 141 return; 142 } 143 udev = xfer->xroot->udev; 144 printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d " 145 "pipe=%p ep=0x%02x attr=0x%02x\n", 146 xfer, udev, 147 UGETW(udev->ddesc.idVendor), 148 UGETW(udev->ddesc.idProduct), 149 udev->address, xfer->pipe, 150 xfer->pipe->edesc->bEndpointAddress, 151 xfer->pipe->edesc->bmAttributes); 152 } 153