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