From 5b096d6ec4bfe1010453d742674fccaee22ed411 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 17 Jun 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-06-17 --- bitsy/devether.c | 73 ++++++++++++++++++++++++++++++------------------ bitsy/etherif.h | 1 + 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/bitsy/devether.c b/bitsy/devether.c index 5cb6100e6e09f2deafcb994018f0eca882568f52..e1e2eb526f706e2b60af4ca295623c6a3d2ddce8 100644 --- a/bitsy/devether.c +++ b/bitsy/devether.c @@ -30,6 +30,42 @@ addethercard(char* t, int (*r)(Ether*)) ncard++; } +void +etherpower(int on) +{ + /* Power all ether cards on or off */ + + for (i = 0; i < MaxEther; i++){ + ether = etherxx[i]; + if (ether == nil) + continue; + if(on){ + if (ether->write == 0){ + print("etherpower: already powered up\n"); + continue; + } + if (ether->power) + ether->power(ether, on); + wunlock(ether); + /* Unlock when power restored */ + }else{ + if (ether->write != 0){ + print("etherpower: already powered down\n"); + continue; + } + /* Keep locked until power goes back on */ + wlock(ether); + if (ether == &noether){ + /* Locked an unconfigured card, undo */ + wunlock(ether); + continue; + } + if (ether->power) + ether->power(ether, on); + } + } +} + int etherconfig(int on, char *spec, DevConf *cf) { @@ -167,14 +203,12 @@ etherwalk(Chan* chan, Chan* nchan, char** name, int nname) Ether *ether; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); q = netifwalk(ether, chan, nchan, name, nname); poperror(); @@ -189,14 +223,12 @@ etherstat(Chan* chan, uchar* dp, int n) Ether *ether; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); s = netifstat(ether, chan, dp, n); poperror(); @@ -211,14 +243,12 @@ etheropen(Chan* chan, int omode) Ether *ether; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); c = netifopen(ether, chan, omode); poperror(); @@ -237,14 +267,12 @@ etherclose(Chan* chan) Ether *ether; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); netifclose(ether, chan); poperror(); @@ -258,14 +286,12 @@ etherread(Chan* chan, void* buf, long n, vlong off) ulong offset = off; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); if((chan->qid.type & QTDIR) == 0 && ether->ifstat){ /* @@ -292,14 +318,13 @@ etherbread(Chan* chan, long n, ulong offset) Ether *ether; ether = etherxx[chan->dev]; - if(ether == &noether) error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); b = netifbread(ether, chan, n, offset); poperror(); @@ -313,14 +338,12 @@ etherwstat(Chan* chan, uchar* dp, int n) Ether *ether; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); n = netifwstat(ether, chan, dp, n); poperror(); @@ -473,14 +496,12 @@ etherwrite(Chan* chan, void* buf, long n, vlong) long l; ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether) + if(ether == &noether) error(Enodev); if(NETTYPE(chan->qid.path) != Ndataqid) { l = netifwrite(ether, chan, buf, n); @@ -527,14 +548,12 @@ etherbwrite(Chan* chan, Block* bp, ulong) return n; } ether = etherxx[chan->dev]; - if(ether == &noether) - error(Enodev); rlock(ether); if(waserror()) { runlock(ether); nexterror(); } - if(etherxx[chan->dev] == &noether){ + if(ether == &noether){ freeb(bp); error(Enodev); } @@ -619,6 +638,6 @@ Dev etherdevtab = { etherbwrite, devremove, etherwstat, - nil, /* no power management */ + etherpower, etherconfig, }; diff --git a/bitsy/etherif.h b/bitsy/etherif.h index 90b957db8f284e199a119ba087a9351d4d61f08a..c6427989af42aa5329f17a1ec8458c23bd141c55 100644 --- a/bitsy/etherif.h +++ b/bitsy/etherif.h @@ -21,6 +21,7 @@ struct Ether { void (*interrupt)(Ureg*, void*); long (*ifstat)(Ether*, void*, long, ulong); long (*ctl)(Ether*, void*, long); /* custom ctl messages */ + long (*power)(Ether*, int); /* power on/off */ void *ctlr; Queue* oq;