Browse Source

Plan 9 from Bell Labs 2006-03-05

David du Colombier 15 years ago
parent
commit
029dfb3c98
4 changed files with 125 additions and 10 deletions
  1. 2 1
      dist/replica/_plan9.db
  2. 2 2
      dist/replica/plan9.db
  3. 3 0
      dist/replica/plan9.log
  4. 118 7
      sys/src/boot/pc/ether83815.c

+ 2 - 1
dist/replica/_plan9.db

@@ -9023,7 +9023,7 @@ sys/src/boot/pc/ether8003.c - 664 sys sys 1015007950 6446
 sys/src/boot/pc/ether8139.c - 664 sys sys 1121393459 14823
 sys/src/boot/pc/ether8169.c - 664 sys sys 1121391787 18687
 sys/src/boot/pc/ether82557.c - 664 sys sys 1140802406 19090
-sys/src/boot/pc/ether83815.c - 664 sys sys 1019537742 19576
+sys/src/boot/pc/ether83815.c - 664 sys sys 1141485864 22026
 sys/src/boot/pc/ether8390.c - 664 sys sys 1112382847 16209
 sys/src/boot/pc/ether8390.h - 664 sys sys 1015007951 1392
 sys/src/boot/pc/etherec2t.c - 664 sys sys 1015007951 3598
@@ -15612,3 +15612,4 @@ usr/glenda/lib/profile - 664 glenda glenda 1105128663 890
 usr/glenda/readme.acme - 664 glenda glenda 1019860628 4753
 usr/glenda/readme.rio - 664 glenda glenda 1019860628 6370
 usr/glenda/tmp - 20000000775 glenda glenda 1018802620 0
+386/9loaddebug - 775 sys sys 1141532057 312489

+ 2 - 2
dist/replica/plan9.db

@@ -1,6 +1,6 @@
 386 - 20000000775 sys sys 1010957353 0
 386/9load - 775 sys sys 1131317303 216948
-386/9loaddebug - 775 sys sys 1140808449 312052
+386/9loaddebug - 775 sys sys 1141532057 312489
 386/9loadlite - 775 sys sys 1131317306 135668
 386/9loadlitedebug - 775 sys sys 1140726314 200137
 386/9pc - 775 sys sys 1141258200 1909853
@@ -9023,7 +9023,7 @@ sys/src/boot/pc/ether8003.c - 664 sys sys 1015007950 6446
 sys/src/boot/pc/ether8139.c - 664 sys sys 1121393459 14823
 sys/src/boot/pc/ether8169.c - 664 sys sys 1121391787 18687
 sys/src/boot/pc/ether82557.c - 664 sys sys 1140802406 19090
-sys/src/boot/pc/ether83815.c - 664 sys sys 1019537742 19576
+sys/src/boot/pc/ether83815.c - 664 sys sys 1141485864 22026
 sys/src/boot/pc/ether8390.c - 664 sys sys 1112382847 16209
 sys/src/boot/pc/ether8390.h - 664 sys sys 1015007951 1392
 sys/src/boot/pc/etherec2t.c - 664 sys sys 1015007951 3598

+ 3 - 0
dist/replica/plan9.log

@@ -27940,3 +27940,6 @@
 1141358474 4 c sys/man/4/INDEX - 664 sys sys 1141357442 1018
 1141358474 5 c sys/man/6/INDEX - 664 sys sys 1141357442 485
 1141358474 6 c sys/man/8/INDEX - 664 sys sys 1141357442 2768
+1141480909 0 c sys/src/boot/pc/ether83815.c - 664 sys sys 1141480443 20019
+1141486310 0 c sys/src/boot/pc/ether83815.c - 664 sys sys 1141485864 22026
+1141533006 0 c 386/9loaddebug - 775 sys sys 1141532057 312489

+ 118 - 7
sys/src/boot/pc/ether83815.c

@@ -3,6 +3,7 @@
  *
  * Supports only internal PHY and has been tested on:
  *	Netgear FA311TX (using Netgear DS108 10/100 hub)
+ *	SiS 900 within SiS 630
  * To do:
  *	check Ethernet address;
  *	test autonegotiation on 10 Mbit, and 100 Mbit full duplex;
@@ -24,7 +25,7 @@
 
 #include "etherif.h"
 
