1b0b3ddf8SFelipe Balbi=============== 2b0b3ddf8SFelipe BalbiUSB3 debug port 3b0b3ddf8SFelipe Balbi=============== 4b0b3ddf8SFelipe Balbi 5b0b3ddf8SFelipe Balbi:Author: Lu Baolu <baolu.lu@linux.intel.com> 6b0b3ddf8SFelipe Balbi:Date: March 2017 7b0b3ddf8SFelipe Balbi 8b0b3ddf8SFelipe BalbiGENERAL 9b0b3ddf8SFelipe Balbi======= 10b0b3ddf8SFelipe Balbi 11b0b3ddf8SFelipe BalbiThis is a HOWTO for using the USB3 debug port on x86 systems. 12b0b3ddf8SFelipe Balbi 13b0b3ddf8SFelipe BalbiBefore using any kernel debugging functionality based on USB3 14b0b3ddf8SFelipe Balbidebug port, you need to:: 15b0b3ddf8SFelipe Balbi 16b0b3ddf8SFelipe Balbi 1) check whether any USB3 debug port is available in 17b0b3ddf8SFelipe Balbi your system; 18b0b3ddf8SFelipe Balbi 2) check which port is used for debugging purposes; 19b0b3ddf8SFelipe Balbi 3) have a USB 3.0 super-speed A-to-A debugging cable. 20b0b3ddf8SFelipe Balbi 21b0b3ddf8SFelipe BalbiINTRODUCTION 22b0b3ddf8SFelipe Balbi============ 23b0b3ddf8SFelipe Balbi 24b0b3ddf8SFelipe BalbiThe xHCI debug capability (DbC) is an optional but standalone 25b0b3ddf8SFelipe Balbifunctionality provided by the xHCI host controller. The xHCI 26b0b3ddf8SFelipe Balbispecification describes DbC in the section 7.6. 27b0b3ddf8SFelipe Balbi 28b0b3ddf8SFelipe BalbiWhen DbC is initialized and enabled, it will present a debug 29b0b3ddf8SFelipe Balbidevice through the debug port (normally the first USB3 30b0b3ddf8SFelipe Balbisuper-speed port). The debug device is fully compliant with 31b0b3ddf8SFelipe Balbithe USB framework and provides the equivalent of a very high 32b0b3ddf8SFelipe Balbiperformance full-duplex serial link between the debug target 33b0b3ddf8SFelipe Balbi(the system under debugging) and a debug host. 34b0b3ddf8SFelipe Balbi 35b0b3ddf8SFelipe BalbiEARLY PRINTK 36b0b3ddf8SFelipe Balbi============ 37b0b3ddf8SFelipe Balbi 38b0b3ddf8SFelipe BalbiDbC has been designed to log early printk messages. One use for 39b0b3ddf8SFelipe Balbithis feature is kernel debugging. For example, when your machine 40b0b3ddf8SFelipe Balbicrashes very early before the regular console code is initialized. 41b0b3ddf8SFelipe BalbiOther uses include simpler, lockless logging instead of a full- 42b0b3ddf8SFelipe Balbiblown printk console driver and klogd. 43b0b3ddf8SFelipe Balbi 44b0b3ddf8SFelipe BalbiOn the debug target system, you need to customize a debugging 45b0b3ddf8SFelipe Balbikernel with CONFIG_EARLY_PRINTK_USB_XDBC enabled. And, add below 46b0b3ddf8SFelipe Balbikernel boot parameter:: 47b0b3ddf8SFelipe Balbi 48b0b3ddf8SFelipe Balbi "earlyprintk=xdbc" 49b0b3ddf8SFelipe Balbi 50b0b3ddf8SFelipe BalbiIf there are multiple xHCI controllers in your system, you can 51*7852fe3aSRandy Dunlapappend a host controller index to this kernel parameter. This 52b0b3ddf8SFelipe Balbiindex starts from 0. 53b0b3ddf8SFelipe Balbi 54b0b3ddf8SFelipe BalbiCurrent design doesn't support DbC runtime suspend/resume. As 55b0b3ddf8SFelipe Balbithe result, you'd better disable runtime power management for 56b0b3ddf8SFelipe BalbiUSB subsystem by adding below kernel boot parameter:: 57b0b3ddf8SFelipe Balbi 58b0b3ddf8SFelipe Balbi "usbcore.autosuspend=-1" 59b0b3ddf8SFelipe Balbi 60b0b3ddf8SFelipe BalbiBefore starting the debug target, you should connect the debug 61b0b3ddf8SFelipe Balbiport to a USB port (root port or port of any external hub) on 62b0b3ddf8SFelipe Balbithe debug host. The cable used to connect these two ports 63b0b3ddf8SFelipe Balbishould be a USB 3.0 super-speed A-to-A debugging cable. 64b0b3ddf8SFelipe Balbi 65b0b3ddf8SFelipe BalbiDuring early boot of the debug target, DbC will be detected and 66b0b3ddf8SFelipe Balbiinitialized. After initialization, the debug host should be able 67b0b3ddf8SFelipe Balbito enumerate the debug device in debug target. The debug host 68b0b3ddf8SFelipe Balbiwill then bind the debug device with the usb_debug driver module 69b0b3ddf8SFelipe Balbiand create the /dev/ttyUSB device. 70b0b3ddf8SFelipe Balbi 71b0b3ddf8SFelipe BalbiIf the debug device enumeration goes smoothly, you should be able 72b0b3ddf8SFelipe Balbito see below kernel messages on the debug host:: 73b0b3ddf8SFelipe Balbi 74b0b3ddf8SFelipe Balbi # tail -f /var/log/kern.log 75b0b3ddf8SFelipe Balbi [ 1815.983374] usb 4-3: new SuperSpeed USB device number 4 using xhci_hcd 76b0b3ddf8SFelipe Balbi [ 1815.999595] usb 4-3: LPM exit latency is zeroed, disabling LPM. 77b0b3ddf8SFelipe Balbi [ 1815.999899] usb 4-3: New USB device found, idVendor=1d6b, idProduct=0004 78b0b3ddf8SFelipe Balbi [ 1815.999902] usb 4-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3 79b0b3ddf8SFelipe Balbi [ 1815.999903] usb 4-3: Product: Remote GDB 80b0b3ddf8SFelipe Balbi [ 1815.999904] usb 4-3: Manufacturer: Linux 81b0b3ddf8SFelipe Balbi [ 1815.999905] usb 4-3: SerialNumber: 0001 82b0b3ddf8SFelipe Balbi [ 1816.000240] usb_debug 4-3:1.0: xhci_dbc converter detected 83b0b3ddf8SFelipe Balbi [ 1816.000360] usb 4-3: xhci_dbc converter now attached to ttyUSB0 84b0b3ddf8SFelipe Balbi 85b0b3ddf8SFelipe BalbiYou can use any communication program, for example minicom, to 86b0b3ddf8SFelipe Balbiread and view the messages. Below simple bash scripts can help 87b0b3ddf8SFelipe Balbiyou to check the sanity of the setup. 88b0b3ddf8SFelipe Balbi 89b0b3ddf8SFelipe Balbi.. code-block:: sh 90b0b3ddf8SFelipe Balbi 91b0b3ddf8SFelipe Balbi ===== start of bash scripts ============= 92b0b3ddf8SFelipe Balbi #!/bin/bash 93b0b3ddf8SFelipe Balbi 94b0b3ddf8SFelipe Balbi while true ; do 95b0b3ddf8SFelipe Balbi while [ ! -d /sys/class/tty/ttyUSB0 ] ; do 96b0b3ddf8SFelipe Balbi : 97b0b3ddf8SFelipe Balbi done 98b0b3ddf8SFelipe Balbi cat /dev/ttyUSB0 99b0b3ddf8SFelipe Balbi done 100b0b3ddf8SFelipe Balbi ===== end of bash scripts =============== 10190b2a01eSLu Baolu 10290b2a01eSLu BaoluSerial TTY 10390b2a01eSLu Baolu========== 10490b2a01eSLu Baolu 10590b2a01eSLu BaoluThe DbC support has been added to the xHCI driver. You can get a 10690b2a01eSLu Baoludebug device provided by the DbC at runtime. 10790b2a01eSLu Baolu 10890b2a01eSLu BaoluIn order to use this, you need to make sure your kernel has been 10990b2a01eSLu Baoluconfigured to support USB_XHCI_DBGCAP. A sysfs attribute under 11090b2a01eSLu Baoluthe xHCI device node is used to enable or disable DbC. By default, 11190b2a01eSLu BaoluDbC is disabled:: 11290b2a01eSLu Baolu 11390b2a01eSLu Baolu root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc 11490b2a01eSLu Baolu disabled 11590b2a01eSLu Baolu 11690b2a01eSLu BaoluEnable DbC with the following command:: 11790b2a01eSLu Baolu 11890b2a01eSLu Baolu root@target:/sys/bus/pci/devices/0000:00:14.0# echo enable > dbc 11990b2a01eSLu Baolu 12090b2a01eSLu BaoluYou can check the DbC state at anytime:: 12190b2a01eSLu Baolu 12290b2a01eSLu Baolu root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc 12390b2a01eSLu Baolu enabled 12490b2a01eSLu Baolu 12590b2a01eSLu BaoluConnect the debug target to the debug host with a USB 3.0 super- 12690b2a01eSLu Baoluspeed A-to-A debugging cable. You can see /dev/ttyDBC0 created 12790b2a01eSLu Baoluon the debug target. You will see below kernel message lines:: 12890b2a01eSLu Baolu 12990b2a01eSLu Baolu root@target: tail -f /var/log/kern.log 13090b2a01eSLu Baolu [ 182.730103] xhci_hcd 0000:00:14.0: DbC connected 13190b2a01eSLu Baolu [ 191.169420] xhci_hcd 0000:00:14.0: DbC configured 13290b2a01eSLu Baolu [ 191.169597] xhci_hcd 0000:00:14.0: DbC now attached to /dev/ttyDBC0 13390b2a01eSLu Baolu 13490b2a01eSLu BaoluAccordingly, the DbC state has been brought up to:: 13590b2a01eSLu Baolu 13690b2a01eSLu Baolu root@target:/sys/bus/pci/devices/0000:00:14.0# cat dbc 13790b2a01eSLu Baolu configured 13890b2a01eSLu Baolu 13990b2a01eSLu BaoluOn the debug host, you will see the debug device has been enumerated. 14090b2a01eSLu BaoluYou will see below kernel message lines:: 14190b2a01eSLu Baolu 14290b2a01eSLu Baolu root@host: tail -f /var/log/kern.log 14390b2a01eSLu Baolu [ 79.454780] usb 2-2.1: new SuperSpeed USB device number 3 using xhci_hcd 14490b2a01eSLu Baolu [ 79.475003] usb 2-2.1: LPM exit latency is zeroed, disabling LPM. 14590b2a01eSLu Baolu [ 79.475389] usb 2-2.1: New USB device found, idVendor=1d6b, idProduct=0010 14690b2a01eSLu Baolu [ 79.475390] usb 2-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 14790b2a01eSLu Baolu [ 79.475391] usb 2-2.1: Product: Linux USB Debug Target 14890b2a01eSLu Baolu [ 79.475392] usb 2-2.1: Manufacturer: Linux Foundation 14990b2a01eSLu Baolu [ 79.475393] usb 2-2.1: SerialNumber: 0001 15090b2a01eSLu Baolu 15190b2a01eSLu BaoluThe debug device works now. You can use any communication or debugging 15290b2a01eSLu Baoluprogram to talk between the host and the target. 153