162306a36Sopenharmony_ci=============== 262306a36Sopenharmony_ciUSB3 debug port 362306a36Sopenharmony_ci=============== 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci:Author: Lu Baolu <baolu.lu@linux.intel.com> 662306a36Sopenharmony_ci:Date: March 2017 762306a36Sopenharmony_ci 862306a36Sopenharmony_ciGENERAL 962306a36Sopenharmony_ci======= 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ciThis is a HOWTO for using the USB3 debug port on x86 systems. 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciBefore using any kernel debugging functionality based on USB3 1462306a36Sopenharmony_cidebug port, you need to:: 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci 1) check whether any USB3 debug port is available in 1762306a36Sopenharmony_ci your system; 1862306a36Sopenharmony_ci 2) check which port is used for debugging purposes; 1962306a36Sopenharmony_ci 3) have a USB 3.0 super-speed A-to-A debugging cable. 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ciINTRODUCTION 2262306a36Sopenharmony_ci============ 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ciThe xHCI debug capability (DbC) is an optional but standalone 2562306a36Sopenharmony_cifunctionality provided by the xHCI host controller. The xHCI 2662306a36Sopenharmony_cispecification describes DbC in the section 7.6. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciWhen DbC is initialized and enabled, it will present a debug 2962306a36Sopenharmony_cidevice through the debug port (normally the first USB3 3062306a36Sopenharmony_cisuper-speed port). The debug device is fully compliant with 3162306a36Sopenharmony_cithe USB framework and provides the equivalent of a very high 3262306a36Sopenharmony_ciperformance full-duplex serial link between the debug target 3362306a36Sopenharmony_ci(the system under debugging) and a debug host. 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ciEARLY PRINTK 3662306a36Sopenharmony_ci============ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ciDbC has been designed to log early printk messages. One use for 3962306a36Sopenharmony_cithis feature is kernel debugging. For example, when your machine 4062306a36Sopenharmony_cicrashes very early before the regular console code is initialized. 4162306a36Sopenharmony_ciOther uses include simpler, lockless logging instead of a full- 4262306a36Sopenharmony_ciblown printk console driver and klogd. 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ciOn the debug target system, you need to customize a debugging 4562306a36Sopenharmony_cikernel with CONFIG_EARLY_PRINTK_USB_XDBC enabled. And, add below 4662306a36Sopenharmony_cikernel boot parameter:: 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci "earlyprintk=xdbc" 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ciIf there are multiple xHCI controllers in your system, you can 5162306a36Sopenharmony_ciappend a host controller index to this kernel parameter. This 5262306a36Sopenharmony_ciindex starts from 0. 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ciCurrent design doesn't support DbC runtime suspend/resume. As 5562306a36Sopenharmony_cithe result, you'd better disable runtime power management for 5662306a36Sopenharmony_ciUSB subsystem by adding below kernel boot parameter:: 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci "usbcore.autosuspend=-1" 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ciBefore starting the debug target, you should connect the debug 6162306a36Sopenharmony_ciport to a USB port (root port or port of any external hub) on 6262306a36Sopenharmony_cithe debug host. The cable used to connect these two ports 6362306a36Sopenharmony_cishould be a USB 3.0 super-speed A-to-A debugging cable. 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ciDuring early boot of the debug target, DbC will be detected and 6662306a36Sopenharmony_ciinitialized. After initialization, the debug host should be able 6762306a36Sopenharmony_cito enumerate the debug device in debug target. The debug host 6862306a36Sopenharmony_ciwill then bind the debug device with the usb_debug driver module 6962306a36Sopenharmony_ciand create the /dev/ttyUSB device. 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ciIf the debug device enumeration goes smoothly, you should be able 7262306a36Sopenharmony_cito see below kernel messages on the debug host:: 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci # tail -f /var/log/kern.log 7562306a36Sopenharmony_ci [ 1815.983374] usb 4-3: new SuperSpeed USB device number 4 using xhci_hcd 7662306a36Sopenharmony_ci [ 1815.999595] usb 4-3: LPM exit latency is zeroed, disabling LPM. 7762306a36Sopenharmony_ci [ 1815.999899] usb 4-3: New USB device found, idVendor=1d6b, idProduct=0004 7862306a36Sopenharmony_ci [ 1815.999902] usb 4-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 7962306a36Sopenharmony_ci [ 1815.999903] usb 4-3: Product: Remote GDB 8062306a36Sopenharmony_ci [ 1815.999904] usb 4-3: Manufacturer: Linux 8162306a36Sopenharmony_ci [ 1815.999905] usb 4-3: SerialNumber: 0001 8262306a36Sopenharmony_ci [ 1816.000240] usb_debug 4-3:1.0: xhci_dbc converter detected 8362306a36Sopenharmony_ci [ 1816.000360] usb 4-3: xhci_dbc converter now attached to ttyUSB0 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ciYou can use any communication program, for example minicom, to 8662306a36Sopenharmony_ciread and view the messages. Below simple bash scripts can help 8762306a36Sopenharmony_ciyou to check the sanity of the setup. 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci.. code-block:: sh 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci ===== start of bash scripts ============= 9262306a36Sopenharmony_ci #!/bin/bash 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci while true ; do 9562306a36Sopenharmony_ci while [ ! -d /sys/class/tty/ttyUSB0 ] ; do 9662306a36Sopenharmony_ci : 9762306a36Sopenharmony_ci done 9862306a36Sopenharmony_ci cat /dev/ttyUSB0 9962306a36Sopenharmony_ci done 10062306a36Sopenharmony_ci ===== end of bash scripts =============== 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciSerial TTY 10362306a36Sopenharmony_ci========== 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciThe DbC support has been added to the xHCI driver. You can get a 10662306a36Sopenharmony_cidebug device provided by the DbC at runtime. 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ciIn order to use this, you need to make sure your kernel has been 10962306a36Sopenharmony_ciconfigured to support USB_XHCI_DBGCAP. A sysfs attribute under 11062306a36Sopenharmony_cithe xHCI device node is used to enable or disable DbC. By default, 11162306a36Sopenharmony_ciDbC is disabled:: 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc 11462306a36Sopenharmony_ci disabled 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ciEnable DbC with the following command:: 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci root@target:/sys/bus/pci/devices/0000:00:14.0# echo enable > dbc 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ciYou can check the DbC state at anytime:: 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc 12362306a36Sopenharmony_ci enabled 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ciConnect the debug target to the debug host with a USB 3.0 super- 12662306a36Sopenharmony_cispeed A-to-A debugging cable. You can see /dev/ttyDBC0 created 12762306a36Sopenharmony_cion the debug target. You will see below kernel message lines:: 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci root@target: tail -f /var/log/kern.log 13062306a36Sopenharmony_ci [ 182.730103] xhci_hcd 0000:00:14.0: DbC connected 13162306a36Sopenharmony_ci [ 191.169420] xhci_hcd 0000:00:14.0: DbC configured 13262306a36Sopenharmony_ci [ 191.169597] xhci_hcd 0000:00:14.0: DbC now attached to /dev/ttyDBC0 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ciAccordingly, the DbC state has been brought up to:: 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc 13762306a36Sopenharmony_ci configured 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciOn the debug host, you will see the debug device has been enumerated. 14062306a36Sopenharmony_ciYou will see below kernel message lines:: 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci root@host: tail -f /var/log/kern.log 14362306a36Sopenharmony_ci [ 79.454780] usb 2-2.1: new SuperSpeed USB device number 3 using xhci_hcd 14462306a36Sopenharmony_ci [ 79.475003] usb 2-2.1: LPM exit latency is zeroed, disabling LPM. 14562306a36Sopenharmony_ci [ 79.475389] usb 2-2.1: New USB device found, idVendor=1d6b, idProduct=0010 14662306a36Sopenharmony_ci [ 79.475390] usb 2-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 14762306a36Sopenharmony_ci [ 79.475391] usb 2-2.1: Product: Linux USB Debug Target 14862306a36Sopenharmony_ci [ 79.475392] usb 2-2.1: Manufacturer: Linux Foundation 14962306a36Sopenharmony_ci [ 79.475393] usb 2-2.1: SerialNumber: 0001 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ciThe debug device works now. You can use any communication or debugging 15262306a36Sopenharmony_ciprogram to talk between the host and the target. 153