Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] xhci: Set port link to RxDetect if port is not enabled after resume
@ 2020-03-11  4:04 Kai-Heng Feng
  2020-03-26 11:33 ` Kai-Heng Feng
  0 siblings, 1 reply; 2+ messages in thread
From: Kai-Heng Feng @ 2020-03-11  4:04 UTC (permalink / raw)
  To: mathias.nyman; +Cc: gregkh, stern, linux-usb, linux-kernel, Kai-Heng Feng

On Dell TB16, Realtek USB ethernet (r8152) connects to an SMSC hub which
then connects to ASMedia xHCI's root hub:

/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 5000M
            |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 004 Device 002: ID 0424:5537 Standard Microsystems Corp. USB5537B
Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter

The port is disabled after resume:
xhci_hcd 0000:3f:00.0: Get port status 4-1 read: 0x280, return 0x280

According to xHCI 4.19.1.2.1, we should set link to RxDetect to transit
it from disabled state to disconnected state, which allows the port to
be set to U0 and completes the resume process.

My own test shows port can still resume when it's not enabled, as long
as its link is in U states. So constrain the new logic only when link is
not in any U state.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/usb/host/xhci-hub.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index a9c87eb8951e..263f9a9237a1 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1776,6 +1776,14 @@ int xhci_bus_resume(struct usb_hcd *hcd)
 			clear_bit(port_index, &bus_state->bus_suspended);
 			continue;
 		}
+
+		/* 4.19.1.2.1 */
+		if (!(portsc & PORT_PE) && (portsc & PORT_PLS_MASK) > XDEV_U3) {
+			portsc = xhci_port_state_to_neutral(portsc);
+			portsc &= ~PORT_PLS_MASK;
+			portsc |= PORT_LINK_STROBE | XDEV_RXDETECT;
+		}
+
 		/* resume if we suspended the link, and it is still suspended */
 		if (test_bit(port_index, &bus_state->bus_suspended))
 			switch (portsc & PORT_PLS_MASK) {
-- 
2.17.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] xhci: Set port link to RxDetect if port is not enabled after resume
  2020-03-11  4:04 [PATCH v2] xhci: Set port link to RxDetect if port is not enabled after resume Kai-Heng Feng
@ 2020-03-26 11:33 ` Kai-Heng Feng
  0 siblings, 0 replies; 2+ messages in thread
From: Kai-Heng Feng @ 2020-03-26 11:33 UTC (permalink / raw)
  To: Mathias Nyman; +Cc: Greg Kroah-Hartman, stern, linux-usb, linux-kernel

Hi Mathias,

> On Mar 11, 2020, at 12:04, Kai-Heng Feng <kai.heng.feng@canonical.com> wrote:
> 
> On Dell TB16, Realtek USB ethernet (r8152) connects to an SMSC hub which
> then connects to ASMedia xHCI's root hub:
> 
> /:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/2p, 5000M
>    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/7p, 5000M
>            |__ Port 2: Dev 3, If 0, Class=Vendor Specific Class, Driver=r8152, 5000M
> 
> Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
> Bus 004 Device 002: ID 0424:5537 Standard Microsystems Corp. USB5537B
> Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
> 
> The port is disabled after resume:
> xhci_hcd 0000:3f:00.0: Get port status 4-1 read: 0x280, return 0x280
> 
> According to xHCI 4.19.1.2.1, we should set link to RxDetect to transit
> it from disabled state to disconnected state, which allows the port to
> be set to U0 and completes the resume process.
> 
> My own test shows port can still resume when it's not enabled, as long
> as its link is in U states. So constrain the new logic only when link is
> not in any U state.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Do you think this is a proper fix?

Kai-Heng

> ---
> drivers/usb/host/xhci-hub.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
> index a9c87eb8951e..263f9a9237a1 100644
> --- a/drivers/usb/host/xhci-hub.c
> +++ b/drivers/usb/host/xhci-hub.c
> @@ -1776,6 +1776,14 @@ int xhci_bus_resume(struct usb_hcd *hcd)
> 			clear_bit(port_index, &bus_state->bus_suspended);
> 			continue;
> 		}
> +
> +		/* 4.19.1.2.1 */
> +		if (!(portsc & PORT_PE) && (portsc & PORT_PLS_MASK) > XDEV_U3) {
> +			portsc = xhci_port_state_to_neutral(portsc);
> +			portsc &= ~PORT_PLS_MASK;
> +			portsc |= PORT_LINK_STROBE | XDEV_RXDETECT;
> +		}
> +
> 		/* resume if we suspended the link, and it is still suspended */
> 		if (test_bit(port_index, &bus_state->bus_suspended))
> 			switch (portsc & PORT_PLS_MASK) {
> -- 
> 2.17.1
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  4:04 [PATCH v2] xhci: Set port link to RxDetect if port is not enabled after resume Kai-Heng Feng
2020-03-26 11:33 ` Kai-Heng Feng

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git