Re: USBDMSC emulated device does not work on FreeBSD

From: Milan Obuch <freebsd-usb_at_dino.sk>
Date: Sat, 13 Nov 2021 07:05:21 UTC
On Fri, 12 Nov 2021 15:22:13 +0100 I wrote:

> On Fri, 12 Nov 2021 14:26:32 +0100
> Hans Petter Selasky <hps@selasky.org> wrote:
> 
> > On 11/12/21 14:25, Hans Petter Selasky wrote:
> > > hw.usb.quirk.0="0x1514 0x0001 0 0xffff UQ_MSC_NO_SYNC_CACHE"
> > > hw.usb.quirk.0="0x1514 0x0001 0 0xffff UQ_NO_STRINGS"  
> > 
> > Should be "1" for second quirk.
> > 
> > hw.usb.quirk.0="0x1514 0x0001 0 0xffff UQ_MSC_NO_SYNC_CACHE"
> > hw.usb.quirk.1="0x1514 0x0001 0 0xffff UQ_NO_STRINGS"
> > 
> > --HPS
> > 
> 
> Thanks for hint, it works now. For some reason, only one quirk works
> on system under test (it is 12.2-STABLE, r368192). I checked it with
> 'usbconfig dump_device_quirks', just the second one was shown. For
> completeness, necessary lines in loader.conf files are
> 
> usb_quirk_load=YES
> hw.usb.quirk.0="0x1514 0x0001 0 0xffff UQ_NO_STRINGS"
> hw.usb.quirk.1="0x1514 0x0001 0 0xffff UQ_MSC_NO_SYNC_CACHE"
> 
> (I think UQ_NO_STRINGS could be omitted, did not test without, but
> 'usbconfig dump_device_quirks | grep 1514' outputs just
> 
> VID=0x1514 PID=0x0001 REVLO=0x0000 REVHI=0xffff
> QUIRK=UQ_MSC_NO_SYNC_CACHE
> 
> nothing more.)
> 
> I am reading from /dev/da0 now... next check would be write, I'll test
> later. If you'd like me to test anything else, just drop a note.
> 
> Again, thanks for help.
> 
> Regards,
> Milan
> 

[ Follow-up to my mail ]

After looking a bit into man page, I found it is actually easy to do it
without reboot (which is important for my main workstation, otherwise
I'd have to reopen quite a number of various windows...). Also, it
looks like some bug in loader makes it not possible to add more than
one quirk on boot time, which I can 'fix' from shell:

kldload usb_quirk
usbconfig add_dev_quirk_vplh 0x1514 0x0001 0 0xffff UQ_NO_STRINGS
usbconfig add_dev_quirk_vplh 0x1514 0x0001 0 0xffff UQ_MSC_NO_SYNC_CACHE

Now I can get expected info from 'usbconfig -d ugen1.3 dump_all_desc'
command:

ugen1.3: <vendor 0x1514 product 0x0001> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (100mA)

  bLength = 0x0012 
  bDescriptorType = 0x0001 
  bcdUSB = 0x0200 
  bDeviceClass = 0x0000  <Probed by interface class>
  bDeviceSubClass = 0x0000 
  bDeviceProtocol = 0x0000 
  bMaxPacketSize0 = 0x0040 
  idVendor = 0x1514 
  idProduct = 0x0001 
  bcdDevice = 0x3000 
  iManufacturer = 0x0001  <Microchip Inc>
  iProduct = 0x0002  <PolarFireSoc-FlashDrive>
  iSerialNumber = 0x0003  <123456789ABCDEF151411111>
  bNumConfigurations = 0x0001 

 Configuration index 0

    bLength = 0x0009 
    bDescriptorType = 0x0002 
    wTotalLength = 0x0020 
    bNumInterfaces = 0x0001 
    bConfigurationValue = 0x0001 
    iConfiguration = 0x0004  <CFG-HS>
    bmAttributes = 0x00c0 
    bMaxPower = 0x0032 

    Interface 0
      bLength = 0x0009 
      bDescriptorType = 0x0004 
      bInterfaceNumber = 0x0000 
      bAlternateSetting = 0x0000 
      bNumEndpoints = 0x0002 
      bInterfaceClass = 0x0008  <Mass storage>
      bInterfaceSubClass = 0x0006 
      bInterfaceProtocol = 0x0050 
      iInterface = 0x0005  <Interface-MSD>

     Endpoint 0
        bLength = 0x0007 
        bDescriptorType = 0x0005 
        bEndpointAddress = 0x0081  <IN>
        bmAttributes = 0x0002  <BULK>
        wMaxPacketSize = 0x0200 
        bInterval = 0x00ff 
        bRefresh = 0x0000 
        bSynchAddress = 0x0000 

     Endpoint 1
        bLength = 0x0007 
        bDescriptorType = 0x0005 
        bEndpointAddress = 0x0001  <OUT>
        bmAttributes = 0x0002  <BULK>
        wMaxPacketSize = 0x0200 
        bInterval = 0x00ff 
        bRefresh = 0x0000 
        bSynchAddress = 0x0000 

and 'usbconfig show_ifdrv' relevant lines are

ugen1.3: <vendor 0x1514 product 0x0001> at usbus1, cfg=0 md=HOST spd=HIGH (480Mbps) pwr=ON (100mA)
ugen1.3.0: umass0: <vendor 0x1514 product 0x0001, class 0/0, rev 2.00/30.00, addr 3>

Relevant lines in console log/dmesg:

ugen1.3: <vendor 0x1514 product 0x0001> at usbus1
umass0 on uhub3
umass0: <vendor 0x1514 product 0x0001, class 0/0, rev 2.00/30.00, addr 3 on usbus1
da0 at umass-sim0 bus 0 scbus8 target 0 lun 0
da0: <MSCC PolarFireSoC_msd 1234> Removable Direct Access SPC-2 SCSI device
da0: 40.000MB/s transfers
da0: 7457MB (15273600 512 byte sectors)
da0: quirks=0x2<NO_6_BYTE>

Now, 'gpart show da0' displays expected partitioning data, I can
'mount_msdosfs /dev/da0p2 /media' and access files there as needed.

Thanks for really valuable help, highly appreciated.

Regards,
Milan