Bug 200679 - broken TRIM support for JMS578 in uas mode
Summary: broken TRIM support for JMS578 in uas mode
Status: NEW
Alias: None
Product: Drivers
Classification: Unclassified
Component: USB (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: Greg Kroah-Hartman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-29 14:09 UTC by mailinglists35
Modified: 2022-11-01 15:33 UTC (History)
5 users (show)

See Also:
Kernel Version: 4.17.9-200.fc28.x86_64
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description mailinglists35 2018-07-29 14:09:25 UTC
I cannot issue TRIM commands to SSD behind a JMS578-based sata to usb-c adapter.
lsblk -D shows that discard is not enabled, but the SSD has this capability (see below)

However Windows 10 successfully TRIMs the device. Also the trimcheck.exe tool validates the TRIM operation. This makes me think the linux uas driver needs additional reverse engineering or support from Jmicron about this chipset.

Steps to Reproduce:
[root@localhost ~]# blkdiscard -v /dev/sda

Actual results:
blkdiscard: /dev/sda: BLKDISCARD ioctl failed: Operation not supported

Expected results:
/dev/sda: Discarded 250059350016 bytes from the offset 0

Additional info:

I believe smartmontools website [https://www.smartmontools.org/wiki/Supported_USB-Devices] incorrectly lists this usb bridge as JMS567, because their firmware upgrade tool identifies the device as 578, something that is suggested by the PID (0x0578 and not 0x0567), and I've been able to successfully try out several firmware versions available on usbdev.ru while the attempts for 567 failed. Also smartmontools drivedb.h update suggests also this is indeed a 578 https://www.smartmontools.org/ticket/841

---

[root@localhost ~]$ grep $ /sys/block/sda/queue/discard_*
/sys/block/sda/queue/discard_granularity:0
/sys/block/sda/queue/discard_max_bytes:0
/sys/block/sda/queue/discard_max_hw_bytes:0
/sys/block/sda/queue/discard_zeroes_data:0

---

[root@localhost ~]# lsblk -D /dev/sda
NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
sda           0        0B       0B         0
└─sda1        0        0B       0B         0

---

dmesg:
[ 1842.832155] usb 2-2: new SuperSpeed USB device number 3 using xhci_hcd
[ 1842.845457] usb 2-2: New USB device found, idVendor=152d, idProduct=0578, bcdDevice= 2.04
[ 1842.845461] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1842.845463] usb 2-2: Product: HDD USB Device
[ 1842.845464] usb 2-2: Manufacturer: JMicron
[ 1842.845466] usb 2-2: SerialNumber: 339AE81B6296382
[ 1842.851744] scsi host1: uas
[ 1842.852472] scsi 1:0:0:0: Direct-Access     sobetter Ext              0204 PQ: 0 ANSI: 6
[ 1842.853765] sd 1:0:0:0: Attached scsi generic sg0 type 0
[ 1842.854104] sd 1:0:0:0: [sda] 488397168 512-byte logical blocks: (250 GB/233 GiB)
[ 1842.854106] sd 1:0:0:0: [sda] 4096-byte physical blocks
[ 1842.854264] sd 1:0:0:0: [sda] Write Protect is off
[ 1842.854266] sd 1:0:0:0: [sda] Mode Sense: 53 00 00 08
[ 1842.854573] sd 1:0:0:0: [sda] Disabling FUA
[ 1842.854575] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 1842.865814]  sda: sda1
[ 1842.867420] sd 1:0:0:0: [sda] Attached SCSI disk

---

[root@localhost ~]# lsusb.py -e
[...]
 2-2             152d:0578 00  3.00 5000MBit/s 896mA 1IF  (JMicron HDD USB Device 339AE81B6296382)
                   (EP) 00: Control  attr 00 len 07 max 200
---

[root@localhost ~]# lsusb -v -d 152d:0578

