I use my RPI4 with an SSD drive via a USB 3.0 adapter. Usually, the drive works well until I find that all my USB devices are unmounted and I can't access the system. My USB keyboard didn't work and my USB drive was unmounted. And everything is fine after restarting the system until I start accessing the hard drive intensively.
I started researching this issue because I'm not sure about my no-name USB case, as well as the no-name SSD drive. I have collected all the information that will be useful for solving this problem with other devices.
How to investigate an incident
First of all, you should check the logs. The files
/var/log/messages,
/var/log/syslog and
/var/log/kern.log will return pretty much every event you could ever need to know to figure out what happened.
In my case all these files contained these messages:
Jul 4 14:48:10 microbox kernel: [ 1667.732392] xhci_hcd 0000:01:00.0: WARNING: Host System Error
Jul 4 14:48:15 microbox kernel: [ 1672.752064] xhci_hcd 0000:01:00.0: xHCI host not responding to stop endpoint command.
Jul 4 14:48:15 microbox kernel: [ 1672.752114] xhci_hcd 0000:01:00.0: xHCI host controller not responding, assume dead
Jul 4 14:48:15 microbox kernel: [ 1672.752462] xhci_hcd 0000:01:00.0: HC died; cleaning up
...
Jul 4 14:48:15 microbox kernel: [ 1672.753142] usb 1-1: USB disconnect, device number 2
Jul 4 14:48:15 microbox kernel: [ 1672.753162] usb 1-1.4: USB disconnect, device number 3
Jul 4 14:48:15 microbox kernel: [ 1672.754724] usb 2-2: USB disconnect, device number 2
Jul 4 14:48:15 microbox kernel: [ 1672.802164] sd 0:0:0:0: Device offlined - not ready after error recovery
...
Jul 4 14:48:15 microbox kernel: [ 1672.852093] print_req_error: I/O error, dev sda, sector 53777216
Jul 4 14:48:15 microbox kernel: [ 1672.852110] Buffer I/O error on dev sda, logical block 53777216, lost async page write
...
Jul 4 14:48:16 microbox kernel: [ 1672.886164] FAT-fs (sda): error, corrupted directory (invalid entries)
...
Jul 4 14:48:16 microbox kernel: [ 1672.887784] FAT-fs (sda): FAT read failed (blocknr 6640)
Jul 4 14:48:16 microbox udisksd[369]: Cleaning up mount point /media/pi/estorage (device 8:0 no longer exists)
All these messages told me that the xHCI host controller was not responding.
Cause of problems
I found that there are two possible reasons:
- The power issue. The drive should be plugged into a USB hub with external power;
- The drive does not support UAS commands. The user must disable the UAS for the device.
"Perhaps the on-board voltage is a marginal - try adding `over_voltage=1` to config.txt and rebooting."
"Just FYI, this issue is no longer occurring after disabling uas." (
source)
"in certain situations the Linux "uas" driver disables SAT transfers, which prevents smartmontools (and other tools, e.g. hdparm) from communicating properly with the attached SATA device. " (
source)
RPI4 uses UAS by default for all USB devices. I believe that UAS support was the cause of the problem in my case because the Linux kernel does not know whether the USB drive supports UAS or not, and relies on a blacklist of devices.
What is the UAS
"USB Attached SCSI (UAS) is an upgraded transport protocol compared to USB mass-storage - commands and data are separated into different queues and multiple outstanding commands can be in flight at the same time, as opposed to USB mass-storage's lock-step relationship between commands and data. This allows better saturation of the 4GBps USB3.0 transport as there can be a continuous stream of data to and from a device.
Prior to Pi 4, the USB host controller software did not support DMA scatter-gather operations. As a result of this limitation, the USB Attached SCSI (UAS) driver was not enabled. With Pi 4, as the xHCI driver does support scatter-gather and to get the most performance out of a USB3.0 attached SSD/disk we enabled UAS by default.
These errors may also appear due to poor power quality or overloading the Pi's maximum 1.2A downstream USB port current, but if they persist when using a powered hub then they are genuine UAS issues." (
source).
Disabling UAS
To disable UAS support, users must specify idVendor and idProduct devices. The
lsusb utility returns this information:
pi@microbox:~ $ lsusb
Bus 002 Device 002: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
For my USB drive, idVendor and idProduct are 152d:0578
Then the user must add the list of idVendor and idProduct pairs to the command in the
/boot/cmdline.txt file:
pi@microbox:~ $ cat /boot/cmdline.txt
usb-storage.quirks=152d:0578:u dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
After restarting, the
dmesg command should show that the UAS is disabled for the device:
[ 1.208487] usb 2-2: new SuperSpeed Gen 1 USB device number 2 using xhci_hcd
[ 1.249773] usb 2-2: New USB device found, idVendor=152d, idProduct=0578, bcdDevice= 2.04
[ 1.251726] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1.252750] usb 2-2: Product: External USB 3.0
[ 1.253780] usb 2-2: Manufacturer: JMicron
[ 1.254797] usb 2-2: SerialNumber: 201703310007F
[ 1.259165] usb 2-2: UAS is blacklisted for this device, using usb-storage instead
[ 1.261360] usb 2-2: UAS is blacklisted for this device, using usb-storage instead
[ 1.263519] usb-storage 2-2:1.0: USB Mass Storage device detected
[ 1.265101] usb-storage 2-2:1.0: Quirks match for vid 152d pid 0578: 1800000
[ 1.266408] scsi host0: usb-storage 2-2:1.0