Browse Source

Split devether.c into architecture-specific and portable parts.

This is a bit ugly; I'll work on getting the interface right in
the coming while.  But this splits the driver so that it can
move.

Signed-off-by: Dan Cross <cross@gajendra.net>
Dan Cross 8 years ago
parent
commit
1166b9d8fe
3 changed files with 17 additions and 95 deletions
  1. 8 67
      sys/src/9/386/devether.c
  2. 1 0
      sys/src/9/amd64/core.json
  3. 8 28
      sys/src/9/amd64/ether.c

+ 8 - 67
sys/src/9/386/devether.c

@@ -20,6 +20,9 @@
 
 static Ether *etherxx[MaxEther];
 
+extern Ether *archetherprobe(int ctlrno, char *type, int (*reset)(Ether *));
+extern void archethershutdown(Ether *ether);
+
 Chan*
 etherattach(char* spec)
 {
@@ -377,72 +380,12 @@ parseether(uint8_t *to, char *from)
 static Ether*
 etherprobe(int cardno, int ctlrno)
 {
-	int i, j;
-	Ether *ether;
-	char buf[128], name[32];
-
-	ether = malloc(sizeof(Ether));
-	memset(ether, 0, sizeof(Ether));
-	ether->ctlrno = ctlrno;
-	ether->tbdf = BUSUNKNOWN;
-	ether->Netif.mbps = 10;
-	ether->Netif.minmtu = ETHERMINTU;
-	ether->Netif.mtu = ETHERMAXTU;
-	ether->Netif.maxmtu = ETHERMAXTU;
-
-	if(cardno >= MaxEther || cards[cardno].type == nil){
-		free(ether);
+
+	if(cardno >= MaxEther)
 		return nil;
-	}
-	if(cards[cardno].reset(ether) < 0){
-		free(ether);
+	if(cards[cardno].type == nil || cards[cardno].reset == nil)
 		return nil;
-	}
-
-	/*
-	 * IRQ2 doesn't really exist, it's used to gang the interrupt
-	 * controllers together. A device set to IRQ2 will appear on
-	 * the second interrupt controller as IRQ9.
-	 */
-	if(ether->ISAConf.irq == 2)
-		ether->ISAConf.irq = 9;
-	snprint(name, sizeof(name), "ether%d", ctlrno);
-
-	/*
-	 * If ether->irq is <0, it is a hack to indicate no interrupt
-	 * used by ethersink.
-	 */
-	if(ether->ISAConf.irq >= 0)
-		intrenable(ether->ISAConf.irq, ether->interrupt, ether, ether->tbdf, name);
-
-	i = sprint(buf, "#l%d: %s: %dMbps port %#p irq %d tu %d",
-		ctlrno, cards[cardno].type, ether->Netif.mbps, ether->ISAConf.port, ether->ISAConf.irq, ether->Netif.mtu);
-	if(ether->ISAConf.mem)
-		i += sprint(buf+i, " addr %#p", ether->ISAConf.mem);
-	if(ether->ISAConf.size)
-		i += sprint(buf+i, " size 0x%lX", ether->ISAConf.size);
-	i += sprint(buf+i, ": %2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
-		ether->ea[0], ether->ea[1], ether->ea[2],
-		ether->ea[3], ether->ea[4], ether->ea[5]);
-	sprint(buf+i, "\n");
-	print(buf);
-
-	j = ether->Netif.mbps;
-	if(j > 1000)
-		j *= 10;
-	for(i = 0; j >= 100; i++)
-		j /= 10;
-	i = (128<<i)*1024;
-	netifinit(&ether->Netif, name, Ntypes, i);
-	if(ether->oq == 0)
-		ether->oq = qopen(i, Qmsg, 0, 0);
-	if(ether->oq == 0)
-		panic("etherreset %s", name);
-	ether->Netif.alen = Eaddrlen;
-	memmove(ether->Netif.addr, ether->ea, Eaddrlen);
-	memset(ether->Netif.bcast, 0xFF, Eaddrlen);
-
-	return ether;
+	return archetherprobe(ctlrno, cards[cardno].type, cards[cardno].reset);
 }
 
 static void
@@ -482,9 +425,7 @@ ethershutdown(void)
 			continue;
 		}
 		snprint(name, sizeof(name), "ether%d", i);