-#define DEBUG		(1)
+#define DEBUG		0
 #define debug		if(DEBUG)print
 
 enum {
@@ -77,8 +78,22 @@ enum {	/* cmdsts */
 	Col =	1<<16,	/* collision during receive */
 };
 
-enum {					/* Variants */
-	Nat83815		= (0x0020<<16)|0x100B,
+enum {				/* PCI vendor & device IDs */
+	Nat83815	= (0x0020<<16)|0x100B,
+	SiS = 	0x1039,
+	SiS900 =	(0x0900<<16)|SiS,
+	SiS7016 =	(0x7016<<16)|SiS,
+
+	SiS630bridge	= 0x0008,
+
+	/* SiS 900 PCI revision codes */
+	SiSrev630s =	0x81,
+	SiSrev630e =	0x82,
+	SiSrev630ea1 =	0x83,
+
+	SiSeenodeaddr =	8,		/* short addr of SiS eeprom mac addr */
+	SiS630eenodeaddr =	9,	/* likewise for the 630 */
+	Nseenodeaddr =	6,		/* " for NS eeprom */
 };
 
 typedef struct Ctlr Ctlr;
@@ -652,6 +667,7 @@ softreset(Ctlr* ctlr, int resetphys)
 		debug("%d ms\n", i);
 		w &= 0xFFFF;
 		debug("bmsr: %4.4ux\n", w);
+		USED(w);
 	}
 	debug("anar: %4.4ux\n", csr16r(ctlr, Ranar));
 	debug("anlpar: %4.4ux\n", csr16r(ctlr, Ranlpar));
@@ -672,8 +688,83 @@ static char* mediatable[9] = {
 	"100BASE-FXFD",
 };
 
+static int
+is630(ulong id, Pcidev *p)
+{
+	if(id == SiS900)
+		switch (p->rid) {
+		case SiSrev630s:
+		case SiSrev630e:
+	  	case SiSrev630ea1:
+			return 1;
+		}
+	return 0;
+}
+
+enum {
+	MagicReg = 0x48,
+	MagicRegSz = 1,
+	Magicrden = 0x40,	/* read enable, apparently */
+	Paddr=		0x70,	/* address port */
+	Pdata=		0x71,	/* data port */
+	Pcinetctlr = 2,
+};
+
+/* rcmos() originally from LANL's SiS 900 driver's rcmos() */
+static int
+sisrdcmos(Ctlr *ctlr)
+{
+	int i;
+	unsigned reg;
+	ulong port;
+	Pcidev *p;
+
+	debug("ns83815: SiS 630 rev. %ux reading mac address from cmos\n", ctlr->pcidev->rid);
+	p = pcimatch(nil, SiS, SiS630bridge);
+	if(p == nil) {
+		print("ns83815: no SiS 630 rev. %ux bridge for mac addr\n",
+			ctlr->pcidev->rid);
+		return 0;
+	}
+	port = p->mem[0].bar & ~0x01;
+	debug("ns83815: SiS 630 rev. %ux reading mac addr from cmos via bridge at port 0x%lux\n", ctlr->pcidev->rid, port);
+
+	reg = pcicfgr8(p, MagicReg);
+	pcicfgw8(p, MagicReg, reg|Magicrden);
+
+	for (i = 0; i < Eaddrlen; i++) {
+		outb(port+Paddr, SiS630eenodeaddr + i);
+		ctlr->sromea[i] = inb(port+Pdata);
+	}
+
+	pcicfgw8(p, MagicReg, reg & ~Magicrden);
+	return 1;
+}
+
+/*
+ * If this is a SiS 630E chipset with an embedded SiS 900 controller,
+ * we have to read the MAC address from the APC CMOS RAM. - sez freebsd.
+ * However, CMOS *is* NVRAM normally.  See devrtc.c:440, memory.c:88.
+ */
 static void
-srom(Ctlr* ctlr)
+sissrom(Ctlr *ctlr)
+{
+	union {
+		uchar	eaddr[Eaddrlen];
+		ushort	alignment;
+	} ee;
+	int i, off = SiSeenodeaddr, cnt = sizeof ee.eaddr / sizeof(short);
+	ushort *shp = (ushort *)ee.eaddr;
+
+	if(!is630(ctlr->id, ctlr->pcidev) || !sisrdcmos(ctlr)) {
+		for (i = 0; i < cnt; i++)
+			*shp++ = eegetw(ctlr, off++);
+		memmove(ctlr->sromea, ee.eaddr, sizeof ctlr->sromea);
+	}
+}
+
+static void
+nssrom(Ctlr* ctlr)
 {
 	int i, j;
 
@@ -683,14 +774,31 @@ srom(Ctlr* ctlr)
 	/*
 	 * the MAC address is reversed, straddling word boundaries
 	 */
-	memset(ctlr->sromea, 0, sizeof(ctlr->sromea));
-	j = 6*16 + 15;
+	j = Nseenodeaddr*16 + 15;
 	for(i=0; i<48; i++){
 		ctlr->sromea[i>>3] |= ((ctlr->srom[j>>4] >> (15-(j&0xF))) & 1) << (i&7);
 		j++;
 	}
 }
 
+static void
+srom(Ctlr* ctlr)
+{
+	memset(ctlr->sromea, 0, sizeof(ctlr->sromea));
+	switch (ctlr->id) {
+	case SiS900:
+	case SiS7016:
+		sissrom(ctlr);
+		break;
+	case Nat83815:
+		nssrom(ctlr);
+		break;
+	default:
+		print("ns83815: srom: unknown id 0x%ux\n", ctlr->id);
+		break;
+	}
+}
+
 static void
 scanpci83815(void)
 {
@@ -706,6 +814,7 @@ scanpci83815(void)
 			continue;
 
 		case Nat83815:
+		case SiS900:
 			break;
 		}
 
@@ -734,6 +843,7 @@ ether83815reset(Ether* ether)
 {
 	Ctlr *ctlr;
 	int i, x;
+	ulong ctladdr;
 	uchar ea[Eaddrlen];
 	static int scandone;
 
@@ -772,7 +882,8 @@ ether83815reset(Ether* ether)
 		memmove(ether->ea, ctlr->sromea, Eaddrlen);
 	for(i=0; i<Eaddrlen; i+=2){
 		x = ether->ea[i] | (ether->ea[i+1]<<8);
-		csr32w(ctlr, Rrfcr, i);
+		ctladdr = (ctlr->id == Nat83815? i: i<<15);
+		csr32w(ctlr, Rrfcr, ctladdr);
 		csr32w(ctlr, Rrfdr, x);
 	}
 	csr32w(ctlr, Rrfcr, Rfen|Apm|Aab|Aam);