9front - general discussion about 9front
 help / color / mirror / Atom feed
* bug: usb hub enumeration hangs
@ 2019-04-16 10:22 Nick Owens
  2019-04-16 10:26 ` [9front] " Ethan Gardener
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Owens @ 2019-04-16 10:22 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 1094 bytes --]

on my new machine xhci/usbd lock up when my IBM ultranav with an
internal hub is plugged in.

attached is a patch that fixes it for me. if it looks ok, i will commit it.

if anyone has hubs, whether just a hub or inside something else like a
keyboard, please test this.

i have traced this down to usbd attempting to set the 'port enable'
feature on one of the ports. when it attempts to enable the port, a
usb request is made but there is no reply, making usbd hang while
doing the endpoint write.

from the USB 2 spec:

11.24.2.7.1.2 PORT_ENABLE
...
This bit may be set only as a result of a SetPortFeature(PORT_RESET) request.
...
The hub response to a SetPortFeature(PORT_ENABLE) request is not
specified. The preferred behavior is
that the hub respond with a Request Error. This may not be used by the
USB System Software. The
ClearPortFeature(PORT_ENABLE) request is supported as specified in
Section 11.5.1.4.

it's pretty clear to me we shouldn't fiddle with this bit. the patch
fixes use of it, and additionally replaces port enabling with
unsuspend when we check for port suspension.

[-- Attachment #2: usbd.patch --]
[-- Type: text/x-patch, Size: 2255 bytes --]

diff --git a/sys/src/cmd/nusb/usbd/dat.h b/sys/src/cmd/nusb/usbd/dat.h
--- a/sys/src/cmd/nusb/usbd/dat.h
+++ b/sys/src/cmd/nusb/usbd/dat.h
@@ -55,7 +55,6 @@ enum
 
 	/* Delays, timeouts (ms) */
 	Spawndelay	= 250,		/* how often may we re-spawn a driver */
-	Connectdelay	= 500,		/* how much to wait after a connect */
 	Resetdelay	= 20,		/* how much to wait after a reset */
 	Enabledelay	= 20,		/* how much to wait after an enable */
 	Powerdelay	= 100,		/* after powering up ports */
diff --git a/sys/src/cmd/nusb/usbd/hub.c b/sys/src/cmd/nusb/usbd/hub.c
--- a/sys/src/cmd/nusb/usbd/hub.c
+++ b/sys/src/cmd/nusb/usbd/hub.c
@@ -362,7 +362,7 @@ portattach(Hub *h, int p, u32int sts)
 	pp->state = Pattached;
 	dprint(2, "%s: %s: port %d attach sts %#ux\n", argv0, d->dir, p, sts);
 	if(h->dev->isusb3){
-		sleep(Connectdelay);
+		sleep(Enabledelay);
 		sts = portstatus(h, p);
 		if(sts == -1)
 			goto Fail;
@@ -372,9 +372,6 @@ portattach(Hub *h, int p, u32int sts)
 		}
 		sp = "super";
 	} else {
-		sleep(Connectdelay);
-		if(hubfeature(h, p, Fportenable, 1) < 0)
-			dprint(2, "%s: %s: port %d: enable: %r\n", argv0, d->dir, p);
 		sleep(Enabledelay);
 		if(hubfeature(h, p, Fportreset, 1) < 0){
 			dprint(2, "%s: %s: port %d: reset: %r\n", argv0, d->dir, p);
@@ -558,12 +555,7 @@ portreset(Hub *h, int p)
 		goto Fail;
 	if((sts & PSenable) == 0){
 		dprint(2, "%s: %s: port %d: not enabled?\n", argv0, d->dir, p);
-		if(h->dev->isusb3)
-			goto Fail;
-		hubfeature(h, p, Fportenable, 1);
-		sts = portstatus(h, p);
-		if((sts & PSenable) == 0)
-			goto Fail;
+		goto Fail;
 	}
 	nd = pp->dev;
 	opendevdata(nd, ORDWR);
@@ -635,11 +627,11 @@ enumhub(Hub *h, int p)
 	onhubs = nhubs;
 	if(!h->dev->isusb3){
 		if((sts & PSsuspend) != 0){
-			if(hubfeature(h, p, Fportenable, 1) < 0)
-				dprint(2, "%s: %s: port %d: enable: %r\n", argv0, d->dir, p);
+			if(hubfeature(h, p, Fportsuspend, 0) < 0)
+				dprint(2, "%s: %s: port %d: unsuspend: %r\n", argv0, d->dir, p);
 			sleep(Enabledelay);
 			sts = portstatus(h, p);
-			fprint(2, "%s: %s: port %d: resumed (sts %#ux)\n", argv0, d->dir, p, sts);
+			fprint(2, "%s: %s: port %d: unsuspended (sts %#ux)\n", argv0, d->dir, p, sts);
 		}
 	}
 	if((pp->sts & PSpresent) == 0 && (sts & PSpresent) != 0){

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [9front] bug: usb hub enumeration hangs
@ 2019-04-16 13:11 cinap_lenrek
  0 siblings, 0 replies; 6+ messages in thread
From: cinap_lenrek @ 2019-04-16 13:11 UTC (permalink / raw)
  To: 9front

good catch! i'll try it.

--
cinap


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [9front] bug: usb hub enumeration hangs
@ 2019-04-16 13:23 cinap_lenrek
  2019-04-18  9:50 ` Nick Owens
  0 siblings, 1 reply; 6+ messages in thread
From: cinap_lenrek @ 2019-04-16 13:23 UTC (permalink / raw)
  To: 9front

works for me!

--
cinap


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

end of thread, other threads:[~2019-04-18  9:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-16 10:22 bug: usb hub enumeration hangs Nick Owens
2019-04-16 10:26 ` [9front] " Ethan Gardener
2019-04-16 11:14   ` Ethan Gardener
2019-04-16 13:11 cinap_lenrek
2019-04-16 13:23 cinap_lenrek
2019-04-18  9:50 ` Nick Owens

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).