-		if(ether->ISAConf.irq >= 0){
-		//	intrdisable(ether->irq, ether->interrupt, ether, ether->tbdf, name);
-		}
+		archethershutdown(ether);
 		(*ether->shutdown)(ether);
 	}
 }

+ 1 - 0
sys/src/9/amd64/core.json

@@ -109,6 +109,7 @@
 			"../port/devmouse.c",
 			"../port/devpci.c",
 			"devpmc.c",
+			"ether.c",
 			"fpu.c",
 			"i8254.c",
 			"i8259.c",

+ 8 - 28
sys/src/9/amd64/ether.c

@@ -19,12 +19,14 @@
 #include "etherif.h"
 
 Ether*
-archetherprobe(int cardno, int ctlrno)
+archetherprobe(int ctlrno, char *type, int (*reset)(Ether *))
 {
 	int i, j;
 	Ether *ether;
 	char buf[128], name[32];
 
+	snprint(name, sizeof(name), "ether%d", ctlrno);
+
 	ether = malloc(sizeof(Ether));
 	memset(ether, 0, sizeof(Ether));
 	ether->ctlrno = ctlrno;
@@ -34,14 +36,8 @@ archetherprobe(int cardno, int ctlrno)
 	ether->Netif.mtu = ETHERMAXTU;
 	ether->Netif.maxmtu = ETHERMAXTU;
 
-	if(cardno >= MaxEther || cards[cardno].type == nil){
-		free(ether);
-		return nil;
-	}
-	if(cards[cardno].reset(ether) < 0){
-		free(ether);
+	if (reset(ether) < 0)
 		return nil;
-	}
 
 	/*
 	 * IRQ2 doesn't really exist, it's used to gang the interrupt
@@ -50,7 +46,6 @@ archetherprobe(int cardno, int ctlrno)
 	 */
 	if(ether->ISAConf.irq == 2)
 		ether->ISAConf.irq = 9;
-	snprint(name, sizeof(name), "ether%d", ctlrno);
 
 	/*
 	 * If ether->irq is <0, it is a hack to indicate no interrupt
@@ -60,7 +55,7 @@ archetherprobe(int cardno, int ctlrno)
 		intrenable(ether->ISAConf.irq, ether->interrupt, ether, ether->tbdf, name);
 
 	i = sprint(buf, "#l%d: %s: %dMbps port %#p irq %d tu %d",
-		ctlrno, cards[cardno].type, ether->Netif.mbps, ether->ISAConf.port, ether->ISAConf.irq, ether->Netif.mtu);
+		ctlrno, type, ether->Netif.mbps, ether->ISAConf.port, ether->ISAConf.irq, ether->Netif.mtu);
 	if(ether->ISAConf.mem)
 		i += sprint(buf+i, " addr %#p", ether->ISAConf.mem);
 	if(ether->ISAConf.size)
@@ -90,24 +85,9 @@ archetherprobe(int cardno, int ctlrno)
 }
 
 void
-archethershutdown(void)
+archethershutdown(Ether *ether)
 {
-	char name[32];
-	int i;
-	Ether *ether;
-
-	for(i = 0; i < MaxEther; i++){
-		ether = etherxx[i];
-		if(ether == nil)
-			continue;
-		if(ether->shutdown == nil) {
-			print("#l%d: no shutdown function\n", i);
-			continue;
-		}
-		snprint(name, sizeof(name), "ether%d", i);
-		if(ether->ISAConf.irq >= 0){
-		//	intrdisable(ether->irq, ether->interrupt, ether, ether->tbdf, name);
-		}
-		(*ether->shutdown)(ether);
+	if(ether->ISAConf.irq >= 0){
+	//	intrdisable(ether->irq, ether->interrupt, ether, ether->tbdf, name);
 	}
 }