From 1d1285d53b346bc78b8aa35b566870badaa9d595 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 13 Jun 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-06-13 --- bitsy/dat.h | 1 + bitsy/devether.c | 85 ++++++++++++++++++++++++++++++++++++----------- bitsy/devpcmcia.c | 5 +-- port/qio.c | 2 +- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/bitsy/dat.h b/bitsy/dat.h index f0b43550e626a9a5b4f1540a523b7574cfe30496..9e3f03b60637a88ab04b0c85c10caefd2ff1f90d 100644 --- a/bitsy/dat.h +++ b/bitsy/dat.h @@ -255,6 +255,7 @@ struct PCMslot */ struct DevConf { + RWlock; /* write: configure/unconfigure/suspend; read: normal access */ ulong mem; /* mapped memory address */ ulong port; /* mapped i/o regs */ int size; /* access size */ diff --git a/bitsy/devether.c b/bitsy/devether.c index d6faa38645e49f2ef50e26c045c62fc66d78a618..a25c39a68f2a0c1830825758d7705d5b8987de0d 100644 --- a/bitsy/devether.c +++ b/bitsy/devether.c @@ -37,14 +37,15 @@ etherconfig(int on, char *spec, DevConf *cf) char name[32], buf[128]; char *p, *e; - /* can't unconfigure yet */ - if(on == 0) - return -1; - ctlrno = atoi(spec); if(etherxx[ctlrno] != nil) return -1; + /* can't unconfigure yet */ + if(on == 0){ + return -1; + } + ether = malloc(sizeof(Ether)); if(ether == nil) panic("etherconfig"); @@ -122,29 +123,46 @@ etherattach(char* spec) if(etherxx[ctlrno] == 0) error(Enodev); + rlock(etherxx[ctlrno]); chan = devattach('l', spec); chan->dev = ctlrno; if(etherxx[ctlrno]->attach) etherxx[ctlrno]->attach(etherxx[ctlrno]); + runlock(etherxx[ctlrno]); return chan; } static Walkqid* etherwalk(Chan* chan, Chan* nchan, char** name, int nname) { - return netifwalk(etherxx[chan->dev], chan, nchan, name, nname); + Walkqid *q; + + rlock(etherxx[chan->dev]); + q = netifwalk(etherxx[chan->dev], chan, nchan, name, nname); + runlock(etherxx[chan->dev]); + return q; } static int etherstat(Chan* chan, uchar* dp, int n) { - return netifstat(etherxx[chan->dev], chan, dp, n); + int s; + + rlock(etherxx[chan->dev]); + s = netifstat(etherxx[chan->dev], chan, dp, n); + runlock(etherxx[chan->dev]); + return s; } static Chan* etheropen(Chan* chan, int omode) { - return netifopen(etherxx[chan->dev], chan, omode); + Chan *c; + + rlock(etherxx[chan->dev]); + c = netifopen(etherxx[chan->dev], chan, omode); + runlock(etherxx[chan->dev]); + return c; } static void @@ -155,7 +173,9 @@ ethercreate(Chan*, char*, int, ulong) static void etherclose(Chan* chan) { + rlock(etherxx[chan->dev]); netifclose(etherxx[chan->dev], chan); + runlock(etherxx[chan->dev]); } static long @@ -163,8 +183,10 @@ etherread(Chan* chan, void* buf, long n, vlong off) { Ether *ether; ulong offset = off; + long n; ether = etherxx[chan->dev]; + rlock(ether); if((chan->qid.type & QTDIR) == 0 && ether->ifstat){ /* * With some controllers it is necessary to reach @@ -176,19 +198,29 @@ etherread(Chan* chan, void* buf, long n, vlong off) ether->ifstat(ether, buf, 0, offset); } - return netifread(ether, chan, buf, n, offset); + n = netifread(ether, chan, buf, n, offset); + runlock(ether); + return n; } static Block* etherbread(Chan* chan, long n, ulong offset) { - return netifbread(etherxx[chan->dev], chan, n, offset); + Block *b; + + rlock(etherxx[chan->dev]); + b = netifbread(etherxx[chan->dev], chan, n, offset); + runlock(etherxx[chan->dev]); + return b; } static int etherwstat(Chan* chan, uchar* dp, int n) { - return netifwstat(etherxx[chan->dev], chan, dp, n); + rlock(etherxx[chan->dev]); + n = netifwstat(etherxx[chan->dev], chan, dp, n); + runlock(etherxx[chan->dev]); + return n; } static void @@ -334,30 +366,41 @@ etherwrite(Chan* chan, void* buf, long n, vlong) Ether *ether; Block *bp; int nn; + long l; ether = etherxx[chan->dev]; + rlock(etherxx[chan->dev]); if(NETTYPE(chan->qid.path) != Ndataqid) { nn = netifwrite(ether, chan, buf, n); - if(nn >= 0) + if(nn >= 0){ + runlock(etherxx[chan->dev]); return nn; - - if(ether->ctl!=nil) - return ether->ctl(ether,buf,n); - + } + if(ether->ctl!=nil){ + l = ether->ctl(ether,buf,n); + runlock(etherxx[chan->dev]); + return l; + } + runlock(etherxx[chan->dev]); error(Ebadctl); } - if(n > ether->maxmtu) + if(n > ether->maxmtu){ + runlock(etherxx[chan->dev]); error(Etoobig); - if(n < ether->minmtu) + } + if(n < ether->minmtu){ + runlock(etherxx[chan->dev]); error(Etoosmall); - + } bp = allocb(n); memmove(bp->rp, buf, n); memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen); bp->wp += n; - return etheroq(ether, bp); + l = etheroq(ether, bp); + runlock(etherxx[chan->dev]); + return l; } static long @@ -377,16 +420,20 @@ etherbwrite(Chan* chan, Block* bp, ulong) freeb(bp); return n; } + rlock(etherxx[chan->dev]); ether = etherxx[chan->dev]; if(n > ether->maxmtu){ freeb(bp); + runlock(etherxx[chan->dev]); error(Etoobig); } if(n < ether->minmtu){ freeb(bp); + runlock(etherxx[chan->dev]); error(Etoosmall); } + runlock(etherxx[chan->dev]); return etheroq(ether, bp); } diff --git a/bitsy/devpcmcia.c b/bitsy/devpcmcia.c index 68bdb08af7519a160bd5324747bd57c520abccf5..5477297d3532491165e596a5a1cda87dd9a7c894 100644 --- a/bitsy/devpcmcia.c +++ b/bitsy/devpcmcia.c @@ -348,15 +348,16 @@ pcmctlwrite(char *p, long n, ulong, PCMslot *sp) } /* configure device */ - cf.type = nil; + memset(&cf, 0, sizeof cf); + wlock(&cf); kstrdup(&cf.type, cmd->f[2]); cf.mem = (ulong)sp->mem; cf.port = (ulong)sp->regs; cf.itype = GPIOfalling; cf.interrupt = bitno(sp == slot ? GPIO_CARD_IRQ0_i : GPIO_CARD_IRQ1_i); - cf.size = 0; if(devtab[dtx]->config(1, p, &cf) < 0) error("couldn't configure device"); + wunlock(&cf); wunlock(sp); poperror(); diff --git a/port/qio.c b/port/qio.c index 3f263741565ce0b8d300918038173055b9ddda7c..a513e0711c2fb9e4e6eed6a81f57ed2199e64f95 100644 --- a/port/qio.c +++ b/port/qio.c @@ -57,7 +57,7 @@ enum Qflow = (1<<3), Qcoalesce = (1<<4), /* coallesce packets on read */ - Maxatomic = 32*1024, + Maxatomic = 64*1024, }; uint qiomaxatomic = Maxatomic;