public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Hardik Gajjar <hgajjar@de.adit-jv.com>
Cc: gregkh@linuxfoundation.org, mathias.nyman@intel.com,
	stern@rowland.harvard.edu, yangyingliang@huawei.com,
	jinpu.wang@ionos.com, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, erosca@de.adit-jv.com
Subject: Re: [PATCH] usb: hcd: xhci: Add set command timer delay API
Date: Tue, 29 Aug 2023 16:57:54 +0300	[thread overview]
Message-ID: <d88dbe7e-4558-970d-5601-d4d906829d47@linux.intel.com> (raw)
In-Reply-To: <20230821095547.GA9820@vmlxhi-118.adit-jv.com>

On 21.8.2023 12.55, Hardik Gajjar wrote:
> On Fri, Aug 18, 2023 at 04:18:30PM +0300, Mathias Nyman wrote:
>> On 18.8.2023 12.23, Hardik Gajjar wrote:
>>> xHCI driver starts the response timer after sending each
>>> command to the device. The default value of this timer is
>>> 5 seconds (XHCI_CMD_DEFAULT_TIMEOUT = HZ*5). This seems
>>> too high in time crtical use case.
>>>
>>> This patch provides an API to change the default value of
>>> the timer from the vendor USB driver.
>>>
>>> The default value will be XHCI_CMD_DEFAULT_TIMEOUT (5 sec)
>>>
>>> Use case:
>>> According to the Smartphone integration certification
>>> requirement in the automotive, the phone connected via USB
>>> should complete enumeration and user space handshake
>>> within 3 sec.
>>
>> The above incorrectly makes it sound as if the command timeout
>> timer causes the delay.
>>
> Thank you, Mathias, for your prompt response. I will enhance the message
> to provide more specificity in the subsequent patch.
>>>
>>> Reducing the response waiting time by setting the smaller
>>> command timer delay helps to speed up overall re-enumeration
>>> process of the USB device in case of device is not responding
>>> properly in first enumeration iteration.
>>
>> So is this a case where addressing a usb device behind xHC always
>> fail on the first attempt, i.e. address device command in xhci
>> never completes. Solution proposed here is to fail faster and
>> retry?
>>
>> Is the rootcause known why first enumeration fails?
>>
>> Does setting old_scheme_first module parameter help?
>>
> Yes, you are correct. The problem occurs when setting the address,
> and in such cases, this patch helps to fail faster and retry.
> 
> Unfortunately, the root cause is unknown. This problem is mainly
> observed with Android phones. Upon analyzing the USB analyzer logs,
> it seems that the device is not responding to the SET_ADDRESS request.

Is this only seen when connecting the device to a Linux xHCI host at USB 3 speeds?
How about connecting to a windows machine? or USB 2 Linux machine with a EHCI host?

> 
> I tried using "old_scheme_first=Y," but that did not help. Below are
> the short logs of the first iteration enumeration failure.
>>
>> The xhci command timeout is more of a xhci internal thing, not sure it's a good
>> idea to add this to hcd.
>>
>> Would it make sense to add a timeout parameter to hcd->driver->address_device(hcd, udev)
>> instead?
>>
>> First priority should of course be finding out why the first enumeration fails,
>> and solve that.
>>
>> Thanks
>> Mathias
> Thanks for the suggestion to modify hcd->driver->address_device.
> I will definitely implement it.However to confirm.
> 
> So, if I understand correctly, the idea is to avoid exposing any
> API from the xhci driver, but instead, create an interface in hcd.c (such as sysfs or API)
> and incorporate the delay in address_device as an additional parameter.

On second thought it only makes sense to do this if we can identify the device in advance
and make a quirk for it. But at this stage we don't know anything about the device.

So I guess this depends on the width of the problem.

If this works on windows then we need to figure out what we do differently.

If this fails with all hosts (well xHCI and EHCI) then hcd level change is probably needed.
For xhci we would pass timeout parameter when calling address_device, for other hosts
the timeout for the SET_ADDRESS control transfer would be adjusted.

If this only fails when connected behind a xHCI host then a local xHCI change should do.

> However, in that case, modifying xhci is still necessary as the timer is controlled from there.

Yes, xhci changes will be needed.

I suggest adding a timeout parameter to struct xhci_command, and use that when calling
xhci_mod_cmd_timer(). This way we can tailor different timeouts for different commands.

-Mathias

  reply	other threads:[~2023-08-29 13:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-18  9:23 [PATCH] usb: hcd: xhci: Add set command timer delay API Hardik Gajjar
2023-08-18 13:18 ` Mathias Nyman
2023-08-21  9:55   ` Hardik Gajjar
2023-08-29 13:57     ` Mathias Nyman [this message]
2023-09-04  9:57       ` Hardik Gajjar
2023-09-05 14:31         ` Mathias Nyman
2023-09-27 14:14           ` Hardik Gajjar
2023-08-21 19:54 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d88dbe7e-4558-970d-5601-d4d906829d47@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=erosca@de.adit-jv.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hgajjar@de.adit-jv.com \
    --cc=jinpu.wang@ionos.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=stern@rowland.harvard.edu \
    --cc=yangyingliang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox