ref: 490c3d87cb558a8cfe8ad4db9f39c9cb3df91d17
parent: 71a1d11a81faba020649408e8c9eaeb10095a341
author: cinap_lenrek <[email protected]>
date: Sun Sep 22 14:51:41 EDT 2019
usbxhci: fix endpoint stall recovery, handle Ep.clrhalt flag after issuing CR_RESETEP command, we have to invalidate the endpoints output context buffer so that the halted/error status reflects the new state. not doing so resulted in the halted state to be stuck and we continued issuing endpoint reset commands when we where already recovered. handle the devusb Ep.clrhalt flag from devusb that userspace uses to force a endpoint reset on the next transaction.
--- a/sys/src/9/port/usbxhci.c
+++ b/sys/src/9/port/usbxhci.c
@@ -1368,7 +1368,7 @@
}
static char*
-unstall(Ring *r)
+unstall(Ep *ep, Ring *r)
{
char *err;
@@ -1375,13 +1375,19 @@
switch(r->ctx[0]&7){
case 2: /* halted */
case 4: /* error */
- r->stopped = 1;
+ ep->clrhalt = 1;
+ }
+ if(ep->clrhalt){
+ ep->clrhalt = 0;
err = ctlrcmd(r->slot->ctlr, CR_RESETEP | (r->id<<16) | (r->slot->id<<24), 0, 0, nil);
+ dmaflush(0, r->ctx, 8*4 << r->slot->ctlr->csz);
if(err != nil)
return err;
+ r->stopped = 1;
}
if(r->stopped){
err = ctlrcmd(r->slot->ctlr, CR_SETTRDQP | (r->id<<16) | (r->slot->id<<24), 0, resetring(r), nil);
+ dmaflush(0, r->ctx, 8*4 << r->slot->ctlr->csz);
if(err != nil)
return err;
r->stopped = 0;
@@ -1444,7 +1450,7 @@
nexterror();
}
- if((err = unstall(io->ring)) != nil)
+ if((err = unstall(ep, io->ring)) != nil)
error(err);
dmaflush(1, p, n);
@@ -1517,7 +1523,7 @@
io->b->wp += len;
}
}
- if((err = unstall(ring)) != nil)
+ if((err = unstall(ep, ring)) != nil)
error(err);
if((ring->ctx[1]>>16) != ep->maxpkt){
@@ -1596,7 +1602,7 @@
nexterror();
}
- if((err = unstall(io->ring)) != nil)
+ if((err = unstall(ep, io->ring)) != nil)
error(err);
dmaflush(1, p, n);