xref: /freebsd/sys/dev/usb/usb_debug.c (revision 02ac6454880b59bbc5f3f74dffaffa90b30adc8b)
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 #include <dev/usb/usb_defs.h>
2902ac6454SAndrew Thompson 
3002ac6454SAndrew Thompson #include <dev/usb/usb_core.h>
3102ac6454SAndrew Thompson #include <dev/usb/usb_debug.h>
3202ac6454SAndrew Thompson #include <dev/usb/usb_process.h>
3302ac6454SAndrew Thompson #include <dev/usb/usb_device.h>
3402ac6454SAndrew Thompson #include <dev/usb/usb_busdma.h>
3502ac6454SAndrew Thompson #include <dev/usb/usb_transfer.h>
3602ac6454SAndrew Thompson 
3702ac6454SAndrew Thompson /*
3802ac6454SAndrew Thompson  * Define this unconditionally in case a kernel module is loaded that
3902ac6454SAndrew Thompson  * has been compiled with debugging options.
4002ac6454SAndrew Thompson  */
4102ac6454SAndrew Thompson int	usb2_debug = 0;
4202ac6454SAndrew Thompson 
4302ac6454SAndrew Thompson SYSCTL_NODE(_hw, OID_AUTO, usb2, CTLFLAG_RW, 0, "USB debugging");
4402ac6454SAndrew Thompson SYSCTL_INT(_hw_usb2, OID_AUTO, debug, CTLFLAG_RW,
4502ac6454SAndrew Thompson     &usb2_debug, 0, "Debug level");
4602ac6454SAndrew Thompson 
4702ac6454SAndrew Thompson /*------------------------------------------------------------------------*
4802ac6454SAndrew Thompson  *	usb2_dump_iface
4902ac6454SAndrew Thompson  *
5002ac6454SAndrew Thompson  * This function dumps information about an USB interface.
5102ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
5202ac6454SAndrew Thompson void
5302ac6454SAndrew Thompson usb2_dump_iface(struct usb2_interface *iface)
5402ac6454SAndrew Thompson {
5502ac6454SAndrew Thompson 	printf("usb2_dump_iface: iface=%p\n", iface);
5602ac6454SAndrew Thompson 	if (iface == NULL) {
5702ac6454SAndrew Thompson 		return;
5802ac6454SAndrew Thompson 	}
5902ac6454SAndrew Thompson 	printf(" iface=%p idesc=%p altindex=%d\n",
6002ac6454SAndrew Thompson 	    iface, iface->idesc, iface->alt_index);
6102ac6454SAndrew Thompson }
6202ac6454SAndrew Thompson 
6302ac6454SAndrew Thompson /*------------------------------------------------------------------------*
6402ac6454SAndrew Thompson  *	usb2_dump_device
6502ac6454SAndrew Thompson  *
6602ac6454SAndrew Thompson  * This function dumps information about an USB device.
6702ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
6802ac6454SAndrew Thompson void
6902ac6454SAndrew Thompson usb2_dump_device(struct usb2_device *udev)
7002ac6454SAndrew Thompson {
7102ac6454SAndrew Thompson 	printf("usb2_dump_device: dev=%p\n", udev);
7202ac6454SAndrew Thompson 	if (udev == NULL) {
7302ac6454SAndrew Thompson 		return;
7402ac6454SAndrew Thompson 	}
7502ac6454SAndrew Thompson 	printf(" bus=%p \n"
7602ac6454SAndrew Thompson 	    " address=%d config=%d depth=%d speed=%d self_powered=%d\n"
7702ac6454SAndrew Thompson 	    " power=%d langid=%d\n",
7802ac6454SAndrew Thompson 	    udev->bus,
7902ac6454SAndrew Thompson 	    udev->address, udev->curr_config_no, udev->depth, udev->speed,
8002ac6454SAndrew Thompson 	    udev->flags.self_powered, udev->power, udev->langid);
8102ac6454SAndrew Thompson }
8202ac6454SAndrew Thompson 
8302ac6454SAndrew Thompson /*------------------------------------------------------------------------*
8402ac6454SAndrew Thompson  *	usb2_dump_queue
8502ac6454SAndrew Thompson  *
8602ac6454SAndrew Thompson  * This function dumps the USB transfer that are queued up on an USB pipe.
8702ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
8802ac6454SAndrew Thompson void
8902ac6454SAndrew Thompson usb2_dump_queue(struct usb2_pipe *pipe)
9002ac6454SAndrew Thompson {
9102ac6454SAndrew Thompson 	struct usb2_xfer *xfer;
9202ac6454SAndrew Thompson 
9302ac6454SAndrew Thompson 	printf("usb2_dump_queue: pipe=%p xfer: ", pipe);
9402ac6454SAndrew Thompson 	TAILQ_FOREACH(xfer, &pipe->pipe_q.head, wait_entry) {
9502ac6454SAndrew Thompson 		printf(" %p", xfer);
9602ac6454SAndrew Thompson 	}
9702ac6454SAndrew Thompson 	printf("\n");
9802ac6454SAndrew Thompson }
9902ac6454SAndrew Thompson 
10002ac6454SAndrew Thompson /*------------------------------------------------------------------------*
10102ac6454SAndrew Thompson  *	usb2_dump_pipe
10202ac6454SAndrew Thompson  *
10302ac6454SAndrew Thompson  * This function dumps information about an USB pipe.
10402ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
10502ac6454SAndrew Thompson void
10602ac6454SAndrew Thompson usb2_dump_pipe(struct usb2_pipe *pipe)
10702ac6454SAndrew Thompson {
10802ac6454SAndrew Thompson 	if (pipe) {
10902ac6454SAndrew Thompson 		printf("usb2_dump_pipe: pipe=%p", pipe);
11002ac6454SAndrew Thompson 
11102ac6454SAndrew Thompson 		printf(" edesc=%p isoc_next=%d toggle_next=%d",
11202ac6454SAndrew Thompson 		    pipe->edesc, pipe->isoc_next, pipe->toggle_next);
11302ac6454SAndrew Thompson 
11402ac6454SAndrew Thompson 		if (pipe->edesc) {
11502ac6454SAndrew Thompson 			printf(" bEndpointAddress=0x%02x",
11602ac6454SAndrew Thompson 			    pipe->edesc->bEndpointAddress);
11702ac6454SAndrew Thompson 		}
11802ac6454SAndrew Thompson 		printf("\n");
11902ac6454SAndrew Thompson 		usb2_dump_queue(pipe);
12002ac6454SAndrew Thompson 	} else {
12102ac6454SAndrew Thompson 		printf("usb2_dump_pipe: pipe=NULL\n");
12202ac6454SAndrew Thompson 	}
12302ac6454SAndrew Thompson }
12402ac6454SAndrew Thompson 
12502ac6454SAndrew Thompson /*------------------------------------------------------------------------*
12602ac6454SAndrew Thompson  *	usb2_dump_xfer
12702ac6454SAndrew Thompson  *
12802ac6454SAndrew Thompson  * This function dumps information about an USB transfer.
12902ac6454SAndrew Thompson  *------------------------------------------------------------------------*/
13002ac6454SAndrew Thompson void
13102ac6454SAndrew Thompson usb2_dump_xfer(struct usb2_xfer *xfer)
13202ac6454SAndrew Thompson {
13302ac6454SAndrew Thompson 	struct usb2_device *udev;
13402ac6454SAndrew Thompson 	printf("usb2_dump_xfer: xfer=%p\n", xfer);
13502ac6454SAndrew Thompson 	if (xfer == NULL) {
13602ac6454SAndrew Thompson 		return;
13702ac6454SAndrew Thompson 	}
13802ac6454SAndrew Thompson 	if (xfer->pipe == NULL) {
13902ac6454SAndrew Thompson 		printf("xfer %p: pipe=NULL\n",
14002ac6454SAndrew Thompson 		    xfer);
14102ac6454SAndrew Thompson 		return;
14202ac6454SAndrew Thompson 	}
14302ac6454SAndrew Thompson 	udev = xfer->xroot->udev;
14402ac6454SAndrew Thompson 	printf("xfer %p: udev=%p vid=0x%04x pid=0x%04x addr=%d "
14502ac6454SAndrew Thompson 	    "pipe=%p ep=0x%02x attr=0x%02x\n",
14602ac6454SAndrew Thompson 	    xfer, udev,
14702ac6454SAndrew Thompson 	    UGETW(udev->ddesc.idVendor),
14802ac6454SAndrew Thompson 	    UGETW(udev->ddesc.idProduct),
14902ac6454SAndrew Thompson 	    udev->address, xfer->pipe,
15002ac6454SAndrew Thompson 	    xfer->pipe->edesc->bEndpointAddress,
15102ac6454SAndrew Thompson 	    xfer->pipe->edesc->bmAttributes);
15202ac6454SAndrew Thompson }
153