Skip to contentSkip to conversation

x86: usb debug port early console

PATCH In review Yinghai Lu 7 participants 25 messages Jul 23, 2008 – Jul 28, 2008

Subsystems (4)
lore
Share & tools
lore

Yinghai Lu

author
#0 lore raw

PATCH 1/1 x86: usb debug port early console

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

---
 Documentation/kernel-parameters.txt |    3 
 arch/x86/kernel/early_printk.c      |  629 +++++++++++++++++++++++++++++++++++-
 arch/x86/kernel/head64.c            |    5 
 drivers/usb/host/ehci.h             |   14 
 4 files changed, 646 insertions(+), 5 deletions(-)
Documentation/kernel-parameters.txt +2 -1
Index: linux-2.6/Documentation/kernel-parameters.txt
===================================================================
@@ -654,11 +654,12 @@ and is between 256 and 4096 characters.
 	earlyprintk=	[X86-32,X86-64,SH,BLACKFIN]
 			earlyprintk=vga
 			earlyprintk=serial[,ttySn[,baudrate]]
+			earlyprintk=dbgp
 
 			Append ",keep" to not disable it when the real console
 			takes over.
 
-			Only vga or serial at a time, not both.
+			Only vga or serial or usb debug port at a time.
 
 			Currently only ttyS0 and ttyS1 are supported.
 
arch/x86/kernel/early_printk.c +626 -3

671 lines not on this page · raw message

arch/x86/kernel/head64.c +5 -0
Index: linux-2.6/arch/x86/kernel/head64.c
===================================================================
@@ -72,6 +72,8 @@ static void __init copy_bootdata(char *r
 	}
 }
 
