From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com ([209.85.222.181]) by ewsd; Fri Jun 12 18:15:51 EDT 2020 Received: by mail-qk1-f181.google.com with SMTP id b27so10510112qka.4 for <9front@9front.org>; Fri, 12 Jun 2020 15:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=LMbD2YzPsZAyQ2wMHcbyOsNN0md1G1jXH6VcwbHGEBk=; b=ssVYOCz+5Gre+dX+ErfOC10/RPqGgF1rC/Q/B0DHfx9Qsm5sSdo8Okd+lvUG+htWwR ZpbbJc5HrkF62z83AQHez7+LqMnd6jxfmpNpqP1nF0VLiComSb5INpqFitT0DTn4Siih Qp63xaZYIWoEMXxqzrhp9sgmDFEEFZj+AWAbStN0USD3VwV7b0rVADYqsJzy7OJrSaDC Pkjtd2lZ0U6dgSE3Dx2a4pjT+ChR+moRWgZXYbTDYJtl37yUv/d5BCtc6Yav37aliotd xn3HqaGDgeCbMDj3PqR/80yFmQJkGnVA5evL6RclEs6txf4WClFJizoAekCv7Vv/WzBc 5R4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=LMbD2YzPsZAyQ2wMHcbyOsNN0md1G1jXH6VcwbHGEBk=; b=Yu4elZIxIR2Q91TIIJZGRoqrbpbDUJ8QNNRPTc2I5W2A9Yg6ZRDAXQU7gLZzUjWWnh yufii8OImhPa1L7EkU3yeqJFcy3UTyBRT8fCegaYOlcxTsC+5oeJsJX+gFynDopqSWeH WDDgydhC6rGb2pAgifIuREtYmCPt6bB/ddTmeSXbhd6S41/gEnfLKjPf3v9CscvM7m9/ QegXd4ggVu9DKUl9emBpkksnK5tNae6Fca6QQ6LFWVC+m3d0gm1gev794c5Go27V4ntf e9VhAXyvX+aRc6hLq08dllRFVX/vCeMe8NbC8jxXEcblIQYmHFm9pLNcTleYdScHfcVS VOEA== X-Gm-Message-State: AOAM530YUfe6nCRydcvHlop9JJT9ynQqFG32pmwN4FzsS2OEmJi4JEgm g1fuseQyJemQdAlZbZqzJybImx5HC61KehWwOKWDvu1y X-Google-Smtp-Source: ABdhPJyXxUMMJwM/qGmCsE5GRjkwu/0GbZfB2BYOFQA/hhUD19yJ4HocgXtmzXnDUBvFqHuTqd2IvhFIadZeJ15NE9c= X-Received: by 2002:a05:620a:122e:: with SMTP id v14mr5283903qkj.94.1592000147930; Fri, 12 Jun 2020 15:15:47 -0700 (PDT) MIME-Version: 1.0 References: <46EFE19EBB1B74CCB387820F084840C6@felloff.net> In-Reply-To: From: Eli Cohen Date: Fri, 12 Jun 2020 15:15:36 -0700 Message-ID: Subject: Re: [9front] new nusb/serial driver To: 9front@9front.org Content-Type: text/plain; charset="UTF-8" List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: flexible compliant session framework I think you need to preserve the indices epintr, epin, and epout in findendpoints. The way it was working, on the first call it would find epintr, then epin and epout were on a difference USB iface. between multiple calls epintr would get reset to -1. On Fri, Jun 12, 2020 at 11:03 AM wrote: > > 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