git: 9front

Download patch

ref: e7161f762ff553b372623a8a7d30661f0d77bed8
parent: ea3cfa808f9231f94c5d68051744a192808c990c
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Dec 16 00:14:45 EST 2024

usbdwc: preserve Prtpwr bit for portstatus, turn off power by default, handle channel timeout

preserve the Prtpwr bit in portstatus instead of
unconditionally setting it.

turn off port powert on init. (let usbd will turn it on).

make chanio() halt the channel and error out
when interrupt status is 0 after timout.

this happens when the port is powered off.

--- a/sys/src/9/bcm/usbdwc.c
+++ b/sys/src/9/bcm/usbdwc.c
@@ -234,14 +234,20 @@
 	int intr, ointr, chan;
 	ulong start, now;
 
+	if(waserror()){
+		chanhalt(ep, hc);
+		nexterror();
+	}
 	chan = hc - ctlr->regs->hchan;
 	for(;;){
-restart:
+	restart:
 		tsleep(&ctlr->chanintr[chan], chandone, hc, 1000);
 		if((intr = hc->hcint) == 0)
-			goto restart;
-		if(intr & Chhltd)
+			error("channel timeout");
+		if(intr & Chhltd){
+			poperror();
 			return intr;
+		}
 		ointr = intr;
 		now = start = fastticks(0);
 		do{
@@ -252,6 +258,7 @@
 				   (now - start) > 60)
 					dprint("ep%d.%d await %x after %ldµs %x -> %x\n",
 						ep->dev->nb, ep->nb, mask, now - start, ointr, intr);
+				poperror();
 				return intr;
 			}
 			if((intr & mask) == 0){
@@ -686,7 +693,7 @@
 	dprint("usbdwc: FIFO depth %d sizes rx/nptx/ptx %8.8ux %8.8ux %8.8ux\n",
 		n, r->grxfsiz, r->gnptxfsiz, r->hptxfsiz);
 
-	r->hport0 = Prtpwr|Prtconndet|Prtenchng|Prtovrcurrchng;
+	r->hport0 = Prtconndet|Prtenchng|Prtovrcurrchng;
 	r->gintsts = ~0;
 	r->gintmsk = Hcintr;
 	r->gahbcfg |= Glblintrmsk;
@@ -982,7 +989,7 @@
 	s = r->hport0;
 	b = s & (Prtconndet|Prtenchng|Prtovrcurrchng);
 	if(b != 0)
-		r->hport0 = Prtpwr | b;
+		r->hport0 = (s & Prtpwr) | b;
 	b = 0;
 	if(s & Prtconnsts)
 		b |= HPpresent;
--