usb: early: add support for early printk through USB3 debug port
Subsystems (5)
v4 cover usb: early: add support for early printk through USB3 debug port
Hi,
This patch series adds support for early printk through USB3 debug port. USB3 debug port is described in xHCI specification as an optional extended capability.
The first patch adds a file in sysfs, through which users can check whether the debug capability is supported by a specific host controller, and the hardware state.
Patch 2 to 10 add the driver for xHCI debug capability. It interfaces with the register set and provides the required ops (read/write/control) to upper layers. Early printk is one consumer of these ops. The hooks for early printk are introduced in patch 9. This design is similar to what we have done in drivers/usb/early/ehci-dbgp.c.
Patch 11 is a minor change to usb_debug module. This change is required to bind usb_debug with the USB3 debug device.
Patch 12 is the design document and user guide.
Change log:v1->v2:
(1) Patch 1 re-implemented. "debugfs" has been replaced with sysfs. The scope reduced from all extended capabilities to debug port specific.
(2) Patch 11 changed. Removed unnecessary .bulk_out_size setting.
v2->v3:
(1) Patch 11 got acked by Johan Hovold.
v3->v4:
(1) Patch 1 code refactored by using xhci_find_ext_cap_by_id() helper.
(2) Patch 3 "bus hung state" changed to "port hung state" in commit message.
(3) Patch 12 added verified platform information.
Lu Baolu (12):
usb: xhci: add sysfs file for xHCI debug port
x86: fixmap: add permanent fixmap for xhci debug port
usb: xhci: dbc: probe and setup xhci debug capability
usb: xhci: dbc: add support for Intel xHCI dbc quirk
usb: xhci: dbc: add debug buffer
usb: xhci: dbc: add bulk out and bulk in interfaces
usb: xhci: dbc: handle dbc-configured exit
usb: xhci: dbc: handle endpoint stall
x86: early_printk: add USB3 debug port earlyprintk support
usb: xhci: dbc: add handshake between debug target and host
usb: serial: usb_debug: add support for dbc debug device
usb: doc: add document for xHCI DbC driver
.../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 23 + Documentation/kernel-parameters.txt | 1 + Documentation/usb/xhci-dbc.txt | 325 +++++ MAINTAINERS | 8 + arch/x86/Kconfig.debug | 12 + arch/x86/include/asm/fixmap.h | 4 + arch/x86/kernel/early_printk.c | 5 + drivers/usb/early/Makefile | 1 + drivers/usb/early/xhci-dbc.c | 1407 ++++++++++++++++++++ drivers/usb/host/Makefile | 2 +- drivers/usb/host/xhci-ext-caps.h | 14 +- drivers/usb/host/xhci-sysfs.c | 80 ++ drivers/usb/host/xhci.c | 4 + drivers/usb/host/xhci.h | 4 + drivers/usb/serial/usb_debug.c | 28 +- include/linux/usb/xhci-dbc.h | 224 ++++ 16 files changed, 2137 insertions(+), 5 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd create mode 100644 Documentation/usb/xhci-dbc.txt create mode 100644 drivers/usb/early/xhci-dbc.c create mode 100644 drivers/usb/host/xhci-sysfs.c create mode 100644 include/linux/usb/xhci-dbc.h
Thanks,
-Baolu
Signature · 1 line
2.1.4
PATCH v4 1/12 usb: xhci: add sysfs file for xHCI debug port
This patch adds a sysfs file for users to check 1) whether the debug capability is implemented by hardware; 2) if supported, which state does it stay at.
With a host that supports debug port, a file named "debug_port_state" will be created under the device sysfs directory. Reading this file will show users the state (disabled, enabled or configured) of the debug port.
With a host that does NOT support debug port, "debug_port_state" file won't be created.
--- .../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 23 +++++++ drivers/usb/host/Makefile | 2 +- drivers/usb/host/xhci-ext-caps.h | 14 +++- drivers/usb/host/xhci-sysfs.c | 80 ++++++++++++++++++++++ drivers/usb/host/xhci.c | 4 ++ drivers/usb/host/xhci.h | 4 ++ 6 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd create mode 100644 drivers/usb/host/xhci-sysfs.c
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd new file +23 -0
@@ -0,0 +1,23 @@ +What: /sys/bus/pci/drivers/xhci_hcd/.../debug_port_state +Date: November 2015 +KernelVersion: 4.3.0 +Contact: Lu Baolu <[email protected]> +Description: + This file is designed for users to check the state of a + USB3 debug port. On a machine which supports USB3 debug + port, this file will be created. Reading this file will + show the state (disabled, enabled or configured) of the + debug port. On a machine that doesn't support USB3 debug + port, this file doesn't exist. + + The state of a debug port could be: + 1) disabled: The debug port is not enabled and the root + port has been switched to xHCI host as a normal + root port. + 2) enabled: The debug port is enabled. The debug port + has been assigned to debug capability. The debug + capability is able to handle the control requests + defined in USB3 spec. + 3) configured: The debug port has been enumerated by the + debug host as a debug device. The debug port is + in use now.
drivers/usb/host/Makefile +1 -1
@@ -12,7 +12,7 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o xhci-hcd-y := xhci.o xhci-mem.o xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o -xhci-hcd-y += xhci-trace.o +xhci-hcd-y += xhci-trace.o xhci-sysfs.o xhci-plat-hcd-y := xhci-plat.o ifneq ($(CONFIG_USB_XHCI_MVEBU), )
drivers/usb/host/xhci-ext-caps.h +13 -1
@@ -49,8 +49,15 @@#define XHCI_EXT_CAPS_PM 3#define XHCI_EXT_CAPS_VIRT 4#define XHCI_EXT_CAPS_ROUTE 5 -/* IDs 6-9 reserved */ +#define XHCI_EXT_CAPS_LOCALMEM 6 +/* IDs 7-9 reserved */ #define XHCI_EXT_CAPS_DEBUG 10 +/* IDs 192-255 vendor specific */ +#define XHCI_EXT_CAPS_VEN_START 192 +#define XHCI_EXT_CAPS_VEN_END 255 +#define XHCI_EXT_CAPS_VENDOR (p) (((p) >= XHCI_EXT_CAPS_VEN_START) && \ + ((p) <= XHCI_EXT_CAPS_VEN_END)) +#define XHCI_EXT_MAX_CAPID XHCI_EXT_CAPS_VEN_END/* USB Legacy Support Capability - section 7.1.1 */ #define XHCI_HC_BIOS_OWNED (1 << 16)#define XHCI_HC_OS_OWNED (1 << 24)
@@ -73,6 +80,11 @@#define XHCI_HLC (1 << 19)#define XHCI_BLC (1 << 20) +/* Debug capability - section 7.6.8 */ +#define XHCI_DBC_DCCTRL 0x20 +#define XHCI_DBC_DCCTRL_DCR (1 << 0) +#define XHCI_DBC_DCCTRL_DCE (1 << 31) +/* command register values to disable interrupts and halt the HC */ /* start/stop HC execution - do not write unless HC is halted*/ #define XHCI_CMD_RUN (1 << 0)
drivers/usb/host/xhci-sysfs.c new file +80 -0
80 lines not on this page · raw message
drivers/usb/host/xhci.c +4 -0
@@ -651,6 +651,9 @@ int xhci_run(struct usb_hcd *hcd) }xhci_dbg_trace (xhci, trace_xhci_dbg_init,"Finished xhci_run for USB2 roothub" ); + +xhci_sysfs_create_files (xhci); +return 0 ; }EXPORT_SYMBOL_GPL (xhci_run);
@@ -684,6 +687,7 @@ void xhci_stop(struct usb_hcd *hcd)xhci_reset (xhci);spin_unlock_irq (&xhci->lock); +xhci_sysfs_remove_files (xhci);xhci_cleanup_msix (xhci);/* Deleting Compliance Mode Recovery Timer */
drivers/usb/host/xhci.h +4 -0
@@ -1949,4 +1949,8 @@ struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_container_struct xhci_slot_ctx *xhci_get_slot_ctx (struct xhci_hcd *xhci,struct xhci_container_ctx *ctx);struct xhci_ep_ctx *xhci_get_ep_ctx (struct xhci_hcd *xhci,struct xhci_container_ctx *ctx,unsigned int ep_index); +/* xHCI sysfs interfaces */ +int xhci_sysfs_create_files (struct xhci_hcd *xhci); +void xhci_sysfs_remove_files (struct xhci_hcd *xhci); +#endif /* __LINUX_XHCI_HCD_H */
Signature · 1 line
2.1.4
Re: [PATCH v4 01/12] usb: xhci: add sysfs file for xHCI debug port
Quoted 43 lines · Lu Baolu
This patch adds a sysfs file for users to check 1) whether the debug capability is implemented by hardware; 2) if supported, which state does it stay at.
With a host that supports debug port, a file named "
debug_port_state" will be created under the device sysfs directory. Reading this file will show users the state (disabled, enabled or configured) of the debug port.With a host that does NOT support debug port, "
debug_port_state" file won't be created.Signed-off-by Lu Baolu <[email protected]>--- .../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 23 +++++++ drivers/usb/host/Makefile | 2 +- drivers/usb/host/xhci-ext-caps.h | 14 +++- drivers/usb/host/xhci-sysfs.c | 80 ++++++++++++++++++++++ drivers/usb/host/xhci.c | 4 ++ drivers/usb/host/xhci.h | 4 ++ 6 files changed, 125 insertions(+), 2 deletions(-)create mode 100644
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcdcreate mode 100644drivers/usb/host/xhci-sysfs.cDocumentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd new file +13
-0@@ -0,0 +1,23 @@ +What: /sys/bus/pci/drivers/xhci_hcd/.../debug_port_state +Date: November 2015 +KernelVersion: 4.3.0 +Contact: Lu Baolu <[email protected]> +Description: + This file is designed for users to check the state of a + USB3 debug port. On a machine which supports USB3 debug + port, this file will be created. Reading this file will + show the state (disabled, enabled or configured) of the + debug port. On a machine that doesn't support USB3 debug + port, this file doesn't exist. + + The state of a debug port could be:
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd line 23
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd new file +10
-0+ 1) disabled: The debug port is not enabled and the root + port has been switched to xHCI host as a normal + root port. + 2) enabled: The debug port is enabled. The debug port + has been assigned to debug capability. The debug + capability is able to handle the control requests + defined in USB3 spec. + 3) configured: The debug port has been enumerated by the + debug host as a debug device. The debug port is + in use now.
How much will this sysfs file be used, It looks more like debugging info needed while developing xhci debug port capability.
Would it be enough to add something like "supports DbC" in one of the dev_info() lines at xhci driver load if capability is supported?
This sysfs file will only be visible after xhci is loaded.
I understood that we would like to use the debug port capability even if xhci driver is not used, or then for earlyprintk before xhci is loaded.
Quoted 18 lines
drivers/usb/host/Makefile +1
-1@@ -12,7 +12,7 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o xhci-hcd-y := xhci.o xhci-mem.o xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o -xhci-hcd-y += xhci-trace.o +xhci-hcd-y += xhci-trace.o xhci-sysfs.o xhci-plat-hcd-y := xhci-plat.o ifneq ($(CONFIG_USB_XHCI_MVEBU), )drivers/usb/host/xhci-ext-caps.h +0
-0
drivers/usb/host/xhci-ext-caps.h line 57
Quoted 10 lines
drivers/usb/host/xhci-ext-caps.h +5
-1@@ -49,8 +49,15 @@#define XHCI_EXT_CAPS_PM 3#define XHCI_EXT_CAPS_VIRT 4#define XHCI_EXT_CAPS_ROUTE 5 -/* IDs 6-9 reserved */ +#define XHCI_EXT_CAPS_LOCALMEM 6 +/* IDs 7-9 reserved */ #define XHCI_EXT_CAPS_DEBUG 10 +/* IDs 192-255 vendor specific */ +#define XHCI_EXT_CAPS_VEN_START 192 +#define XHCI_EXT_CAPS_VEN_END 255
The CAPS_VEN_END is probably not needed,
all capabilities end at 255 (8 bit)
Perhaps just use the EXT_MAX_CAPID defined later
Quoted 47 lines
drivers/usb/host/xhci-ext-caps.h +8
-0+#define XHCI_EXT_CAPS_VENDOR (p) (((p) >= XHCI_EXT_CAPS_VEN_START) && \ + ((p) <= XHCI_EXT_CAPS_VEN_END)) +#define XHCI_EXT_MAX_CAPID XHCI_EXT_CAPS_VEN_END/* USB Legacy Support Capability - section 7.1.1 */ #define XHCI_HC_BIOS_OWNED (1 << 16)#define XHCI_HC_OS_OWNED (1 << 24)@@ -73,6 +80,11 @@#define XHCI_HLC (1 << 19)#define XHCI_BLC (1 << 20) +/* Debug capability - section 7.6.8 */ +#define XHCI_DBC_DCCTRL 0x20 +#define XHCI_DBC_DCCTRL_DCR (1 << 0) +#define XHCI_DBC_DCCTRL_DCE (1 << 31) +/* command register values to disable interrupts and halt the HC */ /* start/stop HC execution - do not write unless HC is halted*/ #define XHCI_CMD_RUN (1 << 0)drivers/usb/host/xhci-sysfs.c new file +23
-0@@ -0,0 +1,80 @@ +/* +* sysfs interface for xHCI host controller driver +* +* Copyright (C) 2015 Intel Corp. +* +* Author: Lu Baolu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#include <linux/kernel.h> + +#include "xhci.h" + +/* +* Return the register offset of a extended capability specified +* by @cap_id. Return 0 if @cap_id capability is not supported or +* in error cases. +*/ +static int get_extended_capability_offset (struct xhci_hcd *xhci, +int cap_id) +{
drivers/usb/host/xhci-sysfs.c line 33
Quoted 10 lines
drivers/usb/host/xhci-sysfs.c new file +10
-0+int offset; +void __iomem *base = (void __iomem *) xhci->cap_regs; +struct usb_hcd *hcd =xhci_to_hcd (xhci); + + offset =xhci_find_next_cap_offset (base,XHCI_HCC_PARAMS_OFFSET ); +if (!HCD_HW_ACCESSIBLE (hcd) || !offset) +return 0 ; + +return xhci_find_ext_cap_by_id (base, offset, cap_id); +}
After looking at how we are parsing the extended capabilities in xhci-mem.c and pci-quirks.c I see that the current helpers are not that useful.
A new, generic one is needed.
I send a rework out shortly, this way we can avoid adding one more capability parsing helper for this case.
-Mathias
Re: [PATCH v4 01/12] usb: xhci: add sysfs file for xHCI debug port
Quoted 60 lines · Mathias Nyman
Quoted 45 lines · Lu Baolu
This patch adds a sysfs file for users to check 1) whether the debug capability is implemented by hardware; 2) if supported, which state does it stay at.
With a host that supports debug port, a file named "
debug_port_state" will be created under the device sysfs directory. Reading this file will show users the state (disabled, enabled or configured) of the debug port.With a host that does NOT support debug port, "
debug_port_state" file won't be created.Signed-off-by Lu Baolu <[email protected]>--- .../ABI/testing/sysfs-bus-pci-drivers-xhci_hcd | 23 +++++++ drivers/usb/host/Makefile | 2 +- drivers/usb/host/xhci-ext-caps.h | 14 +++- drivers/usb/host/xhci-sysfs.c | 80 ++++++++++++++++++++++ drivers/usb/host/xhci.c | 4 ++ drivers/usb/host/xhci.h | 4 ++ 6 files changed, 125 insertions(+), 2 deletions(-)create mode 100644
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd
create mode 100644drivers/usb/host/xhci-sysfs.cDocumentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd new file +13
-0@@ -0,0 +1,23 @@ +What: /sys/bus/pci/drivers/xhci_hcd/.../debug_port_state +Date: November 2015 +KernelVersion: 4.3.0 +Contact: Lu Baolu <[email protected]> +Description: + This file is designed for users to check the state of a + USB3 debug port. On a machine which supports USB3 debug + port, this file will be created. Reading this file will + show the state (disabled, enabled or configured) of the + debug port. On a machine that doesn't support USB3 debug + port, this file doesn't exist. + + The state of a debug port could be:Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd line 23
Quoted 10 lines
Documentation/ABI/testing/sysfs-bus-pci-drivers-xhci_hcd new file +10
-0+ 1) disabled: The debug port is not enabled and the root + port has been switched to xHCI host as a normal + root port. + 2) enabled: The debug port is enabled. The debug port + has been assigned to debug capability. The debug + capability is able to handle the control requests + defined in USB3 spec. + 3) configured: The debug port has been enumerated by the + debug host as a debug device. The debug port is + in use now.How much will this sysfs file be used, It looks more like debugging info needed while developing xhci debug port capability.
Quoted 6 lines
Would it be enough to add something like "supports DbC" in one of the
dev_info()lines at xhci driver load if capability is supported?This sysfs file will only be visible after xhci is loaded.
I understood that we would like to use the debug port capability even if xhci driver is not used, or then for earlyprintk before xhci is loaded.
One use case of this sysfs file is that user can check the DbC status when link disconnection happens during runtime. User then can recover the link with another sysfs file which I will implement later.
Some test and debug tools might use DbC as well. Graphic might be an example. The test applications might want to check the DbC status during runtime.
Quoted 34 lines
Quoted 20 lines
drivers/usb/host/Makefile +1
-1@@ -12,7 +12,7 @@ fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o xhci-hcd-y := xhci.o xhci-mem.o xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o -xhci-hcd-y += xhci-trace.o +xhci-hcd-y += xhci-trace.o xhci-sysfs.o xhci-plat-hcd-y := xhci-plat.o ifneq ($(CONFIG_USB_XHCI_MVEBU), )drivers/usb/host/xhci-ext-caps.h +0
-0drivers/usb/host/xhci-ext-caps.h line 57
Quoted 10 lines
drivers/usb/host/xhci-ext-caps.h +5
-1@@ -49,8 +49,15 @@#define XHCI_EXT_CAPS_PM 3#define XHCI_EXT_CAPS_VIRT 4#define XHCI_EXT_CAPS_ROUTE 5 -/* IDs 6-9 reserved */ +#define XHCI_EXT_CAPS_LOCALMEM 6 +/* IDs 7-9 reserved */ #define XHCI_EXT_CAPS_DEBUG 10 +/* IDs 192-255 vendor specific */ +#define XHCI_EXT_CAPS_VEN_START 192 +#define XHCI_EXT_CAPS_VEN_END 255The
CAPS_VEN_ENDis probably not needed,
all capabilities end at 255 (8 bit)
Quoted 1 line
Perhaps just use the
EXT_MAX_CAPIDdefined later
Yes. I forgot to remove it when refactoring the code.
Quoted 64 lines
Quoted 49 lines
drivers/usb/host/xhci-ext-caps.h +3
-0+#define XHCI_EXT_CAPS_VENDOR (p) (((p) >= XHCI_EXT_CAPS_VEN_START) && \ + ((p) <= XHCI_EXT_CAPS_VEN_END)) +#define XHCI_EXT_MAX_CAPID XHCI_EXT_CAPS_VEN_END/* USB Legacy Support Capability - section 7.1.1 */ #define XHCI_HC_BIOS_OWNED (1 << 16)#define XHCI_HC_OS_OWNED (1 << 24)drivers/usb/host/xhci-ext-caps.h +5
-0@@ -73,6 +80,11 @@#define XHCI_HLC (1 << 19)#define XHCI_BLC (1 << 20) +/* Debug capability - section 7.6.8 */ +#define XHCI_DBC_DCCTRL 0x20 +#define XHCI_DBC_DCCTRL_DCR (1 << 0) +#define XHCI_DBC_DCCTRL_DCE (1 << 31) +/* command register values to disable interrupts and halt the HC */ /* start/stop HC execution - do not write unless HC is halted*/ #define XHCI_CMD_RUN (1 << 0)drivers/usb/host/xhci-sysfs.c new file +23
-0@@ -0,0 +1,80 @@ +/* +* sysfs interface for xHCI host controller driver +* +* Copyright (C) 2015 Intel Corp. +* +* Author: Lu Baolu <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +#include <linux/kernel.h> + +#include "xhci.h" + +/* +* Return the register offset of a extended capability specified +* by @cap_id. Return 0 if @cap_id capability is not supported or +* in error cases. +*/ +static int get_extended_capability_offset (struct xhci_hcd *xhci, +int cap_id) +{drivers/usb/host/xhci-sysfs.c line 33
Quoted 10 lines
drivers/usb/host/xhci-sysfs.c new file +10
-0+int offset; +void __iomem *base = (void __iomem *) xhci->cap_regs; +struct usb_hcd *hcd =xhci_to_hcd (xhci); + + offset =xhci_find_next_cap_offset (base,XHCI_HCC_PARAMS_OFFSET ); +if (!HCD_HW_ACCESSIBLE (hcd) || !offset) +return 0 ; + +return xhci_find_ext_cap_by_id (base, offset, cap_id); +}After looking at how we are parsing the extended capabilities in
xhci-mem.candpci-quirks.cI see that the current helpers are not that useful.
A new, generic one is needed.
Quoted 2 lines
I send a rework out shortly, this way we can avoid adding one more capability parsing helper for this case.
Agree. Looking forward to the new patch.
Quoted 4 lines
-Mathias
Thanks,
Baolu
PATCH v4 2/12 x86: fixmap: add permanent fixmap for xhci debug port
In reply to Lu BaoluxHCI compatible USB3 host controller may provide debug capability which enables low-level system debug over USB. In order to probing this debug capability, Linux kernel needs to map and access the mmio of the host controller during early boot.
This patch adds permenent fixmap pages in fixed_addresses table for xHCI mmio access.
--- arch/x86/include/asm/fixmap.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/x86/include/asm/fixmap.h +4 -0
@@ -82,6 +82,10 @@ enum fixed_addresses {#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT FIX_OHCI1394_BASE,#endif +#ifdef CONFIG_EARLY_PRINTK_XDBC + FIX_XDBC_BASE, + FIX_XDBC_END = FIX_XDBC_BASE + 15, +#endif #ifdef CONFIG_X86_LOCAL_APIC FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */#endif
Signature · 1 line
2.1.4
PATCH v4 3/12 usb: xhci: dbc: probe and setup xhci debug capability
In reply to Lu BaoluxHCI debug capability (DbC) is an optional functionality provided by an xHCI host controller. Software learns this capability by walking through the extended capability list in mmio of the host.
This patch introduces the code to probe and initialize the debug capability hardware during early boot. With hardware initialization done, the debug target (system under debug which has DbC enabled) will present a debug device through the debug port. The debug device is fully compliant with the USB framework and provides the equivalent of a very high performance (USB3) full-duplex serial link between the debug host and target.
--- MAINTAINERS | 7 + arch/x86/Kconfig.debug | 12 + drivers/usb/early/Makefile | 1 + drivers/usb/early/xhci-dbc.c | 787 +++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/xhci-dbc.h | 187 ++++++++++ 5 files changed, 994 insertions(+) create mode 100644 drivers/usb/early/xhci-dbc.c create mode 100644 include/linux/usb/xhci-dbc.h
MAINTAINERS +7 -0
@@ -11250,6 +11250,13 @@ S: Supported F: drivers/usb/host/xhci* F: drivers/usb/host/pci-quirks* +USB XHCI DEBUG PORT +M: Lu Baolu <[email protected]> +L: [email protected] +S: Supported +F: drivers/usb/early/xhci-dbc.c +F: include/linux/usb/xhci-dbc.h + USB ZD1201 DRIVER L: [email protected] W: http://linux-lc100020.sourceforge.net
arch/x86/Kconfig.debug +12 -0
@@ -65,6 +65,18 @@ config EARLY_PRINTK_EFI This is useful for kernel debugging when your machine crashes very early before the console code is initialized. +config EARLY_PRINTK_XDBC + bool "Early printk via xHCI debug port" + depends on EARLY_PRINTK && PCI + ---help--- + Write kernel log output directly into the xHCI 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. + config X86_PTDUMP_CORE def_bool n
drivers/usb/early/Makefile +1 -0
@@ -3,3 +3,4 @@ # obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o +obj-$(CONFIG_EARLY_PRINTK_XDBC) += xhci-dbc.o
drivers/usb/early/xhci-dbc.c new file +787 -0
787 lines not on this page · raw message
include/linux/usb/xhci-dbc.h new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v4 4/12 usb: xhci: dbc: add support for Intel xHCI dbc quirk
In reply to Lu BaoluOn Intel platforms, if the debug target is connected with debug host, enabling DCE bit in command register leads to a port hung state. In the hung state, the host system will not see a port connected status bit set. Hence debug target fails to be probed.
The state could be resolved by performing a port reset to the debug port from the host xHCI. This patch introduces this work around.
--- drivers/usb/early/xhci-dbc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/xhci-dbc.h | 2 ++ 2 files changed, 54 insertions(+)
drivers/usb/early/xhci-dbc.c +52 -0
@@ -255,6 +255,8 @@ static void __iomem *xdbc_map_pci_mmio(u32 bus, xdbcp->bar = bar; xdbcp->xhci_base = base; xdbcp->xhci_length = sz64; + xdbcp->vendor =read_pci_config_16 (bus, dev, func,PCI_VENDOR_ID ); + xdbcp->device =read_pci_config_16 (bus, dev, func,PCI_DEVICE_ID );if (length) *length = sz64;
@@ -651,6 +653,52 @@ static int xdbc_mem_init(void)return 0 ; } +static void xdbc_reset_debug_port_callback (int cap_offset,void *data) +{ +u8 major; +u32 val, port_offset, port_count; +u32 cap_length; +void __iomem *ops_reg; +void __iomem *portsc; +int i; + + val =readl (xdbcp->xhci_base + cap_offset); + major = (u8 )XHCI_EXT_PORT_MAJOR (val); + +/* only reset super-speed port */ +if (major !=0x3 ) +return ; + + val =readl (xdbcp->xhci_base + cap_offset +8 ); + port_offset =XHCI_EXT_PORT_OFF (val); + port_count =XHCI_EXT_PORT_COUNT (val); +xdbc_trace ("Extcap Port offset %d count %d\n" , + port_offset, port_count); + + cap_length =readl (xdbcp->xhci_base) &0xff ; + ops_reg = xdbcp->xhci_base + cap_length; + + port_offset--; +for (i = port_offset; i < (port_offset + port_count); i++) { + portsc = ops_reg +0x400 + i *0x10 ; + val =readl (portsc); +/* reset the port if CCS bit is cleared */ +if (!(val &0x1 )) +writel (val | (1 <<4 ), portsc); + } +} + +static void xdbc_reset_debug_port (void ) +{ +xdbc_walk_excap (xdbcp->bus, + xdbcp->dev, + xdbcp->func, +XHCI_EXT_CAPS_PROTOCOL , + false, + xdbc_reset_debug_port_callback, +NULL ); +} +/* * xdbc_start: start DbC *
@@ -669,6 +717,10 @@ static int xdbc_start(void)return -ENODEV ; } +/* reset port to avoid bus hang */ +if (xdbcp->vendor ==PCI_VENDOR_ID_INTEL ) +xdbc_reset_debug_port (); +/* wait for port connection */ if (handshake (&xdbcp->xdbc_reg->portsc,PORTSC_CCS ,PORTSC_CCS ,5000000 ,100 ) <0 ) {
include/linux/usb/xhci-dbc.h +2 -0
@@ -128,6 +128,8 @@ struct xdbc_state {u32 dev;u32 func;u8 bar; +u16 vendor; +u16 device;void __iomem *xhci_base;size_t xhci_length;#define XDBC_PCI_MAX_BUSES 256
Signature · 1 line
2.1.4
PATCH v4 5/12 usb: xhci: dbc: add debug buffer
In reply to Lu Baolu"printk" is not suitable for dbc debugging especially when console is in usage. This patch adds a debug buffer in dbc driver and puts the debug messages in this local buffer. The debug buffer could be dumped whenever the console is not in use. This part of code will not be visible unless DBC_DEBUG is defined.
--- drivers/usb/early/xhci-dbc.c | 62 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-)
drivers/usb/early/xhci-dbc.c +60 -2
@@ -32,8 +32,64 @@ static struct xdbc_state xdbc_stat;static struct xdbc_state *xdbcp = &xdbc_stat;#ifdef DBC_DEBUG -/* place holder */ -#define xdbc_trace printk +#define XDBC_DEBUG_BUF_SIZE (PAGE_SIZE * 32) +#define MSG_MAX_LINE 128 +static char xdbc_debug_buf[XDBC_DEBUG_BUF_SIZE ]; +static void xdbc_trace (const char *fmt, ...) +{ +int i, size; +va_list args; +static int pos; +char temp_buf[MSG_MAX_LINE ]; + +if (pos >=XDBC_DEBUG_BUF_SIZE -1 ) +return ; + +memset (temp_buf,0 ,MSG_MAX_LINE ); +va_start (args, fmt); +vsnprintf (temp_buf,MSG_MAX_LINE -1 , fmt, args); +va_end (args); + + i =0 ; + size =strlen (temp_buf); +while (i < size) { + xdbc_debug_buf[pos] = temp_buf[i]; + pos++; + i++; + +if (pos >=XDBC_DEBUG_BUF_SIZE -1 ) +break ; + } +} + +static void xdbc_dump_debug_buffer (void ) +{ +int index =0 ; +int count =0 ; +char dump_buf[MSG_MAX_LINE ]; + +xdbc_trace ("The end of DbC trace buffer\n" ); +pr_notice ("DBC debug buffer:\n" ); +memset (dump_buf,0 ,MSG_MAX_LINE ); + +while (index <XDBC_DEBUG_BUF_SIZE ) { +if (!xdbc_debug_buf[index]) +break ; + +if (xdbc_debug_buf[index] =='\n' || + count >=MSG_MAX_LINE -1 ) { +pr_notice ("DBC: @%08x %s\n" , index, dump_buf); +memset (dump_buf,0 ,MSG_MAX_LINE ); + count =0 ; + }else { + dump_buf[count] = xdbc_debug_buf[index]; + count++; + } + + index++; + } +} +static void xdbc_dbg_dump_regs (char *str) {if (!xdbcp->xdbc_reg) {
@@ -165,6 +221,7 @@ static void xdbc_dbg_dump_data(char *str)#else static inline void xdbc_trace (const char *fmt, ...) { } +static inline void xdbc_dump_debug_buffer (void ) { }static inline void xdbc_dbg_dump_regs (char *str) { }static inline void xdbc_dbg_dump_data (char *str) { }#endif /* DBC_DEBUG */
@@ -832,6 +889,7 @@ int __init early_xdbc_init(char *s)pr_notice ("failed to setup xHCI DbC connection\n" ); xdbcp->xhci_base =NULL ; xdbcp->xdbc_reg =NULL ; +xdbc_dump_debug_buffer ();return ret; }
Signature · 1 line
2.1.4
PATCH v4 6/12 usb: xhci: dbc: add bulk out and bulk in interfaces
In reply to Lu BaoluThis patch adds interfaces for bulk out and bulk in ops. These interfaces could be used to implement early printk bootconsole or hook to various system debuggers.
--- drivers/usb/early/xhci-dbc.c | 373 +++++++++++++++++++++++++++++++++++++++++++ include/linux/usb/xhci-dbc.h | 30 ++++ 2 files changed, 403 insertions(+)
drivers/usb/early/xhci-dbc.c +373 -0
@@ -219,11 +219,21 @@ static void xdbc_dbg_dump_data(char *str)xdbc_dbg_dump_string ("String Descriptor:" ); } +static void xdbc_dbg_dump_trb (struct xdbc_trb *trb,char *str) +{ +xdbc_trace ("DBC trb: %s\n" , str); +xdbc_trace ("@%016llx %08x %08x %08x %08x\n" , (u64 )__pa (trb), +le32_to_cpu (trb->field[0 ]), +le32_to_cpu (trb->field[1 ]), +le32_to_cpu (trb->field[2 ]), +le32_to_cpu (trb->field[3 ])); +}#else static inline void xdbc_trace (const char *fmt, ...) { }static inline void xdbc_dump_debug_buffer (void ) { }static inline void xdbc_dbg_dump_regs (char *str) { }static inline void xdbc_dbg_dump_data (char *str) { } +static inline void xdbc_dbg_dump_trb (struct xdbc_trb *trb,char *str) { }#endif /* DBC_DEBUG */ /*
@@ -334,6 +344,7 @@ static void *xdbc_get_page(dma_addr_t *dma_addr,static char in_ring_page[PAGE_SIZE ]__aligned(PAGE_SIZE) ;static char out_ring_page[PAGE_SIZE ]__aligned(PAGE_SIZE) ;static char table_page[PAGE_SIZE ]__aligned(PAGE_SIZE) ; +static char bulk_buf_page[PAGE_SIZE ]__aligned(PAGE_SIZE) ;switch (type) {case XDBC_PAGE_EVENT :
@@ -348,6 +359,9 @@ static void *xdbc_get_page(dma_addr_t *dma_addr,case XDBC_PAGE_TABLE : virt = (void *)table_page;break ; +case XDBC_PAGE_BUFFER : + virt = (void *)bulk_buf_page; +break ;default :return NULL ; }
@@ -707,6 +721,12 @@ static int xdbc_mem_init(void) dev_info =cpu_to_le32 ((XDBC_DEVICE_REV <<16 ) |XDBC_PRODUCT_ID );writel (dev_info, &xdbcp->xdbc_reg->devinfo2); +/* get and store the transfer buffer */ + xdbcp->out_buf =xdbc_get_page (&xdbcp->out_dma, +XDBC_PAGE_BUFFER ); + xdbcp->in_buf = xdbcp->out_buf +XDBC_MAX_PACKET ; + xdbcp->in_dma = xdbcp->out_dma +XDBC_MAX_PACKET ; +return 0 ; }
@@ -802,6 +822,9 @@ static int xdbc_start(void)xdbc_trace ("root hub port number %d\n" ,DCST_DPN (status)); + xdbcp->in_ep_state =EP_RUNNING ; + xdbcp->out_ep_state =EP_RUNNING ; +xdbc_trace ("DbC is running now, control 0x%08x\n" ,readl (&xdbcp->xdbc_reg->control));
@@ -895,3 +918,353 @@ int __init early_xdbc_init(char *s)return 0 ; } + +static void xdbc_queue_trb (struct xdbc_ring *ring, +u32 field1,u32 field2,u32 field3,u32 field4) +{ +struct xdbc_trb *trb, *link_trb; + + trb = ring->enqueue; + trb->field[0 ] =cpu_to_le32 (field1); + trb->field[1 ] =cpu_to_le32 (field2); + trb->field[2 ] =cpu_to_le32 (field3); + trb->field[3 ] =cpu_to_le32 (field4); + +xdbc_dbg_dump_trb (trb,"enqueue trb" ); + + ++(ring->enqueue); +if (ring->enqueue >= &ring->segment->trbs[TRBS_PER_SEGMENT -1 ]) { + link_trb = ring->enqueue; +if (ring->cycle_state) + link_trb->field[3 ] |=cpu_to_le32 (TRB_CYCLE ); +else + link_trb->field[3 ] &=cpu_to_le32 (~TRB_CYCLE ); + + ring->enqueue = ring->segment->trbs; + ring->cycle_state ^=1 ; + } +} + +static void xdbc_ring_doorbell (int target) +{ +writel (DOOR_BELL_TARGET (target), &xdbcp->xdbc_reg->doorbell); +} + +static void xdbc_handle_port_status (struct xdbc_trb *evt_trb) +{ +u32 port_reg; + + port_reg =readl (&xdbcp->xdbc_reg->portsc); + +if (port_reg &PORTSC_CSC ) { +xdbc_trace ("%s: connect status change event\n" , __func__); +writel (port_reg |PORTSC_CSC , &xdbcp->xdbc_reg->portsc); + port_reg =readl (&xdbcp->xdbc_reg->portsc); + } + +if (port_reg &PORTSC_PRC ) { +xdbc_trace ("%s: port reset change event\n" , __func__); +writel (port_reg |PORTSC_PRC , &xdbcp->xdbc_reg->portsc); + port_reg =readl (&xdbcp->xdbc_reg->portsc); + } + +if (port_reg &PORTSC_PLC ) { +xdbc_trace ("%s: port link status change event\n" , __func__); +writel (port_reg |PORTSC_PLC , &xdbcp->xdbc_reg->portsc); + port_reg =readl (&xdbcp->xdbc_reg->portsc); + } + +if (port_reg &PORTSC_CEC ) { +xdbc_trace ("%s: config error change\n" , __func__); +writel (port_reg |PORTSC_CEC , &xdbcp->xdbc_reg->portsc); + port_reg =readl (&xdbcp->xdbc_reg->portsc); + } +} + +static void xdbc_handle_tx_event (struct xdbc_trb *evt_trb) +{ +u32 comp_code; +u32 tx_dma_high, tx_dma_low; +u64 in_dma, out_dma; +size_t remain_length; +int ep_id; + + tx_dma_low =le32_to_cpu (evt_trb->field[0 ]); + tx_dma_high =le32_to_cpu (evt_trb->field[1 ]); + comp_code =GET_COMP_CODE (le32_to_cpu (evt_trb->field[2 ])); + remain_length =EVENT_TRB_LEN (le32_to_cpu (evt_trb->field[2 ])); + ep_id =TRB_TO_EP_ID (le32_to_cpu (evt_trb->field[3 ])); + in_dma =__pa (xdbcp->in_pending); + out_dma =__pa (xdbcp->out_pending); + +/* +* Possible Completion Codes for DbC Transfer Event are Success, +* Stall Error, USB Transaction Error, Babble Detected Error, +* TRB Error, Short Packet, Undefined Error, Event Ring Full Error, +* and Vendor Defined Error. TRB error, undefined error and vendor +* defined error will result in HOT/HIT set and be handled the same +* way as Stall error. +*/ +switch (comp_code) { +case COMP_SUCCESS : + remain_length =0 ; +case COMP_SHORT_TX : +xdbc_trace ("%s: endpoint %d remains %d bytes\n" , __func__, + ep_id, remain_length); +break ; +case COMP_TRB_ERR : +case COMP_BABBLE : +case COMP_TX_ERR : +case COMP_STALL : +default : +xdbc_trace ("%s: endpoint %d halted\n" , __func__, ep_id); +if (ep_id ==XDBC_EPID_OUT ) + xdbcp->out_ep_state =EP_HALTED ; +if (ep_id ==XDBC_EPID_IN ) + xdbcp->in_ep_state =EP_HALTED ; + +break ; + } + +if (lower_32_bits (in_dma) == tx_dma_low && +upper_32_bits (in_dma) == tx_dma_high) { + xdbcp->in_complete = comp_code; + xdbcp->in_complete_length = + (remain_length > xdbcp->in_length) ? +0 : xdbcp->in_length - remain_length; + } + +if (lower_32_bits (out_dma) == tx_dma_low && +upper_32_bits (out_dma) == tx_dma_high) { + xdbcp->out_complete = comp_code; + xdbcp->out_complete_length = + (remain_length > xdbcp->out_length) ? +0 : xdbcp->out_length - remain_length; + } +} + +static void xdbc_handle_events (void ) +{ +struct xdbc_trb *evt_trb; +bool update_erdp = false; + + evt_trb = xdbcp->evt_ring.dequeue; +while ((le32_to_cpu (evt_trb->field[3 ]) &TRB_CYCLE ) == + xdbcp->evt_ring.cycle_state) { +/* +* Memory barrier to ensure software sees the trbs +* enqueued by hardware. +*/ +rmb (); + +xdbc_dbg_dump_trb (evt_trb,"event trb" ); + +/* FIXME: Handle more event types. */ +switch ((le32_to_cpu (evt_trb->field[3 ]) &TRB_TYPE_BITMASK )) { +case TRB_TYPE (TRB_PORT_STATUS ): +xdbc_handle_port_status (evt_trb); +break ; +case TRB_TYPE (TRB_TRANSFER ): +xdbc_handle_tx_event (evt_trb); +break ; +default : +break ; + } + +/* advance to the next trb */ + ++(xdbcp->evt_ring.dequeue); +if (xdbcp->evt_ring.dequeue == + &xdbcp->evt_seg.trbs[TRBS_PER_SEGMENT ]) { + xdbcp->evt_ring.dequeue = xdbcp->evt_seg.trbs; + xdbcp->evt_ring.cycle_state ^=1 ; + } + + evt_trb = xdbcp->evt_ring.dequeue; + update_erdp = true; + } + +/* update event ring dequeue pointer */ +if (update_erdp) +xdbc_write64 (__pa (xdbcp->evt_ring.dequeue), + &xdbcp->xdbc_reg->erdp); +} + +/* +* Check and dispatch events in event ring. It also checks status +* of hardware. This function will be called from multiple threads. +* An atomic lock is applied to protect the access of event ring. +*/ +static int xdbc_check_event (void ) +{ +/* event ring is under checking by other thread? */ +if (!test_bit (XDBC_ATOMIC_EVENT , &xdbcp->atomic_flags) && + !test_and_set_bit (XDBC_ATOMIC_EVENT , + &xdbcp->atomic_flags)) +return 0 ; + +xdbc_handle_events (); + +test_and_clear_bit (XDBC_ATOMIC_EVENT , &xdbcp->atomic_flags); + +return 0 ; +} + +#define BULK_IN_COMPLETED (p) ((xdbcp->in_pending == (p)) && \ + xdbcp->in_complete) +#define BULK_OUT_COMPLETED (p) ((xdbcp->out_pending == (p)) && \ + xdbcp->out_complete) + +/* +* Wait for a bulk-in or bulk-out transfer completion or timed out. +* Return count of the actually transferred bytes or error. +*/ +static int xdbc_wait_until_bulk_done (struct xdbc_trb *trb,int loops) +{ +int timeout =0 ; +bool read; + +if (trb != xdbcp->in_pending && + trb != xdbcp->out_pending) +return -EINVAL ; + + read = (trb == xdbcp->in_pending); + +do { +if (xdbc_check_event () <0 ) +break ; + +if (read &&BULK_IN_COMPLETED (trb)) { +if (xdbcp->in_ep_state ==EP_HALTED ) +return -EAGAIN ; +else +return xdbcp->in_complete_length; + } + +if (!read &&BULK_OUT_COMPLETED (trb)) { +if (xdbcp->out_ep_state ==EP_HALTED ) +return -EAGAIN ; +else +return xdbcp->out_complete_length; + } + +xdbc_udelay (10 ); + }while ((timeout++ < loops) || !loops); + +return -EIO ; +} + +static int xdbc_bulk_transfer (void *data,int size,int loops,bool read) +{ +u64 addr; +u32 length, control; +struct xdbc_trb *trb; +struct xdbc_ring *ring; +u32 cycle; +int ret; + +if (size >XDBC_MAX_PACKET ) { +xdbc_trace ("%s: bad parameter, size %d" , __func__, size); +return -EINVAL ; + } + + ring = (read ? &xdbcp->in_ring : &xdbcp->out_ring); + trb = ring->enqueue; + cycle = ring->cycle_state; + + length =TRB_LEN (size); + control =TRB_TYPE (TRB_NORMAL ) |TRB_IOC ; + +if (cycle) + control &=cpu_to_le32 (~TRB_CYCLE ); +else + control |=cpu_to_le32 (TRB_CYCLE ); + +if (read) { +memset (xdbcp->in_buf,0 ,XDBC_MAX_PACKET ); + addr = xdbcp->in_dma; + + xdbcp->in_pending = trb; + xdbcp->in_length = size; + xdbcp->in_complete =0 ; + xdbcp->in_complete_length =0 ; + }else { +memcpy (xdbcp->out_buf, data, size); + addr = xdbcp->out_dma; + + xdbcp->out_pending = trb; + xdbcp->out_length = size; + xdbcp->out_complete =0 ; + xdbcp->out_complete_length =0 ; + } + +xdbc_queue_trb (ring,lower_32_bits (addr), +upper_32_bits (addr), + length, control); + +/* +* Memory barrier to ensure hardware sees the trbs +* enqueued above. +*/ +wmb (); +if (cycle) + trb->field[3 ] |=cpu_to_le32 (cycle); +else + trb->field[3 ] &=cpu_to_le32 (~TRB_CYCLE ); + +xdbc_ring_doorbell (read ?IN_EP_DOORBELL :OUT_EP_DOORBELL ); + + ret =xdbc_wait_until_bulk_done (trb, loops); + +if (read) + xdbcp->in_pending =NULL ; +else + xdbcp->out_pending =NULL ; + +if (ret >0 ) { +if (read) +memcpy (data, xdbcp->in_buf, size); +else +memset (xdbcp->out_buf,0 ,XDBC_MAX_PACKET ); + }else { +xdbc_trace ("%s: bulk %s transfer results in error %d\n" , + __func__, read ?"in" :"out" , ret); + } + +return ret; +} + +int xdbc_bulk_read (void *data,int size,int loops) +{ +int ret; + +do { +if (!test_bit (XDBC_ATOMIC_BULKIN , &xdbcp->atomic_flags) && + !test_and_set_bit (XDBC_ATOMIC_BULKIN , + &xdbcp->atomic_flags)) +break ; + }while (1 ); + + ret =xdbc_bulk_transfer (data, size, loops, true); + +test_and_clear_bit (XDBC_ATOMIC_BULKIN , &xdbcp->atomic_flags); + +return ret; +} + +int xdbc_bulk_write (const char *bytes,int size) +{ +int ret; + +do { +if (!test_bit (XDBC_ATOMIC_BULKOUT , &xdbcp->atomic_flags) && + !test_and_set_bit (XDBC_ATOMIC_BULKOUT , + &xdbcp->atomic_flags)) +break ; + }while (1 ); + + ret =xdbc_bulk_transfer ((void *)bytes, size,XDBC_LOOPS , false); + +test_and_clear_bit (XDBC_ATOMIC_BULKOUT , &xdbcp->atomic_flags); + +return ret; +}
include/linux/usb/xhci-dbc.h +30 -0
@@ -120,8 +120,17 @@ enum xdbc_page_type { XDBC_PAGE_TXIN,XDBC_PAGE_TXOUT ,XDBC_PAGE_TABLE , + XDBC_PAGE_BUFFER, }; +enum xdbc_ep_state { +EP_DISABLED , +EP_RUNNING , +EP_HALTED , +}; +#define XDBC_EPID_OUT 2 +#define XDBC_EPID_IN 1 +struct xdbc_state {/* pci device info*/ u32 bus;
@@ -170,13 +179,34 @@ struct xdbc_state {/* bulk OUT endpoint */ struct xdbc_ring out_ring;struct xdbc_segment out_seg; +void *out_buf; +dma_addr_t out_dma; +struct xdbc_trb *out_pending;/* IN */ +size_t out_length;/* IN */ +u32 out_complete;/* OUT */ +size_t out_complete_length;/* OUT */ +enum xdbc_ep_state out_ep_state;/* bulk IN endpoint */ struct xdbc_ring in_ring;struct xdbc_segment in_seg; +void *in_buf; +dma_addr_t in_dma; +struct xdbc_trb *in_pending;/* IN */ +size_t in_length;/* IN */ +u32 in_complete;/* OUT */ +size_t in_complete_length;/* OUT */ +enum xdbc_ep_state in_ep_state; + +/* atomic flags */ +unsigned long atomic_flags; +#define XDBC_ATOMIC_BULKOUT 0 +#define XDBC_ATOMIC_BULKIN 1 +#define XDBC_ATOMIC_EVENT 2 };#define XDBC_MAX_PACKET 1024 +#define XDBC_LOOPS 1000/* door bell target */ #define OUT_EP_DOORBELL 0
Signature · 1 line
2.1.4
PATCH v4 7/12 usb: xhci: dbc: handle dbc-configured exit
In reply to Lu BaoluDbC might exit configured state in some cases (refer to 7.6.4.4 in xHCI spec 1.1). Software needs detect and clear this situation by clearing DCCTRL.DCR and wait until the DbC configured before read or write oprations.
--- drivers/usb/early/xhci-dbc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
drivers/usb/early/xhci-dbc.c +28 -0
@@ -1153,6 +1153,29 @@ static int xdbc_wait_until_bulk_done(struct xdbc_trb *trb, int loops)return -EIO ; } +static int xdbc_wait_until_dbc_configured (void ) +{ +int timeout =0 ; +u32 reg; + +/* Port exits configured state */ + reg =readl (&xdbcp->xdbc_reg->control); +if (!(reg &CTRL_DRC )) +return 0 ; + +/* clear run change bit (RW1C) */ +writel (reg |CTRL_DRC , &xdbcp->xdbc_reg->control); + +do { +if (readl (&xdbcp->xdbc_reg->control) &CTRL_DCR ) +return 0 ; + +xdbc_udelay (10 ); + }while (timeout++ <XDBC_LOOPS ); + +return -ETIMEDOUT ; +} +static int xdbc_bulk_transfer (void *data,int size,int loops,bool read) {u64 addr;
@@ -1167,6 +1190,11 @@ static int xdbc_bulk_transfer(void *data, int size, int loops, bool read)return -EINVAL ; } +if (xdbc_wait_until_dbc_configured ()) { +xdbc_trace ("%s: hardware not ready\n" , __func__); +return -EPERM ; + } + ring = (read ? &xdbcp->in_ring : &xdbcp->out_ring); trb = ring->enqueue; cycle = ring->cycle_state;
Signature · 1 line
2.1.4
PATCH v4 8/12 usb: xhci: dbc: handle endpoint stall
In reply to Lu BaoluIn case of endpoint stall, software is able to detect the situation by reading DCCTRL.HIT or DCCTRL.HOT bits. DbC follows the normal USB framework to handle endpoint stall. When software detects endpoint stall situation, it should wait until endpoint is recovered before read or write oprations.
--- drivers/usb/early/xhci-dbc.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
drivers/usb/early/xhci-dbc.c +36 -0
@@ -1176,6 +1176,37 @@ static int xdbc_wait_until_dbc_configured(void)return -ETIMEDOUT ; } +static int xdbc_wait_until_epstall_cleared (bool read) +{ +int timeout =0 ; + +if (read) { +do { +if (!(readl (&xdbcp->xdbc_reg->control) &CTRL_HIT )) { + xdbcp->in_ep_state =EP_RUNNING ; + +return 0 ; + } + + xdbcp->in_ep_state =EP_HALTED ; +xdbc_udelay (10 ); + }while (timeout++ <XDBC_LOOPS ); + }else { +do { +if (!(readl (&xdbcp->xdbc_reg->control) &CTRL_HOT )) { + xdbcp->out_ep_state =EP_RUNNING ; + +return 0 ; + } + + xdbcp->out_ep_state =EP_HALTED ; +xdbc_udelay (10 ); + }while (timeout++ <XDBC_LOOPS ); + } + +return -ETIMEDOUT ; +} +static int xdbc_bulk_transfer (void *data,int size,int loops,bool read) {u64 addr;
@@ -1195,6 +1226,11 @@ static int xdbc_bulk_transfer(void *data, int size, int loops, bool read)return -EPERM ; } +if (xdbc_wait_until_epstall_cleared (read)) { +xdbc_trace ("%s: endpoint not ready\n" , __func__); +return -EPERM ; + } + ring = (read ? &xdbcp->in_ring : &xdbcp->out_ring); trb = ring->enqueue; cycle = ring->cycle_state;
Signature · 1 line
2.1.4
PATCH v4 9/12 x86: early_printk: add USB3 debug port earlyprintk support
In reply to Lu BaoluAdd support for early printk by writing debug messages to the USB3 debug port. Users can use this type of early printk by specifying kernel parameter of "earlyprintk=xdbc". This gives users a chance of providing debug output.
--- Documentation/kernel-parameters.txt | 1 + arch/x86/kernel/early_printk.c | 5 +++++ drivers/usb/early/xhci-dbc.c | 43 +++++++++++++++++++++++++++++++++++++ include/linux/usb/xhci-dbc.h | 5 +++++ 4 files changed, 54 insertions(+)
Documentation/kernel-parameters.txt +1 -0
@@ -1049,6 +1049,7 @@ bytes respectively. Such letter suffixes can also be entirely omitted. earlyprintk=ttySn[,baudrate] earlyprintk=dbgp[debugController#] earlyprintk=pciserial,bus:device.function[,baudrate] + earlyprintk=xdbc[xhciController#] earlyprintk is useful when the kernel crashes before the normal console is initialized. It is not enabled by
arch/x86/kernel/early_printk.c +5 -0
@@ -17,6 +17,7 @@#include <asm/intel-mid.h> #include <asm/pgtable.h> #include <linux/usb/ehci_def.h> +#include <linux/usb/xhci-dbc.h> #include <linux/efi.h> #include <asm/efi.h> #include <asm/pci_x86.h>
@@ -373,6 +374,10 @@ static int __init setup_early_printk(char *buf)if (!strncmp (buf,"dbgp" ,4 ) && !early_dbgp_init (buf +4 ))early_console_register (&early_dbgp_console, keep);#endif +#ifdef CONFIG_EARLY_PRINTK_XDBC +if (!strncmp (buf,"xdbc" ,4 ) && !early_xdbc_init (buf +4 )) +early_console_register (&early_xdbc_console, keep); +#endif #ifdef CONFIG_HVC_XEN if (!strncmp (buf,"xen" ,3 ))early_console_register (&xenboot_console, keep);
drivers/usb/early/xhci-dbc.c +43 -0
52 lines not on this page · raw message
include/linux/usb/xhci-dbc.h +5 -0
@@ -216,4 +216,9 @@ struct xdbc_state {#define xdbc_read64 (regs) xhci_read_64(NULL, (regs))#define xdbc_write64 (val, regs) xhci_write_64(NULL, (val), (regs)) +#ifdef CONFIG_EARLY_PRINTK_XDBC +extern int early_xdbc_init (char *s); +extern struct console early_xdbc_console; +#endif /* CONFIG_EARLY_PRINTK_XDBC */ +#endif /* __LINUX_XHCI_DBC_H */
Signature · 1 line
2.1.4
PATCH v4 10/12 usb: xhci: dbc: add handshake between debug target and host
In reply to Lu BaoluAfter DbC setup, debug target needs to wait until tty driver and application (e.g. mincom) on debug taget start. Otherwise, out messages might be ignored.
This patch adds a ping/pong mechanism between debug target and host. Debug target will be waiting there until user presses 'Y' or 'y' in the tty application.
--- drivers/usb/early/xhci-dbc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/usb/early/xhci-dbc.c +27 -0
@@ -32,6 +32,9 @@static struct xdbc_state xdbc_stat;static struct xdbc_state *xdbcp = &xdbc_stat; +static int early_xdbc_read (struct console *con,char *str,unsigned n); +static void early_xdbc_write (struct console *con,const char *str,u32 n); +#ifdef DBC_DEBUG #define XDBC_DEBUG_BUF_SIZE (PAGE_SIZE * 32)#define MSG_MAX_LINE 128
@@ -873,8 +876,12 @@ int __init early_xdbc_init(char *s) {u32 bus =0 , dev =0 , func =0 ;unsigned long dbgp_num =0 ; +char *ping ="Press Y to continue...\n" ; +char pong[64 ]; +size_t size;u32 offset;int ret; +int retry =20 ;if (!early_pci_allowed ())return -EPERM ;
@@ -917,6 +924,21 @@ int __init early_xdbc_init(char *s)return ret; } +while (retry >0 ) { +early_xdbc_write (NULL , ping,strlen (ping)); + size =early_xdbc_read (NULL , pong,64 ); +if (size >0 ) { +xdbc_trace ("%s: pong message: %s\n" , __func__, pong); +if (pong[0 ] =='Y' || pong[0 ] =='y' ) +break ; + }else { +xdbc_trace ("%s: pong message error %d\n" , + __func__, size); + } + + retry--; + } +return 0 ; }
@@ -1338,6 +1360,11 @@ int xdbc_bulk_write(const char *bytes, int size)* Start a bulk-in or bulk-out transfer, wait until transfer completion * or error. Return the count of actually transferred bytes or error. */ +static int early_xdbc_read (struct console *con,char *str,unsigned n) +{ +return xdbc_bulk_read (str, n,0 ); +} +static void early_xdbc_write (struct console *con,const char *str,u32 n) {int chunk, ret;
Signature · 1 line
2.1.4
PATCH v4 11/12 usb: serial: usb_debug: add support for dbc debug device
In reply to Lu BaoluThis patch add dbc debug device support in usb_debug driver.
--- drivers/usb/serial/usb_debug.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-)
drivers/usb/serial/usb_debug.c +25 -3
@@ -32,7 +32,18 @@ static const struct usb_device_id id_table[] = { { USB_DEVICE(0x0525, 0x127a) }, { }, }; -MODULE_DEVICE_TABLE (usb, id_table); + +static const struct usb_device_id dbc_id_table[] = { + {USB_DEVICE (0x1d6b ,0x0004 ) }, + { }, +}; + +static const struct usb_device_id id_table_combined[] = { + {USB_DEVICE (0x0525 ,0x127a ) }, + {USB_DEVICE (0x1d6b ,0x0004 ) }, + { }, +}; +MODULE_DEVICE_TABLE (usb, id_table_combined);/* This HW really does not support a serial break, so one will be * emulated when ever the break state is set to true.
@@ -71,9 +82,20 @@ static struct usb_serial_driver debug_device = { .process_read_urb = usb_debug_process_read_urb, }; +static struct usb_serial_driver dbc_device = { + .driver = { + .owner =THIS_MODULE , + .name ="xhci_dbc" , + }, + .id_table = dbc_id_table, + .num_ports =1 , + .break_ctl = usb_debug_break_ctl, + .process_read_urb = usb_debug_process_read_urb, +}; +static struct usb_serial_driver *const serial_drivers[] = { - &debug_device,NULL + &debug_device, &dbc_device,NULL }; -module_usb_serial_driver (serial_drivers, id_table); +module_usb_serial_driver (serial_drivers, id_table_combined);MODULE_LICENSE ("GPL" );
Signature · 1 line
2.1.4
PATCH v4 12/12 usb: doc: add document for xHCI DbC driver
In reply to Lu BaoluAdd Documentation/usb/xhci-dbc.txt. This document includes development status and user guide for USB3 debug port.
--- Documentation/usb/xhci-dbc.txt | 325 +++++++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + drivers/usb/early/xhci-dbc.c | 3 + 3 files changed, 329 insertions(+) create mode 100644 Documentation/usb/xhci-dbc.txt
Documentation/usb/xhci-dbc.txt new file +325 -0
@@ -0,0 +1,325 @@ + xHCI debug capability driver + + Lu Baolu <[email protected]> + + Last-updated: September 2015 + + + Contents: + --------- + * What is xHCI DbC? + * Debug topologies + * Debug stacks + * Port Multiplexing + * Hardware initialization + * External reset + * Port reset + * Interrupt/DMA/Memory during early boot + * Endpoint STALL + * Debug device information + * How to use DbC early printk? + * Limitations + + What is xHCI DbC? + ----------------- + +The xHCI Debugging Capability defined in section 7.6 of xHCI spec 1.1 +provides an optional functionality that enables low-level system debug +over USB. It provides a means of connecting two systems where one system +is a Debug Host and the other a Debug Target (System Under Test). The +Debug Capability provides an interface that is completely independent +of the xHCI interface. A Debug Target enumerates as a USB debug device +to the Debug Host, allowing a Debug Host to access a Debug Target through +the standard USB software stack. + + Debug topologies + ---------------- + +Multiple Debug Targets may be attached to a single Debug Host. Debug +Targets may be connected to any downstream facing port below a Debug +Host (i.e. anywhere in the fabric, root port or external hub puts). +A Debug Target may only connect to a Debug Host through a Root Hub port +of the target. That means connection of a Debug Target to a Debug Host +through the ports of an external hub is not supported. + +Below is a typical connection between Debug Host and Debug target. Two +Debug targets are connected to a single Debug host. + + + ________________ ________________ + | Debug Host | | Debug Target | + |________________| |________________| + |xHC without DbC | | xHC with DbC | + |or DbC disabled | | enabled | + |________________| |________________| + |P1| |p2| |P1| |p2| + |__| |__| |__| |__| + | | | + | |_________________________| + |_ + | + _______|________ ________________ + | HUB | | Debug Target | + |________________| |________________| + | Superspeed hub | | xHC with DbC | + | | | enabled | + |________________| |________________| + |P1| |p2| |P1| |p2| + |__| |__| |__| |__| + | | + |_________________________| + + Debug stacks + ------------ + +Below is a software stack diagram of both Debug Host and Debug Target. + + ________________ ________________ + | Debug Host | | Debug Target | + |________________| |________________| + | debug App | | | + | | | system debug | + | usb_debug | | hooks | + | | | | + | usbcore | | | + | | |debug capability| + | xhci_hcd | | driver | + |________________| |________________| + |xHC without DbC | | xHC with DbC | + |or DbC disabled | | enabled | + |________________| |________________| + |P1| |p2| |P1| |p2| + |__| |__| |__| |__| + | | + |_________________________| + + + Port Multiplexing + ----------------- + +A debug port is always multiplexed with the first xHCI root hub port. +Whenever debug capability is supported and enabled, and the first root +hub port is detected to be connected to a downstream super-speed port +of a Debug Host, the root hub port is assigned to the debug capability +and operating in an upstream facing mode. Otherwise, all root hub ports +act as normal downstream facing ports. When the root port is assigned +to debug capability, it appears through the xHCI as a fully functional +root hub port that never sees a device attach. + + Hardware initialization + ----------------------- + +xHCI debug capability is initialized during early boot. "early_param" +micro provides one option. It also provides a global function so that +early code can call it to initialize the hardware. + +int __init early_xdbc_init(char *s) + +early_param("string", early_xdbc_init) + +Keep in mind that things such as interrupt, system memory, DMA memory, +PCI configure space access, etc., are all different from a normal device +driver. + +Software probes the debug capability and all its memory and register +interfaces by walking through the xHCI extended capability List. Debug +capability is implemented with the capability ID of 10. + +After a xHCI debug capability interface was detected, software could +initialize the hardware so that debug host can enumerate it as a debug +device. The USB debug device provided by xHC debug capacity experiences +three modes: disabled mode, enumeration mode and run mode. In each mode, +software and xHC itself should complete required steps to move it to the +next mode. Below diagram describes the evolution of each mode. + + __________ ___________ ___________ + | | | | | | + | | | | | | + | Disabled | DbC enable|Enumeration| DbC run | Run | + | mode |---------->| mode |---------->| mode | + | |flag 0 to 1| |flag 0 to 1| | + | | | | | | + | | | | | | + |__________| |___________| |___________| + +To change DbC mode from disabled to enumeration, software should +1) allocate and initialize all DbC memory data structures. All data +structures required by a DbC are defined in 7.6 of the spec 1.1; +2) initialize the registers. All registers required to be initialized +in disabled mode are defined in 7.6.4.1 of the spec 1.1. With data +structure and registers initialized, software can Set the debug +capability enable (DCE) bit to 1 in the Debug Capability Control +Register (DCCTRL) and DbC enters enumeration mode as soon as this +bit is set. + +DbC hardware is responsible to change DbC mode from enumerate to run. +As soon as DbC enters enumeration mode, DbC appears as a normal USB +device which can be enumerated by debug host. Hence, DbC hardware +should support a default control endpoint, which responds to standard +USB requests, e.g. SET_ADDRESS, GET_DESCRIPTOR, GET_CONFIGURATION, etc. + +After DbC has been configure by debug host, it enters run mode, it's +the working mode. + + External reset + -------------- + +External reset means DbC reset caused by something outside of DbC hardware +and software. The external reset sources depends on the DbC System Bus +Reset(SBR) bit in status register. + +If SBR reads 1, the reset source includes, + +1) Assertion of chip hardware reset; +2) System bus reset (e.g. the assertion of PCI RST#); +3) Transition from the PCI PM D3hot to D0. + +If SBR reads 0, the reset source includes, + +1) Assertion of chip hardware reset; +2) Assertion of host controller reset; +3) Light host controller Reset. + +Resetting the DbC shall clear Debug Capability Enable(DCE) bit to 0. +Software can determing the reset event during runtime by checking the +DCE bit. The debug device enters disabled mode after reset. DbC driver +needs to follow above steps to re-initialize the hardware and bring +the debug device to run state. + + Port reset + ---------- + +Debug port resets itself when it detects reset signal from the debug +host. Software can determine the port reset event by reading the DbC +port control and staus registers. + +The debug device enters enumeration state as soon as the reset signal +completes. DbC driver should follow above steps to bring the debug +device into running mode. + + Interrupt/DMA/Memory during early boot + -------------------------------------- + +The driver code needs to take special care during early boot, especially +when it comes to memory allocation, interrupt, DMA, device MMIO and PCI +configuration space. This section defines the interfaces used in DbC driver +for the prior aspects. + +All events generated by DbC are put in the event ring, software will +periodically poll the Event Ring Not Empty bit in the Debug Capability +Status Register (DCST) to check pending events. To do this, DbC driver +should 1)poll the event ring after a transfer trb queued and wait until +transfer completes, or 2) start a thread to do the periodically poll. + +A segment of fixed virtual address is reserved for MMIO access purpose. +Debug capability driver will map the MMIO physical address (exposed in +PCI BAR) with this fixed virtual address segment. + +Debug Capability needs contiguous memory for DMA purpose. The driver +reserves DMA memory by stating arrays of PAGE_SIZE and ask the compiler +to align the arrays to PAGE_SIZE. + +Base on the following reasons, the driver uses an outb to port 0x80 as +an I/O delay: timer subsystem might not be ready yet when DbC starts +to initialize; DbC driver is independent of OS as possible as it can. + + Endpoint STALL + -------------- + +Endpoint STALL happens when data buffer error, parameter Error, +TRB error, vendor defined error, or undefined error is detected. +A transfer event will be generated to notify software. + +To clear the STALL situation, debug host will send a ClearFeature +(ENDPOINT_HALT) request. DbC will clear the halt transfer ring +flag, clear any internal endpoint state, and move the TR dequeue +pointer to the next TRB in transfer ring. + +DbC does not support Soft Retry. Driver must check and determine +whether to retry the failed transfer. + + Debug device information + ------------------------ + +When debug target boots with xHCI debug capability enabled, it appears +to debug host as a debug device. The debug device is built using one +interface which declares two bulk endpoints: an IN and an OUT. + +class code: 0xdc (diagnostic device, assigned by USB-IF) +subclass code: 0x02 (debug device, assigned by USB-IF) +Manufacturer: "Linux" +Product: "Remote GDB" +Serial: "0001" + +The USB device ID: +idVendor: 0x1d6b (Linux Foundation) +idProduct: 0x0004 + + How to use DbC early printk? + ---------------------------- + +Before using any kernel functionalities based on DbC, users need to check +whether debug port is supported by the xHCI host in the system. + +On a machine which supports USB3 debug port, a file named "debug_port_state" +will be created under /sys/bus/pci/drivers/xhci_hcd/<pci_bus_name>/. Reading +this file will show the state (disabled, enabled or configured) of the debug +port. On a machine that doesn't support USB3 debug port, this file doesn't +exist. + +On debug target system, user needs to enable the following kernel +config option: + + CONFIG_PCI + CONFIG_EARLY_PRINTK + CONFIG_EARLY_PRINTK_XDBC + +Users also need to add below kernel parameter: + + "earlyprintk=xdbc" + +If there are multiple xHCI controllers in the system, user can append +a host contoller index to this kernel parameter. The index is started +from 0. + +On debug host side, user needs to make sure usb_debug module is included. + +On some platforms, such as Intel, you need to disable auto-pm of usb +subsystem on debug host when you are debugging with DbC. + +#echo on | tee /sys/bus/usb/devices/*/power/control + +Before starting the debug target, user needs to connect the debug port +on debug target with a root port or port of external hub on the debug +host. The cable used to connect these two ports should be a USB 3.0 +super-speed A-to-A debugging cable. + +During early boot of debug target, DbC hardware gets initialized. Debug +host should be able to enuerate debug target as a debug device. Debug +host will bind the debug device with usb_debug driver module and create +a tty file for serial communication application. + +After tty file being created, user needs to open serial communication +application, such as minicom. After configuring minicom to open the +tty file created above, user should be able to see below welcome message +in minicom: + +Press Y to continue... + +After 'Y' key is pressed, debug target will go ahead with booting and +all early printk messages should be routed to the minicom on debug +host. + + Limitations + ----------- + +Early printk through DbC has been verified to work with Intel Sunrise Point +chip with below known issues: + +1. DbC debug device doesn't support suspend/resume. Users need to disable +auto-pm of the host controller on debug host. + +2. Early prink "keep" option doesn't support by current phase. + +3. After several restarts of debug target, debug host might fail to read +the device descriptor of debug device. Users need to restart the debug host.
MAINTAINERS +1 -0
@@ -11256,6 +11256,7 @@ L: [email protected] S: Supported F: drivers/usb/early/xhci-dbc.c F: include/linux/usb/xhci-dbc.h +F: Documentation/usb/xhci-dbc.txt USB ZD1201 DRIVER L: [email protected]
drivers/usb/early/xhci-dbc.c +3 -0
@@ -6,6 +6,9 @@* Author: Lu Baolu <[email protected]> * Some code shared with EHCI debug port and xHCI driver. * +* Please read Documentation/usb/xhci-dbc.txt before you start to develop +* or use code in this file. +* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation.
Signature · 1 line
2.1.4