Bus 002 Device 003: ID 152d:0578 JMicron Technology Corp. / JMicron USA Technology Corp. JMS567 SATA 6Gb/s bridge
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.00
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         9
  idVendor           0x152d JMicron Technology Corp. / JMicron USA Technology Corp.
  idProduct          0x0578 JMS567 SATA 6Gb/s bridge
  bcdDevice            2.04
  iManufacturer           1 JMicron
  iProduct                2 HDD USB Device
  iSerial                 3 339AE81B6296382
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          121
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              896mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst              15
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst              15
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       1
      bNumEndpoints           4
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     98 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               0
        Command pipe (0x01)
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               0
        MaxStreams             32
        Status pipe (0x02)
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst              15
        MaxStreams             32
        Data-in pipe (0x03)
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x04  EP 4 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               7
        MaxStreams             32
        Data-out pipe (0x04)
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength           22
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000f0e
      BESL Link Power Management (LPM) Supported
    BESL value     3840 us 
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x00
    wSpeedsSupported   0x000e
      Device can operate at Full Speed (12Mbps)
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   1
      Lowest fully-functional device speed is Full Speed (12Mbps)
    bU1DevExitLat          10 micro seconds
    bU2DevExitLat          32 micro seconds
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x000c
  (Bus Powered)
  U1 Enabled
  U2 Enabled

---

[asus@localhost ~]$ sudo sg_readcap -l /dev/sda
Read Capacity results:
   Protection: prot_en=0, p_type=0, p_i_exponent=0
   Logical block provisioning: lbpme=0, lbprz=0
   Last logical block address=488397167 (0x1d1c596f), Number of logical blocks=488397168
   Logical block length=512 bytes
   Logical blocks per physical block exponent=3 [so physical block length=4096 bytes]
   Lowest aligned logical block address=0
Hence:
   Device size: 250059350016 bytes, 238475.2 MiB, 250.06 GB

---

[asus@localhost ~]$ sudo sg_vpd -p thpv /dev/sda
abbreviation doesn't match a VPD page
Available standard VPD pages:
  ai         0x89      ATA information (SAT)
  aod        0x82      ASCII implemented operating definition (obsolete)
  adsn       0xb3      Automation device serial number (SSC)
  bl         0xb0      Block limits (SBC)
  ble        0xb7      Block limits extension (SBC)
  bdc        0xb1      Block device characteristics (SBC)
  bdce       0xb5      Block device characteristics extension (SBC)
  cfa        0x8c      CFA profile information
  dc         0x8b      Device constituents
  di         0x83      Device identification
  di_asis    0x83      Like 'di' but designators ordered as found
  di_lu      0x83      Device identification, lu only
  di_port    0x83      Device identification, target port only
  di_target  0x83      Device identification, target device only
  dtde       0xb4      Data transfer device element address (SSC)
  ei         0x86      Extended inquiry data
  iod        0x81      Implemented operating definition (obsolete)
  lbpro      0xb5      Logical block protection (SSC)
  lbpv       0xb2      Logical block provisioning (SBC)
  mas        0xb1      Manufacturer assigned serial number (SSC)
  masa       0xb1      Manufacturer assigned serial number (ADC)
  mna        0x85      Management network addresses
  mpp        0x87      Mode page policy
  oi         0xb0      OSD information
  pc         0x8a      Power condition
  psm        0x8d      Power consumption
  pslu       0x90      Protocol-specific logical unit information
  pspo       0x91      Protocol-specific port information
  ref        0xb3      Referrals (SBC)
  sad        0xb0      Sequential access device capabilities (SSC)
  sii        0x84      Software interface identification
  sinq       -1        Standard inquiry response
  sn         0x80      Unit serial number
  sp         0x88      SCSI ports
  st         0xb1      Security token (OSD)
  sbl        0xb4      Supported block lengths and protection types (SBC)
  sv         0x00      Supported VPD pages
  tas        0xb2      TapeAlert supported flags (SSC)
  tpc        0x8f      Third party copy
  zbdc       0xb6      Zoned block device characteristics

