xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/usb/usb3-debug-port.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun===============
2*4882a593SmuzhiyunUSB3 debug port
3*4882a593Smuzhiyun===============
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun:Author: Lu Baolu <baolu.lu@linux.intel.com>
6*4882a593Smuzhiyun:Date: March 2017
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunGENERAL
9*4882a593Smuzhiyun=======
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunThis is a HOWTO for using the USB3 debug port on x86 systems.
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunBefore using any kernel debugging functionality based on USB3
14*4882a593Smuzhiyundebug port, you need to::
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun	1) check whether any USB3 debug port is available in
17*4882a593Smuzhiyun	   your system;
18*4882a593Smuzhiyun	2) check which port is used for debugging purposes;
19*4882a593Smuzhiyun	3) have a USB 3.0 super-speed A-to-A debugging cable.
20*4882a593Smuzhiyun
21*4882a593SmuzhiyunINTRODUCTION
22*4882a593Smuzhiyun============
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunThe xHCI debug capability (DbC) is an optional but standalone
25*4882a593Smuzhiyunfunctionality provided by the xHCI host controller. The xHCI
26*4882a593Smuzhiyunspecification describes DbC in the section 7.6.
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunWhen DbC is initialized and enabled, it will present a debug
29*4882a593Smuzhiyundevice through the debug port (normally the first USB3
30*4882a593Smuzhiyunsuper-speed port). The debug device is fully compliant with
31*4882a593Smuzhiyunthe USB framework and provides the equivalent of a very high
32*4882a593Smuzhiyunperformance full-duplex serial link between the debug target
33*4882a593Smuzhiyun(the system under debugging) and a debug host.
34*4882a593Smuzhiyun
35*4882a593SmuzhiyunEARLY PRINTK
36*4882a593Smuzhiyun============
37*4882a593Smuzhiyun
38*4882a593SmuzhiyunDbC has been designed to log early printk messages. One use for
39*4882a593Smuzhiyunthis feature is kernel debugging. For example, when your machine
40*4882a593Smuzhiyuncrashes very early before the regular console code is initialized.
41*4882a593SmuzhiyunOther uses include simpler, lockless logging instead of a full-
42*4882a593Smuzhiyunblown printk console driver and klogd.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunOn the debug target system, you need to customize a debugging
45*4882a593Smuzhiyunkernel with CONFIG_EARLY_PRINTK_USB_XDBC enabled. And, add below
46*4882a593Smuzhiyunkernel boot parameter::
47*4882a593Smuzhiyun
48*4882a593Smuzhiyun	"earlyprintk=xdbc"
49*4882a593Smuzhiyun
50*4882a593SmuzhiyunIf there are multiple xHCI controllers in your system, you can
51*4882a593Smuzhiyunappend a host contoller index to this kernel parameter. This
52*4882a593Smuzhiyunindex starts from 0.
53*4882a593Smuzhiyun
54*4882a593SmuzhiyunCurrent design doesn't support DbC runtime suspend/resume. As
55*4882a593Smuzhiyunthe result, you'd better disable runtime power management for
56*4882a593SmuzhiyunUSB subsystem by adding below kernel boot parameter::
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun	"usbcore.autosuspend=-1"
59*4882a593Smuzhiyun
60*4882a593SmuzhiyunBefore starting the debug target, you should connect the debug
61*4882a593Smuzhiyunport to a USB port (root port or port of any external hub) on
62*4882a593Smuzhiyunthe debug host. The cable used to connect these two ports
63*4882a593Smuzhiyunshould be a USB 3.0 super-speed A-to-A debugging cable.
64*4882a593Smuzhiyun
65*4882a593SmuzhiyunDuring early boot of the debug target, DbC will be detected and
66*4882a593Smuzhiyuninitialized. After initialization, the debug host should be able
67*4882a593Smuzhiyunto enumerate the debug device in debug target. The debug host
68*4882a593Smuzhiyunwill then bind the debug device with the usb_debug driver module
69*4882a593Smuzhiyunand create the /dev/ttyUSB device.
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunIf the debug device enumeration goes smoothly, you should be able
72*4882a593Smuzhiyunto see below kernel messages on the debug host::
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun	# tail -f /var/log/kern.log
75*4882a593Smuzhiyun	[ 1815.983374] usb 4-3: new SuperSpeed USB device number 4 using xhci_hcd
76*4882a593Smuzhiyun	[ 1815.999595] usb 4-3: LPM exit latency is zeroed, disabling LPM.
77*4882a593Smuzhiyun	[ 1815.999899] usb 4-3: New USB device found, idVendor=1d6b, idProduct=0004
78*4882a593Smuzhiyun	[ 1815.999902] usb 4-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
79*4882a593Smuzhiyun	[ 1815.999903] usb 4-3: Product: Remote GDB
80*4882a593Smuzhiyun	[ 1815.999904] usb 4-3: Manufacturer: Linux
81*4882a593Smuzhiyun	[ 1815.999905] usb 4-3: SerialNumber: 0001
82*4882a593Smuzhiyun	[ 1816.000240] usb_debug 4-3:1.0: xhci_dbc converter detected
83*4882a593Smuzhiyun	[ 1816.000360] usb 4-3: xhci_dbc converter now attached to ttyUSB0
84*4882a593Smuzhiyun
85*4882a593SmuzhiyunYou can use any communication program, for example minicom, to
86*4882a593Smuzhiyunread and view the messages. Below simple bash scripts can help
87*4882a593Smuzhiyunyou to check the sanity of the setup.
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun.. code-block:: sh
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun	===== start of bash scripts =============
92*4882a593Smuzhiyun	#!/bin/bash
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun	while true ; do
95*4882a593Smuzhiyun		while [ ! -d /sys/class/tty/ttyUSB0 ] ; do
96*4882a593Smuzhiyun			:
97*4882a593Smuzhiyun		done
98*4882a593Smuzhiyun	cat /dev/ttyUSB0
99*4882a593Smuzhiyun	done
100*4882a593Smuzhiyun	===== end of bash scripts ===============
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunSerial TTY
103*4882a593Smuzhiyun==========
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunThe DbC support has been added to the xHCI driver. You can get a
106*4882a593Smuzhiyundebug device provided by the DbC at runtime.
107*4882a593Smuzhiyun
108*4882a593SmuzhiyunIn order to use this, you need to make sure your kernel has been
109*4882a593Smuzhiyunconfigured to support USB_XHCI_DBGCAP. A sysfs attribute under
110*4882a593Smuzhiyunthe xHCI device node is used to enable or disable DbC. By default,
111*4882a593SmuzhiyunDbC is disabled::
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun	root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc
114*4882a593Smuzhiyun	disabled
115*4882a593Smuzhiyun
116*4882a593SmuzhiyunEnable DbC with the following command::
117*4882a593Smuzhiyun
118*4882a593Smuzhiyun	root@target:/sys/bus/pci/devices/0000:00:14.0# echo enable > dbc
119*4882a593Smuzhiyun
120*4882a593SmuzhiyunYou can check the DbC state at anytime::
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun	root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc
123*4882a593Smuzhiyun	enabled
124*4882a593Smuzhiyun
125*4882a593SmuzhiyunConnect the debug target to the debug host with a USB 3.0 super-
126*4882a593Smuzhiyunspeed A-to-A debugging cable. You can see /dev/ttyDBC0 created
127*4882a593Smuzhiyunon the debug target. You will see below kernel message lines::
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun	root@target: tail -f /var/log/kern.log
130*4882a593Smuzhiyun	[  182.730103] xhci_hcd 0000:00:14.0: DbC connected
131*4882a593Smuzhiyun	[  191.169420] xhci_hcd 0000:00:14.0: DbC configured
132*4882a593Smuzhiyun	[  191.169597] xhci_hcd 0000:00:14.0: DbC now attached to /dev/ttyDBC0
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunAccordingly, the DbC state has been brought up to::
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun	root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc
137*4882a593Smuzhiyun	configured
138*4882a593Smuzhiyun
139*4882a593SmuzhiyunOn the debug host, you will see the debug device has been enumerated.
140*4882a593SmuzhiyunYou will see below kernel message lines::
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun	root@host: tail -f /var/log/kern.log
143*4882a593Smuzhiyun	[   79.454780] usb 2-2.1: new SuperSpeed USB device number 3 using xhci_hcd
144*4882a593Smuzhiyun	[   79.475003] usb 2-2.1: LPM exit latency is zeroed, disabling LPM.
145*4882a593Smuzhiyun	[   79.475389] usb 2-2.1: New USB device found, idVendor=1d6b, idProduct=0010
146*4882a593Smuzhiyun	[   79.475390] usb 2-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
147*4882a593Smuzhiyun	[   79.475391] usb 2-2.1: Product: Linux USB Debug Target
148*4882a593Smuzhiyun	[   79.475392] usb 2-2.1: Manufacturer: Linux Foundation
149*4882a593Smuzhiyun	[   79.475393] usb 2-2.1: SerialNumber: 0001
150*4882a593Smuzhiyun
151*4882a593SmuzhiyunThe debug device works now. You can use any communication or debugging
152*4882a593Smuzhiyunprogram to talk between the host and the target.
153