patch-2.3.34 linux/drivers/usb/uhci-debug.c

Next file: linux/drivers/usb/uhci-debug.h
Previous file: linux/drivers/usb/proc_usb.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.33/linux/drivers/usb/uhci-debug.c linux/drivers/usb/uhci-debug.c
@@ -1,208 +1,251 @@
 /*
- * UHCI-specific debugging code. Invaluable when something
- * goes wrong, but don't get in my face.
- *
- * Kernel visible pointers are surrounded in []'s and bus
- * visible pointers are surrounded in ()'s
- *
- * (C) Copyright 1999 Linus Torvalds
- * (C) Copyright 1999 Johannes Erdfelt
+ * $Id: uhci-debug.c,v 1.12 1999/12/13 15:24:42 fliegl Exp $
  */
-
+#include <linux/version.h>
 #include <linux/kernel.h>
 #include <asm/io.h>
 
+#include "usb.h"
 #include "uhci.h"
-
-void uhci_show_td(struct uhci_td * td)
+#define DEBUG
+#ifdef DEBUG
+#define dbg printk
+#else
+#define dbg nix
+static void nix (const char *format,...)
 {
-	char *spid;
+}
 
-	printk("%08x ", td->link);
-	printk("e%d %s%s%s%s%s%s%s%s%s%sLength=%x ",
-		((td->status >> 27) & 3),
-		(td->status & TD_CTRL_SPD) ?      "SPD " : "",
-		(td->status & TD_CTRL_LS) ?       "LS " : "",
-		(td->status & TD_CTRL_IOC) ?      "IOC " : "",
-		(td->status & TD_CTRL_ACTIVE) ?   "Active " : "",
-		(td->status & TD_CTRL_STALLED) ?  "Stalled " : "",
-		(td->status & TD_CTRL_DBUFERR) ?  "DataBufErr " : "",
-		(td->status & TD_CTRL_BABBLE) ?   "Babble " : "",
-		(td->status & TD_CTRL_NAK) ?      "NAK " : "",
-		(td->status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
-		(td->status & TD_CTRL_BITSTUFF) ? "BitStuff " : "",
-		td->status & 0x7ff);
-
-	switch (td->info & 0xff) {
-		case USB_PID_SETUP:
-			spid = "SETUP";
-			break;
-		case USB_PID_OUT:
-			spid = "OUT";
-			break;
-		case USB_PID_IN:
-			spid = "IN";
-			break;
-		default:
-			spid = "?";
-			break;
+#endif
+void dump_urb (purb_t purb)
+{
+	printk ("urb                   :%p\n", purb);
+	printk ("next                  :%p\n", purb->next);
+	printk ("dev                   :%p\n", purb->dev);
+	printk ("pipe                  :%08X\n", purb->pipe);
+	printk ("status                :%d\n", purb->status);
+	printk ("transfer_flags        :%08X\n", purb->transfer_flags);
+	printk ("transfer_buffer       :%p\n", purb->transfer_buffer);
+	printk ("transfer_buffer_length:%d\n", purb->transfer_buffer_length);
+	printk ("actual_length         :%d\n", purb->actual_length);
+	printk ("setup_packet          :%p\n", purb->setup_packet);
+	printk ("start_frame           :%d\n", purb->start_frame);
+	printk ("number_of_packets     :%d\n", purb->number_of_packets);
+	printk ("interval              :%d\n", purb->interval);
+	printk ("error_count           :%d\n", purb->error_count);
+	printk ("context               :%p\n", purb->context);
+	printk ("complete              :%p\n", purb->complete);
+}
+
+void beep (long freq)
+{
+	long v;
+	char low, high;
+
+	if (!freq)
+		outb (inb (0x61) & 252, 0x61);
+	else {
+		outb (inb (0x61) | 0x3, 0x61);
+
+		v = 1193180L / freq;
+
+		low = (char) (v & 255);
+		high = (char) ((v >> 8) & 255);
+
+		outb (182, 0x43);
+		outb (low, 0x42);
+		outb (high, 0x42);
 	}
-
-	printk("MaxLen=%x DT%d EndPt=%x Dev=%x, PID=%x(%s) ",
-		td->info >> 21,
-		((td->info >> 19) & 1),
-		(td->info >> 15) & 15,
-		(td->info >> 8) & 127,
-		(td->info & 0xff),
-		spid);
-	printk("(buf=%08x)\n", td->buffer);
-}
-
-static void uhci_show_sc(int port, unsigned short status)
-{
-	printk("  stat%d     =     %04x   %s%s%s%s%s%s%s%s\n",
-		port,
-		status,
-		(status & USBPORTSC_SUSP) ? "PortSuspend " : "",
-		(status & USBPORTSC_PR) ?   "PortReset " : "",
-		(status & USBPORTSC_LSDA) ? "LowSpeed " : "",
-		(status & USBPORTSC_RD) ?   "ResumeDetect " : "",
-		(status & USBPORTSC_PEC) ?  "EnableChange " : "",
-		(status & USBPORTSC_PE) ?   "PortEnabled " : "",
-		(status & USBPORTSC_CSC) ?  "ConnectChange " : "",
-		(status & USBPORTSC_CCS) ?  "PortConnected " : "");
 }
 
-void uhci_show_status(struct uhci *uhci)
+void uhci_show_qh (puhci_desc_t qh)
 {
-	unsigned int io_addr = uhci->io_addr;
-	unsigned short usbcmd, usbstat, usbint, usbfrnum;
-	unsigned int flbaseadd;
-	unsigned char sof;
-	unsigned short portsc1, portsc2;
+	if (qh->type != QH_TYPE) {
+		dbg (KERN_DEBUG MODSTR "qh has not QH_TYPE\n");
+		return;
+	}
+	dbg (KERN_DEBUG MODSTR "uhci_show_qh %p (%08lX):\n", qh, virt_to_bus (qh));
 
-	usbcmd    = inw(io_addr + 0);
-	usbstat   = inw(io_addr + 2);
-	usbint    = inw(io_addr + 4);
-	usbfrnum  = inw(io_addr + 6);
-	flbaseadd = inl(io_addr + 8);
-	sof       = inb(io_addr + 12);
-	portsc1   = inw(io_addr + 16);
-	portsc2   = inw(io_addr + 18);
-
-	printk("  usbcmd    =     %04x   %s%s%s%s%s%s%s%s\n",
-		usbcmd,
-		(usbcmd & USBCMD_MAXP) ?    "Maxp64 " : "Maxp32 ",
-		(usbcmd & USBCMD_CF) ?      "CF " : "",
-		(usbcmd & USBCMD_SWDBG) ?   "SWDBG " : "",
-		(usbcmd & USBCMD_FGR) ?     "FGR " : "",
-		(usbcmd & USBCMD_EGSM) ?    "EGSM " : "",
-		(usbcmd & USBCMD_GRESET) ?  "GRESET " : "",
-		(usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
-		(usbcmd & USBCMD_RS) ?      "RS " : "");
-
-	printk("  usbstat   =     %04x   %s%s%s%s%s%s\n",
-		usbstat,
-		(usbstat & USBSTS_HCH) ?    "HCHalted " : "",
-		(usbstat & USBSTS_HCPE) ?   "HostControllerProcessError " : "",
-		(usbstat & USBSTS_HSE) ?    "HostSystemError " : "",
-		(usbstat & USBSTS_RD) ?     "ResumeDetect " : "",
-		(usbstat & USBSTS_ERROR) ?  "USBError " : "",
-		(usbstat & USBSTS_USBINT) ? "USBINT " : "");
-
-	printk("  usbint    =     %04x\n", usbint);
-	printk("  usbfrnum  =   (%d)%03x\n", (usbfrnum >> 10) & 1,
-		0xfff & (4*(unsigned int)usbfrnum));
-	printk("  flbaseadd = %08x\n", flbaseadd);
-	printk("  sof       =       %02x\n", sof);
-	uhci_show_sc(1, portsc1);
-	uhci_show_sc(2, portsc2);
-}
-
-#define uhci_link_to_qh(x) ((struct uhci_qh *) uhci_link_to_td(x))
-
-struct uhci_td *uhci_link_to_td(unsigned int link)
-{
-	if (link & UHCI_PTR_TERM)
-		return NULL;
-
-	return bus_to_virt(link & ~UHCI_PTR_BITS);
-}
-
-void uhci_show_queue(struct uhci_qh *qh)
-{
-	struct uhci_td *td, *first;
-	int i = 0, count = 1000;
-
-	if (qh->element & UHCI_PTR_QH)
-		printk("      Element points to QH (bug?)\n");
+	if (qh->hw.qh.head & UHCI_PTR_TERM)
+		dbg (KERN_DEBUG MODSTR "Head Terminate\n");
+	else {
+		if (qh->hw.qh.head & UHCI_PTR_QH)
+			dbg (KERN_DEBUG MODSTR "Head points to QH\n");
+		else
+			dbg (KERN_DEBUG MODSTR "Head points to TD\n");
 
-	if (qh->element & UHCI_PTR_DEPTH)
-		printk("      Depth traverse\n");
+		dbg (KERN_DEBUG MODSTR "head: %08X\n", qh->hw.qh.head & ~UHCI_PTR_BITS);
+	}
+	if (qh->hw.qh.element & UHCI_PTR_TERM)
+		dbg (KERN_DEBUG MODSTR "Element Terminate\n");
+	else {
+
+		if (qh->hw.qh.element & UHCI_PTR_QH)
+			dbg (KERN_DEBUG MODSTR "Element points to QH\n");
+		else
+			dbg (KERN_DEBUG MODSTR "Element points to TD\n");
+		dbg (KERN_DEBUG MODSTR "element: %08X\n", qh->hw.qh.element & ~UHCI_PTR_BITS);
+	}
+}
 
-	if (qh->element & UHCI_PTR_TERM)
-		printk("      Terminate\n");
+void uhci_show_td (puhci_desc_t td)
+{
+	char *spid;
+	dbg (KERN_DEBUG MODSTR "uhci_show_td %p (%08lX) ", td, virt_to_bus (td));
 
-	if (!(qh->element & ~UHCI_PTR_BITS)) {
-		printk("      td 0: [NULL]\n");
-		return;
+	switch (td->hw.td.info & 0xff) {
+	case USB_PID_SETUP:
+		spid = "SETUP";
+		break;
+	case USB_PID_OUT:
+		spid = " OUT ";
+		break;
+	case USB_PID_IN:
+		spid = " IN  ";
+		break;
+	default:
+		spid = "  ?  ";
+		break;
 	}
 
-	if (qh->first)
-		first = qh->first;
-	else
-		first = uhci_link_to_td(qh->element);
-
-	/* Make sure it doesn't runaway */
-	for (td = first; td && count > 0; 
-	     td = uhci_link_to_td(td->link), --count) {
-		printk("      td %d: [%p]\n", i++, td);
-		printk("      ");
-		uhci_show_td(td);
+	dbg ("MaxLen=%02x DT%d EndPt=%x Dev=%x, PID=%x(%s) (buf=%08x)\n",
+	     td->hw.td.info >> 21,
+	     ((td->hw.td.info >> 19) & 1),
+	     (td->hw.td.info >> 15) & 15,
+	     (td->hw.td.info >> 8) & 127,
+	     (td->hw.td.info & 0xff),
+	     spid,
+	     td->hw.td.buffer);
+
+	dbg (KERN_DEBUG MODSTR "Len=%02x e%d %s%s%s%s%s%s%s%s%s%s\n",
+	     td->hw.td.status & 0x7ff,
+	     ((td->hw.td.status >> 27) & 3),
+	     (td->hw.td.status & TD_CTRL_SPD) ? "SPD " : "",
+	     (td->hw.td.status & TD_CTRL_LS) ? "LS " : "",
+	     (td->hw.td.status & TD_CTRL_IOC) ? "IOC " : "",
+	     (td->hw.td.status & TD_CTRL_ACTIVE) ? "Active " : "",
+	     (td->hw.td.status & TD_CTRL_STALLED) ? "Stalled " : "",
+	     (td->hw.td.status & TD_CTRL_DBUFERR) ? "DataBufErr " : "",
+	     (td->hw.td.status & TD_CTRL_BABBLE) ? "Babble " : "",
+	     (td->hw.td.status & TD_CTRL_NAK) ? "NAK " : "",
+	     (td->hw.td.status & TD_CTRL_CRCTIMEO) ? "CRC/Timeo " : "",
+	     (td->hw.td.status & TD_CTRL_BITSTUFF) ? "BitStuff " : ""
+		);
+#if 1
+	if (td->hw.td.link & UHCI_PTR_TERM)
+		dbg (KERN_DEBUG MODSTR "Link Terminate\n");
+	else {
+		if (td->hw.td.link & UHCI_PTR_QH)
+			dbg (KERN_DEBUG MODSTR "%s, link points to QH @ %08x\n",
+			     (td->hw.td.link & UHCI_PTR_DEPTH ? "Depth first" : " Breadth first"),
+			     td->hw.td.link & ~UHCI_PTR_BITS);
+		else
+			dbg (KERN_DEBUG MODSTR "%s, link points to TD @ %08x \n",
+			     (td->hw.td.link & UHCI_PTR_DEPTH ? "Depth first" : " Breadth first"),
+			     td->hw.td.link & ~UHCI_PTR_BITS);
+	}
+#endif
+}
 
-		if (td == uhci_link_to_td(td->link)) {
-			printk(KERN_ERR "td links to itself!\n");
+void uhci_show_td_queue (puhci_desc_t td)
+{
+	dbg (KERN_DEBUG MODSTR "uhci_show_td_queue %p (%08lX):\n", td, virt_to_bus (td));
+	while (1) {
+		uhci_show_td (td);
+		if (td->hw.td.link & UHCI_PTR_TERM)
+			break;
+		//if(!(td->hw.td.link&UHCI_PTR_DEPTH))
+		//      break;
+		if (td != bus_to_virt (td->hw.td.link & ~UHCI_PTR_BITS))
+			td = bus_to_virt (td->hw.td.link & ~UHCI_PTR_BITS);
+		else {
+			dbg (KERN_DEBUG MODSTR "td points to itself!\n");
 			break;
 		}
+//              schedule();
 	}
 }
 
-static int uhci_is_skeleton_qh(struct uhci *uhci, struct uhci_qh *qh)
+void uhci_show_queue (puhci_desc_t qh)
 {
-	int j;
+	dbg (KERN_DEBUG MODSTR "uhci_show_queue %p:\n", qh);
+	while (1) {
+		uhci_show_qh (qh);
+
+		if (qh->hw.qh.element & UHCI_PTR_QH)
+			dbg (KERN_DEBUG MODSTR "Warning: qh->element points to qh!\n");
+		else if (!(qh->hw.qh.element & UHCI_PTR_TERM))
+			uhci_show_td_queue (bus_to_virt (qh->hw.qh.element & ~UHCI_PTR_BITS));
 
-	for (j = 0; j < UHCI_NUM_SKELQH; j++)
-		if (qh == uhci->skelqh + j)
-			return 1;
+		if (qh->hw.qh.head & UHCI_PTR_TERM)
+			break;
 
-	return 0;
+		if (qh != bus_to_virt (qh->hw.qh.head & ~UHCI_PTR_BITS))
+			qh = bus_to_virt (qh->hw.qh.head & ~UHCI_PTR_BITS);
+		else {
+			dbg (KERN_DEBUG MODSTR "qh points to itself!\n");
+			break;
+		}
+	}
 }
 
-static const char *qh_names[] = {"interrupt2", "interrupt4", "interrupt8",
-				 "interrupt16", "interrupt32", "interrupt64",
-				 "interrupt128", "interrupt256", "control",
-				 "bulk"};
-
-void uhci_show_queues(struct uhci *uhci)
+static void uhci_show_sc (int port, unsigned short status)
 {
-	int i;
-	struct uhci_qh *qh;
-
-	for (i = 0; i < UHCI_NUM_SKELQH; ++i) {
-		printk("  %s: [%p] (%08X) (%08X)\n", qh_names[i],
-			&uhci->skelqh[i],
-			uhci->skelqh[i].link, uhci->skelqh[i].element);
-
-		qh = uhci_link_to_qh(uhci->skelqh[i].link);
-		for (; qh; qh = uhci_link_to_qh(qh->link)) {
-			if (uhci_is_skeleton_qh(uhci, qh))
-				break;
+	dbg ("  stat%d     =     %04x   %s%s%s%s%s%s%s%s\n",
+	     port,
+	     status,
+	     (status & USBPORTSC_SUSP) ? "PortSuspend " : "",
+	     (status & USBPORTSC_PR) ? "PortReset " : "",
+	     (status & USBPORTSC_LSDA) ? "LowSpeed " : "",
+	     (status & USBPORTSC_RD) ? "ResumeDetect " : "",
+	     (status & USBPORTSC_PEC) ? "EnableChange " : "",
+	     (status & USBPORTSC_PE) ? "PortEnabled " : "",
+	     (status & USBPORTSC_CSC) ? "ConnectChange " : "",
+	     (status & USBPORTSC_CCS) ? "PortConnected " : "");
+}
 
-			printk("    [%p] (%08X) (%08x)\n",
-				qh, qh->link, qh->element);
+void uhci_show_status (puhci_t s)
+{
+	unsigned int io_addr = s->io_addr;
+	unsigned short usbcmd, usbstat, usbint, usbfrnum;
+	unsigned int flbaseadd;
+	unsigned char sof;
+	unsigned short portsc1, portsc2;
 
-			uhci_show_queue(qh);
-		}
-	}
+	usbcmd = inw (io_addr + 0);
+	usbstat = inw (io_addr + 2);
+	usbint = inw (io_addr + 4);
+	usbfrnum = inw (io_addr + 6);
+	flbaseadd = inl (io_addr + 8);
+	sof = inb (io_addr + 12);
+	portsc1 = inw (io_addr + 16);
+	portsc2 = inw (io_addr + 18);
+
+	dbg ("  usbcmd    =     %04x   %s%s%s%s%s%s%s%s\n",
+	     usbcmd,
+	     (usbcmd & USBCMD_MAXP) ? "Maxp64 " : "Maxp32 ",
+	     (usbcmd & USBCMD_CF) ? "CF " : "",
+	     (usbcmd & USBCMD_SWDBG) ? "SWDBG " : "",
+	     (usbcmd & USBCMD_FGR) ? "FGR " : "",
+	     (usbcmd & USBCMD_EGSM) ? "EGSM " : "",
+	     (usbcmd & USBCMD_GRESET) ? "GRESET " : "",
+	     (usbcmd & USBCMD_HCRESET) ? "HCRESET " : "",
+	     (usbcmd & USBCMD_RS) ? "RS " : "");
+
+	dbg ("  usbstat   =     %04x   %s%s%s%s%s%s\n",
+	     usbstat,
+	     (usbstat & USBSTS_HCH) ? "HCHalted " : "",
+	     (usbstat & USBSTS_HCPE) ? "HostControllerProcessError " : "",
+	     (usbstat & USBSTS_HSE) ? "HostSystemError " : "",
+	     (usbstat & USBSTS_RD) ? "ResumeDetect " : "",
+	     (usbstat & USBSTS_ERROR) ? "USBError " : "",
+	     (usbstat & USBSTS_USBINT) ? "USBINT " : "");
+
+	dbg ("  usbint    =     %04x\n", usbint);
+	dbg ("  usbfrnum  =   (%d)%03x\n", (usbfrnum >> 10) & 1,
+	     0xfff & (4 * (unsigned int) usbfrnum));
+	dbg ("  flbaseadd = %08x\n", flbaseadd);
+	dbg ("  sof       =       %02x\n", sof);
+	uhci_show_sc (1, portsc1);
+	uhci_show_sc (2, portsc2);
 }
-

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)