From 9443499037a67210f4c9282c5b89c280413f4799 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Fri, 18 Apr 1997 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1997-04-18 --- pc/devether.c | 4 +- pc/ether8390.c | 100 ++++++++++++++++++++++++++++-------------------- pc/ether8390.h | 1 + pc/etherelnk3.c | 1 - 4 files changed, 61 insertions(+), 45 deletions(-) diff --git a/pc/devether.c b/pc/devether.c index 138c937b7799385539465e2c696d6dc830c1f3ad..33a020de90b18e7b43882f82475437ebb3f26e4f 100644 --- a/pc/devether.c +++ b/pc/devether.c @@ -398,9 +398,7 @@ ethercrc(uchar *p, int len) for(i = 0; i < len; i++){ b = *p++; for(j = 0; j < 8; j++){ - crc = (crc>>1); - if((crc^b) & 1) - crc ^= POLY; + crc = (crc>>1) ^ (((crc^b) & 1) ? POLY : 0); b >>= 1; } } diff --git a/pc/ether8390.c b/pc/ether8390.c index 1eb53a5536633f500d0e4385ec02b8406adee789..f0fcc85c597bf0258bc8d2e315bec8dd2fadf111 100644 --- a/pc/ether8390.c +++ b/pc/ether8390.c @@ -604,77 +604,95 @@ interrupt(Ureg*, void* arg) unlock(ctlr); } +static uchar allmar[8] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; + +static void +setfilter(Ether *ether, Dp8390 *ctlr) +{ + uchar r, cr; + int i; + uchar *mar; + + r = Ab; + mar = 0; + if(ether->prom){ + r |= Pro|Am; + mar = allmar; + } else if(ether->nmaddr){ + r |= Am; + mar = ctlr->mar; + } + if(mar){ + cr = regr(ctlr, Cr) & ~Txp; + regw(ctlr, Cr, Page1|(~(Ps1|Ps0) & cr)); + for(i = 0; i < 8; i++) + regw(ctlr, Mar0+i, *(mar++)); + regw(ctlr, Cr, cr); + } + regw(ctlr, Rcr, r); +} + static void promiscuous(void *arg, int on) { Ether *ether; Dp8390 *ctlr; - uchar r; + + USED(on); ether = arg; ctlr = ether->ctlr; - /* - * Set/reset promiscuous mode. - */ - r = Ab; - if(on) - r |= Pro; - if(ether->nmaddr) - r |= Am; ilock(ctlr); - regw(ctlr, Rcr, r); + setfilter(ether, ctlr); iunlock(ctlr); } +static void +setbit(Dp8390 *ctlr, int bit, int on) +{ + int i, h; + + i = bit/8; + h = bit%8; + if(on){ + if(++(ctlr->mref[bit]) == 1) + ctlr->mar[i] |= 1<mref[bit]) <= 0){ + ctlr->mref[bit] = 0; + ctlr->mar[i] &= ~(1<ctlr; + if(reverse[1] == 0){ + for(i = 0; i < 64; i++) + reverse[i] = ((i&1)<<5) | ((i&2)<<3) | ((i&4)<<1) + | ((i&8)>>1) | ((i&16)>>3) | ((i&32)>>5); + } /* * change filter bits */ h = ethercrc(addr, 6); - h = h>>(32-6); - i = h/8; - h = h%8; ilock(ctlr); - cr = regr(ctlr, Cr) & ~Txp; - regw(ctlr, Cr, Page1|(~(Ps1|Ps0) & cr)); - r = regr(ctlr, Mar0+i); - if(on){ - if(++(ctlr->mref[h]) == 1) - r |= 1<mref[h]) <= 0){ - ctlr->mref[h] = 0; - r &= ~(1<nmaddr) - r |= Am; - if(ether->prom) - r |= Pro; - ilock(ctlr); - regw(ctlr, Rcr, r); + setbit(ctlr, reverse[h&0x3f], on); + setfilter(ether, ctlr); iunlock(ctlr); } diff --git a/pc/ether8390.h b/pc/ether8390.h index 8fff39432a14275a36fff9be9eb061b0042e4cd6..b5bf6e55528cfd0f9e9e3f3360140a7b218030df 100644 --- a/pc/ether8390.h +++ b/pc/ether8390.h @@ -20,6 +20,7 @@ typedef struct { int txbusy; /* transmit */ uchar tstart; /* 8390 ring addresses */ + uchar mar[8]; /* shadow multicast address registers */ int mref[64]; /* reference counts for multicast groups */ } Dp8390; diff --git a/pc/etherelnk3.c b/pc/etherelnk3.c index 647a844510353acb203dab1e7af6464e06ed439a..9e3dd8a43676d5195245ff7c5d5cbcd44d67d90d 100644 --- a/pc/etherelnk3.c +++ b/pc/etherelnk3.c @@ -467,7 +467,6 @@ multicast(void* arg, uchar *addr, int on) ether = (Ether*)arg; port = ether->port; -print("multicast nmaddr == %d\n", ether->nmaddr); filter = receiveBroadcast|receiveIndividual; if(ether->nmaddr) filter |= receiveMulticast;