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

1990/1228/port/devlance.c (diff list | history)

1990/11211/sys/src/9/port/devlance.c:24,401990/1228/sys/src/9/port/devlance.c:24,29 (short | long | prev | next)
1990/0707    
#define NOW (MACHP(0)->ticks*MS2HZ) 
1990/03042    
 
1990/0227    
/* 
1990/0911    
 *  Ethernet packet buffers.  These must also be in lance addressible RAM. 
 */ 
typedef struct { 
	uchar d[6]; 
	uchar s[6]; 
	uchar type[2]; 
	uchar data[1500]; 
	uchar crc[4]; 
} Pkt; 
                 
/* 
1990/0227    
 *  Communication with the lance is via a transmit and receive ring of 
 *  message descriptors.  The Initblock contains pointers to and sizes of 
 *  these rings.  The rings must be in RAM addressible by the lance 
1990/11211/sys/src/9/port/devlance.c:70,811990/1228/sys/src/9/port/devlance.c:59,69
1990/0227    
	Msg	tmr[Ntrb];		/* transmit message ring */ 
 
	/* 
1990/0911    
	 *  packet buffers (for IO2 version) 
1990/1228    
	 *  packet buffers (for SGI IO2 version only) 
1990/0227    
	 */ 
1990/0911    
	Pkt	rp[Nrrb]; 
	Pkt	tp[Ntrb]; 
1990/1228    
	Etherpkt	rp[Nrrb]; 
	Etherpkt	tp[Ntrb]; 
1990/0227    
} Lancemem; 
1990/0911    
#define LANCEMEM ((Lancemem*)0) 
1990/0227    
 
/* 
 *  Some macros for dealing with lance memory addresses.  The lance splits 
1990/11211/sys/src/9/port/devlance.c:83,881990/1228/sys/src/9/port/devlance.c:71,86
1990/0227    
 */ 
1990/0911    
#define HADDR(a) ((((ulong)(a))>>16)&0xFF) 
1990/0227    
#define LADDR(a) (((ulong)a)&0xFFFF) 
1990/1228    
 
/* 
 *  The following functions exist to sidestep a quirk in the SGI IO3 lance 
 *  interface.  In all other processors, the lance's initialization block and 
 *  descriptor rings look like normal memory.  In the SGI IO3, the CPU sees a 
 *  6 byte pad twixt all lance memory shorts.  Therefore, we use the following 
 *  macros to compute the address whenever accessing the lance memory to make 
 *  the code portable.  Sic transit gloria. 
 */ 
#define LANCEMEM ((Lancemem*)0) 
1990/0911    
#define MPs(a) (*(short *)(l.lanceram + l.sep*((ushort*)&a - (ushort*)0))) 
#define MPus(a) (*(ushort *)(l.lanceram + l.sep*((ushort*)&a - (ushort*)0))) 
1990/0227    
 
1990/11211/sys/src/9/port/devlance.c:147,1541990/1228/sys/src/9/port/devlance.c:145,152
1990/0227    
	int	kstarted; 
	Debqueue dq; 
1990/0911    
 
	Pkt	*rp;		/* receive buffers */ 
	Pkt	*tp;		/* transmit buffers */ 
1990/1228    
	Etherpkt	*rp;		/* receive buffers */ 
	Etherpkt	*tp;		/* transmit buffers */ 
1990/0911    
	uchar	*rpa[Nrrb];	/* receive buffer address in lance space */ 
	uchar	*tpa[Ntrb];	/* transmit buffer address in lance space */ 
 
1990/11211/sys/src/9/port/devlance.c:256,2621990/1228/sys/src/9/port/devlance.c:254,260
1990/0227    
 *  save a message in a circular queue for later debugging 
 */ 
