usb4bsd: Port input devices (uep, uhid, ukbd, ums) and hook into build.
[dragonfly.git] / sys / bus / u4b / usb_debug.c
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/queue.h>
29 #include <sys/types.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/bus.h>
33 #include <sys/module.h>
34 #include <sys/lock.h>
35 #include <sys/mutex.h>
36 #include <sys/condvar.h>
37 #include <sys/sysctl.h>
38 #include <sys/unistd.h>
39 #include <sys/callout.h>
40 #include <sys/malloc.h>
41 #include <sys/priv.h>
42
43 #include <bus/u4b/usb.h>
44 #include <bus/u4b/usbdi.h>
45
46 #include <bus/u4b/usb_core.h>
47 #include <bus/u4b/usb_debug.h>
48 #include <bus/u4b/usb_process.h>
49 #include <bus/u4b/usb_device.h>
50 #include <bus/u4b/usb_busdma.h>
51 #include <bus/u4b/usb_transfer.h>
52
53 #include <ddb/ddb.h>
54 #include <ddb/db_sym.h>
55
56 /*
57  * Define this unconditionally in case a kernel module is loaded that
58  * has been compiled with debugging options.
59  */
60 int     usb_debug = 0;
61
62 SYSCTL_NODE(_hw, OID_AUTO, usb, CTLFLAG_RW, 0, "USB debugging");
63 SYSCTL_INT(_hw_usb, OID_AUTO, debug, CTLFLAG_RW,
64     &usb_debug, 0, "Debug level");
65
66 TUNABLE_INT("hw.usb.debug", &usb_debug);
67
68 /*------------------------------------------------------------------------*
69  *      usb_dump_iface
70  *
71  * This function dumps information about an USB interface.
72  *------------------------------------------------------------------------*/
73 void
74 usb_dump_iface(struct usb_interface *iface)
75 {
76         kprintf("usb_dump_iface: iface=%p\n", iface);
77         if (iface == NULL) {
78                 return;
79         }
80         kprintf(" iface=%p idesc=%p altindex=%d\n",
81             iface, iface->idesc, iface->alt_index);
82 }
83
84 /*------------------------------------------------------------------------*
85  *      usb_dump_device
86  *
87  * This function dumps information about an USB device.
88  *------------------------------------------------------------------------*/
89 void
90 usb_dump_device(struct usb_device *udev)
91 {
92         kprintf("usb_dump_device: dev=%p\n", udev);
93         if (udev == NULL) {
94                 return;
95         }
96         kprintf(" bus=%p \n"
97             " address=%d config=%d depth=%d speed=%d self_powered=%d\n"
98             " power=%d langid=%d\n",
99             udev->bus,
100             udev->address, udev->curr_config_no, udev->depth, udev->speed,
101             udev->flags.self_powered, udev->power, udev->langid);
102 }
103
104 /*------------------------------------------------------------------------*
105  *      usb_dump_queue
106  *
107  * This function dumps the USB transfer that are queued up on an USB endpoint.
108  *------------------------------------------------------------------------*/
109 void
110 usb_dump_queue(struct usb_endpoint *ep)
111 {
112         struct usb_xfer *xfer;
113
114         kprintf("usb_dump_queue: endpoint=%p xfer: ", ep);
115         TAILQ_FOREACH(xfer, &ep->endpoint_q.head, wait_entry) {
116                 kprintf(" %p", xfer);
117         }
118         kprintf("\n");
119 }
120
121 /*------------------------------------------------------------------------*
122  *      usb_dump_endpoint
123  *
124  * This function dumps information about an USB endpoint.
125  *------------------------------------------------------------------------*/
126 void
127 usb_dump_endpoint(struct usb_endpoint *ep)
128 {
129         if (ep) {
130                 kprintf("usb_dump_endpoint: endpoint=%p", ep);
131
132                 kprintf(" edesc=%p isoc_next=%d toggle_next=%d",
133                     ep->edesc, ep->isoc_next, ep->toggle_next);
134
135                 if (ep->edesc) {
136                         kprintf(" bEndpointAddress=0x%02x",
137                             ep->edesc->bEndpointAddress);
138                 }
139                 kprintf("\n");
140                 usb_dump_queue(ep);
141         } else {
142                 kprintf("usb_dump_endpoint: endpoint=NULL\n");
143         }
144 }
145
146 /*------------------------------------------------------------------------*
147  *      usb_dump_xfer
148  *
149  * This function dumps information about an USB transfer.
150  *------------------------------------------------------------------------*/
151 void
152 usb_dump_xfer(struct usb_xfer *xfer)
153 {
154         struct usb_device *udev;
155         kprintf("usb_dump_xfer: xfer=%p\n", xfer);
156         if (xfer == NULL) {
157                 return;
158         }
159         if (xfer->endpoint == NULL) {
160                 kprintf("xfer %p: endpoint=NULL\n",
161                     xfer);
162                 return;
163         }
164         udev = xfer->xroot->udev;
165         kprintf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d "
166             "endpoint=%p ep=0x%02x attr=0x%02x\n",
167             xfer, udev,
168             UGETW(udev->ddesc.idVendor),
169             UGETW(udev->ddesc.idProduct),
170             udev->address, xfer->endpoint,
171             xfer->endpoint->edesc->bEndpointAddress,
172             xfer->endpoint->edesc->bmAttributes);
173 }