Kprof uses an IRQ alarm
[akaros.git] / kern / drivers / dev / ether.c
index 29eb3f7..2637485 100644 (file)
 #include <ip.h>
 
 enum {
-       Type8021Q=      0x8100, /* value of type field for 802.1[pQ] tags */
+       Type8021Q = 0x8100,                     /* value of type field for 802.1[pQ] tags */
 };
 
 static struct ether *etherxx[MaxEther];        /* real controllers */
-static struct ether*   vlanalloc(struct ether*, int);
-static void    vlanoq(struct ether*, struct block*);
+static struct ether *vlanalloc(struct ether *, int);
+static void vlanoq(struct ether *, struct block *);
 
-struct chan*
-etherattach(char* spec)
+struct chan *etherattach(char *spec)
 {
        ERRSTACK(1);
        uint32_t ctlrno;
@@ -47,32 +46,31 @@ etherattach(char* spec)
 
        ctlrno = 0;
        vlanid = 0;
-       if(spec && *spec){
+       if (spec && *spec) {
                ctlrno = strtoul(spec, &p, 0);
                /* somebody interpret this for me. */
                if (((ctlrno == 0) && (p == spec)) ||
-                   (ctlrno >= MaxEther) ||
-                   ((*p) && (*p != '.')))
+                       (ctlrno >= MaxEther) || ((*p) && (*p != '.')))
                        error(Ebadarg);
-               if(*p == '.'){  /* vlan */
-                       vlanid = strtoul(p+1, &p, 0);
-                       if(vlanid <= 0 || vlanid > 0xFFF || *p)
+               if (*p == '.') {        /* vlan */
+                       vlanid = strtoul(p + 1, &p, 0);
+                       if (vlanid <= 0 || vlanid > 0xFFF || *p)
                                error(Ebadarg);
                }
        }
-       if((ether = etherxx[ctlrno]) == 0)
+       if ((ether = etherxx[ctlrno]) == 0)
                error(Enodev);
        rlock(&ether->rwlock);
-       if(waserror()){
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
-       if(vlanid){
-               if(ether->maxmtu < ETHERMAXTU+4)
+       if (vlanid) {
+               if (ether->maxmtu < ETHERMAXTU + 4)
                        error("interface cannot support 802.1 tags");
                vlan = vlanalloc(ether, vlanid);
                chan = devattach('l', spec);
-               chan->dev = ctlrno  + (vlanid<<8);
+               chan->dev = ctlrno + (vlanid << 8);
                chan->aux = vlan;
                poperror();
                runlock(&ether->rwlock);
@@ -81,28 +79,27 @@ etherattach(char* spec)
        chan = devattach('l', spec);
        chan->dev = ctlrno;
        chan->aux = ether;
-       if(ether->attach)
+       if (ether->attach)
                ether->attach(ether);
        poperror();
        runlock(&ether->rwlock);
        return chan;
 }
 
-static void
-ethershutdown(void)
+static void ethershutdown(void)
 {
        struct ether *ether;
        int i;
 
-       for(i=0; i<MaxEther; i++){
+       for (i = 0; i < MaxEther; i++) {
                ether = etherxx[i];
-               if(ether != NULL && ether->detach != NULL)
+               if (ether != NULL && ether->detach != NULL)
                        ether->detach(ether);
        }
 }
 
-static struct walkqid*
-etherwalk(struct chan* chan, struct chan *nchan, char **name, int nname)
+static struct walkqid *etherwalk(struct chan *chan, struct chan *nchan,
+                                                                char **name, int nname)
 {
        ERRSTACK(1);
        struct walkqid *wq;
@@ -110,20 +107,19 @@ etherwalk(struct chan* chan, struct chan *nchan, char **name, int nname)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
        wq = netifwalk(&ether->netif, chan, nchan, name, nname);
-       if(wq && wq->clone != NULL && wq->clone != chan)
+       if (wq && wq->clone != NULL && wq->clone != chan)
                wq->clone->aux = ether;
        poperror();
        runlock(&ether->rwlock);
        return wq;
 }
 
-static int
-etherstat(struct chan* chan, uint8_t* dp, int n)
+static int etherstat(struct chan *chan, uint8_t * dp, int n)
 {
        ERRSTACK(1);
        int s;
@@ -131,7 +127,7 @@ etherstat(struct chan* chan, uint8_t* dp, int n)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
@@ -141,8 +137,7 @@ etherstat(struct chan* chan, uint8_t* dp, int n)
        return s;
 }
 
-static struct chan*
-etheropen(struct chan* chan, int omode)
+static struct chan *etheropen(struct chan *chan, int omode)
 {
        ERRSTACK(1);
        struct chan *c;
@@ -150,7 +145,7 @@ etheropen(struct chan* chan, int omode)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
@@ -160,15 +155,14 @@ etheropen(struct chan* chan, int omode)
        return c;
 }
 
-static void
-etherclose(struct chan* chan)
+static void etherclose(struct chan *chan)
 {
        ERRSTACK(1);
        struct ether *ether;
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
@@ -177,8 +171,7 @@ etherclose(struct chan* chan)
        runlock(&ether->rwlock);
 }
 
-static long
-etherread(struct chan* chan, void* buf, long n, int64_t off)
+static long etherread(struct chan *chan, void *buf, long n, int64_t off)
 {
        ERRSTACK(1);
        struct ether *ether;
@@ -187,20 +180,20 @@ etherread(struct chan* chan, void* buf, long n, int64_t off)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
-       if((chan->qid.type & QTDIR) == 0 && ether->ifstat){
+       if ((chan->qid.type & QTDIR) == 0 && ether->ifstat) {
                /*
                 * With some controllers it is necessary to reach
                 * into the chip to extract statistics.
                 */
-               if(NETTYPE(chan->qid.path) == Nifstatqid){
+               if (NETTYPE(chan->qid.path) == Nifstatqid) {
                        r = ether->ifstat(ether, buf, n, offset);
                        goto out;
                }
-               if(NETTYPE(chan->qid.path) == Nstatqid)
+               if (NETTYPE(chan->qid.path) == Nstatqid)
                        ether->ifstat(ether, buf, 0, offset);
        }
        r = netifread(&ether->netif, chan, buf, n, offset);
@@ -210,8 +203,7 @@ out:
        return r;
 }
 
-static struct block*
-etherbread(struct chan* chan, long n, uint32_t offset)
+static struct block *etherbread(struct chan *chan, long n, uint32_t offset)
 {
        ERRSTACK(1);
        struct block *b;
@@ -219,7 +211,7 @@ etherbread(struct chan* chan, long n, uint32_t offset)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
@@ -229,8 +221,7 @@ etherbread(struct chan* chan, long n, uint32_t offset)
        return b;
 }
 
-static int
-etherwstat(struct chan* chan, uint8_t* dp, int n)
+static int etherwstat(struct chan *chan, uint8_t * dp, int n)
 {
        ERRSTACK(1);
        struct ether *ether;
@@ -238,7 +229,7 @@ etherwstat(struct chan* chan, uint8_t* dp, int n)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
@@ -248,35 +239,33 @@ etherwstat(struct chan* chan, uint8_t* dp, int n)
        return r;
 }
 
-static void
-etherrtrace(struct netfile* f, struct etherpkt* pkt, int len)
+static void etherrtrace(struct netfile *f, struct etherpkt *pkt, int len)
 {
        int i, n;
        struct block *bp;
 
-       if(qwindow(f->in) <= 0)
+       if (qwindow(f->in) <= 0)
                return;
-       if(len > 58)
+       if (len > 58)
                n = 58;
        else
                n = len;
        bp = iallocb(64);
-       if(bp == NULL)
+       if (bp == NULL)
                return;
        memmove(bp->wp, pkt->d, n);
        i = milliseconds();
-       bp->wp[58] = len>>8;
+       bp->wp[58] = len >> 8;
        bp->wp[59] = len;
-       bp->wp[60] = i>>24;
-       bp->wp[61] = i>>16;
-       bp->wp[62] = i>>8;
+       bp->wp[60] = i >> 24;
+       bp->wp[61] = i >> 16;
+       bp->wp[62] = i >> 8;
        bp->wp[63] = i;
        bp->wp += 64;
        qpass(f->in, bp);
 }
 
-struct block*
-etheriq(struct ether* ether, struct block* bp, int fromwire)
+struct block *etheriq(struct ether *ether, struct block *bp, int fromwire)
 {
        struct etherpkt *pkt;
        uint16_t type;
@@ -287,16 +276,16 @@ etheriq(struct ether* ether, struct block* bp, int fromwire)
 
        ether->netif.inpackets++;
 
-       pkt = (struct etherpkt*)bp->rp;
+       pkt = (struct etherpkt *)bp->rp;
        len = BLEN(bp);
-       type = (pkt->type[0]<<8)|pkt->type[1];
-       if(type == Type8021Q && ether->nvlan){
-               vlanid = nhgets(bp->rp+2*Eaddrlen+2) & 0xFFF;
-               if(vlanid){
-                       for(i = 0; i < ARRAY_SIZE(ether->vlans); i++){
+       type = (pkt->type[0] << 8) | pkt->type[1];
+       if (type == Type8021Q && ether->nvlan) {
+               vlanid = nhgets(bp->rp + 2 * Eaddrlen + 2) & 0xFFF;
+               if (vlanid) {
+                       for (i = 0; i < ARRAY_SIZE(ether->vlans); i++) {
                                vlan = ether->vlans[i];
-                               if(vlan != NULL && vlan->vlanid == vlanid){
-                                       memmove(bp->rp+4, bp->rp, 2*Eaddrlen);
+                               if (vlan != NULL && vlan->vlanid == vlanid) {
+                                       memmove(bp->rp + 4, bp->rp, 2 * Eaddrlen);
                                        bp->rp += 4;
                                        return etheriq(vlan, bp, fromwire);
                                }
@@ -310,9 +299,10 @@ etheriq(struct ether* ether, struct block* bp, int fromwire)
 
        multi = pkt->d[0] & 1;
        /* check for valid multcast addresses */
-       if(multi && memcmp(pkt->d, ether->netif.bcast, sizeof(pkt->d)) != 0 && ether->netif.prom == 0){
-               if(!activemulti(&ether->netif, pkt->d, sizeof(pkt->d))){
-                       if(fromwire){
+       if (multi && memcmp(pkt->d, ether->netif.bcast, sizeof(pkt->d)) != 0
+               && ether->netif.prom == 0) {
+               if (!activemulti(&ether->netif, pkt->d, sizeof(pkt->d))) {
+                       if (fromwire) {
                                freeb(bp);
                                bp = 0;
                        }
@@ -330,35 +320,33 @@ etheriq(struct ether* ether, struct block* bp, int fromwire)
         * attempt to simply pass it into one of the connections, thereby
         * saving a copy of the data (usual case hopefully).
         */
-       for(fp = ether->netif.f; fp < ep; fp++){
-               if((f = *fp) && (f->type == type || f->type < 0))
-               if(tome || multi || f->prom){
-                       /* Don't want to hear bridged packets */
-                       if(f->bridge && !fromwire && !fromme)
-                               continue;
-                       if(!f->headersonly){
-                               if(fromwire && fx == 0)
-                                       fx = f;
-                               else if((xbp = iallocb(len))){
-                                       memmove(xbp->wp, pkt, len);
-                                       xbp->wp += len;
-                                       if(qpass(f->in, xbp) < 0)
+       for (fp = ether->netif.f; fp < ep; fp++) {
+               if ((f = *fp) && (f->type == type || f->type < 0))
+                       if (tome || multi || f->prom) {
+                               /* Don't want to hear bridged packets */
+                               if (f->bridge && !fromwire && !fromme)
+                                       continue;
+                               if (!f->headersonly) {
+                                       if (fromwire && fx == 0)
+                                               fx = f;
+                                       else if ((xbp = iallocb(len))) {
+                                               memmove(xbp->wp, pkt, len);
+                                               xbp->wp += len;
+                                               if (qpass(f->in, xbp) < 0)
+                                                       ether->netif.soverflows++;
+                                       } else
                                                ether->netif.soverflows++;
-                               }
-                               else
-                                       ether->netif.soverflows++;
+                               } else
+                                       etherrtrace(f, pkt, len);
                        }
-                       else
-                               etherrtrace(f, pkt, len);
-               }
        }
 
-       if(fx){
-               if(qpass(fx->in, bp) < 0)
+       if (fx) {
+               if (qpass(fx->in, bp) < 0)
                        ether->netif.soverflows++;
                return 0;
        }
-       if(fromwire){
+       if (fromwire) {
                freeb(bp);
                return 0;
        }
@@ -366,8 +354,7 @@ etheriq(struct ether* ether, struct block* bp, int fromwire)
        return bp;
 }
 
-static int
-etheroq(struct ether* ether, struct block* bp)
+static int etheroq(struct ether *ether, struct block *bp)
 {
        int len, loopback;
        struct etherpkt *pkt;
@@ -384,35 +371,35 @@ etheroq(struct ether* ether, struct block* bp)
         * To enable bridging to work, only packets that were originated
         * by this interface are fed back.
         */
-       pkt = (struct etherpkt*)bp->rp;
+       pkt = (struct etherpkt *)bp->rp;
        len = BLEN(bp);
        loopback = memcmp(pkt->d, ether->ea, sizeof(pkt->d)) == 0;
-       if(loopback || memcmp(pkt->d, ether->netif.bcast, sizeof(pkt->d)) == 0 || ether->netif.prom){
+       if (loopback || memcmp(pkt->d, ether->netif.bcast, sizeof(pkt->d)) == 0
+               || ether->netif.prom) {
                disable_irqsave(&irq_state);
                etheriq(ether, bp, 0);
                enable_irqsave(&irq_state);
        }
 
-       if(!loopback){
-               if(ether->vlanid){
+       if (!loopback) {
+               if (ether->vlanid) {
                        /* add tag */
-                       bp = padblock(bp, 2+2);
-                       memmove(bp->rp, bp->rp+4, 2*Eaddrlen);
-                       hnputs(bp->rp+2*Eaddrlen, Type8021Q);
-                       hnputs(bp->rp+2*Eaddrlen+2, ether->vlanid & 0xFFF);     /* prio:3 0:1 vid:12 */
+                       bp = padblock(bp, 2 + 2);
+                       memmove(bp->rp, bp->rp + 4, 2 * Eaddrlen);
+                       hnputs(bp->rp + 2 * Eaddrlen, Type8021Q);
+                       hnputs(bp->rp + 2 * Eaddrlen + 2, ether->vlanid & 0xFFF);       /* prio:3 0:1 vid:12 */
                        ether = ether->ctlr;
                }
                qbwrite(ether->oq, bp);
-               if(ether->transmit != NULL)
+               if (ether->transmit != NULL)
                        ether->transmit(ether);
-       }else
+       } else
                freeb(bp);
 
        return len;
 }
 
-static long
-etherwrite(struct chan* chan, void* buf, long n, int64_t unused)
+static long etherwrite(struct chan *chan, void *buf, long n, int64_t unused)
 {
        ERRSTACK(2);
        struct ether *ether;
@@ -423,44 +410,44 @@ etherwrite(struct chan* chan, void* buf, long n, int64_t unused)
 
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
-       if(NETTYPE(chan->qid.path) != Ndataqid) {
+       if (NETTYPE(chan->qid.path) != Ndataqid) {
                l = netifwrite(&ether->netif, chan, buf, n);
-               if(l >= 0)
+               if (l >= 0)
                        goto out;
                cb = parsecmd(buf, n);
-               if(strcmp(cb->f[0], "nonblocking") == 0){
-                       if(cb->nf <= 1)
+               if (strcmp(cb->f[0], "nonblocking") == 0) {
+                       if (cb->nf <= 1)
                                onoff = 1;
                        else
                                onoff = atoi(cb->f[1]);
-                       if(ether->oq != NULL)
+                       if (ether->oq != NULL)
                                qnoblock(ether->oq, onoff);
                        kfree(cb);
                        goto out;
                }
                kfree(cb);
-               if(ether->ctl!=NULL){
-                       l = ether->ctl(ether,buf,n);
+               if (ether->ctl != NULL) {
+                       l = ether->ctl(ether, buf, n);
                        goto out;
                }
                error(Ebadctl);
        }
 
-       if(n > ether->maxmtu)
+       if (n > ether->maxmtu)
                error(Etoobig);
-       if(n < ether->minmtu)
+       if (n < ether->minmtu)
                error(Etoosmall);
        bp = allocb(n);
-       if(waserror()){
+       if (waserror()) {
                freeb(bp);
                nexterror();
        }
        memmove(bp->rp, buf, n);
-       memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
+       memmove(bp->rp + Eaddrlen, ether->ea, Eaddrlen);
        bp->wp += n;
        poperror();
 
@@ -471,16 +458,15 @@ out:
        return l;
 }
 
-static long
-etherbwrite(struct chan* chan, struct block* bp, uint32_t unused)
+static long etherbwrite(struct chan *chan, struct block *bp, uint32_t unused)
 {
        ERRSTACK(1);
        struct ether *ether;
        long n;
 
        n = BLEN(bp);
-       if(NETTYPE(chan->qid.path) != Ndataqid){
-               if(waserror()) {
+       if (NETTYPE(chan->qid.path) != Ndataqid) {
+               if (waserror()) {
                        freeb(bp);
                        nexterror();
                }
@@ -491,15 +477,15 @@ etherbwrite(struct chan* chan, struct block* bp, uint32_t unused)
        }
        ether = chan->aux;
        rlock(&ether->rwlock);
-       if(waserror()) {
+       if (waserror()) {
                runlock(&ether->rwlock);
                nexterror();
        }
-       if(n > ether->maxmtu){
+       if (n > ether->maxmtu) {
                freeb(bp);
                error(Etoobig);
        }
-       if(n < ether->minmtu){
+       if (n < ether->minmtu) {
                freeb(bp);
                error(Etoosmall);
        }
@@ -509,13 +495,11 @@ etherbwrite(struct chan* chan, struct block* bp, uint32_t unused)
        return n;
 }
 
-static void
-nop(struct ether*unused)
+static void nop(struct ether *unused)
 {
 }
 
-static long
-vlanctl(struct ether *ether, void *buf, long n)
+static long vlanctl(struct ether *ether, void *buf, long n)
 {
        uint8_t ea[Eaddrlen];
        struct ether *master;
@@ -523,19 +507,18 @@ vlanctl(struct ether *ether, void *buf, long n)
        int i;
 
        cb = parsecmd(buf, n);
-       if(cb->nf >= 2
-       && strcmp(cb->f[0], "ea")==0
-       && parseether(ea, cb->f[1]) == 0){
+       if (cb->nf >= 2
+               && strcmp(cb->f[0], "ea") == 0 && parseether(ea, cb->f[1]) == 0) {
                kfree(cb);
                memmove(ether->ea, ea, Eaddrlen);
                memmove(ether->netif.addr, ether->ea, Eaddrlen);
                return 0;
        }
-       if(cb->nf == 1 && strcmp(cb->f[0], "disable") == 0){
+       if (cb->nf == 1 && strcmp(cb->f[0], "disable") == 0) {
                master = ether->ctlr;
                qlock(&master->vlq);
-               for(i = 0; i < ARRAY_SIZE(master->vlans); i++)
-                       if(master->vlans[i] == ether){
+               for (i = 0; i < ARRAY_SIZE(master->vlans); i++)
+                       if (master->vlans[i] == ether) {
                                ether->vlanid = 0;
                                master->nvlan--;
                                break;
@@ -549,8 +532,7 @@ vlanctl(struct ether *ether, void *buf, long n)
        return -1;      /* not reached */
 }
 
-static struct ether*
-vlanalloc(struct ether *ether, int id)
+static struct ether *vlanalloc(struct ether *ether, int id)
 {
        ERRSTACK(1);
        struct ether *vlan;
@@ -558,36 +540,36 @@ vlanalloc(struct ether *ether, int id)
        char name[KNAMELEN];
 
        qlock(&ether->vlq);
-       if(waserror()){
+       if (waserror()) {
                qunlock(&ether->vlq);
                nexterror();
        }
        fid = -1;
-       for(i = 0; i < ARRAY_SIZE(ether->vlans); i++){
+       for (i = 0; i < ARRAY_SIZE(ether->vlans); i++) {
                vlan = ether->vlans[i];
-               if(vlan != NULL && vlan->vlanid == id){
+               if (vlan != NULL && vlan->vlanid == id) {
                        poperror();
                        qunlock(&ether->vlq);
                        return vlan;
                }
-               if(fid < 0 && (vlan == NULL || vlan->vlanid == 0))
+               if (fid < 0 && (vlan == NULL || vlan->vlanid == 0))
                        fid = i;
        }
-       if(fid < 0)
+       if (fid < 0)
                error(Enoifc);
        snprintf(name, sizeof(name), "ether%d.%d", ether->ctlrno, id);
        vlan = ether->vlans[fid];
-       if(vlan == NULL){
+       if (vlan == NULL) {
                vlan = kzmalloc(sizeof(struct ether), 1);
-               if(vlan == NULL)
+               if (vlan == NULL)
                        error(Enovmem);
                rwinit(&vlan->rwlock);
                qlock_init(&vlan->vlq);
                netifinit(&vlan->netif, name, Ntypes, ether->netif.limit);
                ether->vlans[fid] = vlan;       /* id is still zero, can't be matched */
                ether->nvlan++;
-       }else
-               memmove(vlan->netif.name, name, KNAMELEN-1);
+       } else
+               memmove(vlan->netif.name, name, KNAMELEN - 1);
        vlan->attach = nop;
        vlan->transmit = NULL;
        vlan->ctl = vlanctl;
@@ -614,54 +596,51 @@ vlanalloc(struct ether *ether, int id)
 }
 
 static struct {
-       char*   type;
-       int     (*reset)(struct ether*);
-} cards[MaxEther+1];
+       char *type;
+       int (*reset) (struct ether *);
+} cards[MaxEther + 1];
 
-void
-addethercard(char* t, int (*r)(struct ether*))
+void addethercard(char *t, int (*r) (struct ether *))
 {
        static int ncard;
 
-       if(ncard == MaxEther)
+       if (ncard == MaxEther)
                panic("too many ether cards");
        cards[ncard].type = t;
        cards[ncard].reset = r;
        ncard++;
 }
 
-int
-parseether(uint8_t *to, char *from)
+int parseether(uint8_t * to, char *from)
 {
        char nip[4];
        char *p;
        int i;
 
        p = from;
-       for(i = 0; i < Eaddrlen; i++){
-               if(*p == 0)
+       for (i = 0; i < Eaddrlen; i++) {
+               if (*p == 0)
                        return -1;
                nip[0] = *p++;
-               if(*p == 0)
+               if (*p == 0)
                        return -1;
                nip[1] = *p++;
                nip[2] = 0;
                to[i] = strtoul(nip, 0, 16);
-               if(*p == ':')
+               if (*p == ':')
                        p++;
        }
        return 0;
 }
 
-static void
-etherreset(void)
+static void etherreset(void)
 {
        struct ether *ether;
        int i, n, ctlrno;
        char name[KNAMELEN], buf[128];
 
-       for(ether = 0, ctlrno = 0; ctlrno < MaxEther; ctlrno++){
-               if(ether == 0)
+       for (ether = 0, ctlrno = 0; ctlrno < MaxEther; ctlrno++) {
+               if (ether == 0)
                        ether = kzmalloc(sizeof(struct ether), 0);
                memset(ether, 0, sizeof(struct ether));
                rwinit(&ether->rwlock);
@@ -678,64 +657,60 @@ etherreset(void)
                 * around online, it seems to find out ether config settings, so that we
                 * can set some flags in the opt parseing below. */
                //if(archether(ctlrno, ether) <= 0)
-               //      continue;
+               //  continue;
 
-               for(n = 0; cards[n].type; n++){
-                       #if 0
-                       if(cistrcmp(cards[n].type, ether->type))
+               for (n = 0; cards[n].type; n++) {
+#if 0
+                       if (cistrcmp(cards[n].type, ether->type))
                                continue;
-                       for(i = 0; i < ether->nopt; i++){
-                               if(cistrncmp(ether->opt[i], "ea=", 3) == 0){
-                                       if(parseether(ether->ea, &ether->opt[i][3]) == -1)
+                       for (i = 0; i < ether->nopt; i++) {
+                               if (cistrncmp(ether->opt[i], "ea=", 3) == 0) {
+                                       if (parseether(ether->ea, &ether->opt[i][3]) == -1)
                                                memset(ether->ea, 0, Eaddrlen);
-                               }else if(cistrcmp(ether->opt[i], "fullduplex") == 0 ||
-                                       cistrcmp(ether->opt[i], "10BASE-TFD") == 0)
+                               } else if (cistrcmp(ether->opt[i], "fullduplex") == 0 ||
+                                                  cistrcmp(ether->opt[i], "10BASE-TFD") == 0)
                                        ether->fullduplex = 1;
-                               else if(cistrcmp(ether->opt[i], "100BASE-TXFD") == 0)
+                               else if (cistrcmp(ether->opt[i], "100BASE-TXFD") == 0)
                                        ether->mbps = 100;
                        }
-                       #endif
-                       if(cards[n].reset(ether))
-                               break;
+#endif
+                       if (cards[n].reset(ether))
+                               continue;
                        /* might be fucked a bit - reset() doesn't know the type.  might not
                         * even matter, except for debugging. */
                        ether->type = cards[n].type;
                        snprintf(name, sizeof(name), "ether%d", ctlrno);
 
-                       if(ether->interrupt != NULL)
-                               register_dev_irq(ether->irq, ether->interrupt, ether);
-
                        i = snprintf(buf, sizeof(buf),
-                                    "#l%d: %s: %dMbps port 0x%x irq %u", ctlrno,
-                                    ether->type, ether->netif.mbps, ether->port,
-                                    ether->irq);
+                                                "#l%d: %s: %dMbps port 0x%x irq %u", ctlrno,
+                                                ether->type, ether->netif.mbps, ether->port,
+                                                ether->irq);
                        /* Looks like this is for printing MMIO addrs */
-                       #if 0
-                       if(ether->mem)
+#if 0
+                       if (ether->mem)
                                i += snprintf(buf + i, sizeof(buf) - i, " addr 0x%lx",
-                                             PADDR(ether->mem));
-                       if(ether->size)
+                                                         PADDR(ether->mem));
+                       if (ether->size)
                                i += snprintf(buf + i, sizeof(buf) - i, " size 0x%lx",
-                                             ether->size);
-                       #endif
+                                                         ether->size);
+#endif
                        i += snprintf(buf + i, sizeof(buf) - i,
-                                     ": %02.2x:%02.2x:%02.2x:%02.2x:%02.2x:%02.2x",
-                                     ether->ea[0], ether->ea[1], ether->ea[2],
-                                     ether->ea[3], ether->ea[4], ether->ea[5]);
+                                                 ": %02.2x:%02.2x:%02.2x:%02.2x:%02.2x:%02.2x",
+                                                 ether->ea[0], ether->ea[1], ether->ea[2],
+                                                 ether->ea[3], ether->ea[4], ether->ea[5]);
                        snprintf(buf + i, sizeof(buf) - i, "\n");
                        printk(buf);
 
-                       if(ether->netif.mbps == 100){
-                               netifinit(&ether->netif, name, Ntypes, 256*1024);
-                               if(ether->oq == 0)
-                                       ether->oq = qopen(256*1024, Qmsg, 0, 0);
+                       if (ether->netif.mbps == 100) {
+                               netifinit(&ether->netif, name, Ntypes, 256 * 1024);
+                               if (ether->oq == 0)
+                                       ether->oq = qopen(256 * 1024, Qmsg, 0, 0);
+                       } else {
+                               netifinit(&ether->netif, name, Ntypes, 64 * 1024);
+                               if (ether->oq == 0)
+                                       ether->oq = qopen(64 * 1024, Qmsg, 0, 0);
                        }
-                       else{
-                               netifinit(&ether->netif, name, Ntypes, 64*1024);
-                               if(ether->oq == 0)
-                                       ether->oq = qopen(64*1024, Qmsg, 0, 0);
-                       }
-                       if(ether->oq == 0)
+                       if (ether->oq == 0)
                                panic("etherreset %s", name);
                        ether->netif.alen = Eaddrlen;
                        memmove(ether->netif.addr, ether->ea, Eaddrlen);
@@ -746,41 +721,40 @@ etherreset(void)
                        break;
                }
        }
-       if(ether)
+       if (ether)
                kfree(ether);
 }
 
-static void
-etherpower(int on)
+static void etherpower(int on)
 {
        int i;
        struct ether *ether;
 
        /* TODO: fix etherpower.  locking and ether->readers are broken. */
        warn("%s needs attention.  had a rough porting from inferno", __FUNCTION__);
-       for(i = 0; i < MaxEther; i++){
-               if((ether = etherxx[i]) == NULL || ether->power == NULL)
+       for (i = 0; i < MaxEther; i++) {
+               if ((ether = etherxx[i]) == NULL || ether->power == NULL)
                        continue;
-               if(on){
+               if (on) {
                        /* brho: not sure what they are doing.  there seem to be certain
                         * assumptions about calling etherpower.  i think they are using
                         * canrlock to see if the lock is currently writelocked.  and if it
                         * was not lockable, they would assume they had the write lock and
                         * could unlock.  this is super fucked up. */
-                       if(canrlock(&ether->rwlock)) {
+                       if (canrlock(&ether->rwlock)) {
                                runlock(&ether->rwlock);        // brho added this
                                continue;
                        }
-                       if(ether->power != NULL)
+                       if (ether->power != NULL)
                                ether->power(ether, on);
                        wunlock(&ether->rwlock);
-               }else{
+               } else {
                        /* readers isn't in the ether struct...
-                       if(ether->readers)
-                               continue;
-                       */
+                          if(ether->readers)
+                          continue;
+                        */
                        wlock(&ether->rwlock);
-                       if(ether->power != NULL)
+                       if (ether->power != NULL)
                                ether->power(ether, on);
                        /* Keep locked until power goes back on */
                }
@@ -790,17 +764,16 @@ etherpower(int on)
 #define ETHERPOLY 0xedb88320
 
 /* really slow 32 bit crc for ethers */
-uint32_t
-ethercrc(uint8_t *p, int len)
+uint32_t ethercrc(uint8_t * p, int len)
 {
        int i, j;
        uint32_t crc, b;
 
        crc = 0xffffffff;
-       for(i = 0; i < len; i++){
+       for (i = 0; i < len; i++) {
                b = *p++;
-               for(j = 0; j < 8; j++){
-                       crc = (crc>>1) ^ (((crc^b) & 1) ? ETHERPOLY : 0);
+               for (j = 0; j < 8; j++) {
+                       crc = (crc >> 1) ^ (((crc ^ b) & 1) ? ETHERPOLY : 0);
                        b >>= 1;
                }
        }
@@ -827,4 +800,5 @@ struct dev etherdevtab __devtab = {
        devremove,
        etherwstat,
        etherpower,
+       devchaninfo,
 };