Vendor/product identifiers:
  dds        3      DDS tape family from IBM
  emc        2      EMC (company)
  hp3par     4      3PAR array (HP was Left Hand)
  ibm_lto    5      IBM LTO tape/systems
  hp_lto     6      HP LTO tape/systems
  rdac       1      RDAC array (NetApp E-Series)
  sea        0      Seagate disk

Vendor specific VPD pages:
  aci        0xc5,6      ACI revision level (HP LTO)
  datc       0xc1,0      Date code (Seagate)
  dcrl       0xc0,5      Drive component revision levels (IBM LTO)
  ddsver     0xc0,3      Firmware revision (DDS)
  devb       0xc3,0      Device behavior (Seagate)
  dsn        0xc1,5      Drive serial numbers (IBM LTO)
  ducd       0xc7,5      Device unique configuration data (IBM LTO)
  edid       0xc8,1      Extended device identification (RDAC)
  prm4       0xc3,1      Feature Parameters (RDAC)
  firm       0xc0,0      Firmware numbers (Seagate)
  frl        0xc0,6      Firmware revision level (HP LTO)
  fwr4       0xc1,1      Firmware version (RDAC)
  head       0xc4,6      Head Assy revision level (HP LTO)
  hp3par     0xc0,4      Volume information (HP/3PAR)
  hrl        0xc1,6      Hardware revision level (HP LTO)
  hwr4       0xc0,1      Hardware version (RDAC)
  jump       0xc2,0      Jump setting (Seagate)
  mech       0xc3,6      Mechanism revision level (HP LTO)
  mpds       0xc8,5      Mode parameter default settings (IBM LTO)
  pca        0xc2,6      PCA revision level (HP LTO)
  rvsi       0xca,1      Replicated volume source identifier (RDAC)
  said       0xd0,1      Storage array world wide name (RDAC)
  subs       0xc4,1      Subsystem identifier (RDAC)
  swr4       0xc2,1      Software version (RDAC)
  upr        0xc0,2      Unit path report (EMC)
  vac1       0xc9,1      Volume access control (RDAC)

---

[asus@localhost ~]$ sudo hdparm -I /dev/sda | grep -i trim
	   *	Data Set Management TRIM supported (limit 8 blocks)
	   *	Deterministic read ZEROs after TRIM
Comment 1 Greg Kroah-Hartman 2018-07-30 07:50:52 UTC
On Sun, Jul 29, 2018 at 02:09:25PM +0000, bugzilla-daemon@bugzilla.kernel.org wrote:
> https://bugzilla.kernel.org/show_bug.cgi?id=200679
> 
>             Bug ID: 200679
>            Summary: broken TRIM support for JMS578 in uas mode
>            Product: Drivers
>            Version: 2.5
>     Kernel Version: 4.17.9-200.fc28.x86_64


