shithub: riscv

Download patch

ref: da62091c0765ca8994d558f1339dad7c2223a95e
parent: f14b49f8bf736dc9cd9b3bd596d3ff2bbfd3116a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Mar 19 05:00:20 EDT 2014

pc64: port etherbcm

do not store Block* pointer in packet descriptor, assumed
pointer would fit in a long. we use pointer table now to
record the Block* pointer and store index instead.

--- a/sys/src/9/pc/etherbcm.c
+++ b/sys/src/9/pc/etherbcm.c
@@ -30,7 +30,7 @@
 	ulong *recvret, *recvprod, *sendr;
 	ulong port;
 	ulong recvreti, recvprodi, sendri, sendcleani;
-	Block **sends;
+	Block **sends, **recvs;
 	int active, duplex;
 };
 
@@ -370,21 +370,24 @@
 replenish(Ctlr *ctlr)
 {
 	ulong *next;
-	ulong incr;
+	ulong incr, idx;
 	Block *bp;
-	
-	incr = (ctlr->recvprodi + 1) & (RecvProdRingLen - 1);
+
+	idx = ctlr->recvprodi;
+	incr = (idx + 1) & (RecvProdRingLen - 1);
 	if(incr == (ctlr->status[2] >> 16)) return -1;
+	if(ctlr->recvs[idx] != 0) return -1;
 	bp = iallocb(Rbsz);
 	if(bp == nil) {
 		print("bcm: out of memory for receive buffers\n");
 		return -1;
 	}
-	next = ctlr->recvprod + ctlr->recvprodi * 8;
+	ctlr->recvs[idx] = bp;
+	next = ctlr->recvprod + idx * 8;
 	memset(next, 0, 32);
 	next[1] = PADDR(bp->rp);
 	next[2] = Rbsz;
-	next[7] = (ulong) bp;
+	next[7] = idx;
 	coherence();
 	csr32(ctlr, RecvProdBDRingIndex) = ctlr->recvprodi = incr;
 	return 0;
@@ -395,11 +398,17 @@
 {
 	Ctlr *ctlr;
 	Block *bp;
-	ulong *pkt, len;
+	ulong *pkt, len, idx;
 	
 	ctlr = edev->ctlr;
 	for(; pkt = currentrecvret(ctlr); replenish(ctlr), consumerecvret(ctlr)) {
-		bp = (Block*) pkt[7];
+		idx = pkt[7] & (RecvProdRingLen - 1);
+		bp = ctlr->recvs[idx];
+		if(bp == 0) {
+			print("bcm: nil block at %lux -- shouldn't happen\n", idx);
+			break;
+		}
+		ctlr->recvs[idx] = 0;
 		len = pkt[2] & 0xFFFF;
 		bp->wp = bp->rp + len;
 		if((pkt[3] & PacketEnd) == 0) print("bcm: partial frame received -- shouldn't happen\n");
@@ -446,7 +455,6 @@
 		}
 		bp = qget(edev->oq);
 		if(bp == nil) break;
-		setmalloctag(bp, (ulong)(void*)bcmtransmit);
 		next = ctlr->sendr + ctlr->sendri * 4;
 		next[0] = 0;
 		next[1] = PADDR(bp->rp);
@@ -792,8 +800,11 @@
 			continue;
 		}
 		ctlr->sends = malloc(sizeof(ctlr->sends[0]) * SendRingLen);
-		if(ctlr->sends == nil){
-			print("bcm: unable to alloc ctlr->sends\n");
+		ctlr->recvs = malloc(sizeof(ctlr->recvs[0]) * RecvProdRingLen);
+		if(ctlr->sends == nil || ctlr->recvs == nil){
+			print("bcm: unable to alloc ctlr->sends and ctlr->recvs\n");
+			free(ctlr->sends);
+			free(ctlr->recvs);
 			free(ctlr);
 			continue;
 		}
--- a/sys/src/9/pc64/pc64
+++ b/sys/src/9/pc64/pc64
@@ -54,7 +54,7 @@
 	ether82563	pci
 #	ether82598	pci
 #	ether83815	pci
-#	etherbcm        pci
+	etherbcm        pci
 #	etherdp83820	pci
 #	etherec2t	ether8390
 #	etherelnk3	pci