plan 9 kernel history: overview | file list | diff list

1999/0608/mpc/devether.c (diff list | history)

1999/0508/sys/src/9/mpc/devether.c:12,191999/0608/sys/src/9/mpc/devether.c:12,17 (short | long | prev | next)
1999/0121    
 
static Ether *etherxx[MaxEther]; 
 
void ethermediumlink(void); 
                 
Chan* 
etherattach(char* spec) 
{ 
1999/0508/sys/src/9/mpc/devether.c:37,551999/0608/sys/src/9/mpc/devether.c:35,40
1999/0121    
	return chan; 
} 
 
static void 
etherdetach(void) 
{ 
	Ether **ether; 
                 
	ether = etherxx; 
	while(*ether){ 
		if((*ether)->detach) 
			(*ether)->detach(*ether); 
		ether++; 
	} 
} 
                 
static int 
etherwalk(Chan* chan, char* name) 
{ 
1999/0508/sys/src/9/mpc/devether.c:76,931999/0608/sys/src/9/mpc/devether.c:61,74
1999/0121    
static void 
etherclose(Chan* chan) 
{ 
	Ether *ether; 
                 
	ether = etherxx[chan->dev]; 
	netifclose(ether, chan); 
	if(ether->closed) 
		ether->closed(ether); 
1999/0608    
	netifclose(etherxx[chan->dev], chan); 
1999/0121    
} 
 
static long 
etherread(Chan* chan, void* buf, long n, vlong offset) 
1999/0608    
etherread(Chan* chan, void* buf, long n, vlong off) 
1999/0121    
{ 
	Ether *ether; 
1999/0608    
	ulong offset = off; 
1999/0121    
 
	ether = etherxx[chan->dev]; 
	if((chan->qid.path & CHDIR) == 0 && ether->ifstat){ 
1999/0508/sys/src/9/mpc/devether.c:153,1591999/0608/sys/src/9/mpc/devether.c:134,140
1999/0121    
{ 
	Etherpkt *pkt; 
	ushort type; 
	int len; 
1999/0608    
	int len, multi, forme; 
1999/0121    
	Netfile **ep, *f, **fp, *fx; 
	Block *xbp; 
 
1999/0508/sys/src/9/mpc/devether.c:165,1721999/0608/sys/src/9/mpc/devether.c:146,154
1999/0121    
	fx = 0; 
	ep = ðer->f[Ntypes]; 
 
1999/0608    
	multi = pkt->d[0] & 1; 
1999/0121    
	/* check for valid multcast addresses */ 
	if((pkt->d[0] & 1) && memcmp(pkt->d, ether->bcast, sizeof(pkt->d)) != 0 && ether->prom == 0){ 
1999/0608    
	if(multi && memcmp(pkt->d, ether->bcast, sizeof(pkt->d)) && ether->prom == 0){ 
1999/0121    
		if(!activemulti(ether, pkt->d, sizeof(pkt->d))){ 
			if(freebp){ 
				freeb(bp); 
1999/0508/sys/src/9/mpc/devether.c:176,1811999/0608/sys/src/9/mpc/devether.c:158,166
1999/0121    
		} 
	} 
 
1999/0608    
	// is it for me? 
	forme = memcmp(pkt->d, ether->ea, sizeof(pkt->d)) == 0; 
 
1999/0121    
	/* 
	 * Multiplex the packet to all the connections which want it. 
	 * If the packet is not to be used subsequently (freebp != 0), 
1999/0508/sys/src/9/mpc/devether.c:183,1891999/0608/sys/src/9/mpc/devether.c:168,174
1999/0121    
	 * saving a copy of the data (usual case hopefully). 
	 */ 
	for(fp = ether->f; fp < ep; fp++){ 
		if((f = *fp) && (f->type == type || f->type < 0)){ 
1999/0608    
		if((f = *fp) && (f->type == type || f->type < 0) && (forme || multi || f->prom)){ 
1999/0121    
			if(f->type > -2){ 
				if(freebp && fx == 0) 
					fx = f; 
1999/0508/sys/src/9/mpc/devether.c:201,2071999/0608/sys/src/9/mpc/devether.c:186,193
1999/0121    
	} 
 
	if(fx){ 
		qpass(fx->in, bp); 
1999/0608    
		if(qpass(fx->in, bp) < 0) 
			ether->soverflows++; 
1999/0121    
		return 0; 
	} 
	if(freebp){ 
1999/0508/sys/src/9/mpc/devether.c:215,2211999/0608/sys/src/9/mpc/devether.c:201,207
1999/0121    
static int 
etheroq(Ether* ether, Block* bp) 
{ 
	int len, loopback, s; 
1999/0608    
	int len, loopback, s, mine; 
1999/0121    
	Etherpkt *pkt; 
 
	ether->outpackets++; 
1999/0508/sys/src/9/mpc/devether.c:226,2351999/0608/sys/src/9/mpc/devether.c:212,225
1999/0121    
	 * in promiscuous mode. 
	 * If it's a loopback packet indicate to etheriq that the data isn't 
	 * needed and return, etheriq will pass-on or free the block. 
1999/0608    
	 * To enable bridging to work, only packets that were originated 
	 * by this interface are fed back. 
1999/0121    
	 */ 
	pkt = (Etherpkt*)bp->rp; 
	len = BLEN(bp); 
	loopback = (memcmp(pkt->d, ether->ea, sizeof(pkt->d)) == 0); 
1999/0608    
	mine = memcmp(pkt->s, ether->ea, sizeof(pkt->s)) == 0; 
	if(mine) 
1999/0121    
	if(loopback || memcmp(pkt->d, ether->bcast, sizeof(pkt->d)) == 0 || ether->prom){ 
		s = splhi(); 
		etheriq(ether, bp, loopback); 
1999/0508/sys/src/9/mpc/devether.c:256,2631999/0608/sys/src/9/mpc/devether.c:246,253
1999/0121    
 
	if(n > ETHERMAXTU) 
		error(Etoobig); 
//	if(n < ETHERMINTU) 
//		error(Etoosmall); 
1999/0608    
	if(n < ETHERMINTU) 
		error(Etoosmall); 
1999/0121    
 
	bp = allocb(n); 
	if(waserror()){ 
1999/0508/sys/src/9/mpc/devether.c:279,2851999/0608/sys/src/9/mpc/devether.c:269,274
1999/0121    
	long n; 
 
	n = BLEN(bp); 
                 
	ether = etherxx[chan->dev]; 
	if(NETTYPE(chan->qid.path) != Ndataqid){ 
		n = netifwrite(ether, chan, bp->rp, n); 
1999/0508/sys/src/9/mpc/devether.c:291,2961999/0608/sys/src/9/mpc/devether.c:280,289
1999/0121    
		freeb(bp); 
		error(Ebadarg); 
	} 
1999/0608    
	if(n < ETHERMINTU){ 
		freeb(bp); 
		error(Etoosmall); 
	} 
1999/0121    
 
	return etheroq(ether, bp); 
} 
1999/0508/sys/src/9/mpc/devether.c:304,3101999/0608/sys/src/9/mpc/devether.c:297,303
1999/0121    
addethercard(char* t, int (*r)(Ether*)) 
{ 
	static int ncard; 
1999/0508    
print("addethercard\n"); 
1999/0608    
 
1999/0121    
	if(ncard == MaxEther) 
		panic("too many ether cards"); 
	cards[ncard].type = t; 
1999/0508/sys/src/9/mpc/devether.c:342,3491999/0608/sys/src/9/mpc/devether.c:335,340
1999/0121    
	int i, n, ctlrno; 
	char name[NAMELEN], buf[128]; 
 
1999/0508    
print("etherreset\n"); 
1999/0121    
	//ethermediumlink(); 
	for(ether = 0, ctlrno = 0; ctlrno < MaxEther; ctlrno++){ 
		if(ether == 0) 
			ether = malloc(sizeof(Ether)); 
1999/0508/sys/src/9/mpc/devether.c:353,3611999/0608/sys/src/9/mpc/devether.c:344,350
1999/0121    
		ether->mbps = 10; 
		if(isaconfig("ether", ctlrno, ether) == 0) 
			continue; 
1999/0508    
print("after isaconfig %d\n", n); 
1999/0121    
		for(n = 0; cards[n].type; n++){ 
1999/0508    
print("card %d\n", n); 
1999/0121    
			if(cistrcmp(cards[n].type, ether->type)) 
				continue; 
			for(i = 0; i < ether->nopt; i++){ 
1999/0508/sys/src/9/mpc/devether.c:367,3751999/0608/sys/src/9/mpc/devether.c:356,371
1999/0121    
			if(cards[n].reset(ether)) 
				break; 
 
1999/0608    
			/* 
			 * 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->irq == 2) 
				ether->irq = 9; 
1999/0121    
			intrenable(ether->irq, ether->interrupt, ether, ether->tbdf); 
 
			i = sprint(buf, "#l%d: %s: %dMbps port 0x%luX irq %d", 
1999/0608    
			i = sprint(buf, "#l%d: %s: %dMbps port 0x%luX irq %lud", 
1999/0121    
				ctlrno, ether->type, ether->mbps, ether->port, ether->irq); 
			if(ether->mem) 
				i += sprint(buf+i, " addr 0x%luX", PADDR(ether->mem)); 
1999/0508/sys/src/9/mpc/devether.c:388,3961999/0608/sys/src/9/mpc/devether.c:384,392
1999/0121    
					ether->oq = qopen(256*1024, 1, 0, 0); 
			} 
			else{ 
				netifinit(ether, name, Ntypes, 32*1024); 
1999/0608    
				netifinit(ether, name, Ntypes, 65*1024); 
1999/0121    
				if(ether->oq == 0) 
					ether->oq = qopen(64*1024, 1, 0, 0); 
1999/0608    
					ether->oq = qopen(65*1024, 1, 0, 0); 
1999/0121    
			} 
			if(ether->oq == 0) 
				panic("etherreset %s", name); 
1999/0508/sys/src/9/mpc/devether.c:434,4401999/0608/sys/src/9/mpc/devether.c:430,435
1999/0121    
	etherreset, 
	devinit, 
	etherattach, 
	/*etherdetach,*/ 
	devclone, 
	etherwalk, 
	etherstat, 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)