All USB bugs should be sent to the linux-usb@vger.kernel.org mailing
list, and not entered into bugzilla.  Please bring this issue up there,
if it is still a problem in the latest kernel release.
Comment 2 mailinglists35 2018-07-30 11:54:10 UTC
(In reply to Greg Kroah-Hartman from comment #1)
> On Sun, Jul 29, 2018 at 02:09:25PM +0000,
> bugzilla-daemon@bugzilla.kernel.org wrote:
> > https://bugzilla.kernel.org/show_bug.cgi?id=200679
> > 
> >             Bug ID: 200679
> >            Summary: broken TRIM support for JMS578 in uas mode
> >            Product: Drivers
> >            Version: 2.5
> >     Kernel Version: 4.17.9-200.fc28.x86_64
> 
> 
> All USB bugs should be sent to the linux-usb@vger.kernel.org mailing
> list, and not entered into bugzilla.  Please bring this issue up there,
> if it is still a problem in the latest kernel release.

https://marc.info/?l=linux-usb&m=153295104606185&w=2

Tested with rc6 (I don't see anything related to uas in usb changelog between rc6 and latest rc7)
Comment 3 anonymous 2019-03-21 11:06:11 UTC
I checked linux-usb@vger.kernel.org, and the discussion was discontinued there.

Is TRIM for JMS578 supported by the latest linux kernel?
Comment 4 mirh 2021-01-10 20:38:04 UTC
Yes it should
https://mvysny.github.io/ssd-usb-enclosure/

*But* this should always have been the case from the get go, the only possibly nefarious variable is the firmware but OP reported to have tried more than one. 
And of course he said W10 was just fine. 


https://www.spinics.net/lists/linux-usb/msg172736.html
It seems like something in the linux drivers isn't able to configure the right setting. 


p.s. I wonder if this isn't also the problem experienced in bug 83181?
Comment 5 Janos Szigetvari 2022-02-08 14:45:12 UTC
I don't mean to resurrect a long-forgotten bug, but I have a similar problem:
(I use the stock Ubuntu 20.04 kernel: 5.11.0-46-generic #51~20.04.1-Ubuntu SMP Fri Jan 7 06:51:40 UTC 2022)

I have a slightly different device:
152d:0580 JMicron Technology Corp. / JMicron USA Technology Corp. USB 3.1 Storage Device

The enclosure is actually an IcyBox IB-1817M-C31 enclosure-
According to the product ID the controller should be a JMS580, which according to the manufacturer supports TRIM.
However when I want to use blkdiscard, I am getting the following error:

# LANG=en_US blkdiscard -v /dev/sdb
blkdiscard: /dev/sdb: BLKDISCARD ioctl failed: Operation not supported

And this is the manufacturer's product information sheet for the controller:
https://www.jmicron.com/file/download/1021/JMS580_Product+Brief.pdf
Comment 6 mirh 2022-02-08 22:57:47 UTC
You are very OT, and you should have opened a new bug. 

https://www.touslesdrivers.com/index.php?v_page=23&v_code=59438&v_langue=en
https://www.station-drivers.com/index.php/en/outils/Drivers/Jmicron/JMS580-Sata-USB-3.1-Controller/Jmicron-JMS580-Sata-USB-3.0-Controller-Firmware-Version-234.01.00.01/lang,en-gb/
If you have problems, I could only recommend to try newer firmware (hoping they are the right ones)
Comment 7 Paul Menzel 2022-10-12 12:08:31 UTC
To original poster, can you still reproduce this issue with Linux 6.0? If yes, the mailing list thread should be revived.
Comment 8 Roman Mamedov 2022-10-12 14:08:41 UTC
I can reproduce with kernel 5.10.146 and a JMS576:

  # blkdiscard /dev/sdc3
  blkdiscard: /dev/sdc3: BLKDISCARD ioctl failed: Operation not supported

However, as detailed in this message:
https://www.spinics.net/lists/linux-usb/msg172736.html
it can be fixed:

  # cat /sys/class/scsi_disk/6\:0\:0\:0/provisioning_mode
  full

  # lsblk -D /dev/sdc
  NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
  sdc           0        0B       0B         0
  ├─sdc1        0        0B       0B         0
  ├─sdc2        0        0B       0B         0
  └─sdc3        0        0B       0B         0

  # echo unmap > /sys/class/scsi_disk/6\:0\:0\:0/provisioning_mode

  # lsblk -D /dev/sdc
  NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
  sdc           0        4K       4G         0
  ├─sdc1        0        4K       4G         0
  ├─sdc2        0        4K       4G         0
  └─sdc3        0        4K       4G         0

Except that's not all:

  # blkdiscard /dev/sdc3
  blkdiscard: /dev/sdc3: BLKDISCARD ioctl failed: Remote I/O error

Some trial and error results in finding the actual working discard size of 31 MiB (32 fails):

  # echo $((31*1024*1024)) > /sys/block/sdc/queue/discard_max_bytes

  # blkdiscard /dev/sdc3 && echo done
  done

Confirmed that /dev/sdc3 now contains zeroes instead of previously written data.
Comment 9 Roman Mamedov 2022-11-01 15:33:25 UTC
Turns out there's an entire wiki article about this: 
https://wiki.gentoo.org/wiki/Discard_over_USB

What is the reason that discard is not just automatically enabled for USB disks?

Note You need to log in before you can comment on or make changes to this bug.