Linux USB
 help / color / mirror / Atom feed
From: Mathias Nyman <mathias.nyman@linux.intel.com>
To: Wesley Cheng <quic_wcheng@quicinc.com>,
	mathias.nyman@intel.com, gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	quic_jackp@quicinc.com
Subject: Re: [PATCH v2] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present
Date: Wed, 13 Sep 2023 17:21:32 +0300	[thread overview]
Message-ID: <fa815665-5b50-87b9-eb21-535f1f883061@linux.intel.com> (raw)
In-Reply-To: <d68aa806-b26a-0e43-42fb-b8067325e967@quicinc.com>

Hi

On 13.9.2023 0.51, Wesley Cheng wrote:
> Hi Mathias,
> 
>>> This is one way, but we can probably avoid re-reading all the usb3 portsc registers
>>> by checking if any bit is set in either:
>>>
>>>   // bitfield, set if xhci usb3 port neatly set to U3 with a hub request
>>> xhci->usb3_rhub.bus_state.suspended_ports
>>>
>>> // bitfield, set if xhci usb3 port is forced to U3 during xhci suspend.
>>> xhci->usb3_rhub.bus_state.bus_suspended
>>>
>>> But haven't checked this works in all corner cases.
>>>
>> Thanks for the suggestion.  I think I also looked at seeing if we could use the suspended_ports param, and it was missing one of the use cases we had.  I haven't thought on combining it with the bus_suspend param also to see if it could work.  Let me give it a try, and I'll get back to you.
>>
> 
> So in one of our normal use cases, which is to use an USB OTG adapter with our devices, we can have this connected with no device.  In this situation, the XHCI HCD and root hub are enumerated, and is in a state where nothing is connected to the port.  I added a print to the xhci_resume() path to check the status of "suspended_ports" and "bus_suspended" and they seem to reflect the same status as when there is something connected (to a device that supports autosuspend).  Here's some pointers I've found on why these parameters may not work:
> 
> 1.  bus_suspended is only set (for the bus) if we reach the bus_suspend() callback from USB HCD if the link is still in U0.  If USB autosuspend is enabled, then the suspending of the root hub udev, would have caused a call to suspend the port (usb_port_suspend()), and that would set "suspended_ports" and placed the link in U3 already.
> 
> 2. "suspended_ports" can't differentiate if a device is connected or not after plugging in a USB3 device that has autosuspend enabled.  It looks like on device disconnection, the suspended_ports isn't cleared for that port number.  It is only cleared during the resume path where a get port status is queried:
> 
> static void xhci_get_usb3_port_status(struct xhci_port *port, u32 *status,
>                        u32 portsc)
> {
> ...
>       /* USB3 specific wPortStatus bits */
>       if (portsc & PORT_POWER) {
>           *status |= USB_SS_PORT_STAT_POWER;
>           /* link state handling */
>           if (link_state == XDEV_U0)
>               bus_state->suspended_ports &= ~(1 << portnum);
>       }
> 
> IMO, this seems kind of weird, because the PLS shows that the port is in the RxDetect state, so it technically isn't suspended.  If you think we should clear suspended_ports on disconnect, then I think we can also change the logic to rely on it for avoiding the unnecessary delay in xhci_resume().

I think you found a bug.

We should clear suspended_ports bit if link state in portsc is anything other than U3, Resume or Recovery.

Not doing so might cause USB_PORT_STAT_C_SUSPEND bit to be set incorrectly in a USB2 get port status request.

So we want something like:
if (suspended_ports bit is set) {
	if (U3 || Resume || Recovery) {
		don't touch anything
	} else {
		clear suspended_port bit
		if ((U2 || U0) && USB2)
			set bus_state->port_c_suspend bit
}

I'll look into it

-Mathias


  reply	other threads:[~2023-09-13 14:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-01  0:15 [PATCH v2] usb: host: xhci: Avoid XHCI resume delay if SSUSB device is not present Wesley Cheng
2023-09-11 13:50 ` Mathias Nyman
2023-09-12  0:15   ` Wesley Cheng
2023-09-12 21:51     ` Wesley Cheng
2023-09-13 14:21       ` Mathias Nyman [this message]
2023-09-13 21:08         ` Wesley Cheng
2023-09-14  9:27           ` [RFT PATCH] xhci: track port suspend state correctly in unsuccessful resume cases Mathias Nyman
2023-09-15  0:34             ` Wesley Cheng

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=fa815665-5b50-87b9-eb21-535f1f883061@linux.intel.com \
    --to=mathias.nyman@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=quic_jackp@quicinc.com \
    --cc=quic_wcheng@quicinc.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