Skip to content

USB: DW driver does not work properly with mass storage class #5678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jfischer-no opened this issue Jan 15, 2018 · 17 comments
Closed

USB: DW driver does not work properly with mass storage class #5678

jfischer-no opened this issue Jan 15, 2018 · 17 comments
Assignees
Labels
area: Drivers area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@jfischer-no
Copy link
Collaborator

DW USB device driver does not work properly with mass storage class (MSC).

Tested with sample/subsys/usb/mass on Arduino 101 connected to Linux host:

  • does not work on UHCI. Arduino 101 flashed with the sample can be enumerated by the host, after detecting the mass storage device, the host resets the device several times because the device stops respond to requests. Works sometimes (mount, read and write to partition) on UHCI with path introduced in USB:Flush tx fifo when available space not enough #5496.
  • does not work on XHCI. Behavior is similar to above, in addition, the partition will not be detected.
    There is also a note in sample/subsys/usb/mass/README.txt about issues with Arduino 101.

I have also tested sample/subsys/usb/mass on FRDM-K64F with #542 and I have not observed any problems with Linux and Windows 7 host.

Similar behavior was observed under Windows OS, see #5496

@jfischer-no jfischer-no added bug The issue is a bug, or the PR is fixing a bug area: Drivers area: USB Universal Serial Bus labels Jan 15, 2018
@nashif nashif added the priority: medium Medium impact/importance bug label Jan 18, 2018
@jfischer-no
Copy link
Collaborator Author

@finikorg Can you test please sample/subsys/usb/mass on quark_se_c1000_devboard?

@finikorg
Copy link
Collaborator

finikorg commented Jan 26, 2018

@jfischer-phytec-iot Should it build without extra configuration? I cannot do fresh build only specifying the board.

disk_access_flash.c:21:27: error: ‘CONFIG_DISK_ERASE_BLOCK_SIZE’ undeclared here (not in a function)
 static u8_t read_copy_buf[CONFIG_DISK_ERASE_BLOCK_SIZE];
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is defined only for:
boards/x86/arduino_101/Kconfig.defconfig:config DISK_ERASE_BLOCK_SIZE

@jfischer-no
Copy link
Collaborator Author

@finikorg another issue 😄, it should build with DISK_ACCESS_RAM enabled.

--- a/samples/subsys/usb/mass/prj.conf
+++ b/samples/subsys/usb/mass/prj.conf
@@ -17,8 +17,8 @@ CONFIG_SYS_LOG_USB_MASS_STORAGE_LEVEL=1
 #CONFIG_FILE_SYSTEM=y
 
 #SPI flash related configs
-CONFIG_DISK_ACCESS_FLASH=y
-CONFIG_SPI=y
+#CONFIG_DISK_ACCESS_FLASH=y
+#CONFIG_SPI=y
 
 #Want RAM DISK instead ? comment the whole flash block and uncomment
-#CONFIG_DISK_ACCESS_RAM=y
+CONFIG_DISK_ACCESS_RAM=y

@finikorg
Copy link
Collaborator

finikorg commented Jan 31, 2018

@jfischer-phytec-iot that configuration seems to work somehow. I see new disk added in my (virtual) Linux

[80370.696107] usb 1-2.8.2: reset full-speed USB device number 5 using uhci_hcd
[80476.591288] usb 1-2.8.2: USB disconnect, device number 5
[80490.484192] usb 1-2.8.2: new full-speed USB device number 6 using uhci_hcd
[80490.809696] usb 1-2.8.2: New USB device found, idVendor=2fe3, idProduct=0100
[80490.809699] usb 1-2.8.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[80490.809701] usb 1-2.8.2: Product: USB-DEV
[80490.809738] usb 1-2.8.2: Manufacturer: ZEPHYR
[80490.809740] usb 1-2.8.2: SerialNumber: 0.01
[80490.818195] usb-storage 1-2.8.2:1.0: USB Mass Storage device detected
[80490.818656] scsi host2: usb-storage 1-2.8.2:1.0
[80491.860398] scsi 2:0:0:0: Direct-Access     ZEPHYR   ZEPHYR USB DISK  0.01 PQ: 0 ANSI: 0 CCS
[80491.876222] sd 2:0:0:0: Attached scsi generic sg2 type 0
[80491.906381] sd 2:0:0:0: [sdb] 32 512-byte logical blocks: (16.4 kB/16.0 KiB)
[80491.926938] sd 2:0:0:0: [sdb] Write Protect is off
[80491.926941] sd 2:0:0:0: [sdb] Mode Sense: 03 00 00 00
[80491.947771] sd 2:0:0:0: [sdb] No Caching mode page found
[80491.949092] sd 2:0:0:0: [sdb] Assuming drive cache: write through
[80492.163342]  sdb:
[80492.311284] sd 2:0:0:0: [sdb] Attached SCSI removable disk

I can create partition:

Disk /dev/sdb: 16 KiB, 16384 bytes, 32 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7f018a19

Device     Boot Start End Sectors  Size Id Type
/dev/sdb1           1  31      31 15.5K 83 Linux

I think that the size of the disk is a bit small to create file system, how do you test it?

@jfischer-no
Copy link
Collaborator Author

There is a text file on it. You can also test it with something like:

dd if=/dev/urandom of=test.in bs=16k count=1
dd if=test.in of=/dev/sdb; sync
dd if=/dev/sdb of=test.out
diff test.in test.out

@jfischer-no
Copy link
Collaborator Author

jfischer-no commented Feb 2, 2018

I found usb analyzer in our storage room.

The error seems to be in the usb_dw_tx . Below kernel log and the screenshots (master and #5496)

[60101.323665] usb-storage 9-2:1.0: USB Mass Storage device detected              
[60101.323956] scsi host8: usb-storage 9-2:1.0                              
[60102.338663] scsi 8:0:0:0: Direct-Access     ZEPHYR   ZEPHYR USB DISK  0.01 PQ: 0 ANSI: 0 CCS
[60102.339253] sd 8:0:0:0: Attached scsi generic sg3 type 0                                  
[60102.344582] sd 8:0:0:0: [sdc] 4096 512-byte logical blocks: (2.10 MB/2.00 MiB) 
[60102.347655] sd 8:0:0:0: [sdc] Write Protect is off                                        
[60102.347659] sd 8:0:0:0: [sdc] Mode Sense: 03 00 00 00                          
[60102.350645] sd 8:0:0:0: [sdc] No Caching mode page found                 
[60102.350650] sd 8:0:0:0: [sdc] Assuming drive cache: write through                         
[60102.490702] sd 8:0:0:0: [sdc] Attached SCSI removable disk                     
[60102.637594] usb 9-2: reset full-speed USB device number 23 using uhci_hcd                 
[60102.961482] usb 9-2: reset full-speed USB device number 23 using uhci_hcd                 
[60103.277449] usb 9-2: reset full-speed USB device number 23 using uhci_hcd                 
[60103.593552] usb 9-2: reset full-speed USB device number 23 using uhci_hcd                 
[60103.905564] usb 9-2: reset full-speed USB device number 23 using uhci_hcd      
[60104.221484] usb 9-2: reset full-speed USB device number 23 using uhci_hcd                 
[60104.389645] sd 8:0:0:0: [sdc] tag#0 FAILED Result: hostbyte=DID_ERROR driverbyte=DRIVER_OK
[60104.389651] sd 8:0:0:0: [sdc] tag#0 CDB: Read(10) 28 00 00 00 0f 80 00 00 08 00           
[60104.389654] print_req_error: I/O error, dev sdc, sector 3968                              
[60104.729527] usb 9-2: reset full-speed USB device number 23 using uhci_hcd

sample/subsys/usb/mass, master
101_git_master_connect_1

sample/subsys/usb/mass, #5496
101_git_5496_connect_1

@SavinayDharmappa FYI

@nashif
Copy link
Member

nashif commented Feb 20, 2018

@finikorg are you looking at this bug?

@finikorg
Copy link
Collaborator

@nashif Yes, at the moment I see that when sending data we sometimes "send" extra 4 bytes, apparently left from the previous send operation. This is clearly seen in the trace below. The extra 4 bytes is CSW Signature, which is first 4 bytes of usual reply sent to this endpoint. If we remove these 4 bytes the operation would succeed. Looks like issue with USD DW driver, although the MSC code is not very good in terms that it handles most of operations in callbacks called from ISR, it would be better to use packets queues and processing in threads, ...

After receiving this message Linux resets USB device, and since we do not reset our USB stack usually everything works even after reset.

image

@finikorg
Copy link
Collaborator

Root cause is the same as for #3515

@nashif
Copy link
Member

nashif commented May 29, 2018

@finikorg so is this fixed? Can we close it?

@finikorg
Copy link
Collaborator

@nashif we still have no solution yet for this issue

@jfischer-no
Copy link
Collaborator Author

It behaves differently now, I noticed it when I tested #4661 on Arduino 101. With the longer cable it works without problems on xhci, if the cable is short (0.5m), the host resets the device again and again. @finikorg What about quark_se_c1000_devboard?

@finikorg
Copy link
Collaborator

finikorg commented Jun 4, 2018

@jfischer-phytec-iot I see the same issue like before, first 4 bytes duplicated.

@nashif nashif added priority: low Low impact/importance bug and removed priority: medium Medium impact/importance bug labels Jul 24, 2018
@galak
Copy link
Collaborator

galak commented Dec 6, 2018

You guys still work on this?

@laperie
Copy link
Collaborator

laperie commented Mar 11, 2019

@jfischer-phytec-iot - Is this isssue still relevant to you?

@jfischer-no
Copy link
Collaborator Author

@laperie It is not relevant, but in consideration of all the USB issues on this SiP/SoC we maybe have to disable USB support on Arduino 101 or at last document all the issues?

@laperie
Copy link
Collaborator

laperie commented Mar 13, 2019

@jfischer-phytec-iot actually, Arduino 101 is no longer (officially) supported, as per @nashif . So we can just close this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Drivers area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

5 participants