From 006b04b503ed2daaf43e7ab0e056c687497813ef Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 2 Feb 1994 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1994-02-02 --- pc/devether.c | 15 ++------------- pc/ether509.c | 11 ++--------- pc/ether8003.c | 2 +- pc/ether8390.c | 33 +++++++++++++++++---------------- pc/etherif.h | 10 ++++++++-- pc/l.s | 38 ++++++-------------------------------- 6 files changed, 36 insertions(+), 73 deletions(-) diff --git a/pc/devether.c b/pc/devether.c index 8afe838658f7a3eb455317c3eb0446a8230243e9..43f1421dd95b5f52c9f4f4519295a4201f845b4a 100644 --- a/pc/devether.c +++ b/pc/devether.c @@ -103,19 +103,8 @@ etherrloop(Ether *ctlr, Etherpkt *pkt, long len) type = (pkt->type[0]<<8)|pkt->type[1]; ep = &ctlr->f[Ntypes]; for(fp = ctlr->f; fp < ep; fp++){ - f = *fp; - if(f && (f->type == type || f->type < 0)){ - switch(qproduce(f->in, pkt->d, len)){ - - case -1: - print("etherrloop overflow\n"); - break; - - case -2: - print("etherrloop memory\n"); - break; - } - } + if((f = *fp) && (f->type == type || f->type < 0)) + qproduce(f->in, pkt->d, len); } } diff --git a/pc/ether509.c b/pc/ether509.c index 820b1090a5526c5ceadd3dae01d9141175b9499c..916de20a8a8567f5f43a2837929a84c3d92c5143 100644 --- a/pc/ether509.c +++ b/pc/ether509.c @@ -122,10 +122,9 @@ promiscuous(void *arg, int on) static void receive(Ether *ether) { - ushort status, type; + ushort status; int len; ulong port; - Netfile *f, **fp, **ep; port = ether->port; while(((status = ins(port+RxStatus)) & RxEmpty) == 0){ @@ -169,13 +168,7 @@ receive(Ether *ether) /* * Copy the packet to whoever wants it. */ - type = (ether->rpkt.type[0]<<8)|ether->rpkt.type[1]; - ep = ðer->f[Ntypes]; - for(fp = ether->f; fp < ep; fp++) { - f = *fp; - if(f && (f->type == type || f->type < 0)) - qproduce(f->in, ðer->rpkt, len); - } + etherrloop(ether, ðer->rpkt, len); } /* diff --git a/pc/ether8003.c b/pc/ether8003.c index 542b788ca432b9154ac0a77fe53dd5a010aa11c7..8d23e7533e0708e25071d7f42cc00973c886b70a 100644 --- a/pc/ether8003.c +++ b/pc/ether8003.c @@ -96,7 +96,7 @@ reset(Ether *ether) sum = 0; for(i = 0; i < sizeof(ether->ea); i++){ ea[i] = inb(port+Lar+i); - sum += ether->ea[i]; + sum += ea[i]; ic[i] = inb(port+i); } sum += inb(port+Id); diff --git a/pc/ether8390.c b/pc/ether8390.c index cd459099984eaf7971a88109a6fdfcad3c9be158..67ce7094792dfe78af226b6ec233a00033a95b84 100644 --- a/pc/ether8390.c +++ b/pc/ether8390.c @@ -287,7 +287,12 @@ dp8390write(Dp8390 *dp8390, ulong to, void *from, ulong len) uchar cr; int s, tries; + /* + * Keep out interrupts since reading and writing + * use the same DMA engine. + */ s = splhi(); + /* * Write some data to offset 'to' in the card's memory * using the DP8390 remote DMA facility, reading it at @@ -338,22 +343,23 @@ dp8390write(Dp8390 *dp8390, ulong to, void *from, ulong len) outss(dp8390->data, from, len/2); else outsb(dp8390->data, from, len); - splx(s); /* - * Wait for the remote DMA to finish. We'll need - * a timeout here if this ever gets called before - * we know there really is a chip there. + * Wait for the remote DMA to finish. It should + * be almost immediate. */ tries = 0; - while((slowinb(port+Isr) & Rdc) == 0) - if(tries++ >= 10000000){ - print("dp8390write whoops\n"); + while((slowinb(port+Isr) & Rdc) == 0){ + if(tries++ >= 100000){ + print("dp8390write dma timed out\n"); break; } + } slowoutb(port+Isr, Rdc); slowoutb(port+Cr, cr); + splx(s); + return (void*)to; } @@ -377,8 +383,6 @@ receive(Ether *ether) uchar curr, *pkt; Hdr hdr; ulong port, data, len, len1; - ushort type; - Netfile *f, **fp, **ep; dp8390 = ether->private; port = dp8390->dp8390; @@ -421,6 +425,9 @@ receive(Ether *ether) /* * If it's a good packet read it in to the software buffer. * If the packet wraps round the hardware ring, read it in two pieces. + * + * We could conceivably remove the copy into rpkt here by wrapping + * this up with the etherrloop code. */ if((hdr.status & (Fo|Fae|Crce|Prxok)) == Prxok){ pkt = (uchar*)ðer->rpkt; @@ -448,13 +455,7 @@ receive(Ether *ether) /* * Copy the packet to whoever wants it. */ - type = (ether->rpkt.type[0]<<8)|ether->rpkt.type[1]; - ep = ðer->f[Ntypes]; - for(fp = ether->f; fp < ep; fp++) { - f = *fp; - if(f && (f->type == type || f->type < 0)) - qproduce(f->in, ðer->rpkt, len); - } + etherrloop(ether, ðer->rpkt, len); } /* diff --git a/pc/etherif.h b/pc/etherif.h index a761d7fc0dd7d67c1de5e6c4978c817ffffec6fe..05fe578bb45a23df776536771fd9ee07296b9f65 100644 --- a/pc/etherif.h +++ b/pc/etherif.h @@ -22,6 +22,14 @@ struct Ether { Netif; }; +extern void etherrloop(Ether*, Etherpkt*, long); +extern void addethercard(char*, int(*)(Ether*)); + +/* + * Stuff for the boards using the National Semiconductor DP8390 + * and SMC 83C90 Network Interface Controller. + * Common code is in ether8390.c. + */ typedef struct { uchar bit16; /* true if a 16 bit interface */ uchar ram; /* true if card has shared memory */ @@ -46,5 +54,3 @@ extern void dp8390setea(Ether*); #define NEXT(x, l) (((x)+1)%(l)) #define HOWMANY(x, y) (((x)+((y)-1))/(y)) #define ROUNDUP(x, y) (HOWMANY((x), (y))*(y)) - -extern void addethercard(char*, int(*)(Ether*)); diff --git a/pc/l.s b/pc/l.s index 939fea89e1bdf3fc1a452c2c650230d00289a934..0728627d7f5470c3559748e64891e46f88595d0c 100644 --- a/pc/l.s +++ b/pc/l.s @@ -733,58 +733,32 @@ l20: LOOP l20 RET -#ifdef notdef /* * The DP8390 ethernet chip needs some time between * successive chip selects, so we force a jump into * the instruction stream to break the pipeline. */ -TEXT dp8390inb(SB), $0 +TEXT slowinb(SB), $0 MOVL p+0(FP),DX XORL AX,AX /* CF = 0 */ INB - JCC _dp8390inb0 /* always true */ + JCC _slowinb0 /* always true */ MOVL AX,AX -_dp8390inb0: +_slowinb0: RET -TEXT dp8390outb(SB), $0 +TEXT slowoutb(SB), $0 MOVL p+0(FP),DX MOVL b+4(FP),AX OUTB CLC /* CF = 0 */ - JCC _dp8390outb0 /* always true */ + JCC _slowoutb0 /* always true */ MOVL AX,AX -_dp8390outb0: - RET -#endif - -TEXT slowinb(SB), $0 - MOVL $0x84, DX - INB - INB - - MOVL p+0(FP),DX - XORL AX,AX - INB - RET - -TEXT slowoutb(SB),$0 - MOVL $0x84, DX - INB - INB - - MOVL p+0(FP),DX - MOVL b+4(FP),AX - OUTB - - MOVL $0x84, DX - INB - +_slowoutb0: RET /*