Browse Source

Plan 9 from Bell Labs 2009-01-23

David du Colombier 15 years ago
parent
commit
29c7f604e7

+ 7 - 7
sys/src/9/pc/ether82543gc.c

@@ -506,7 +506,7 @@ gc82543ifstat(Ether* edev, void* a, long n, ulong offset)
 
 	ctlr = edev->ctlr;
 	lock(&ctlr->slock);
-	p = malloc(2*READSTR);
+	p = malloc(READSTR);
 	l = 0;
 	for(i = 0; i < Nstatistics; i++){
 		r = csr32r(ctlr, Statistics+i*4);
@@ -526,7 +526,7 @@ gc82543ifstat(Ether* edev, void* a, long n, ulong offset)
 				continue;
 			ctlr->statistics[i] = tuvl;
 			ctlr->statistics[i+1] = tuvl>>32;
-			l += snprint(p+l, 2*READSTR-l, "%s: %llud %llud\n",
+			l += snprint(p+l, READSTR-l, "%s: %llud %llud\n",
 				s, tuvl, ruvl);
 			i++;
 			break;
@@ -535,20 +535,20 @@ gc82543ifstat(Ether* edev, void* a, long n, ulong offset)
 			ctlr->statistics[i] += r;
 			if(ctlr->statistics[i] == 0)
 				continue;
-			l += snprint(p+l, 2*READSTR-l, "%s: %ud %ud\n",
+			l += snprint(p+l, READSTR-l, "%s: %ud %ud\n",
 				s, ctlr->statistics[i], r);
 			break;
 		}
 	}
 
-	l += snprint(p+l, 2*READSTR-l, "eeprom:");
+	l += snprint(p+l, READSTR-l, "eeprom:");
 	for(i = 0; i < 0x40; i++){
 		if(i && ((i & 0x07) == 0))
-			l += snprint(p+l, 2*READSTR-l, "\n       ");
-		l += snprint(p+l, 2*READSTR-l, " %4.4uX", ctlr->eeprom[i]);
+			l += snprint(p+l, READSTR-l, "\n       ");
+		l += snprint(p+l, READSTR-l, " %4.4uX", ctlr->eeprom[i]);
 	}
 
-	snprint(p+l, 2*READSTR-l, "\ntxstalled %d\n", ctlr->txstalled);
+	snprint(p+l, READSTR-l, "\ntxstalled %d\n", ctlr->txstalled);
 	n = readstr(offset, a, n, p);
 	free(p);
 	unlock(&ctlr->slock);

+ 17 - 4
sys/src/9/pc/ether82563.c

@@ -412,7 +412,7 @@ enum {
 enum {
 	Nrd		= 256,		/* power of two */
 	Ntd		= 128,		/* power of two */
-	Nrb		= 512,		/* private receive buffers per Ctlr */
+	Nrb		= 1024,		/* private receive buffers per Ctlr */
 };
 
 enum {
@@ -450,6 +450,7 @@ struct Ctlr {
 	int	port;
 	Pcidev	*pcidev;
 	Ctlr	*next;
+	Ether	*edev;
 	int	active;
 	int	type;
 	ushort	eeprom[0x40];
@@ -603,8 +604,8 @@ i82563ifstat(Ether* edev, void* a, long n, ulong offset)
 
 	ctlr = edev->ctlr;
 	qlock(&ctlr->slock);
-	p = s = malloc(2*READSTR);
-	e = p + 2*READSTR;
+	p = s = malloc(READSTR);
+	e = p + READSTR;
 
 	for(i = 0; i < Nstatistics; i++){
 		r = csr32r(ctlr, Statistics + i*4);
@@ -924,7 +925,15 @@ i82563replenish(Ctlr* ctlr)
 		}
 		bp = i82563rballoc();
 		if(bp == nil){
-			iprint("82563: no available buffers\n");
+			vlong now;
+			static vlong lasttime;
+
+			/* don't flood the console */
+			now = tk2ms(MACHP(0)->ticks);
+			if (now - lasttime > 2000)
+				iprint("#l%d: 82563: all %d rx buffers in use\n",
+					ctlr->edev->ctlrno, ctlr->nrb);
+			lasttime = now;
 			break;
 		}
 		ctlr->rb[rdt] = bp;
@@ -1213,6 +1222,7 @@ i82563attach(Ether* edev)
 	char name[KNAMELEN];
 
 	ctlr = edev->ctlr;
+	ctlr->edev = edev;			/* point back to Ether* */
 	qlock(&ctlr->alock);
 	if(ctlr->attached){
 		qunlock(&ctlr->alock);
@@ -1536,6 +1546,9 @@ i82563reset(Ctlr *ctlr)
 	csr32w(ctlr, Fct, 0x8808);
 	csr32w(ctlr, Fcttv, 0x0100);
 
+	ctlr->fcrtl = ctlr->fcrth = 0;
+	// ctlr->fcrtl = 0x00002000;
+	// ctlr->fcrth = 0x00004000;
 	csr32w(ctlr, Fcrtl, ctlr->fcrtl);
 	csr32w(ctlr, Fcrth, ctlr->fcrth);
 

+ 2 - 2
sys/src/9/pc/ether82598.c

@@ -337,8 +337,8 @@ ifstat(Ether *e, void *a, long n, ulong offset)
 	Ctlr *c;
 
 	c = e->ctlr;
-	p = s = malloc(2*READSTR);
-	q = p + 2*READSTR;
+	p = s = malloc(READSTR);
+	q = p + READSTR;
 
 	readstats(c);
 	for(i = 0; i < nelem(stattab); i++)

+ 17 - 17
sys/src/9/pc/etherigbe.c

@@ -598,7 +598,7 @@ igbeifstat(Ether* edev, void* a, long n, ulong offset)
 
 	ctlr = edev->ctlr;
 	qlock(&ctlr->slock);
-	p = malloc(2*READSTR);
+	p = malloc(READSTR);
 	l = 0;
 	for(i = 0; i < Nstatistics; i++){
 		r = csr32r(ctlr, Statistics+i*4);
@@ -618,7 +618,7 @@ igbeifstat(Ether* edev, void* a, long n, ulong offset)
 				continue;
 			ctlr->statistics[i] = tuvl;
 			ctlr->statistics[i+1] = tuvl>>32;
-			l += snprint(p+l, 2*READSTR-l, "%s: %llud %llud\n",
+			l += snprint(p+l, READSTR-l, "%s: %llud %llud\n",
 				s, tuvl, ruvl);
 			i++;
 			break;
@@ -627,40 +627,40 @@ igbeifstat(Ether* edev, void* a, long n, ulong offset)
 			ctlr->statistics[i] += r;
 			if(ctlr->statistics[i] == 0)
 				continue;
-			l += snprint(p+l, 2*READSTR-l, "%s: %ud %ud\n",
+			l += snprint(p+l, READSTR-l, "%s: %ud %ud\n",
 				s, ctlr->statistics[i], r);
 			break;
 		}
 	}
 
-	l += snprint(p+l, 2*READSTR-l, "lintr: %ud %ud\n",
+	l += snprint(p+l, READSTR-l, "lintr: %ud %ud\n",
 		ctlr->lintr, ctlr->lsleep);
-	l += snprint(p+l, 2*READSTR-l, "rintr: %ud %ud\n",
+	l += snprint(p+l, READSTR-l, "rintr: %ud %ud\n",
 		ctlr->rintr, ctlr->rsleep);
-	l += snprint(p+l, 2*READSTR-l, "tintr: %ud %ud\n",
+	l += snprint(p+l, READSTR-l, "tintr: %ud %ud\n",
 		ctlr->tintr, ctlr->txdw);
-	l += snprint(p+l, 2*READSTR-l, "ixcs: %ud %ud %ud\n",
+	l += snprint(p+l, READSTR-l, "ixcs: %ud %ud %ud\n",
 		ctlr->ixsm, ctlr->ipcs, ctlr->tcpcs);
-	l += snprint(p+l, 2*READSTR-l, "rdtr: %ud\n", ctlr->rdtr);
-	l += snprint(p+l, 2*READSTR-l, "Ctrlext: %08x\n", csr32r(ctlr, Ctrlext));
+	l += snprint(p+l, READSTR-l, "rdtr: %ud\n", ctlr->rdtr);
+	l += snprint(p+l, READSTR-l, "Ctrlext: %08x\n", csr32r(ctlr, Ctrlext));
 
-	l += snprint(p+l, 2*READSTR-l, "eeprom:");
+	l += snprint(p+l, READSTR-l, "eeprom:");
 	for(i = 0; i < 0x40; i++){
 		if(i && ((i & 0x07) == 0))
-			l += snprint(p+l, 2*READSTR-l, "\n       ");
-		l += snprint(p+l, 2*READSTR-l, " %4.4uX", ctlr->eeprom[i]);
+			l += snprint(p+l, READSTR-l, "\n       ");
+		l += snprint(p+l, READSTR-l, " %4.4uX", ctlr->eeprom[i]);
 	}
-	l += snprint(p+l, 2*READSTR-l, "\n");
+	l += snprint(p+l, READSTR-l, "\n");
 
 	if(ctlr->mii != nil && ctlr->mii->curphy != nil){
-		l += snprint(p+l, 2*READSTR, "phy:   ");
+		l += snprint(p+l, READSTR, "phy:   ");
 		for(i = 0; i < NMiiPhyr; i++){
 			if(i && ((i & 0x07) == 0))
-				l += snprint(p+l, 2*READSTR-l, "\n       ");
+				l += snprint(p+l, READSTR-l, "\n       ");
 			r = miimir(ctlr->mii, i);
-			l += snprint(p+l, 2*READSTR-l, " %4.4uX", r);
+			l += snprint(p+l, READSTR-l, " %4.4uX", r);
 		}
-		snprint(p+l, 2*READSTR-l, "\n");
+		snprint(p+l, READSTR-l, "\n");
 	}
 	n = readstr(offset, a, n, p);
 	free(p);

+ 3 - 4
sys/src/9/pc/etherm10g.c

@@ -1368,20 +1368,19 @@ lstcount(Block *b)
 static long
 m10gifstat(Ether *e, void *v, long n, ulong off)
 {
-	int l, lim;
+	int l;
 	char *p;
 	Ctlr *c;
 	Stats s;
 
 	c = e->ctlr;
-	lim = 2*READSTR-1;
-	p = malloc(lim+1);
+	p = malloc(READSTR+1);
 	l = 0;
 	/* no point in locking this because this is done via dma. */
 	memmove(&s, c->stats, sizeof s);
 
 	// l +=
-	snprint(p+l, lim,
+	snprint(p+l, READSTR,
 		"txcnt = %lud\n"  "linkstat = %lud\n" 	"dlink = %lud\n"
 		"derror = %lud\n" "drunt = %lud\n" 	"doverrun = %lud\n"
 		"dnosm = %lud\n"  "dnobg = %lud\n"	"nrdma = %lud\n"

+ 6 - 6
sys/src/9/pc/ethervgbe.c

@@ -401,13 +401,13 @@ vgbeifstat(Ether* edev, void* a, long n, ulong offset)
 
 	ctlr = edev->ctlr;
 
-	p = malloc(2*READSTR);
+	p = malloc(READSTR);
 	l = 0;
-	l += snprint(p+l, 2*READSTR-l, "tx: %uld\n", ctlr->stats.tx);
-	l += snprint(p+l, 2*READSTR-l, "tx [errs]: %uld\n", ctlr->stats.txe);
-	l += snprint(p+l, 2*READSTR-l, "rx: %uld\n", ctlr->stats.rx);
-	l += snprint(p+l, 2*READSTR-l, "intr: %uld\n", ctlr->stats.intr);
-	snprint(p+l, 2*READSTR-l, "\n");
+	l += snprint(p+l, READSTR-l, "tx: %uld\n", ctlr->stats.tx);
+	l += snprint(p+l, READSTR-l, "tx [errs]: %uld\n", ctlr->stats.txe);
+	l += snprint(p+l, READSTR-l, "rx: %uld\n", ctlr->stats.rx);
+	l += snprint(p+l, READSTR-l, "intr: %uld\n", ctlr->stats.intr);
+	snprint(p+l, READSTR-l, "\n");
 
 	n = readstr(offset, a, n, p);
 	free(p);

+ 19 - 19
sys/src/9/pc/ethervt6102.c

@@ -346,41 +346,41 @@ vt6102ifstat(Ether* edev, void* a, long n, ulong offset)
 
 	ctlr = edev->ctlr;
 
-	p = malloc(2*READSTR);
+	p = malloc(READSTR);
 	l = 0;
 	for(i = 0; i < Nrxstats; i++){
-		l += snprint(p+l, 2*READSTR-l, "%s: %ud\n",
+		l += snprint(p+l, READSTR-l, "%s: %ud\n",
 			rxstats[i], ctlr->rxstats[i]);
 	}
 	for(i = 0; i < Ntxstats; i++){
 		if(txstats[i] == nil)
 			continue;
-		l += snprint(p+l, 2*READSTR-l, "%s: %ud\n",
+		l += snprint(p+l, READSTR-l, "%s: %ud\n",
 			txstats[i], ctlr->txstats[i]);
 	}
-	l += snprint(p+l, 2*READSTR-l, "cls: %ud\n", ctlr->cls);
-	l += snprint(p+l, 2*READSTR-l, "intr: %ud\n", ctlr->intr);
-	l += snprint(p+l, 2*READSTR-l, "lintr: %ud\n", ctlr->lintr);
-	l += snprint(p+l, 2*READSTR-l, "lsleep: %ud\n", ctlr->lsleep);
-	l += snprint(p+l, 2*READSTR-l, "rintr: %ud\n", ctlr->rintr);
-	l += snprint(p+l, 2*READSTR-l, "tintr: %ud\n", ctlr->tintr);
-	l += snprint(p+l, 2*READSTR-l, "taligned: %ud\n", ctlr->taligned);
-	l += snprint(p+l, 2*READSTR-l, "tsplit: %ud\n", ctlr->tsplit);
-	l += snprint(p+l, 2*READSTR-l, "tcopied: %ud\n", ctlr->tcopied);
-	l += snprint(p+l, 2*READSTR-l, "txdw: %ud\n", ctlr->txdw);
-	l += snprint(p+l, 2*READSTR-l, "tft: %ud\n", ctlr->tft);
+	l += snprint(p+l, READSTR-l, "cls: %ud\n", ctlr->cls);
+	l += snprint(p+l, READSTR-l, "intr: %ud\n", ctlr->intr);
+	l += snprint(p+l, READSTR-l, "lintr: %ud\n", ctlr->lintr);
+	l += snprint(p+l, READSTR-l, "lsleep: %ud\n", ctlr->lsleep);
+	l += snprint(p+l, READSTR-l, "rintr: %ud\n", ctlr->rintr);
+	l += snprint(p+l, READSTR-l, "tintr: %ud\n", ctlr->tintr);
+	l += snprint(p+l, READSTR-l, "taligned: %ud\n", ctlr->taligned);
+	l += snprint(p+l, READSTR-l, "tsplit: %ud\n", ctlr->tsplit);
+	l += snprint(p+l, READSTR-l, "tcopied: %ud\n", ctlr->tcopied);
+	l += snprint(p+l, READSTR-l, "txdw: %ud\n", ctlr->txdw);
+	l += snprint(p+l, READSTR-l, "tft: %ud\n", ctlr->tft);
 
 	if(ctlr->mii != nil && ctlr->mii->curphy != nil){
-		l += snprint(p+l, 2*READSTR, "phy:   ");
+		l += snprint(p+l, READSTR, "phy:   ");
 		for(i = 0; i < NMiiPhyr; i++){
 			if(i && ((i & 0x07) == 0))
-				l += snprint(p+l, 2*READSTR-l, "\n       ");
+				l += snprint(p+l, READSTR-l, "\n       ");
 			r = miimir(ctlr->mii, i);
-			l += snprint(p+l, 2*READSTR-l, " %4.4uX", r);
+			l += snprint(p+l, READSTR-l, " %4.4uX", r);
 		}
-		snprint(p+l, 2*READSTR-l, "\n");
+		snprint(p+l, READSTR-l, "\n");
 	}
-	snprint(p+l, 2*READSTR-l, "\n");
+	snprint(p+l, READSTR-l, "\n");
 
 	n = readstr(offset, a, n, p);
 	free(p);

+ 2 - 2
sys/src/9/pc/ethervt6105m.c

@@ -440,9 +440,9 @@ vt6105Mifstat(Ether* edev, void* a, long n, ulong offset)
 
 	ctlr = edev->ctlr;
 
-	alloc = malloc(2*READSTR);
+	alloc = malloc(READSTR);
 	p = alloc;
-	e = p + 2*READSTR;
+	e = p + READSTR;
 	for(i = 0; i < Nrxstats; i++){
 		p = seprint(p, e, "%s: %ud\n", rxstats[i], ctlr->rxstats[i]);
 	}

+ 17 - 33
sys/src/9/port/devwd.c

@@ -1,3 +1,6 @@
+/*
+ * watchdog framework
+ */
 #include	"u.h"
 #include	"../port/lib.h"
 #include	"mem.h"
@@ -62,8 +65,8 @@ wdclose(Chan*)
 static long
 wdread(Chan* c, void* a, long n, vlong off)
 {
-	char *p;
 	ulong offset = off;
+	char *p;
 
 	switch((ulong)c->qid.path){
 	case Qdir:
@@ -81,8 +84,8 @@ wdread(Chan* c, void* a, long n, vlong off)
 
 		wd->stat(p, p + READSTR);
 		n = readstr(offset, a, n, p);
-		poperror();
 		free(p);
+		poperror();
 		return n;
 
 	default:
@@ -92,31 +95,11 @@ wdread(Chan* c, void* a, long n, vlong off)
 	return 0;
 }
 
-static void
-wdctl(char *a)
-{
-	int n;
-	char *field[6];
-
-	n = tokenize(a, field, nelem(field));
-	if(n < 1)
-		error(Ebadarg);
-
-	if(!strcmp(field[0], "enable"))
-		wd->enable();
-	else if(!strcmp(field[0], "disable"))
-		wd->disable();
-	else if(!strcmp(field[0], "restart"))
-		wd->restart();
-	else
-		error(Ebadarg);
-}
-
 static long
 wdwrite(Chan* c, void* a, long n, vlong off)
 {
-	char *p;
 	ulong offset = off;
+	char *p;
 
 	switch((ulong)c->qid.path){
 	case Qdir:
@@ -129,16 +112,17 @@ wdwrite(Chan* c, void* a, long n, vlong off)
 		if(offset || n >= READSTR)
 			error(Ebadarg);
 
-		p = malloc(READSTR);
-		if(waserror()){
-			free(p);
-			nexterror();
-		}
-		memmove(p, a, n);
-		p[n] = 0;
-		wdctl(p);
-		poperror();
-		free(p);
+		if((p = strchr(a, '\n')) != nil)
+			*p = 0;
+
+		if(strncmp(a, "enable", n) == 0)
+			wd->enable();
+		else if(strncmp(a, "disable", n) == 0)
+			wd->disable();
+		else if(strncmp(a, "restart", n) == 0)
+			wd->restart();
+		else
+			error(Ebadarg);
 		return n;
 
 	default:

+ 2 - 1
sys/src/9/port/portdat.h

@@ -753,7 +753,8 @@ enum
 	MAXCRYPT = 	127,
 	NUMSIZE	=	12,		/* size of formatted number */
 	MB =		(1024*1024),
-	READSTR =	1000,		/* temporary buffer size for device reads */
+	/* READSTR was 1000, which is way too small for usb's ctl file */
+	READSTR =	4000,		/* temporary buffer size for device reads */
 };
 
 extern	Conf	conf;

+ 16 - 16
sys/src/9/ppc/etherfcc.c

@@ -466,34 +466,34 @@ ifstat(Ether* ether, void* a, long n, ulong offset)
 
 	ctlr = ether->ctlr;
 
-	p = malloc(2*READSTR);
-	len = snprint(p, 2*READSTR, "interrupts: %lud\n", ctlr->interrupts);
-	len += snprint(p+len, 2*READSTR-len, "carrierlost: %lud\n", ctlr->carrierlost);
-	len += snprint(p+len, 2*READSTR-len, "heartbeat: %lud\n", ctlr->heartbeat);
-	len += snprint(p+len, 2*READSTR-len, "retrylimit: %lud\n", ctlr->retrylim);
-	len += snprint(p+len, 2*READSTR-len, "retrycount: %lud\n", ctlr->retrycount);
-	len += snprint(p+len, 2*READSTR-len, "latecollisions: %lud\n", ctlr->latecoll);
-	len += snprint(p+len, 2*READSTR-len, "rxoverruns: %lud\n", ctlr->overrun);
-	len += snprint(p+len, 2*READSTR-len, "txunderruns: %lud\n", ctlr->underrun);
-	len += snprint(p+len, 2*READSTR-len, "framesdeferred: %lud\n", ctlr->deferred);
+	p = malloc(READSTR);
+	len = snprint(p, READSTR, "interrupts: %lud\n", ctlr->interrupts);
+	len += snprint(p+len, READSTR-len, "carrierlost: %lud\n", ctlr->carrierlost);
+	len += snprint(p+len, READSTR-len, "heartbeat: %lud\n", ctlr->heartbeat);
+	len += snprint(p+len, READSTR-len, "retrylimit: %lud\n", ctlr->retrylim);
+	len += snprint(p+len, READSTR-len, "retrycount: %lud\n", ctlr->retrycount);
+	len += snprint(p+len, READSTR-len, "latecollisions: %lud\n", ctlr->latecoll);
+	len += snprint(p+len, READSTR-len, "rxoverruns: %lud\n", ctlr->overrun);
+	len += snprint(p+len, READSTR-len, "txunderruns: %lud\n", ctlr->underrun);
+	len += snprint(p+len, READSTR-len, "framesdeferred: %lud\n", ctlr->deferred);
 	miistatus(ctlr->mii);
 	phy = ctlr->mii->curphy;
-	len += snprint(p+len, 2*READSTR-len, "phy: link=%d, tfc=%d, rfc=%d, speed=%d, fd=%d\n",
+	len += snprint(p+len, READSTR-len, "phy: link=%d, tfc=%d, rfc=%d, speed=%d, fd=%d\n",
 		phy->link, phy->tfc, phy->rfc, phy->speed, phy->fd);
 
 #ifdef DBG
 	if(ctlr->mii != nil && ctlr->mii->curphy != nil){
-		len += snprint(p+len, 2*READSTR, "phy:   ");
+		len += snprint(p+len, READSTR, "phy:   ");
 		for(i = 0; i < NMiiPhyr; i++){
 			if(i && ((i & 0x07) == 0))
-				len += snprint(p+len, 2*READSTR-len, "\n       ");
+				len += snprint(p+len, READSTR-len, "\n       ");
 			r = miimir(ctlr->mii, i);
-			len += snprint(p+len, 2*READSTR-len, " %4.4uX", r);
+			len += snprint(p+len, READSTR-len, " %4.4uX", r);
 		}
-		snprint(p+len, 2*READSTR-len, "\n");
+		snprint(p+len, READSTR-len, "\n");
 	}
 #endif
-	snprint(p+len, 2*READSTR-len, "\n");
+	snprint(p+len, READSTR-len, "\n");
 
 	n = readstr(offset, a, n, p);
 	free(p);