Re: git: 7520b88860d7 - main - usb(4): Automagically apply all quirks for USB mass storage devices.

From: Hans Petter Selasky <hps_at_selasky.org>
Date: Mon, 28 Feb 2022 09:54:33 UTC
On 2/28/22 10:19, Ruslan Bukin wrote:
> On Sun, Feb 27, 2022 at 09:34:42PM +0100, Hans Petter Selasky wrote:
>> On 2/27/22 20:48, Ruslan Bukin wrote:
>>> Hi,
>>>
>>> I've an xhci issue with this change on my ARM Morello Board.
>>> I've attached boot log. Can you look?
>>>
>>> Thanks.
>>>
>>> Ruslan
>>
>> Hi,
>>
>> The "xhci0: Resetting controller" indicates that the XHCI hardware
>> halted. If you just need this device working, then just load
>> usb_quirk.ko in /boot/loader.conf and add the same quirk there!
>>
>> man usb_quirk
>>
>> Maybe you can enable hw.usb.xhci.debug=17 from the loader during boot.
>> If there is only one device it shouldn't spam the console too much.
>>
>> Sorry for the breakage. Seems to be related to xhci.c and probably its
>> handling of the unconfigure command.
>>
> 
> Here is the output with xhcidebug = 17:
> https://people.freebsd.org/~br/usb_issue_debug_17.txt
> Can you look? I've unplugged mouse and keyboard, but left USB storage device.
> 

Hi Ruslan,

First this happens:

> xhci_check_transfer: TD is last
> xhci_generic_done: xfer=0xffff00012a7a7180 endpoint=0xffffa00006d55128 transfer done
> xhci_generic_done_sub: xfer=0xffff00012a7a7180[0/2] rem=0/8 status=1
> xhci_generic_done_sub: xfer=0xffff00012a7a7180[1/2] rem=0/1 status=1
                                                           ^^^ the 
device returns 1 byte worth of data, and status=1 means success.

> xhci_generic_done_sub: xfer=0xffff00012a7a7180[2/2] rem=0/0 status=1
> xhci_device_done: xfer=0xffff00012a7a7180, endpoint=0xffffa00006d55128, error=0
> xhci_interrupt_poll: event[86] = 32 (0x0000000086a77310 0x01000000 0x01018001)
                                                           ^^^ 0x01 -> 
XHCI_TRB_ERROR_SUCCESS
> xhci_check_transfer: slot=1 epno=1 remainder=0 status=1

This quirk gets set because the byte returned is zero, most likely.
> usb_msc_auto_quirk: UQ_MSC_NO_GETMAXLUN set for USB mass storage device SanDisk Extreme (0x0781:0x5580)
> xhci_device_generic_open: 

I suspect a CPU cache sync issue in busdma_dmamap_sync on your platform, 
as invoked by usb_pc_cpu_xxx(). Maybe you should print all the 
parameters for the intial usb_pc_cpu_xxx() calls?

The LUN byte should be non-zero!

Then comes the next problem:

> xhci_cmd_set_tr_dequeue_ptr: 
> xhci_do_command: command[10] = 16 (0x0000000086a84001, 0x00000000, 0x01044000)
> xhci_interrupt: real interrupt (status=0x00000008)
> xhci_interrupt_poll: event[87] = 33 (0x000000008508ffa0 0x13000000 0x01008401)
> xhci_check_command: Received command event
> xhci_configure_reset_endpoint: Could not set dequeue ptr for endpoint 4
> xhci_cmd_configure_ep: 

0x13 = XHCI_TRB_ERROR_CONTEXT_STATE as found in 
sys/dev/usb/controller/xhci*.h (Refer to xHCI_Specification_for_USB.pdf 
for more details)

--HPS