void 
1990/03042    
lancedebq(char tag, Pkt *p, int len) 
1990/1228    
lancedebq(char tag, Etherpkt *p, int len) 
1990/0227    
{ 
1990/03042    
	Trace *t; 
 
1990/11211/sys/src/9/port/devlance.c:338,3441990/1228/sys/src/9/port/devlance.c:336,342
1990/0227    
lanceoput(Queue *q, Block *bp ) 
{ 
	int n, len; 
	Pkt *p; 
1990/1228    
	Etherpkt *p; 
1990/0227    
	Msg *m; 
 
	if(bp->type == M_CTL){ 
1990/11211/sys/src/9/port/devlance.c:375,3811990/1228/sys/src/9/port/devlance.c:373,379
1990/0227    
	 */ 
	len = 0; 
	while(bp = getq(q)){ 
1990/0312    
		if(sizeof(Pkt) - len >= (n = BLEN(bp))){ 
1990/1228    
		if(sizeof(Etherpkt) - len >= (n = BLEN(bp))){ 
1990/03042    
			memcpy(((uchar *)p)+len, bp->rptr, n); 
1990/0227    
			len += n; 
		} else 
1990/11211/sys/src/9/port/devlance.c:425,4301990/1228/sys/src/9/port/devlance.c:423,444
1990/03042    
Dirtab lancedir[Ndir]; 
1990/0227    
 
/* 
1990/1228    
 *  configure the lance 
 */ 
void 
lanceconfig(void *ramstart, void *ramend, void *rap, void *rdp, int sep, 
	void *lancemem, uchar* ea) 
{ 
	l.lanceram = ramstart; 
	l.lanceend = ramend; 
	l.rap = rap; 
	l.rdp = rdp; 
	l.sep = sep; 
	l.lm = lancemem;	/* where lance sees its memory start */ 
	memcpy(l.ea, ea, 6); 
} 
 
/* 
1990/0227    
 *  stop the lance, disable all ring buffers, and free all staged rcv buffers 
 */ 
void 
1990/11211/sys/src/9/port/devlance.c:431,4661990/1228/sys/src/9/port/devlance.c:445,464
1990/0227    
lancereset(void) 
{ 
	int i; 
1990/0911    
	ushort *sp; 
	ulong x; 
	int index; 
	static int already; 
1990/0227    
 
	/* 
1990/0911    
	 *  so that we don't have to indirect through constants 
1990/1228    
	 *  stop the lance 
1990/0227    
	 */ 
1990/0911    
	l.rap = LANCERAP; 
	l.rdp = LANCERDP; 
1990/1228    
	*l.rap = 0; 
	*l.rdp = STOP; 
1990/0227    
 
	/* 
1990/0911    
	 *  allocate the send and receive buffers and map them into 
	 *  the lance's address space. 
1990/0227    
	 */ 
1990/0911    
	if(already == 0){ 
		already = 1; 
		if(ioid < IO3R1){ 
			/* 
			 *  toggle lance's reset line 
			 */ 
			MODEREG->promenet &= ~1; 
			MODEREG->promenet |= 1; 
1990/0227    
                 
1990/0911    
			l.lanceram = LANCERAM; 
			l.lanceend = LANCEEND; 
			l.lm = (Lancemem *)0; 
			l.sep = 1; 
                 
			/* 
			 *  allocate packet buffers in lance memory 
			 */ 
			for(i = 0; i < Nrrb; i++) 
1990/11211/sys/src/9/port/devlance.c:468,4921990/1228/sys/src/9/port/devlance.c:466,479
1990/0911    
			for(i = 0; i < Ntrb; i++) 
				l.tpa[i] = (uchar *)&l.lm->tp[i]; 
1990/0912    
 
			l.rp = ((Lancemem *)LANCERAM)->rp; 
			l.tp = ((Lancemem *)LANCERAM)->tp; 
1990/1228    
			l.rp = ((Lancemem *)l.lanceram)->rp; 
			l.tp = ((Lancemem *)l.lanceram)->tp; 
1990/0911    
		} else { 
			/* 
			 *  toggle lance's reset line 
			 */ 
			MODEREG->promenet |= 1; 
			MODEREG->promenet &= ~1; 
                 
			l.lanceram = LANCE3RAM; 
			l.lanceend = LANCE3END; 
			l.lm = (Lancemem *)0x800000; 
			l.sep = 4; 
                 
			/* 
			 *  allocate packet buffers in MP bus memory 
			 *  and map it into lance space 
			 */ 
			l.rp = (Pkt *)ialloc((Nrrb + Ntrb)*sizeof(Pkt), 1); 
1990/1228    
			l.rp = (Etherpkt *)ialloc((Nrrb + Ntrb)*sizeof(Etherpkt), 1); 
1990/0911    
			l.tp = l.rp + Nrrb; 
			index = 0x1E00; 
			for(i = 0; i < Nrrb; i++){ 
1990/11211/sys/src/9/port/devlance.c:504,5151990/1228/sys/src/9/port/devlance.c:491,496
1990/0911    
		} 
	} 
 
1990/0227    
	/* 
	 *  run through all lance memory to set parity 
	 */ 
1990/0911    
	for(sp = l.lanceram; sp < l.lanceend; sp += l.sep) 
		*sp = 0; 
                 
1990/0227    
} 
 
/* 
1990/11211/sys/src/9/port/devlance.c:520,5261990/1228/sys/src/9/port/devlance.c:501,507
1990/0227    
lancestart(void) 
{ 
	int i; 
	Pkt *p; 
1990/1228    
	Etherpkt *p; 
1990/0911    
	Lancemem *lm = LANCEMEM; 
	Msg *m; 
1990/0227    
 
1990/11211/sys/src/9/port/devlance.c:536,5501990/1228/sys/src/9/port/devlance.c:517,525
1990/0227    
	 *  the id prom has them in reverse order, the init 
	 *  structure wants them in byte swapped order 
	 */ 
1990/0911    
	MPus(lm->etheraddr[0]) = (LANCEID[16]&0xff00)|((LANCEID[20]>>8)&0xff); 
	MPus(lm->etheraddr[1]) = (LANCEID[8]&0xff00)|((LANCEID[12]>>8)&0xff); 
	MPus(lm->etheraddr[2]) = (LANCEID[0]&0xff00)|((LANCEID[4]>>8)&0xff); 
1990/0227    
	l.ea[0] = LANCEID[20]>>8; 
	l.ea[1] = LANCEID[16]>>8; 
	l.ea[2] = LANCEID[12]>>8; 
	l.ea[3] = LANCEID[8]>>8; 
	l.ea[4] = LANCEID[4]>>8; 
	l.ea[5] = LANCEID[0]>>8; 
1990/1228    
	MPus(lm->etheraddr[0]) = (l.ea[1]<<8) | l.ea[0]; 
	MPus(lm->etheraddr[1]) = (l.ea[3]<<8) | l.ea[2]; 
	MPus(lm->etheraddr[2]) = (l.ea[5]<<8) | l.ea[4]; 
1990/0227    
 
	/* 
	 *  ignore multicast addresses 
1990/11211/sys/src/9/port/devlance.c:559,5651990/1228/sys/src/9/port/devlance.c:534,540
1990/0227    
	 */ 
1990/0911    
	m = lm->rmr; 
	for(i = 0; i < Nrrb; i++, m++){ 
		MPs(m->size) = -sizeof(Pkt); 
1990/1228    
		MPs(m->size) = -sizeof(Etherpkt); 
1990/0911    
		MPus(m->cntflags) = 0; 
		MPus(m->laddr) = LADDR(l.rpa[i]); 
		MPus(m->flags) = HADDR(l.rpa[i]); 
1990/11211/sys/src/9/port/devlance.c:860,8661990/1228/sys/src/9/port/devlance.c:835,841
1990/0227    
lancekproc(void *arg) 
{ 
	Block *bp; 
	Pkt *p; 
1990/1228    
	Etherpkt *p; 
1990/0227    
	Ethertype *e; 
	int t; 
	int len; 
1990/11211/sys/src/9/port/devlance.c:930,9361990/1228/sys/src/9/port/devlance.c:905,911
1990/0227    
			 *  stage the next input buffer 
			 */ 
			m = &(lm->rmr[l.rc]); 
1990/0911    
			MPs(m->size) = -sizeof(Pkt); 
1990/1228    
			MPs(m->size) = -sizeof(Etherpkt); 
1990/0911    
			MPus(m->cntflags) = 0; 
			MPus(m->laddr) = LADDR(l.rpa[l.rc]); 
			MPus(m->flags) = OWN|HADDR(l.rpa[l.rc]); 


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