From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from duke.felloff.net ([216.126.196.34]) by ewsd; Fri Jun 12 14:03:00 EDT 2020 Message-ID: Date: Fri, 12 Jun 2020 20:02:49 +0200 From: cinap_lenrek@felloff.net To: 9front@9front.org Subject: Re: [9front] new nusb/serial driver In-Reply-To: <46EFE19EBB1B74CCB387820F084840C6@felloff.net> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: social overflow-preventing map/reduce method i see. we need to stop assuming that the port index is equivalent to the usb interface index. This appears to be consistent with the code in ftgettype(): ser->nifcs = 0; for(i = 0; i < Niface; i++) if(cnf->iface[i] != nil) ser->nifcs++; how about this? diff -r 307fbb6fd10a sys/src/cmd/nusb/serial/serial.c --- a/sys/src/cmd/nusb/serial/serial.c Fri Jun 12 01:36:50 2020 +0200 +++ b/sys/src/cmd/nusb/serial/serial.c Fri Jun 12 19:58:17 2020 +0200 @@ -617,19 +617,17 @@ } static int -findendpoints(Serial *ser, int ifc) +findendpoints(Serialport *p) { int i, epin, epout, epintr; Ep *ep, **eps; + Serial *ser; + ser = p->s; + if(ser->dev->usb->conf[0]->iface[p->interfc] == nil) + return -1; + eps = ser->dev->usb->conf[0]->iface[p->interfc]->ep; epintr = epin = epout = -1; - - /* - * interfc 0 means start from the start which is equiv to - * iterate through endpoints probably, could be done better - */ - eps = ser->dev->usb->conf[0]->iface[ifc]->ep; - for(i = 0; i < Nep; i++){ if((ep = eps[i]) == nil) continue; @@ -643,22 +641,22 @@ epout = ep->id; } } - dprint(2, "serial[%d]: ep ids: in %d out %d intr %d\n", ifc, epin, epout, epintr); + dprint(2, "serial[%d]: ep ids: in %d out %d intr %d\n", p->interfc, epin, epout, epintr); if(epin == -1 || epout == -1 || (ser->hasepintr && epintr == -1)) return -1; - if(openeps(&ser->p[ifc], epin, epout, epintr) < 0) + if(openeps(p, epin, epout, epintr) < 0) return -1; - dprint(2, "serial: ep in %s out %s\n", ser->p[ifc].epin->dir, ser->p[ifc].epout->dir); + dprint(2, "serial: ep in %s out %s\n", p->epin->dir, p->epout->dir); if(ser->hasepintr) - dprint(2, "serial: ep intr %s\n", ser->p[ifc].epintr->dir); + dprint(2, "serial: ep intr %s\n", p->epintr->dir); if(usbdebug > 1 || serialdebug > 2){ - devctl(ser->p[ifc].epin, "debug 1"); - devctl(ser->p[ifc].epout, "debug 1"); + devctl(p->epin, "debug 1"); + devctl(p->epout, "debug 1"); if(ser->hasepintr) - devctl(ser->p[ifc].epintr, "debug 1"); + devctl(p->epintr, "debug 1"); devctl(ser->dev, "debug 1"); } return 0; @@ -722,7 +720,7 @@ Dev *dev; char buf[50]; Serialport *p; - int i; + int i, ifc; ARGBEGIN{ case 'd': @@ -753,18 +751,23 @@ && chprobe(ser)) sysfatal("no serial devices found"); - for(i = 0; i < ser->nifcs; i++){ + i = 0; + for(ifc = 0; ifc < Niface; ifc++) { p = &ser->p[i]; + p->s = ser; p->baud = ~0; - p->interfc = i; - p->s = ser; - if(i == ser->jtag) - p->isjtag++; - if(findendpoints(ser, i) < 0) - sysfatal("no endpoints found for ifc %d", i); + p->isjtag = (i == ser->jtag); + p->interfc = ifc; + if(findendpoints(p) < 0) + continue; p->w4data = chancreate(sizeof(ulong), 0); p->gotdata = chancreate(sizeof(ulong), 0); + if(++i >= ser->nifcs) + break; } + if(i == 0) + sysfatal("no endpoints found"); + ser->nifcs = i; qlock(ser); serialreset(ser); -- cinap