Changes between Version 2 and Version 3 of SAT-with-UAS-Linux


Ignore:
Timestamp:
Aug 5, 2019, 8:30:32 AM (5 years ago)
Author:
Nathan Stratton Treadway
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SAT-with-UAS-Linux

    v2 v3  
    1 {{{
    2 #!div style="border: 1pt solid; float:right; background-color: #E6E6FA; padding:10px; margin-right:30px; margin-top:20px; margin-left:30px"
    3 {{{
    4 #!html
    5 }}}
    6 }}}
    71
    82= SAT with UAS under Linux =
     
    137As mentioned on the [wiki:USB USB devices and smartmontools] page, 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.  See [query:?keywords=~uas+linux related tickets] for examples.
    148
    15 This is because the Linux kernel rejects SAT ATA pass-through commands for certain devices with broken pass-through support.
    16 This depends on Kernel version and may include
     9This is because the Linux kernel rejects SAT ATA pass-through commands for certain devices with broken pass-through support.  This list of devices affected depends on the kernel version, and may include
    1710[https://github.com/torvalds/linux/commit/7fee72d5e8f1e7b8d8212e28291b1a0243ecf2f1 all Seagate enclosures],
    1811[https://github.com/torvalds/linux/commit/bda13e35d584dabf52c9f77e0fe62683ac4d9f86 Initio INIC-3069] and
     
    2720For more information on the usb-storage flags, search for the 'usb-storage.quirks' entry in the [https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html Kernel Parameters Documentation].
    2821
    29 The detailed selection logic used by the kernel to decide which devices get this flag can be found in the `uas_use_uas_driver()` function in the [https://github.com/torvalds/linux/blob/master/drivers/usb/storage/uas-detect.h drivers/usb/storage/uas-detect.h]  combined with the list of entries found in the [https://github.com/torvalds/linux/blob/master/drivers/usb/storage/unusual_uas.h drivers/usb/storage/unusual_uas.h]
     22You can easily check to see whether the kernel using uas or usbstorage for a particular device using the `lsusb -t` command:
     23
     24{{{
     25# lsusb -t
     26/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
     27/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
     28/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
     29    |__ Port 1: Dev 11, If 0, Class=Mass Storage, Driver=usb-storage, 5000M
     30[...]
     31}}}
     32or
     33{{{
     34# lsusb -t
     35/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 10000M
     36/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 480M
     37/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/4p, 5000M
     38    |__ Port 1: Dev 8, If 0, Class=Mass Storage, Driver=uas, 5000M
     39[...]
     40}}}
     41
     42Alternatively you can check the messages that appear in kern.log when the device is first connected and look for the driver name mentioned at the end of the "scsi hostN" line:
     43{{{
     44usb 2-1: new SuperSpeed USB device number 8 using xhci_hcd
     45usb 2-1: New USB device found, idVendor=NNNN, idProduct=NNN
     46usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
     47[...]
     48scsi host4: uas
     49scsi 4:0:0:0: Direct-Access     VENDOR-NAME               0204 PQ: 0 ANSI: 6
     50sd 4:0:0:0: Attached scsi generic sg2 type 0
     51sd 4:0:0:0: [sdc] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
     52sd 4:0:0:0: [sdc] 4096-byte physical blocks
     53sd 4:0:0:0: [sdc] Write Protect is off
     54sd 4:0:0:0: [sdc] Mode Sense: 53 00 00 08
     55sd 4:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
     56 sdc: sdc1 sdc2
     57sd 4:0:0:0: [sdc] Attached SCSI disk
     58}}}
     59
     60or
     61
     62{{{
     63usb 2-1: new SuperSpeed USB device number 9 using xhci_hcd
     64usb 2-1: New USB device found, idVendor=NNNN, idProduct=NNNN
     65usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
     66[...]
     67usb-storage 2-1:1.0: USB Mass Storage device detected
     68scsi host4: usb-storage 2-1:1.0
     69scsi 4:0:0:0: Direct-Access     VENDOR-NAME                   0204 PQ: 0 ANSI: 6
     70sd 4:0:0:0: Attached scsi generic sg2 type 0
     711953525168 512-byte logical blocks: (1.00 TB/932 GiB)
     72sd 4:0:0:0: [sdc] Write Protect is off
     73sd 4:0:0:0: [sdc] Mode Sense: 47 00 00 08
     74sd 4:0:0:0: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
     75 sdc: sdc1 sdc2
     76sd 4:0:0:0: [sdc] Attached
     77}}}
     78
     79The detailed selection logic used by the kernel to decide which devices get this flag can be found in the `uas_use_uas_driver()` function in the [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/storage/uas-detect.h drivers/usb/storage/uas-detect.h]  combined with the list of entries found in the [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/usb/storage/unusual_uas.h drivers/usb/storage/unusual_uas.h]
    3080file.  (As far as smartmontools/SAT passthrough is concerned, only the NO_ATA_1X flag is significant.)
    3181
     
    90140
    91141
    92 == Permanent Workarounds ==
    93 
    94 
    95 
    96 == Short-term Workarounds ==
    97 
     142== Workarounds ==
     143
     144There are two approaches to getting smartmontools to work with one of these devices, both involving setting a "quirks" flag for the device in question.
     145
     146* If you just want to get smartmontools working again and don't care about the performance improvements the come from using UAS mode, you can simply use the IGNORE_UAS flag to tell Linux to stick with the usb-storage mode instead, by using the "u" flag on the `usb-storage.quirks` setting.
     147
     148* If you want to continue using UAS mode and are sure your particular device does properly support SAT mode even though the kernel detects it as a device that does not (e.g. as described in ticket:971#comment:12) , you can override that default configuration by passing an empty flag list in the `usb-storage.quirks` setting.
     149
     150Note that in either case, you will need to find the idVendor and idProduct fields for your device, in 4-digit hex format.  This information is found in the `New USB device found, idVendor=NNNN, idProduct=NNNN`
     151kern.log line, or in the output from "lsusb".  (In the option strings below, the 4-digit numbers can optionally be preceded a "0x" prefix.)
     152
     153== Permanent Flag Settings ==
     154
     155The `usb-storage.quirks` option is part of the more general mechanism for setting kernel/module options, and the exact mechanisms available for setting it will vary depending on your distribution.  In brief:
     156
     157* if your system has the "usb-storage" driver compiled as a loadable kernel module, you can set it by creating a file (e.g. `disable_uas.conf`) under `/etc/modprobe.d/` containing the line (with the proper id numbers substituted)
     158{{{
     159options usb-storage quirks=0bc2:231a:u
     160}}}
     161   to disable UAS for that device (or
     162{{{
     163options usb-storage quirks=0bc2:231a:
     164}}}
     165   to try overriding the default NO_ATA_1X flag).
     166
     167   You will then probably need to follow your distribution's instructions for rebuilding your initramdisk in order to make the change apply when usb-storage drives are detected upon initial bootup.
     168
     169* If the "usb-storage" driver is built in to the kernel, or if you simply prefer to make this change at the boot level rather than under /etc/modproble.d/, you can pass the option to the kernel as part of your boot configuration.  For example, if your system uses grub2, you can edit `/boot/grub/default` so that in includes a line similar to
     170{{{
     171GRUB_CMDLINE_LINUX="usb_storage.quirks=0bc2:231a:u"
     172}}}
     173   and then run `update-grub`, and then reboot.
     174
     175(Note that while the basic information used in these two approaches in the same, the punctuation used is different.)
     176
     177In either case, you can then try plugging your USB device in again, and confirm using one of the methods above that the change had taken effect.  (Note that if you use the `:u` flag, the kern.log messages generated when the device is detected should now include
     178{{{
     179usb 2-1: UAS is blacklisted for this device, using usb-storage instead
     180usb-storage 2-1:1.0: USB Mass Storage device detected
     181usb-storage 2-1:1.0: Quirks match for vid 0bc2 pid ab38: 800000
     182scsi host4: usb-storage 2-1:1.0
     183}}}
     184
     185
     186== Temporary Settings ==
     187
     188If you would like to temporarily set the quirks flag rather than making a permanent change (e.g. in order to run smartctl manually at some point but continuing to use UAS mode normally when using the drive for data transfers), you can do so by dynamically updating the module configuration.
     189
     190First, unmount/unplug the USB device, then run the following commands (as root):
     191
     192{{{
     193# cat /sys/module/usb_storage/parameters/quirks
     194
     195# echo "0x0bc2:0x231a:u" > /sys/module/usb_storage/parameters/quirks
     196# cat /sys/module/usb_storage/parameters/quirks
     1970x0bc2:0x231a:u
     198
     199}}}
     200
     201(Note that the "echo" command completely replaces the current setting, so the first "cat" command makes sure that no quirks have been previously configured; it should just show a blank line.)
     202
     203At this point you can plug the device's USB cable back in, and (after confirming via lsusb/kern.log that the device is connected to the usb-storage driver) you can then proceed to access the device using SAT.
     204
     205A quirk set in this manner will automatically get cleared the next time the system is rebooted, but if you want to clear it more quickly you can simply execute:
     206{{{
     207# echo "" > /sys/module/usb_storage/parameters/quirks
     208}}}
     209to clear the configuration for the next time the device is plugged in.
     210
     211== Useful Links ==
     212
     213A few pages with useful additional information:
     214
     215General info:
     216* [https://superuser.com/questions/928741/how-can-i-check-whether-usb3-0-uasp-usb-attached-scsi-protocol-mode-is-enabled StackExchange: How can I check whether USB3.0 UASP (USB Attached SCSI Protocol) mode is enabled in Linux?]
     217* [https://en.opensuse.org/SDB:USB_3.0_Hard_Drive_troubleshooting Suze:USB 3.0 Hard Drive troubleshooting]
     218
     219Examples of the problems that originally triggered the current kernel behavior:
     220* [https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1584557 Seagate external drive causes SCSI bus resets when UAS enabled]
     221* [https://unix.stackexchange.com/questions/441668/debian-usb3-hdd-uas-i-o-errors StackExchange: Debian + USB3 HDD + UAS: I/O errors]
     222* [https://unix.stackexchange.com/questions/418326/how-do-i-make-my-seagate-2tb-usb-hdd-work-in-linux StackExchange: How do I make my Seagate 2Tb usb hdd work in Linux?]
     223