+extern void __init enable_debug_console(char *buf);
+
 void __init x86_64_start_kernel(char * real_mode_data)
 {
 	int i;
@@ -111,6 +113,9 @@ void __init x86_64_start_kernel(char * r
 
 	x86_64_init_pda();
 
+	enable_debug_console("ttyS0,115200");
+	enable_debug_console("dbgp");
+
 	early_printk("Kernel really alive\n");
 
 	x86_64_start_reservations(real_mode_data);
drivers/usb/host/ehci.h +13 -1
Index: linux-2.6/drivers/usb/host/ehci.h
===================================================================
@@ -62,6 +62,7 @@ struct ehci_stats {
 
 #define	EHCI_MAX_ROOT_PORTS	15		/* see HCS_N_PORTS */
 
+#ifndef EARLY_PRINTK
 struct ehci_hcd {			/* one per controller */
 	/* glue to PCI and HCD framework */
 	struct ehci_caps __iomem *caps;
@@ -207,6 +208,7 @@ timer_action (struct ehci_hcd *ehci, enu
 		mod_timer(&ehci->watchdog, t + jiffies);
 	}
 }
+#endif /* EARLY_PRINTK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -352,6 +354,8 @@ struct ehci_dbg_port {
 
 #define	QTD_NEXT(ehci, dma)	cpu_to_hc32(ehci, (u32)dma)
 
+#ifndef EARLY_PRINTK
+
 /*
  * EHCI Specification 0.95 Section 3.5
  * QTD: describe data transfer components (buffer, direction, ...)
@@ -392,7 +396,7 @@ struct ehci_qtd {
 	struct urb		*urb;			/* qtd's urb */
 	size_t			length;			/* length of buffer */
 } __attribute__ ((aligned (32)));
-
+#endif
 /* mask NakCnt+T in qh->hw_alt_next */
 #define QTD_MASK(ehci)	cpu_to_hc32 (ehci, ~0x1f)
 
@@ -449,6 +453,7 @@ union ehci_shadow {
  * These appear in both the async and (for interrupt) periodic schedules.
  */
 
+#ifndef EARLY_PRINTK
 struct ehci_qh {
 	/* first part defined by EHCI spec */
 	__hc32			hw_next;	/* see EHCI 3.6.1 */
@@ -504,6 +509,7 @@ struct ehci_qh {
 #define NO_FRAME ((unsigned short)~0)			/* pick new start */
 	struct usb_device	*dev;		/* access to TT */
 } __attribute__ ((aligned (32)));
+#endif /* EARLY_PRITNK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -517,6 +523,7 @@ struct ehci_iso_packet {
 	u32			buf1;
 };
 
+#ifndef EARLY_PRINTK
 /* temporary schedule data for packets from iso urbs (both speeds)
  * each packet is one logical usb transaction to the device (not TT),
  * beginning at stream->next_uframe
@@ -651,6 +658,7 @@ struct ehci_sitd {
 	unsigned		frame;
 	unsigned		index;
 } __attribute__ ((aligned (32)));
+#endif
 
 /*-------------------------------------------------------------------------*/
 
@@ -672,6 +680,8 @@ struct ehci_fstn {
 	union ehci_shadow	fstn_next;	/* ptr to periodic q entry */
 } __attribute__ ((aligned (32)));
 
+#ifndef EARLY_PRINTK
+
 /*-------------------------------------------------------------------------*/
 
 #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
@@ -843,4 +853,6 @@ static inline u32 hc32_to_cpup (const st
 
 /*-------------------------------------------------------------------------*/
 
+#endif /* EARLY_PRINTK */
+
 #endif /* __LINUX_EHCI_HCD_H */
#1 lore raw
Quoted 8 lines · On Wed, 23 Jul 2008 12:52:20 -0700 Yinghai Lu <[email protected]> wrote:

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

...

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 250

Quoted 8 lines
arch/x86/kernel/early_printk.c +8 -0
+static void dbgp_mdelay(int ms)
+{
+	int i;
+	while (ms--) {
+		for (i = 0; i < 1000; i++)
+			outb(0x1, 0x80);
+	}
+}

hm. port 80 has a guaranteed one microsecond? Why not udelay()/mdelay()/etc?

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 255

Quoted 4 lines
arch/x86/kernel/early_printk.c +4 -0
+static void dbgp_breath(void)
+{
+	/* Sleep to give the debug port a chance to breathe */
+}

I expect the compiler will optimise away any calls to this.

arch/x86/kernel/head64.c static void __init copy_bootdata(char *r · line 75

Quoted 10 lines

...

arch/x86/kernel/head64.c +1 -0
@@ -72,6 +72,8 @@ static void __init copy_bootdata(char *r
 	}
 }
 
+extern void __init enable_debug_console(char *buf);

Please always pass all patches through scripts/checkpatch.pl.

author
#2 lore raw
Quoted 39 lines · Andrew Morton
Quoted 8 lines · On Wed, 23 Jul 2008 12:52:20 -0700 Yinghai Lu <[email protected]> wrote:

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

...

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 250

Quoted 8 lines
arch/x86/kernel/early_printk.c +8 -0
+static void dbgp_mdelay(int ms)
+{
+     int i;
+     while (ms--) {
+             for (i = 0; i < 1000; i++)
+                     outb(0x1, 0x80);
+     }
+}

hm. port 80 has a guaranteed one microsecond? Why not udelay()/mdelay()/etc?

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 255

Quoted 4 lines
arch/x86/kernel/early_printk.c +4 -0
+static void dbgp_breath(void)
+{
+     /* Sleep to give the debug port a chance to breathe */
+}

I expect the compiler will optimise away any calls to this.

Quoted 9 lines

...

arch/x86/kernel/head64.c +0 -0
@@ -72,6 +72,8 @@ static void __init copy_bootdata(char *r
      }
 }
 
Quoted 3 lines

arch/x86/kernel/head64.c static void __init copy_bootdata(char *r · line 75

Quoted 1 line
arch/x86/kernel/head64.c +1 -0
+extern void __init enable_debug_console(char *buf);

Please always pass all patches through scripts/checkpatch.pl.

yhlu@linux-zpir:~/xx/xx/kernel/tip/linux-2.6> ./scripts/checkpatch.pl patches/9xxx.patch
WARNING: line over 80 characters
#319: FILE: arch/x86/kernel/early_printk.c:420:
+ if (!(read_pci_config_16(num, slot, func, PCI_STATUS) &
PCI_STATUS_CAP_LIST))

WARNING: line over 80 characters
#330: FILE: arch/x86/kernel/early_printk.c:431:
+ pos = read_pci_config_byte(num, slot, func,
pos+PCI_CAP_LIST_NEXT);

WARNING: line over 80 characters
#335: FILE: arch/x86/kernel/early_printk.c:436:
+static __u32 __init find_dbgp(int ehci_num, unsigned *rbus, unsigned *rslot, unsigned *rfunc)

WARNING: line over 80 characters
#344: FILE: arch/x86/kernel/early_printk.c:445:
+ class = read_pci_config(bus, slot,
func, PCI_CLASS_REVISION);

WARNING: line over 80 characters
#347: FILE: arch/x86/kernel/early_printk.c:448:
+ cap = find_cap(bus, slot, func,
PCI_CAP_ID_EHCI_DEBUG);

WARNING: line over 80 characters
#386: FILE: arch/x86/kernel/early_printk.c:487:
+ portsc =
readl(&ehci_regs->port_status[port - 1]);

WARNING: externs should be avoided in .c files
#425: FILE: arch/x86/kernel/early_printk.c:526:
+void early_printk(const char *fmt, ...);

WARNING: consider using strict_strtoul in preference to simple_strtoul #518: FILE: arch/x86/kernel/early_printk.c:619:
+ dbgp_num = simple_strtoul(s, &e, 10);

WARNING: externs should be avoided in .c files #722: FILE: arch/x86/kernel/head64.c:75:
+extern void __init enable_debug_console(char *buf);

total: 0 errors, 9 warnings, 773 lines checked

patches/9xxx.patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

YH

#3 lore raw
Quoted 1 line · On Wed, 23 Jul 2008 13:18:12 -0700 "Yinghai Lu" <[email protected]> wrote:
Quoted 1 line

Please always pass all patches through scripts/checkpatch.pl.

What I meant was to use checkpatch and then to actually read its output ;)

Quoted 27 lines

yhlu@linux-zpir:~/xx/xx/kernel/tip/linux-2.6> ./scripts/checkpatch.pl patches/9xxx.patch
WARNING: line over 80 characters
#319: FILE: arch/x86/kernel/early_printk.c:420:
+ if (!(read_pci_config_16(num, slot, func, PCI_STATUS) &
PCI_STATUS_CAP_LIST))

WARNING: line over 80 characters
#330: FILE: arch/x86/kernel/early_printk.c:431:
+ pos = read_pci_config_byte(num, slot, func,
pos+PCI_CAP_LIST_NEXT);

WARNING: line over 80 characters
#335: FILE: arch/x86/kernel/early_printk.c:436:
+static __u32 __init find_dbgp(int ehci_num, unsigned *rbus, unsigned *rslot, unsigned *rfunc)

WARNING: line over 80 characters
#344: FILE: arch/x86/kernel/early_printk.c:445:
+ class = read_pci_config(bus, slot,
func, PCI_CLASS_REVISION);

WARNING: line over 80 characters
#347: FILE: arch/x86/kernel/early_printk.c:448:
+ cap = find_cap(bus, slot, func,
PCI_CAP_ID_EHCI_DEBUG);

Quoted 4 lines

WARNING: line over 80 characters
#386: FILE: arch/x86/kernel/early_printk.c:487:
+ portsc =
readl(&ehci_regs->port_status[port - 1]);

I don't think the 80-col warnigns should necessarily all be fixed. But one should take a look at the code and ask "did I really need to do it that way?".

Quoted 3 lines

WARNING: externs should be avoided in .c files
#425: FILE: arch/x86/kernel/early_printk.c:526:
+void early_printk(const char *fmt, ...);

This one is a must-fix.

Quoted 3 lines

WARNING: consider using strict_strtoul in preference to simple_strtoul #518: FILE: arch/x86/kernel/early_printk.c:619:
+ dbgp_num = simple_strtoul(s, &e, 10);

simple_strtoul() is sometimes OK for kernel parameters, sometimes strict_strtoul() is better.

Quoted 3 lines

WARNING: externs should be avoided in .c files #722: FILE: arch/x86/kernel/head64.c:75:
+extern void __init enable_debug_console(char *buf);

This one also should be fixed.

author
#6 lore raw

PATCH 1/1 x86: usb debug port early console v2

In reply to Yinghai Lu

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

v2: fix checkpatch warning

---
 Documentation/kernel-parameters.txt |    3 
 arch/x86/kernel/early_printk.c      |  642 +++++++++++++++++++++++++++++++++++-
 drivers/usb/host/ehci.h             |   14 
 3 files changed, 654 insertions(+), 5 deletions(-)
Documentation/kernel-parameters.txt +2 -1
Index: linux-2.6/Documentation/kernel-parameters.txt
===================================================================
@@ -654,11 +654,12 @@ and is between 256 and 4096 characters.
 	earlyprintk=	[X86-32,X86-64,SH,BLACKFIN]
 			earlyprintk=vga
 			earlyprintk=serial[,ttySn[,baudrate]]
+			earlyprintk=dbgp
 
 			Append ",keep" to not disable it when the real console
 			takes over.
 
-			Only vga or serial at a time, not both.
+			Only vga or serial or usb debug port at a time.
 
 			Currently only ttyS0 and ttyS1 are supported.
 
arch/x86/kernel/early_printk.c +639 -3

702 lines not on this page · raw message

drivers/usb/host/ehci.h +13 -1
Index: linux-2.6/drivers/usb/host/ehci.h
===================================================================
@@ -62,6 +62,7 @@ struct ehci_stats {
 
 #define	EHCI_MAX_ROOT_PORTS	15		/* see HCS_N_PORTS */
 
+#ifndef EARLY_PRINTK
 struct ehci_hcd {			/* one per controller */
 	/* glue to PCI and HCD framework */
 	struct ehci_caps __iomem *caps;
@@ -207,6 +208,7 @@ timer_action (struct ehci_hcd *ehci, enu
 		mod_timer(&ehci->watchdog, t + jiffies);
 	}
 }
+#endif /* EARLY_PRINTK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -352,6 +354,8 @@ struct ehci_dbg_port {
 
 #define	QTD_NEXT(ehci, dma)	cpu_to_hc32(ehci, (u32)dma)
 
+#ifndef EARLY_PRINTK
+
 /*
  * EHCI Specification 0.95 Section 3.5
  * QTD: describe data transfer components (buffer, direction, ...)
@@ -392,7 +396,7 @@ struct ehci_qtd {
 	struct urb		*urb;			/* qtd's urb */
 	size_t			length;			/* length of buffer */
 } __attribute__ ((aligned (32)));
-
+#endif
 /* mask NakCnt+T in qh->hw_alt_next */
 #define QTD_MASK(ehci)	cpu_to_hc32 (ehci, ~0x1f)
 
@@ -449,6 +453,7 @@ union ehci_shadow {
  * These appear in both the async and (for interrupt) periodic schedules.
  */
 
+#ifndef EARLY_PRINTK
 struct ehci_qh {
 	/* first part defined by EHCI spec */
 	__hc32			hw_next;	/* see EHCI 3.6.1 */
@@ -504,6 +509,7 @@ struct ehci_qh {
 #define NO_FRAME ((unsigned short)~0)			/* pick new start */
 	struct usb_device	*dev;		/* access to TT */
 } __attribute__ ((aligned (32)));
+#endif /* EARLY_PRITNK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -517,6 +523,7 @@ struct ehci_iso_packet {
 	u32			buf1;
 };
 
+#ifndef EARLY_PRINTK
 /* temporary schedule data for packets from iso urbs (both speeds)
  * each packet is one logical usb transaction to the device (not TT),
  * beginning at stream->next_uframe
@@ -651,6 +658,7 @@ struct ehci_sitd {
 	unsigned		frame;
 	unsigned		index;
 } __attribute__ ((aligned (32)));
+#endif
 
 /*-------------------------------------------------------------------------*/
 
@@ -672,6 +680,8 @@ struct ehci_fstn {
 	union ehci_shadow	fstn_next;	/* ptr to periodic q entry */
 } __attribute__ ((aligned (32)));
 
+#ifndef EARLY_PRINTK
+
 /*-------------------------------------------------------------------------*/
 
 #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
@@ -843,4 +853,6 @@ static inline u32 hc32_to_cpup (const st
 
 /*-------------------------------------------------------------------------*/
 
+#endif /* EARLY_PRINTK */
+
 #endif /* __LINUX_EHCI_HCD_H */
#7 lore raw

Re: [PATCH] x86: usb debug port early console v2

Quoted 78 lines · Yinghai Lu
drivers/usb/host/ehci.h +11 -1
@@ -62,6 +62,7 @@ struct ehci_stats {
 
 #define	EHCI_MAX_ROOT_PORTS	15		/* see HCS_N_PORTS */
 
+#ifndef EARLY_PRINTK
 struct ehci_hcd {			/* one per controller */
 	/* glue to PCI and HCD framework */
 	struct ehci_caps __iomem *caps;
@@ -207,6 +208,7 @@ timer_action (struct ehci_hcd *ehci, enu
 		mod_timer(&ehci->watchdog, t + jiffies);
 	}
 }
+#endif /* EARLY_PRINTK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -352,6 +354,8 @@ struct ehci_dbg_port {
 
 #define	QTD_NEXT(ehci, dma)	cpu_to_hc32(ehci, (u32)dma)
 
+#ifndef EARLY_PRINTK
+
 /*
  * EHCI Specification 0.95 Section 3.5
  * QTD: describe data transfer components (buffer, direction, ...)
@@ -392,7 +396,7 @@ struct ehci_qtd {
 	struct urb		*urb;			/* qtd's urb */
 	size_t			length;			/* length of buffer */
 } __attribute__ ((aligned (32)));
-
+#endif
 /* mask NakCnt+T in qh->hw_alt_next */
 #define QTD_MASK(ehci)	cpu_to_hc32 (ehci, ~0x1f)
 
@@ -449,6 +453,7 @@ union ehci_shadow {
  * These appear in both the async and (for interrupt) periodic schedules.
  */
 
+#ifndef EARLY_PRINTK
 struct ehci_qh {
 	/* first part defined by EHCI spec */
 	__hc32			hw_next;	/* see EHCI 3.6.1 */
@@ -504,6 +509,7 @@ struct ehci_qh {
 #define NO_FRAME ((unsigned short)~0)			/* pick new start */
 	struct usb_device	*dev;		/* access to TT */
 } __attribute__ ((aligned (32)));
+#endif /* EARLY_PRITNK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -517,6 +523,7 @@ struct ehci_iso_packet {
 	u32			buf1;
 };
 
+#ifndef EARLY_PRINTK
 /* temporary schedule data for packets from iso urbs (both speeds)
  * each packet is one logical usb transaction to the device (not TT),
  * beginning at stream->next_uframe
@@ -651,6 +658,7 @@ struct ehci_sitd {
 	unsigned		frame;
 	unsigned		index;
 } __attribute__ ((aligned (32)));
+#endif
 
 /*-------------------------------------------------------------------------*/
 
@@ -672,6 +680,8 @@ struct ehci_fstn {
 	union ehci_shadow	fstn_next;	/* ptr to periodic q entry */
 } __attribute__ ((aligned (32)));
 
+#ifndef EARLY_PRINTK
+
 /*-------------------------------------------------------------------------*/
 
 #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT

drivers/usb/host/ehci.h static inline u32 hc32_to_cpup (const st · line 858

Quoted 6 lines
drivers/usb/host/ehci.h +2 -0
@@ -843,4 +853,6 @@ static inline u32 hc32_to_cpup (const st
 
 /*-------------------------------------------------------------------------*/
 
+#endif /* EARLY_PRINTK */
+
 #endif /* __LINUX_EHCI_HCD_H */

I don't understand the issue of any of these #ifdefs here. Why are they needed?

And shouldn't there be a separate config option for early printk through the ehci debug port?

thanks,

greg k-h

author
#8 lore raw

Re: [PATCH] x86: usb debug port early console v2

Quoted 80 lines · Greg KH
Quoted 79 lines · Yinghai Lu
drivers/usb/host/ehci.h +11 -1
@@ -62,6 +62,7 @@ struct ehci_stats {
 
 #define      EHCI_MAX_ROOT_PORTS     15              /* see HCS_N_PORTS */
 
+#ifndef EARLY_PRINTK
 struct ehci_hcd {                    /* one per controller */
      /* glue to PCI and HCD framework */
      struct ehci_caps __iomem *caps;
@@ -207,6 +208,7 @@ timer_action (struct ehci_hcd *ehci, enu
              mod_timer(&ehci->watchdog, t + jiffies);
      }
 }
+#endif /* EARLY_PRINTK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -352,6 +354,8 @@ struct ehci_dbg_port {
 
 #define      QTD_NEXT(ehci, dma)     cpu_to_hc32(ehci, (u32)dma)
 
+#ifndef EARLY_PRINTK
+
 /*
  * EHCI Specification 0.95 Section 3.5
  * QTD: describe data transfer components (buffer, direction, ...)
@@ -392,7 +396,7 @@ struct ehci_qtd {
      struct urb              *urb;                   /* qtd's urb */
      size_t                  length;                 /* length of buffer */
 } __attribute__ ((aligned (32)));
-
+#endif
 /* mask NakCnt+T in qh->hw_alt_next */
 #define QTD_MASK(ehci)       cpu_to_hc32 (ehci, ~0x1f)
 
@@ -449,6 +453,7 @@ union ehci_shadow {
  * These appear in both the async and (for interrupt) periodic schedules.
  */
 
+#ifndef EARLY_PRINTK
 struct ehci_qh {
      /* first part defined by EHCI spec */
      __hc32                  hw_next;        /* see EHCI 3.6.1 */
@@ -504,6 +509,7 @@ struct ehci_qh {
 #define NO_FRAME ((unsigned short)~0)                        /* pick new start */
      struct usb_device       *dev;           /* access to TT */
 } __attribute__ ((aligned (32)));
+#endif /* EARLY_PRITNK */
 
 /*-------------------------------------------------------------------------*/
 
@@ -517,6 +523,7 @@ struct ehci_iso_packet {
      u32                     buf1;
 };
 
+#ifndef EARLY_PRINTK
 /* temporary schedule data for packets from iso urbs (both speeds)
  * each packet is one logical usb transaction to the device (not TT),
  * beginning at stream->next_uframe
@@ -651,6 +658,7 @@ struct ehci_sitd {
      unsigned                frame;
      unsigned                index;
 } __attribute__ ((aligned (32)));
+#endif
 
 /*-------------------------------------------------------------------------*/
 
@@ -672,6 +680,8 @@ struct ehci_fstn {
      union ehci_shadow       fstn_next;      /* ptr to periodic q entry */
 } __attribute__ ((aligned (32)));
 
+#ifndef EARLY_PRINTK
+
 /*-------------------------------------------------------------------------*/
 
 #ifdef CONFIG_USB_EHCI_ROOT_HUB_TT
@@ -843,4 +853,6 @@ static inline u32 hc32_to_cpup (const st
 
Quoted 8 lines

drivers/usb/host/ehci.h static inline u32 hc32_to_cpup (const st · line 858

Quoted 5 lines
drivers/usb/host/ehci.h +2 -0
 /*-------------------------------------------------------------------------*/
 
+#endif /* EARLY_PRINTK */
+
 #endif /* __LINUX_EHCI_HCD_H */

I don't understand the issue of any of these #ifdefs here. Why are they needed?

In file included from arch/x86/kernel/early_printk.c:19:
arch/x86/kernel/../../../drivers/usb/host/ehci.h:109: error: field 'iaa_watchdog' has incomplete type arch/x86/kernel/../../../drivers/usb/host/ehci.h:110: error: field 'watchdog' has incomplete type arch/x86/kernel/../../../drivers/usb/host/ehci.h:142: warning: 'struct usb_hcd' declared inside parameter list arch/x86/kernel/../../../drivers/usb/host/ehci.h:142: warning: its scope is only this definition or declaration, which is probably not what you want
arch/x86/kernel/../../../drivers/usb/host/ehci.h: In function 'hcd_to_ehci':
arch/x86/kernel/../../../drivers/usb/host/ehci.h:144: error:
dereferencing pointer to incomplete type arch/x86/kernel/../../../drivers/usb/host/ehci.h: In function 'ehci_to_hcd':
arch/x86/kernel/../../../drivers/usb/host/ehci.h:148: error:
dereferencing pointer to incomplete type arch/x86/kernel/../../../drivers/usb/host/ehci.h:148: warning: type defaults to 'int' in declaration of '__mptr' arch/x86/kernel/../../../drivers/usb/host/ehci.h:148: error: invalid use of undefined type 'struct usb_hcd' arch/x86/kernel/../../../drivers/usb/host/ehci.h: In function 'iaa_watchdog_start':
arch/x86/kernel/../../../drivers/usb/host/ehci.h:155: error: implicit declaration of function 'timer_pending' arch/x86/kernel/../../../drivers/usb/host/ehci.h:156: error: implicit declaration of function 'mod_timer' arch/x86/kernel/../../../drivers/usb/host/ehci.h:157: error: 'jiffies' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h:157: error: (Each undeclared identifier is reported only once arch/x86/kernel/../../../drivers/usb/host/ehci.h:157: error: for each function it appears in.) arch/x86/kernel/../../../drivers/usb/host/ehci.h:157: error: implicit declaration of function 'msecs_to_jiffies' arch/x86/kernel/../../../drivers/usb/host/ehci.h:157: error:
'EHCI_IAA_MSECS' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h: In function 'iaa_watchdog_done':
arch/x86/kernel/../../../drivers/usb/host/ehci.h:162: error: implicit declaration of function 'del_timer' arch/x86/kernel/../../../drivers/usb/host/ehci.h: In function 'timer_action':
arch/x86/kernel/../../../drivers/usb/host/ehci.h:194: error:
'EHCI_IO_JIFFIES' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h:197: error:
'EHCI_ASYNC_JIFFIES' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h:204: error:
'EHCI_SHRINK_FRAMES' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h:204: error: 'HZ' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h:207: error: 'jiffies' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h: In function 'ehci_port_speed':
arch/x86/kernel/../../../drivers/usb/host/ehci.h:692: error:
dereferencing pointer to incomplete type arch/x86/kernel/../../../drivers/usb/host/ehci.h:697: error:
'USB_PORT_FEAT_LOWSPEED' undeclared (first use in this function) arch/x86/kernel/../../../drivers/usb/host/ehci.h:700: error:
'USB_PORT_FEAT_HIGHSPEED' undeclared (first use in this function) arch/x86/kernel/early_printk.c: In function 'early_dbgp_init':
arch/x86/kernel/early_printk.c:629: warning: passing argument 3 of 'strict_strtoul' from incompatible pointer type
make[1]: *** [arch/x86/kernel/early_printk.o] Error 1

Quoted 3 lines

And shouldn't there be a separate config option for early printk through the ehci debug port?

under usb or processor?

YH

#9 lore raw

Re: [PATCH] x86: usb debug port early console v2

Quoted 11 lines · Yinghai Lu
Quoted 6 lines · Greg KH

drivers/usb/host/ehci.h

Quoted 2 lines · Yinghai Lu
drivers/usb/host/ehci.h +0 -0

I don't understand the issue of any of these #ifdefs here. Why are they needed?

In file included from arch/x86/kernel/early_printk.c:19:
arch/x86/kernel/../../../drivers/usb/host/ehci.h:109: error: field 'iaa_watchdog' has incomplete type

Ah, so you are papering over the real problem here, right?

Why not just include the properly needed #includes either where you are including this header file, or add the dependancies to the ehci.h file itself (which is usually preferred.)

Quoted 4 lines
Quoted 2 lines

And shouldn't there be a separate config option for early printk through the ehci debug port?

under usb or processor?

Somewhere.

Also, usb patches should be cc:ed to the linux-usb mailing list. I'm sure the EHCI authors would like to comment on this patch...

thanks,

greg k-h

author
#10 lore raw

Re: [PATCH] x86: usb debug port early console v2

Quoted 13 lines · Greg KH
Quoted 11 lines · Yinghai Lu
Quoted 6 lines · Greg KH

drivers/usb/host/ehci.h

Quoted 2 lines · Yinghai Lu
drivers/usb/host/ehci.h +0 -0

I don't understand the issue of any of these #ifdefs here. Why are they needed?

In file included from arch/x86/kernel/early_printk.c:19:
arch/x86/kernel/../../../drivers/usb/host/ehci.h:109: error: field 'iaa_watchdog' has incomplete type

Quoted 5 lines

Ah, so you are papering over the real problem here, right?

Why not just include the properly needed #includes either where you are including this header file, or add the dependancies to the ehci.h file itself (which is usually preferred.)

how about moving

struct ehci_caps;
struct ehci_regs;
struct ehci_dbg_port;

to one header file in include/usb
so could use
#include <linux/usb/ehci_def.h>
instead of
#include "../../../drivers/usb/host/ehci.h"

Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

And shouldn't there be a separate config option for early printk through the ehci debug port?

under usb or processor?

Somewhere.

Also, usb patches should be cc:ed to the linux-usb mailing list. I'm sure the EHCI authors would like to comment on this patch...

oh, i thought you wrote the ehci code.

YH

#11 lore raw

Re: [PATCH] x86: usb debug port early console v2

Quoted 26 lines · Yinghai Lu
Quoted 13 lines · Greg KH
Quoted 11 lines · Yinghai Lu
Quoted 6 lines · Greg KH

drivers/usb/host/ehci.h

Quoted 2 lines · Yinghai Lu
drivers/usb/host/ehci.h +0 -0

I don't understand the issue of any of these #ifdefs here. Why are they needed?

In file included from arch/x86/kernel/early_printk.c:19:
arch/x86/kernel/../../../drivers/usb/host/ehci.h:109: error: field 'iaa_watchdog' has incomplete type

Quoted 5 lines

Ah, so you are papering over the real problem here, right?

Why not just include the properly needed #includes either where you are including this header file, or add the dependancies to the ehci.h file itself (which is usually preferred.)

how about moving

struct ehci_caps;
struct ehci_regs;
struct ehci_dbg_port;

Quoted 5 lines

to one header file in include/usb
so could use
#include <linux/usb/ehci_def.h>
instead of
#include "../../../drivers/usb/host/ehci.h"

Sure, feel free to do that instead, that makes more sense.

Quoted 11 lines
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

And shouldn't there be a separate config option for early printk through the ehci debug port?

under usb or processor?

Somewhere.

Also, usb patches should be cc:ed to the linux-usb mailing list. I'm sure the EHCI authors would like to comment on this patch...

oh, i thought you wrote the ehci code.

Heh, no.

thanks,

greg k-h

author
#12 lore raw

PATCH 1/1 x86: usb debug port early console v3

In reply to Yinghai Lu

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

v2: fix checkpatch warning
v3: move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h
also add CONFIG_EARLY_PRINTK_DBGP to disable it by default

---
 Documentation/kernel-parameters.txt |    3 
 arch/x86/Kconfig.debug              |   13 
 arch/x86/kernel/early_printk.c      |  643 +++++++++++++++++++++++++++++++++++-
 drivers/usb/host/ehci.h             |  139 -------
 include/linux/usb/ehci_def.h        |  160 ++++++++
 5 files changed, 817 insertions(+), 141 deletions(-)
Documentation/kernel-parameters.txt +2 -1
Index: linux-2.6/Documentation/kernel-parameters.txt
===================================================================
@@ -654,11 +654,12 @@ and is between 256 and 4096 characters.
 	earlyprintk=	[X86-32,X86-64,SH,BLACKFIN]
 			earlyprintk=vga
 			earlyprintk=serial[,ttySn[,baudrate]]
+			earlyprintk=dbgp
 
 			Append ",keep" to not disable it when the real console
 			takes over.
 
-			Only vga or serial at a time, not both.
+			Only vga or serial or usb debug port at a time.
 
 			Currently only ttyS0 and ttyS1 are supported.
 
arch/x86/kernel/early_printk.c +640 -3

703 lines not on this page · raw message

drivers/usb/host/ehci.h +2 -137

148 lines not on this page · raw message

include/linux/usb/ehci_def.h new file +160 -0

160 lines not on this page · raw message

arch/x86/Kconfig.debug +13 -0
Index: linux-2.6/arch/x86/Kconfig.debug
===================================================================
@@ -43,6 +43,19 @@ config EARLY_PRINTK
 	  with klogd/syslogd or the X server. You should normally N here,
 	  unless you want to debug such a crash.
 
+config EARLY_PRINTK_DBGP
+	bool "Early printk via EHCI debug port"
+	default n
+	depends on EARLY_PRINTK
+	help
+	  Write kernel log output directly into the EHCI debug port.
+
+	  This is useful for kernel debugging when your machine crashes very
+	  early before the console code is initialized. For normal operation
+	  it is not recommended because it looks ugly and doesn't cooperate
+	  with klogd/syslogd or the X server. You should normally N here,
+	  unless you want to debug such a crash. You need usb debug device.
+
 config DEBUG_STACKOVERFLOW
 	bool "Check for stack overflows"
 	depends on DEBUG_KERNEL
#4 lore raw
In reply to Andrew Morton
Quoted 12 lines · Andrew Morton
Quoted 3 lines · On Wed, 23 Jul 2008 12:52:20 -0700 Yinghai Lu <[email protected]> wrote:

based on work from Eric, and add some timeout so don't dead loop when debug

device

Quoted 5 lines

is not installed

...

Quoted 10 lines

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 250

Quoted 8 lines
arch/x86/kernel/early_printk.c +8 -0
+static void dbgp_mdelay(int ms)
+{
+	int i;
+	while (ms--) {
+		for (i = 0; i < 1000; i++)
+			outb(0x1, 0x80);
+	}
+}

hm. port 80 has a guaranteed one microsecond?

It usually longer, but it is in the 1 microsecond ballpark, accurate enough to be a usable delay before we have anything else.

Quoted 1 line

Why not udelay()/mdelay()/etc?

This code runs ages before udelay and mdelay work. Certainly before calibrate delay is called, so the normal kernel delay routines don't come anywhere close and an out to port 0x80 comes.

Quoted 6 lines

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 255

Quoted 4 lines
arch/x86/kernel/early_printk.c +4 -0
+static void dbgp_breath(void)
+{
+	/* Sleep to give the debug port a chance to breathe */
+}

I expect the compiler will optimise away any calls to this.

It is documentation that is if it might be a good idea to not hit the hardware there.

Eric

#5 lore raw
Quoted 10 lines · Eric W. Biederman
Quoted 6 lines

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 255

Quoted 5 lines
arch/x86/kernel/early_printk.c +4 -0
+static void dbgp_breath(void)
+{
+	/* Sleep to give the debug port a chance to breathe */
+}

I expect the compiler will optimise away any calls to this.

It is documentation that is if it might be a good idea to not hit the hardware there.

Sounds an awful lot like cpu_relax(); doesn't it?

-hpa

#13 lore raw

Re: [PATCH] x86: usb debug port early console v3

In reply to Yinghai Lu

very nice feature!

The code structure looks good to me, here's a few minor style nits:

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 239

Quoted 3 lines
arch/x86/kernel/early_printk.c +3 -0
+	/* Now that we have observed the completed transaction,
+	 * clear the done bit.
+	 */

while i understand that this is cut & pasted code, please use standard comment style:

/*
* Comment ...
* ... line.
*/

(ditto the same mistake in other places too)

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 415

Quoted 3 lines
arch/x86/kernel/early_printk.c +3 -0
+	/* Read the result */
+	ret = dbgp_bulk_read(devnum, 0, data, size);
+	return ret;

do:

    return dbgp_bulk_read(devnum, 0, data, size);

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 428

Quoted 4 lines
arch/x86/kernel/early_printk.c +4 -0
+	if (!(read_pci_config_16(num, slot, func, PCI_STATUS) &
+		PCI_STATUS_CAP_LIST))
+		return 0;
+	pos = read_pci_config_byte(num, slot, func, PCI_CAPABILITY_LIST);

it's generally nicer to the eyes to add an extra newline after a block with return in it.

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 431

Quoted 3 lines
arch/x86/kernel/early_printk.c +3 -0
+	for (bytes = 0; bytes < 48 && pos >= 0x40; bytes++) {
+		u8 id;
+		pos &= ~3;

please put a newline between variable definitions and first statement.

Quoted 8 lines
arch/x86/kernel/early_printk.c +8 -0
+
+static __u32 __init find_dbgp(int ehci_num, unsigned *rbus, unsigned *rslot,
+				unsigned *rfunc)
+{
+	unsigned bus, slot, func;
+
+	for (bus = 0; bus < 256; bus++) {
+		for (slot = 0; slot < 32; slot++) {

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 459

Quoted 10 lines
arch/x86/kernel/early_printk.c +10 -0
+			for (func = 0; func < 8; func++) {
+				u32 class;
+				unsigned cap;
+
+				class = read_pci_config(bus, slot, func,
+							 PCI_CLASS_REVISION);
+				if ((class >> 8) != PCI_CLASS_SERIAL_USB_EHCI)
+					continue;
+				cap = find_cap(bus, slot, func,
+						 PCI_CAP_ID_EHCI_DEBUG);

the line 80 breaks you had to add here show that the nesting is too deep here - i'd suggest a helper __find_dbgp() function to put the iterator into.

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 600

Quoted 6 lines
arch/x86/kernel/early_printk.c +6 -0
+	if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) {
+		dbgp_printk("No device in debug port\n");
+		writel(ctrl & ~DBGP_CLAIM, &ehci_debug->control);
+		return -1;
+
+	}

stray newline.

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 620

Quoted 11 lines
arch/x86/kernel/early_printk.c +11 -0
+static int __init early_dbgp_init(char *s)
+{
+	struct usb_debug_descriptor dbgp_desc;
+	void __iomem *ehci_bar;
+	unsigned ctrl, devnum;
+	unsigned bus, slot, func, cap;
+	unsigned debug_port, bar, offset;
+	unsigned bar_val;
+	char *e;
+	int ret;
+	unsigned dbgp_num;

use an explicit integer type please instead of 'unsigned'. Also, try to use reverse christmas-tree ordering for same-type entries (and where possible, between different types as well):

Review

Quoted 9 lines
(quoted diff) +9 -0
+	struct usb_debug_descriptor dbgp_desc;
+	unsigned int debug_port, bar, offset;
+	unsigned int bus, slot, func, cap;
+	unsigned int ctrl, devnum;
+	unsigned int dbgp_num;
+	unsigned int bar_val;
+	void __iomem *ehci_bar;
+	char *e;
+	int ret;

here:

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 633

Quoted 9 lines
arch/x86/kernel/early_printk.c +9 -0
+	dbgp_num = 0;
+	if (*s)
+		dbgp_num = simple_strtoul(s, &e, 10);
+	dbgp_printk("dbgp_num: %d\n", dbgp_num);
+	cap = find_dbgp(dbgp_num, &bus, &slot, &func);
+	if (!cap)
+		return -1;
+
+	dbgp_printk("Found EHCI debug port\n");

i'd suggest a newline after the first dbgp_printk(), to make the two sections stand out better.

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 183

Quoted 3 lines
arch/x86/kernel/early_printk.c +3 -0
+	}
+
+

stray newline.

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 655

Quoted 3 lines
arch/x86/kernel/early_printk.c +3 -0
+	/* FIXME I don't have the bar size so just guess PAGE_SIZE is more
+	 * than enough.  1K is the biggest I have seen.
+	 */

comment style.

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 669

Quoted 5 lines
arch/x86/kernel/early_printk.c +5 -0
+	ret = ehci_setup();
+	if (ret < 0) {
+		dbgp_printk("ehci_setup failed\n");
+		ehci_debug = 0;
+		return -1;

please put newlines before return statements, to make sure there's a hickup in the visual flow during review. (which hickup return statements should cause, they must not be glossed over)

arch/x86/kernel/early_printk.c static struct console early_serial_conso · line 183

Quoted 3 lines
arch/x86/kernel/early_printk.c +3 -0
+	}
+
+

stray newline.

drivers/usb/host/ehci.h timer_action (struct ehci_hcd *ehci, enu

Quoted 5 lines

Index: linux-2.6/drivers/usb/host/ehci.h
===================================================================

drivers/usb/host/ehci.h +0 -0
@@ -210,146 +210,11 @@ timer_action (struct ehci_hcd *ehci, enu

i suggest you make this code movement a separate patch. In the unlikely event of there being any regression it's an easier bisection target.

looks good to me otherwise.

Ingo

author
#14 lore raw

PATCH 1/1 usb: move ehci reg def

In reply to Yinghai Lu

prepare x86: usb debug port early console

move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h

---
 drivers/usb/host/ehci.h      |  139 -------------------------------------
 include/linux/usb/ehci_def.h |  160 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 162 insertions(+), 137 deletions(-)
drivers/usb/host/ehci.h +2 -137
Index: linux-2.6/drivers/usb/host/ehci.h
===================================================================
@@ -210,146 +210,11 @@ timer_action (struct ehci_hcd *ehci, enu
 
 /*-------------------------------------------------------------------------*/
 
-/* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
-
-/* Section 2.2 Host Controller Capability Registers */
-struct ehci_caps {
-	/* these fields are specified as 8 and 16 bit registers,
-	 * but some hosts can't perform 8 or 16 bit PCI accesses.
-	 */
-	u32		hc_capbase;
-#define HC_LENGTH(p)		(((p)>>00)&0x00ff)	/* bits 7:0 */
-#define HC_VERSION(p)		(((p)>>16)&0xffff)	/* bits 31:16 */
-	u32		hcs_params;     /* HCSPARAMS - offset 0x4 */
-#define HCS_DEBUG_PORT(p)	(((p)>>20)&0xf)	/* bits 23:20, debug port? */
-#define HCS_INDICATOR(p)	((p)&(1 << 16))	/* true: has port indicators */
-#define HCS_N_CC(p)		(((p)>>12)&0xf)	/* bits 15:12, #companion HCs */
-#define HCS_N_PCC(p)		(((p)>>8)&0xf)	/* bits 11:8, ports per CC */
-#define HCS_PORTROUTED(p)	((p)&(1 << 7))	/* true: port routing */
-#define HCS_PPC(p)		((p)&(1 << 4))	/* true: port power control */
-#define HCS_N_PORTS(p)		(((p)>>0)&0xf)	/* bits 3:0, ports on HC */
-
-	u32		hcc_params;      /* HCCPARAMS - offset 0x8 */
-#define HCC_EXT_CAPS(p)		(((p)>>8)&0xff)	/* for pci extended caps */
-#define HCC_ISOC_CACHE(p)       ((p)&(1 << 7))  /* true: can cache isoc frame */
-#define HCC_ISOC_THRES(p)       (((p)>>4)&0x7)  /* bits 6:4, uframes cached */
-#define HCC_CANPARK(p)		((p)&(1 << 2))  /* true: can park on async qh */
-#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1))  /* true: periodic_size changes*/
-#define HCC_64BIT_ADDR(p)       ((p)&(1))       /* true: can use 64-bit addr */
-	u8		portroute [8];	 /* nibbles for routing - offset 0xC */
-} __attribute__ ((packed));
-
-
-/* Section 2.3 Host Controller Operational Registers */
-struct ehci_regs {
-
-	/* USBCMD: offset 0x00 */
-	u32		command;
-/* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */
-#define CMD_PARK	(1<<11)		/* enable "park" on async qh */
-#define CMD_PARK_CNT(c)	(((c)>>8)&3)	/* how many transfers to park for */
-#define CMD_LRESET	(1<<7)		/* partial reset (no ports, etc) */
-#define CMD_IAAD	(1<<6)		/* "doorbell" interrupt async advance */
-#define CMD_ASE		(1<<5)		/* async schedule enable */
-#define CMD_PSE		(1<<4)		/* periodic schedule enable */
-/* 3:2 is periodic frame list size */
-#define CMD_RESET	(1<<1)		/* reset HC not bus */
-#define CMD_RUN		(1<<0)		/* start/stop HC */
-
-	/* USBSTS: offset 0x04 */
-	u32		status;
-#define STS_ASS		(1<<15)		/* Async Schedule Status */
-#define STS_PSS		(1<<14)		/* Periodic Schedule Status */
-#define STS_RECL	(1<<13)		/* Reclamation */
-#define STS_HALT	(1<<12)		/* Not running (any reason) */
-/* some bits reserved */
-	/* these STS_* flags are also intr_enable bits (USBINTR) */
-#define STS_IAA		(1<<5)		/* Interrupted on async advance */
-#define STS_FATAL	(1<<4)		/* such as some PCI access errors */
-#define STS_FLR		(1<<3)		/* frame list rolled over */
-#define STS_PCD		(1<<2)		/* port change detect */
-#define STS_ERR		(1<<1)		/* "error" completion (overflow, ...) */
-#define STS_INT		(1<<0)		/* "normal" completion (short, ...) */
-
-	/* USBINTR: offset 0x08 */
-	u32		intr_enable;
-
-	/* FRINDEX: offset 0x0C */
-	u32		frame_index;	/* current microframe number */
-	/* CTRLDSSEGMENT: offset 0x10 */
-	u32		segment;	/* address bits 63:32 if needed */
-	/* PERIODICLISTBASE: offset 0x14 */
-	u32		frame_list;	/* points to periodic list */
-	/* ASYNCLISTADDR: offset 0x18 */
-	u32		async_next;	/* address of next async queue head */
-
-	u32		reserved [9];
-
-	/* CONFIGFLAG: offset 0x40 */
-	u32		configured_flag;
-#define FLAG_CF		(1<<0)		/* true: we'll support "high speed" */
-
-	/* PORTSC: offset 0x44 */
-	u32		port_status [0];	/* up to N_PORTS */
-/* 31:23 reserved */
-#define PORT_WKOC_E	(1<<22)		/* wake on overcurrent (enable) */
-#define PORT_WKDISC_E	(1<<21)		/* wake on disconnect (enable) */
-#define PORT_WKCONN_E	(1<<20)		/* wake on connect (enable) */
-/* 19:16 for port testing */
-#define PORT_LED_OFF	(0<<14)
-#define PORT_LED_AMBER	(1<<14)
-#define PORT_LED_GREEN	(2<<14)
-#define PORT_LED_MASK	(3<<14)
-#define PORT_OWNER	(1<<13)		/* true: companion hc owns this port */
-#define PORT_POWER	(1<<12)		/* true: has power (see PPC) */
-#define PORT_USB11(x) (((x)&(3<<10))==(1<<10))	/* USB 1.1 device */
-/* 11:10 for detecting lowspeed devices (reset vs release ownership) */
-/* 9 reserved */
-#define PORT_RESET	(1<<8)		/* reset port */
-#define PORT_SUSPEND	(1<<7)		/* suspend port */
-#define PORT_RESUME	(1<<6)		/* resume it */
-#define PORT_OCC	(1<<5)		/* over current change */
-#define PORT_OC		(1<<4)		/* over current active */
-#define PORT_PEC	(1<<3)		/* port enable change */
-#define PORT_PE		(1<<2)		/* port enable */
-#define PORT_CSC	(1<<1)		/* connect status change */
-#define PORT_CONNECT	(1<<0)		/* device connected */
-#define PORT_RWC_BITS   (PORT_CSC | PORT_PEC | PORT_OCC)
-} __attribute__ ((packed));
-
-#define USBMODE		0x68		/* USB Device mode */
-#define USBMODE_SDIS	(1<<3)		/* Stream disable */
-#define USBMODE_BE	(1<<2)		/* BE/LE endianness select */
-#define USBMODE_CM_HC	(3<<0)		/* host controller mode */
-#define USBMODE_CM_IDLE	(0<<0)		/* idle state */
-
-/* Appendix C, Debug port ... intended for use with special "debug devices"
- * that can help if there's no serial console.  (nonstandard enumeration.)
- */
-struct ehci_dbg_port {
-	u32	control;
-#define DBGP_OWNER	(1<<30)
-#define DBGP_ENABLED	(1<<28)
-#define DBGP_DONE	(1<<16)
-#define DBGP_INUSE	(1<<10)
-#define DBGP_ERRCODE(x)	(((x)>>7)&0x07)
-#	define DBGP_ERR_BAD	1
-#	define DBGP_ERR_SIGNAL	2
-#define DBGP_ERROR	(1<<6)
-#define DBGP_GO		(1<<5)
-#define DBGP_OUT	(1<<4)
-#define DBGP_LEN(x)	(((x)>>0)&0x0f)
-	u32	pids;
-#define DBGP_PID_GET(x)		(((x)>>16)&0xff)
-#define DBGP_PID_SET(data,tok)	(((data)<<8)|(tok))
-	u32	data03;
-	u32	data47;
-	u32	address;
-#define DBGP_EPADDR(dev,ep)	(((dev)<<8)|(ep))
-} __attribute__ ((packed));
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
+
 #define	QTD_NEXT(ehci, dma)	cpu_to_hc32(ehci, (u32)dma)
 
 /*
include/linux/usb/ehci_def.h new file +160 -0

160 lines not on this page · raw message

author
#22 lore raw

PATCH 1/1 x86: usb debug port early console v4

In reply to Yinghai Lu

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

v2: fix checkpatch warning
v3: move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h
also add CONFIG_EARLY_PRINTK_DBGP to disable it by default
v4: address comments from Ingo, seperate ehci reg def moving to another patch
also add auto detect port that connect to debug device for Nvidia southbridge

---
 Documentation/kernel-parameters.txt |    3 
 arch/x86/Kconfig.debug              |   13 
 arch/x86/kernel/early_printk.c      |  764 +++++++++++++++++++++++++++++++++++-
 3 files changed, 776 insertions(+), 4 deletions(-)
Documentation/kernel-parameters.txt +2 -1
Index: linux-2.6/Documentation/kernel-parameters.txt
===================================================================
@@ -654,11 +654,12 @@ and is between 256 and 4096 characters.
 	earlyprintk=	[X86-32,X86-64,SH,BLACKFIN]
 			earlyprintk=vga
 			earlyprintk=serial[,ttySn[,baudrate]]
+			earlyprintk=dbgp
 
 			Append ",keep" to not disable it when the real console
 			takes over.
 
-			Only vga or serial at a time, not both.
+			Only vga or serial or usb debug port at a time.
 
 			Currently only ttyS0 and ttyS1 are supported.
 
arch/x86/kernel/early_printk.c +759 -3

822 lines not on this page · raw message

arch/x86/Kconfig.debug +13 -0
Index: linux-2.6/arch/x86/Kconfig.debug
===================================================================
@@ -43,6 +43,19 @@ config EARLY_PRINTK
 	  with klogd/syslogd or the X server. You should normally N here,
 	  unless you want to debug such a crash.
 
+config EARLY_PRINTK_DBGP
+	bool "Early printk via EHCI debug port"
+	default n
+	depends on EARLY_PRINTK
+	help
+	  Write kernel log output directly into the EHCI debug port.
+
+	  This is useful for kernel debugging when your machine crashes very
+	  early before the console code is initialized. For normal operation
+	  it is not recommended because it looks ugly and doesn't cooperate
+	  with klogd/syslogd or the X server. You should normally N here,
+	  unless you want to debug such a crash. You need usb debug device.
+
 config DEBUG_STACKOVERFLOW
 	bool "Check for stack overflows"
 	depends on DEBUG_KERNEL
Acked-by on v1 1/1
#15 lore raw

Re: [PATCH] usb: move ehci reg def

In reply to Yinghai Lu
Quoted 6 lines · Yinghai Lu

prepare x86: usb debug port early console

move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h

so long as the minor issue below is fixed:

drivers/usb/host/ehci.h timer_action (struct ehci_hcd *ehci, enu · line 217

Quoted 7 lines
 
	...
drivers/usb/host/ehci.h +2 -0
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
+

Only one blank line needed please. ;)

Quoted 3 lines

#define QTD_NEXT(ehci, dma) cpu_to_hc32(ehci, (u32)dma)

/*

author
#16 lore raw

Re: [PATCH] usb: move ehci reg def

Quoted 14 lines · David Brownell
Quoted 6 lines · Yinghai Lu

prepare x86: usb debug port early console

move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h

so long as the minor issue below is fixed:

Quoted 1 line
Quoted 8 lines

drivers/usb/host/ehci.h timer_action (struct ehci_hcd *ehci, enu · line 217

Quoted 6 lines
      ...
drivers/usb/host/ehci.h +2 -0
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
+

Only one blank line needed please. ;)

thanks.
Greg, Do i need to resend ?

YH

Applied
#23 lore raw

Re: [PATCH] x86: usb debug port early console v4

In reply to Yinghai Lu
Quoted 10 lines · Yinghai Lu

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

v2: fix checkpatch warning
v3: move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h
also add CONFIG_EARLY_PRINTK_DBGP to disable it by default
v4: address comments from Ingo, seperate ehci reg def moving to another patch
also add auto detect port that connect to debug device for Nvidia southbridge

applied to tip/x86/early-printk - thanks Yinghai.

Ingo

#17 lore raw

Re: [PATCH] usb: move ehci reg def

In reply to Yinghai Lu
Quoted 10 lines · Yinghai Lu
Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +2 -0
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
+

Only one blank line needed please. ;)

thanks.
Greg, Do i need to resend ?

i've fixed it up - see updated patch below.

Greg, could you please pull this change from the tip/usb-for-greg git tree:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git usb-for-greg

so that we can share the commit ID, without you having to carry unrelated x86 fixes? I'll merge this tree too into x86/early-printk.

Thanks,

Ingo

------------------>
Yinghai Lu (1):
usb: move ehci reg def

 drivers/usb/host/ehci.h      |  138 +------------------------------------
 include/linux/usb/ehci_def.h |  160 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 161 insertions(+), 137 deletions(-)
 create mode 100644 include/linux/usb/ehci_def.h
drivers/usb/host/ehci.h +1 -137
index 5799298..b697a13 100644
@@ -210,143 +210,7 @@ timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
 
 /*-------------------------------------------------------------------------*/
 
-/* EHCI register interface, corresponds to EHCI Revision 0.95 specification */
-
-/* Section 2.2 Host Controller Capability Registers */
-struct ehci_caps {
-	/* these fields are specified as 8 and 16 bit registers,
-	 * but some hosts can't perform 8 or 16 bit PCI accesses.
-	 */
-	u32		hc_capbase;
-#define HC_LENGTH(p)		(((p)>>00)&0x00ff)	/* bits 7:0 */
-#define HC_VERSION(p)		(((p)>>16)&0xffff)	/* bits 31:16 */
-	u32		hcs_params;     /* HCSPARAMS - offset 0x4 */
-#define HCS_DEBUG_PORT(p)	(((p)>>20)&0xf)	/* bits 23:20, debug port? */
-#define HCS_INDICATOR(p)	((p)&(1 << 16))	/* true: has port indicators */
-#define HCS_N_CC(p)		(((p)>>12)&0xf)	/* bits 15:12, #companion HCs */
-#define HCS_N_PCC(p)		(((p)>>8)&0xf)	/* bits 11:8, ports per CC */
-#define HCS_PORTROUTED(p)	((p)&(1 << 7))	/* true: port routing */
-#define HCS_PPC(p)		((p)&(1 << 4))	/* true: port power control */
-#define HCS_N_PORTS(p)		(((p)>>0)&0xf)	/* bits 3:0, ports on HC */
-
-	u32		hcc_params;      /* HCCPARAMS - offset 0x8 */
-#define HCC_EXT_CAPS(p)		(((p)>>8)&0xff)	/* for pci extended caps */
-#define HCC_ISOC_CACHE(p)       ((p)&(1 << 7))  /* true: can cache isoc frame */
-#define HCC_ISOC_THRES(p)       (((p)>>4)&0x7)  /* bits 6:4, uframes cached */
-#define HCC_CANPARK(p)		((p)&(1 << 2))  /* true: can park on async qh */
-#define HCC_PGM_FRAMELISTLEN(p) ((p)&(1 << 1))  /* true: periodic_size changes*/
-#define HCC_64BIT_ADDR(p)       ((p)&(1))       /* true: can use 64-bit addr */
-	u8		portroute [8];	 /* nibbles for routing - offset 0xC */
-} __attribute__ ((packed));
-
-
-/* Section 2.3 Host Controller Operational Registers */
-struct ehci_regs {
-
-	/* USBCMD: offset 0x00 */
-	u32		command;
-/* 23:16 is r/w intr rate, in microframes; default "8" == 1/msec */
-#define CMD_PARK	(1<<11)		/* enable "park" on async qh */
-#define CMD_PARK_CNT(c)	(((c)>>8)&3)	/* how many transfers to park for */
-#define CMD_LRESET	(1<<7)		/* partial reset (no ports, etc) */
-#define CMD_IAAD	(1<<6)		/* "doorbell" interrupt async advance */
-#define CMD_ASE		(1<<5)		/* async schedule enable */
-#define CMD_PSE		(1<<4)		/* periodic schedule enable */
-/* 3:2 is periodic frame list size */
-#define CMD_RESET	(1<<1)		/* reset HC not bus */
-#define CMD_RUN		(1<<0)		/* start/stop HC */
-
-	/* USBSTS: offset 0x04 */
-	u32		status;
-#define STS_ASS		(1<<15)		/* Async Schedule Status */
-#define STS_PSS		(1<<14)		/* Periodic Schedule Status */
-#define STS_RECL	(1<<13)		/* Reclamation */
-#define STS_HALT	(1<<12)		/* Not running (any reason) */
-/* some bits reserved */
-	/* these STS_* flags are also intr_enable bits (USBINTR) */
-#define STS_IAA		(1<<5)		/* Interrupted on async advance */
-#define STS_FATAL	(1<<4)		/* such as some PCI access errors */
-#define STS_FLR		(1<<3)		/* frame list rolled over */
-#define STS_PCD		(1<<2)		/* port change detect */
-#define STS_ERR		(1<<1)		/* "error" completion (overflow, ...) */
-#define STS_INT		(1<<0)		/* "normal" completion (short, ...) */
-
-	/* USBINTR: offset 0x08 */
-	u32		intr_enable;
-
-	/* FRINDEX: offset 0x0C */
-	u32		frame_index;	/* current microframe number */
-	/* CTRLDSSEGMENT: offset 0x10 */
-	u32		segment;	/* address bits 63:32 if needed */
-	/* PERIODICLISTBASE: offset 0x14 */
-	u32		frame_list;	/* points to periodic list */
-	/* ASYNCLISTADDR: offset 0x18 */
-	u32		async_next;	/* address of next async queue head */
-
-	u32		reserved [9];
-
-	/* CONFIGFLAG: offset 0x40 */
-	u32		configured_flag;
-#define FLAG_CF		(1<<0)		/* true: we'll support "high speed" */
-
-	/* PORTSC: offset 0x44 */
-	u32		port_status [0];	/* up to N_PORTS */
-/* 31:23 reserved */
-#define PORT_WKOC_E	(1<<22)		/* wake on overcurrent (enable) */
-#define PORT_WKDISC_E	(1<<21)		/* wake on disconnect (enable) */
-#define PORT_WKCONN_E	(1<<20)		/* wake on connect (enable) */
-/* 19:16 for port testing */
-#define PORT_LED_OFF	(0<<14)
-#define PORT_LED_AMBER	(1<<14)
-#define PORT_LED_GREEN	(2<<14)
-#define PORT_LED_MASK	(3<<14)
-#define PORT_OWNER	(1<<13)		/* true: companion hc owns this port */
-#define PORT_POWER	(1<<12)		/* true: has power (see PPC) */
-#define PORT_USB11(x) (((x)&(3<<10))==(1<<10))	/* USB 1.1 device */
-/* 11:10 for detecting lowspeed devices (reset vs release ownership) */
-/* 9 reserved */
-#define PORT_RESET	(1<<8)		/* reset port */
-#define PORT_SUSPEND	(1<<7)		/* suspend port */
-#define PORT_RESUME	(1<<6)		/* resume it */
-#define PORT_OCC	(1<<5)		/* over current change */
-#define PORT_OC		(1<<4)		/* over current active */
-#define PORT_PEC	(1<<3)		/* port enable change */
-#define PORT_PE		(1<<2)		/* port enable */
-#define PORT_CSC	(1<<1)		/* connect status change */
-#define PORT_CONNECT	(1<<0)		/* device connected */
-#define PORT_RWC_BITS   (PORT_CSC | PORT_PEC | PORT_OCC)
-} __attribute__ ((packed));
-
-#define USBMODE		0x68		/* USB Device mode */
-#define USBMODE_SDIS	(1<<3)		/* Stream disable */
-#define USBMODE_BE	(1<<2)		/* BE/LE endianness select */
-#define USBMODE_CM_HC	(3<<0)		/* host controller mode */
-#define USBMODE_CM_IDLE	(0<<0)		/* idle state */
-
-/* Appendix C, Debug port ... intended for use with special "debug devices"
- * that can help if there's no serial console.  (nonstandard enumeration.)
- */
-struct ehci_dbg_port {
-	u32	control;
-#define DBGP_OWNER	(1<<30)
-#define DBGP_ENABLED	(1<<28)
-#define DBGP_DONE	(1<<16)
-#define DBGP_INUSE	(1<<10)
-#define DBGP_ERRCODE(x)	(((x)>>7)&0x07)
-#	define DBGP_ERR_BAD	1
-#	define DBGP_ERR_SIGNAL	2
-#define DBGP_ERROR	(1<<6)
-#define DBGP_GO		(1<<5)
-#define DBGP_OUT	(1<<4)
-#define DBGP_LEN(x)	(((x)>>0)&0x0f)
-	u32	pids;
-#define DBGP_PID_GET(x)		(((x)>>16)&0xff)
-#define DBGP_PID_SET(data,tok)	(((data)<<8)|(tok))
-	u32	data03;
-	u32	data47;
-	u32	address;
-#define DBGP_EPADDR(dev,ep)	(((dev)<<8)|(ep))
-} __attribute__ ((packed));
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
include/linux/usb/ehci_def.h new file +160 -0

160 lines not on this page · raw message

#24 lore raw

Re: [PATCH] x86: usb debug port early console v4

In reply to Ingo Molnar
Quoted 9 lines · Ingo Molnar
Quoted 9 lines

based on work from Eric, and add some timeout so don't dead loop when debug device is not installed

v2: fix checkpatch warning
v3: move ehci struct def to linux/usrb/ehci_def.h from host/ehci.h
also add CONFIG_EARLY_PRINTK_DBGP to disable it by default
v4: address comments from Ingo, seperate ehci reg def moving to another patch
also add auto detect port that connect to debug device for Nvidia southbridge

Quoted 3 lines
Quoted 1 line

applied to tip/x86/early-printk - thanks Yinghai.

small build fix below.

Ingo

------------>

Quoted 1 line

From 9749986a878e91182ff027ff0010ab8e3211031a Mon Sep 17 00:00:00 2001

From: Ingo Molnar <[email protected]>
Date: Sat, 26 Jul 2008 17:28:11 +0200
Subject: [PATCH] x86: usb debug port early console, fix

fix:

arch/x86/kernel/built-in.o: In function `nvidia_set_debug_port':
early_printk.c:(.text+0xf8b1): undefined reference to read_pci_config' early_printk.c:(.text+0xf8dc): undefined reference to write_pci_config' arch/x86/kernel/built-in.o: In function `setup_early_printk':
early_printk.c:(.init.text+0x5487): undefined reference to early_pci_allowed' early_printk.c:(.init.text+0x54cb): undefined reference to read_pci_config' early_printk.c:(.init.text+0x54ec): undefined reference to `read_pci_config_16' [...]

---
 arch/x86/Kconfig.debug |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/Kconfig.debug +1 -1
index 93422d2..2a3dfbd 100644
@@ -46,7 +46,7 @@ config EARLY_PRINTK
 config EARLY_PRINTK_DBGP
 	bool "Early printk via EHCI debug port"
 	default n
-	depends on EARLY_PRINTK
+	depends on EARLY_PRINTK && PCI
 	help
 	  Write kernel log output directly into the EHCI debug port.
 
#18 lore raw

Re: [PATCH] usb: move ehci reg def

In reply to Ingo Molnar
Quoted 16 lines · Ingo Molnar
Quoted 10 lines · Yinghai Lu
Quoted 7 lines

drivers/usb/host/ehci.h timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)

Quoted 5 lines
drivers/usb/host/ehci.h +2 -0
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
+

Only one blank line needed please. ;)

thanks.
Greg, Do i need to resend ?

i've fixed it up - see updated patch below.

Quoted 7 lines

Greg, could you please pull this change from the tip/usb-for-greg git tree:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git usb-for-greg

so that we can share the commit ID, without you having to carry unrelated x86 fixes? I'll merge this tree too into x86/early-printk.

I only use git for sending stuff to Linus, so that will not really work.

I have no objection for you keeping this in your tree, as that probably makes it easier.

thanks,

greg k-h

#19 lore raw

Re: [PATCH] usb: move ehci reg def

Quoted 20 lines · Greg KH
Quoted 19 lines · Ingo Molnar
Quoted 10 lines · Yinghai Lu
Quoted 7 lines

drivers/usb/host/ehci.h timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)

Quoted 5 lines
drivers/usb/host/ehci.h +2 -0
+#include <linux/usb/ehci_def.h>
 
 /*-------------------------------------------------------------------------*/
 
+

Only one blank line needed please. ;)

thanks.
Greg, Do i need to resend ?

i've fixed it up - see updated patch below.

Greg, could you please pull this change from the tip/usb-for-greg git tree:

Quoted 7 lines
Quoted 4 lines

git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip.git usb-for-greg

so that we can share the commit ID, without you having to carry unrelated x86 fixes? I'll merge this tree too into x86/early-printk.

I only use git for sending stuff to Linus, so that will not really work.

oh, didnt know that.

Quoted 2 lines

I have no objection for you keeping this in your tree, as that probably makes it easier.

okay - i just wanted to keep your options maximally flexible, it's code you maintain, we are just trespassing :)

the commit will eventually show up in linux-next via tip/auto-x86-next.

Given that it's all pretty uncontroversial, we might as well send it upstream after -rc1 - this is an isolated debug feature. (and a much desired one to begin with. We could even get printks out of terminally hung suspend/resume laptops this way i think!)

Any objections to that course of action?

Ingo

#20 lore raw

Re: [PATCH] usb: move ehci reg def

Quoted 7 lines · Ingo Molnar
Quoted 2 lines · Greg KH

I have no objection for you keeping this in your tree, as that probably makes it easier.

okay - i just wanted to keep your options maximally flexible, it's code you maintain, we are just trespassing :)

Quoted 8 lines

the commit will eventually show up in linux-next via tip/auto-x86-next.

Given that it's all pretty uncontroversial, we might as well send it upstream after -rc1 - this is an isolated debug feature. (and a much desired one to begin with. We could even get printks out of terminally hung suspend/resume laptops this way i think!)

Any objections to that course of action?

No objections from me at all, I would like to see this code finaly get moved into the tree.

thanks for doing this.

greg k-h

#21 lore raw

Re: [PATCH] usb: move ehci reg def

Quoted 2 lines · Greg KH

No objections from me at all, I would like to see this code finaly get moved into the tree.

Yes ... with serial ports increasingly scarce, getting some use out of this USB debug widget would be nice!

- dave