From 3c31d13f829e88121ca6a7851b466a0225197acb Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sat, 23 Jun 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-06-23 --- bitsy/power.c | 16 +++++++--------- ip/esp.c | 2 +- ip/ethermedium.c | 2 +- ip/gre.c | 2 +- ip/icmp.c | 6 +++--- ip/igmp.c | 2 +- ip/il.c | 4 ++-- ip/ip.c | 6 +++--- ip/ip.h | 6 +++--- ip/ipmux.c | 7 +++++-- ip/loopbackmedium.c | 2 +- ip/netdevmedium.c | 2 +- ip/pktmedium.c | 2 +- ip/rudp.c | 8 ++++---- ip/tcp.c | 4 ++-- ip/tripmedium.c | 2 +- ip/udp.c | 8 ++++---- pc/etherelnk3.c | 37 ++++++++++++++++++++++++++++++++----- pc/etherwavelan.c | 4 +++- 19 files changed, 76 insertions(+), 46 deletions(-) diff --git a/bitsy/power.c b/bitsy/power.c index 856652dfa7f5cf8fb62c7b7b3a8299b30fae3cfd..8dfbf39283609614de45c29d4b0a8629c15a1db5 100644 --- a/bitsy/power.c +++ b/bitsy/power.c @@ -77,9 +77,9 @@ void (*restart)(void) = nil; static void sa1100_power_off(void) { - cacheflush(); - mmuinvalidate(); - mmudisable(); + +iprint("calling resume\n"); +sa1100_power_resume(); /* enable wakeup by µcontroller, on/off switch or real-time clock alarm */ powerregs->pwer = 1 << IRQrtc | 1 << IRQgpio0 | 1 << IRQgpio1; @@ -87,18 +87,16 @@ sa1100_power_off(void) /* clear previous reset status */ resetregs->rcsr = RCSR_all; -sa1100_power_resume(); - /* disable internal oscillator, float CS lines */ powerregs->pcfr = PCFR_opde | PCFR_fp | PCFR_fs; powerregs->pgsr = 0; /* set resume address. The loader jumps to it */ // powerregs->pspr = (ulong)sa1100_power_resume; -// powerregs->pspr = (ulong)_start; + powerregs->pspr = (ulong)_start; /* set lowest clock; delay to avoid resume hangs on fast sa1110 */ delay(90); -// powerregs->ppcr = 0; + powerregs->ppcr = 0; delay(90); /* set all GPIOs to input mode */ @@ -179,9 +177,9 @@ deepsleep(void) { clockpower(0); irpower(0); audiopower(0); - screenpower(0); +// screenpower(0); µcpower(0); - rs232power(0); +// rs232power(0); sa1100_power_off(); /* no return */ } diff --git a/ip/esp.c b/ip/esp.c index 44aa8f28066ef1e6a48453aee9bd53184a7e96f8..550f9ad9cdd38624f873851eb945485fc2801353 100644 --- a/ip/esp.c +++ b/ip/esp.c @@ -301,7 +301,7 @@ espkick(Conv *c) } void -espiput(Proto *esp, uchar*, Block *bp) +espiput(Proto *esp, Ipifc*, Block *bp) { Esphdr *eh; Esptail *et; diff --git a/ip/ethermedium.c b/ip/ethermedium.c index 3ca1c164f0287f2c87e8289aeef02269649dbd9b..775742894f6a05e92c94b3fc5673f8c7c824569e 100644 --- a/ip/ethermedium.c +++ b/ip/ethermedium.c @@ -283,7 +283,7 @@ etherread(void *a) if(ifc->lifc == nil) freeb(bp); else - ipiput(er->f, ifc->lifc->local, bp); + ipiput(er->f, ifc, bp); runlock(ifc); poperror(); } diff --git a/ip/gre.c b/ip/gre.c index a2d397ac8f03e1c7b999aaa7d3ee4da0de8f1ea3..b53004bf270bf15880127574daac61007704865c 100644 --- a/ip/gre.c +++ b/ip/gre.c @@ -160,7 +160,7 @@ grekick(Conv *c) } static void -greiput(Proto *gre, uchar*, Block *bp) +greiput(Proto *gre, Ipifc*, Block *bp) { int len; GREhdr *ghp; diff --git a/ip/icmp.c b/ip/icmp.c index 1bab0c58cb46baa5d0837955a16230670f986f45..14125ef9429852ecd0ccc0c7acf59054d74124ee 100644 --- a/ip/icmp.c +++ b/ip/icmp.c @@ -178,7 +178,7 @@ icmpkick(Conv *c) } extern void -icmpttlexceeded(Fs *f, uchar *ia, Block *bp) +icmpttlexceeded(Fs *f, Ipifc *ifc, Block *bp) { Block *nbp; Icmp *p, *np; @@ -190,7 +190,7 @@ icmpttlexceeded(Fs *f, uchar *ia, Block *bp) nbp->wp += ICMP_IPSIZE + ICMP_HDRSIZE + ICMP_IPSIZE + 8; np = (Icmp *)nbp->rp; memmove(np->dst, p->src, sizeof(np->dst)); - v6tov4(np->src, ia); + v6tov4(np->src, ifc->lifc->local); memmove(np->data, bp->rp, ICMP_IPSIZE + 8); np->type = TimeExceed; np->code = 0; @@ -293,7 +293,7 @@ static char *unreachcode[] = }; static void -icmpiput(Proto *icmp, uchar*, Block *bp) +icmpiput(Proto *icmp, Ipifc*, Block *bp) { int n, iplen; Icmp *p; diff --git a/ip/igmp.c b/ip/igmp.c index 54c7af97fa37addf5b3ccc421c1c559e5c878a15..10f58993bdda0c6e1a64ace4268eb362604ee19d 100644 --- a/ip/igmp.c +++ b/ip/igmp.c @@ -166,7 +166,7 @@ igmpproc(void *a) } void -igmpiput(Media *m, Block *bp) +igmpiput(Media *m, Ipifc*, Block *bp) { int n; IGMPpkt *ghp; diff --git a/ip/il.c b/ip/il.c index a5283336b3e1e27bb0f3fbc65243a4e061d578d2..129bd60d7f31447d50b8cfd922e993b5720af380 100644 --- a/ip/il.c +++ b/ip/il.c @@ -218,7 +218,7 @@ void ilsettimeout(Ilcb*); char* ilstart(Conv*, int, int); void ilackproc(void*); void iloutoforder(Conv*, Ilhdr*, Block*); -void iliput(Proto*, uchar*, Block*); +void iliput(Proto*, Ipifc*, Block*); void iladvise(Proto*, Block*, char*); int ilnextqt(Ilcb*); void ilcbinit(Ilcb*); @@ -528,7 +528,7 @@ ilackto(Ilcb *ic, ulong ackto, Block *bp) } void -iliput(Proto *il, uchar*, Block *bp) +iliput(Proto *il, Ipifc*, Block *bp) { char *st; Ilcb *ic; diff --git a/ip/ip.c b/ip/ip.c index efe80f06028f1f35f2be209992def65dc1bbbcba..559d0cd6a7619f00f014570998276084b7a2b6d7 100644 --- a/ip/ip.c +++ b/ip/ip.c @@ -344,7 +344,7 @@ initfrag(IP *ip, int size) #define DBG(x) if((logmask & Logipmsg) && (iponly == 0 || x == iponly))netlog void -ipiput(Fs *f, uchar *ia, Block *bp) +ipiput(Fs *f, Ipifc *ifc, Block *bp) { int hl; Iphdr *h; @@ -428,7 +428,7 @@ ipiput(Fs *f, uchar *ia, Block *bp) /* don't forward if packet has timed out */ if(h->ttl <= 1){ ip->stats[InHdrErrors]++; - icmpttlexceeded(f, ia, bp); + icmpttlexceeded(f, ifc, bp); freeblist(bp); return; } @@ -455,7 +455,7 @@ ipiput(Fs *f, uchar *ia, Block *bp) p = Fsrcvpcol(f, h->proto); if(p != nil && p->rcv != nil) { ip->stats[InDelivers]++; - (*p->rcv)(p, ia, bp); + (*p->rcv)(p, ifc, bp); return; } ip->stats[InDiscards]++; diff --git a/ip/ip.h b/ip/ip.h index d4d13bbc575fb724d042906bf5fa7fe31f46cc14..590b79afb495396b13754363cb1acd04ca45ecf1 100644 --- a/ip/ip.h +++ b/ip/ip.h @@ -245,7 +245,7 @@ struct Proto int (*state)(Conv*, char*, int); void (*create)(Conv*); void (*close)(Conv*); - void (*rcv)(Proto*, uchar*, Block*); + void (*rcv)(Proto*, Ipifc*, Block*); char* (*ctl)(Conv*, char**, int); void (*advise)(Proto*, Block*, char*); int (*stats)(Proto*, char*, int); @@ -531,10 +531,10 @@ extern long ipselftabread(Fs*, char *a, ulong offset, int n); extern void iprouting(Fs*, int); extern void closeifcconv(Ifcconv*); extern void icmpnoconv(Fs*, Block*); -extern void icmpttlexceeded(Fs*, uchar*, Block*); +extern void icmpttlexceeded(Fs*, Ipifc*, Block*); extern void initfrag(IP*, int); extern ushort ipcsum(uchar*); -extern void ipiput(Fs*, uchar*, Block*); +extern void ipiput(Fs*, Ipifc*, Block*); extern void ipoput(Fs*, Block*, int, int, int); extern int ipstats(Fs*, char*, int); extern ushort ptclbsum(uchar*, int); diff --git a/ip/ipmux.c b/ip/ipmux.c index ddea33d9ef9985c7d3f12e6b3f0a012f5110a3e8..021d9bc83f5b10847c8e28fe3046de423a1b4bf2 100644 --- a/ip/ipmux.c +++ b/ip/ipmux.c @@ -641,7 +641,7 @@ ipmuxkick(Conv *c) } static void -ipmuxiput(Proto *p, uchar *ia, Block *bp) +ipmuxiput(Proto *p, Ipifc *ifc, Block *bp) { int len; Fs *f = p->f; @@ -649,6 +649,9 @@ ipmuxiput(Proto *p, uchar *ia, Block *bp) Conv *c; Ipmux *mux; Iphdr *ip; + uchar *ia; + + ia = ifc->lifc->local; if(p->priv == nil) goto nomatch; @@ -737,7 +740,7 @@ nomatch: ip = (Iphdr*)bp->rp; p = f->t2p[ip->proto]; if(p) - (*p->rcv)(p, ia, bp); + (*p->rcv)(p, ifc, bp); else freeblist(bp); return; diff --git a/ip/loopbackmedium.c b/ip/loopbackmedium.c index 6bc98b9281999a76a3bfb7965afc6f971d16c333..b0f2fb9971e8b79a7ccfb6a0e87e953185bef6f9 100644 --- a/ip/loopbackmedium.c +++ b/ip/loopbackmedium.c @@ -94,7 +94,7 @@ loopbackread(void *a) if(ifc->lifc == nil) freeb(bp); else - ipiput(lb->f, ifc->lifc->local, bp); + ipiput(lb->f, ifc, bp); runlock(ifc); poperror(); } diff --git a/ip/netdevmedium.c b/ip/netdevmedium.c index aa2539bb24e7346ad4dfea1cc973d34ba529a91f..5dd90a0588821771ef0cee4c8002a628491bf181 100644 --- a/ip/netdevmedium.c +++ b/ip/netdevmedium.c @@ -140,7 +140,7 @@ ZZZ is this a good idea? if(ifc->lifc == nil) freeb(bp); else - ipiput(er->f, ifc->lifc->local, bp); + ipiput(er->f, ifc, bp); runlock(ifc); poperror(); } diff --git a/ip/pktmedium.c b/ip/pktmedium.c index 7a92e5601355eb41a60858059112263b0b883172..3432ad42d021458bf1e5aa4e4cce2455586d6e7b 100644 --- a/ip/pktmedium.c +++ b/ip/pktmedium.c @@ -64,7 +64,7 @@ pktin(Fs *f, Ipifc *ifc, Block *bp) if(ifc->lifc == nil) freeb(bp); else - ipiput(f, ifc->lifc->local, bp); + ipiput(f, ifc, bp); } void diff --git a/ip/rudp.c b/ip/rudp.c index 463e766d6c1126298d4d7eaef104cbc9f99e1554..86f1b42e0965d226e6b3f5bf77c76495b315cb3c 100644 --- a/ip/rudp.c +++ b/ip/rudp.c @@ -475,7 +475,7 @@ rudpkick(Conv *c) } void -rudpiput(Proto *rudp, uchar *ia, Block *bp) +rudpiput(Proto *rudp, Ipifc *ifc, Block *bp) { int len, olen, ottl; Udphdr *uh; @@ -569,7 +569,7 @@ rudpiput(Proto *rudp, uchar *ia, Block *bp) if(ipforme(f, laddr) == Runi) ipmove(bp->rp+IPaddrlen, laddr); else - ipmove(bp->rp+IPaddrlen, ia); + ipmove(bp->rp+IPaddrlen, ifc->lifc->local); hnputs(bp->rp+2*IPaddrlen, rport); hnputs(bp->rp+2*IPaddrlen+2, lport); break; @@ -580,7 +580,7 @@ rudpiput(Proto *rudp, uchar *ia, Block *bp) if(ipforme(f, laddr) == Runi) v6tov4(bp->rp+IPv4addrlen, laddr); else - v6tov4(bp->rp+IPv4addrlen, ia); + v6tov4(bp->rp+IPv4addrlen, ifc->lifc->local); hnputs(bp->rp + 2*IPv4addrlen, rport); hnputs(bp->rp + 2*IPv4addrlen + 2, lport); break; @@ -595,7 +595,7 @@ rudpiput(Proto *rudp, uchar *ia, Block *bp) if(ipforme(f, laddr) == Runi) ipmove(c->laddr, laddr); else - v4tov6(c->laddr, ia); + v4tov6(c->laddr, ifc->lifc->local); } break; } diff --git a/ip/tcp.c b/ip/tcp.c index 551d79896af486a5af29016e2f601d54a5e85cc1..670eb29b29e462696d9930cf8d71b665535d37ff 100644 --- a/ip/tcp.c +++ b/ip/tcp.c @@ -259,7 +259,7 @@ int addreseq(Tcpctl*, Tcp*, Block*, ushort); void getreseq(Tcpctl*, Tcp*, Block**, ushort*); void localclose(Conv*, char*); void procsyn(Conv*, Tcp*); -void tcpiput(Proto*, uchar*, Block*); +void tcpiput(Proto*, Ipifc*, Block*); void tcpoutput(Conv*); int tcptrim(Tcpctl*, Tcp*, Block**, ushort*); void tcpstart(Conv*, int, ushort); @@ -1234,7 +1234,7 @@ done: } void -tcpiput(Proto *tcp, uchar*, Block *bp) +tcpiput(Proto *tcp, Ipifc*, Block *bp) { Tcp seg; Tcphdr *h; diff --git a/ip/tripmedium.c b/ip/tripmedium.c index ec96661fde78918d8ae7c9b1f4059ea87ea5092e..eb2baa1c065a78312dbe3605b08b5b1bbcbc88cf 100644 --- a/ip/tripmedium.c +++ b/ip/tripmedium.c @@ -142,7 +142,7 @@ tripread(void *a) for(;;) { bp = devtab[er->mchan->type]->bread(er->mchan, ifc->maxmtu, 0); ifc->in++; - ipiput(er->fs, ifc->lifc->local, bp); + ipiput(er->fs, ifc, bp); } pexit("hangup", 1); diff --git a/ip/udp.c b/ip/udp.c index bfd438b3f5df08b98c46192e6de94f8e95858182..40d38df92413e6132788b33a874bdfe33babd8e2 100644 --- a/ip/udp.c +++ b/ip/udp.c @@ -251,7 +251,7 @@ udpincoming(Conv *c, uchar *raddr, ushort rport, uchar *laddr, ushort lport) } void -udpiput(Proto *udp, uchar *ia, Block *bp) +udpiput(Proto *udp, Ipifc *ifc, Block *bp) { int len, olen, ottl; Udphdr *uh; @@ -312,7 +312,7 @@ udpiput(Proto *udp, uchar *ia, Block *bp) if(ucb->headers == 0){ /* create a new conversation */ if(ipforme(f, laddr) != Runi) - v4tov6(laddr, ia); + v4tov6(laddr, ifc->lifc->local); c = Fsnewcall(c, raddr, rport, laddr, lport); if(c == nil){ qunlock(udp); @@ -351,7 +351,7 @@ udpiput(Proto *udp, uchar *ia, Block *bp) if(ipforme(f, laddr) == Runi) ipmove(bp->rp+IPaddrlen, laddr); else - ipmove(bp->rp+IPaddrlen, ia); + ipmove(bp->rp+IPaddrlen, ifc->lifc->local); hnputs(bp->rp+2*IPaddrlen, rport); hnputs(bp->rp+2*IPaddrlen+2, lport); break; @@ -362,7 +362,7 @@ udpiput(Proto *udp, uchar *ia, Block *bp) if(ipforme(f, laddr) == Runi) v6tov4(bp->rp+IPv4addrlen, laddr); else - v6tov4(bp->rp+IPv4addrlen, ia); + v6tov4(bp->rp+IPv4addrlen, ifc->lifc->local); hnputs(bp->rp + 2*IPv4addrlen, rport); hnputs(bp->rp + 2*IPv4addrlen + 2, lport); break; diff --git a/pc/etherelnk3.c b/pc/etherelnk3.c index 89ab002dd4ecff6c1be90d9343947a35259d79ff..a9004cde71e140971321d6284ad5711a1a5ba373 100644 --- a/pc/etherelnk3.c +++ b/pc/etherelnk3.c @@ -441,6 +441,9 @@ typedef struct { ulong dninterrupts; ulong dnqueued; + int did; /* Controller's device ID */ + ulong cbfns; /* CardBus functions */ + int xcvr; /* transceiver type */ int rxstatus9; /* old-style RxStatus register */ int rxearly; /* RxEarlyThreshold */ @@ -615,9 +618,9 @@ attach(Ether* ether) COMMAND(port, RxEnable, 0); COMMAND(port, TxEnable, 0); - if (ether->mem) + if (ctlr->cbfns) /* This must be a cardbus card. Acknowledge the interrupt */ - intrack3c575(KADDR(ether->mem)); + intrack3c575(KADDR(ctlr->cbfns)); /* * Prime the busmaster channel for receiving directly into a @@ -960,6 +963,18 @@ receive(Ether* ether) } } +static int +ejectable(int did) +{ + switch (did) { + case 0x5157: + return 1; + + default: + return 0; + } +} + static void interrupt(Ureg*, void* arg) { @@ -996,6 +1011,13 @@ interrupt(Ureg*, void* arg) COMMAND(port, SelectRegisterWindow, Wdiagnostic); x = ins(port+FifoDiagnostic); COMMAND(port, SelectRegisterWindow, Wop); + + if (status == 0xFFFF && x == 0xFFFF && ejectable(ctlr->did)) { + print("#l%d: Card ejected?\n", ether->ctlrno); + iunlock(&ctlr->wlock); + return; + } + print("#l%d: status 0x%uX, diag 0x%uX\n", ether->ctlrno, status, x); @@ -1138,7 +1160,7 @@ interrupt(Ureg*, void* arg) panic("#l%d: interrupt mask 0x%uX\n", ether->ctlrno, status); COMMAND(port, AcknowledgeInterrupt, interruptLatch); - if (ether->mem) intrack3c575((ulong *)KADDR(ether->mem)); + if (ctlr->cbfns) intrack3c575((ulong *)KADDR(ctlr->cbfns)); }while((status = STATUS(port)) & (interruptMask|interruptLatch)); @@ -1482,7 +1504,7 @@ tcm59Xpci(void) if (p->did == 0x5157) { /* Map the CardBus functions */ bar = pcicfgr32(p, PciBAR2); - print("tcmp59Xpci: CardBus functions at %.8uX\n", bar & ~KZERO); + print("tcmp59Xpci: CardBus functions at %.8ulX\n", bar & ~KZERO); } tcmadapter(port, irq, p->tbdf, p->did, bar); @@ -1759,6 +1781,7 @@ etherelnk3reset(Ether* ether) Ctlr *ctlr; static int scandone; char *p; + ulong cbfns; /* * Scan for adapter on PCI, EISA and finally @@ -1777,6 +1800,7 @@ etherelnk3reset(Ether* ether) */ port = 0; did = 0; + cbfns = 0; bpp = &adapter; for(bp = *bpp; bp; bp = bp->next){ ap = (Adapter*)bp->rp; @@ -1785,7 +1809,7 @@ etherelnk3reset(Ether* ether) did = ap->did; ether->irq = ap->irq; ether->tbdf = ap->tbdf; - ether->mem = ap->cbfns; + cbfns = ap->cbfns; *bpp = bp->next; freeb(bp); break; @@ -2034,6 +2058,9 @@ etherelnk3reset(Ether* ether) if(rxearly >= 2048) ctlr->ts = 2; + ctlr->did = did; + ctlr->cbfns = cbfns; + COMMAND(port, StatisticsEnable, 0); /* diff --git a/pc/etherwavelan.c b/pc/etherwavelan.c index 11156b1d0d888982e6326620fcabe20797b9f85f..f8044a9231e39dc3631913944bf99a34fbb88ace 100644 --- a/pc/etherwavelan.c +++ b/pc/etherwavelan.c @@ -1187,7 +1187,7 @@ reset(Ether* ether) if (ioalloc(ether->port,WIOLen,0,"wavelan")<0){ print("#l%d: port 0x%lx in use\n", ether->ctlrno, ether->port); - goto abort; + goto abort1; } if ((ctlr->slot = pcmspecial("WaveLAN/IEEE", ether))<0){ @@ -1267,6 +1267,8 @@ reset(Ether* ether) return 0; abort: + iofree(ether->port); +abort1: iunlock(&ctlr->Lock); free(ctlr); ether->ctlr = nil;