9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] new nusb/serial driver
Date: Fri, 12 Jun 2020 20:02:49 +0200	[thread overview]
Message-ID: <A92891A668957E4DECC7EBDFE7070B88@felloff.net> (raw)
In-Reply-To: <46EFE19EBB1B74CCB387820F084840C6@felloff.net>

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


  parent reply	other threads:[~2020-06-12 18:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-11  7:03 Eli Cohen
2020-06-11  7:17 ` [9front] " Alex Musolino
2020-06-11  7:19   ` Eli Cohen
2020-06-11  7:29     ` Alex Musolino
2020-06-11  7:36       ` Eli Cohen
2020-06-11  7:57         ` Eli Cohen
2020-06-11 12:15           ` cinap_lenrek
2020-06-11 14:08             ` Eli Cohen
2020-06-11 17:10               ` cinap_lenrek
2020-06-12  1:28                 ` Eli Cohen
2020-06-12 18:02                 ` cinap_lenrek [this message]
2020-06-12 22:15                   ` Eli Cohen
2020-06-13 14:03                     ` cinap_lenrek
2020-06-13 14:18                       ` Eli Cohen
2020-06-13 15:37                         ` cinap_lenrek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=A92891A668957E4DECC7EBDFE7070B88@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).