]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/pc/ethervirtio.c
kernel: cleanup makefile for $CONF.$O target
[plan9front.git] / sys / src / 9 / pc / ethervirtio.c
index 170425a0ea078bfea7d9ac52ecf9680420d2f4fb..eb1fa98c10a733a2565b809684866feb5ceb831c 100644 (file)
@@ -6,7 +6,7 @@
 #include "io.h"
 #include "../port/error.h"
 #include "../port/netif.h"
-#include "etherif.h"
+#include "../port/etherif.h"
 
 /*
  * virtio ethernet driver
@@ -324,8 +324,8 @@ rxproc(void *v)
 
                        blocks[i] = nil;
 
-                       b->wp = b->rp + u->len;
-                       etheriq(edev, b, 1);
+                       b->wp = b->rp + u->len - VheaderSize;
+                       etheriq(edev, b);
                        q->lastused++;
                }
        }
@@ -470,6 +470,7 @@ shutdown(Ether* edev)
 {
        Ctlr *ctlr = edev->ctlr;
        outb(ctlr->port+Qstatus, 0);
+       pciclrbme(ctlr->pcidev);
 }
 
 static void
@@ -577,6 +578,7 @@ pciprobe(int typ)
 
                c->typ = typ;
                c->pcidev = p;
+               pcienable(p);
                c->id = (p->did<<16)|p->vid;
 
                /* ยง3.1.2 Legacy Device Initialization */
@@ -591,13 +593,22 @@ pciprobe(int typ)
                for(i=0; i<nelem(c->queue); i++){
                        outs(c->port+Qselect, i);
                        n = ins(c->port+Qsize);
-                       if(n == 0 || (n & (n-1)) != 0)
+                       if(n == 0 || (n & (n-1)) != 0){
+                               if(i < 2)
+                                       print("ethervirtio: queue %d has invalid size %d\n", i, n);
                                break;
+                       }
                        if(initqueue(&c->queue[i], n) < 0)
                                break;
                        coherence();
                        outl(c->port+Qaddr, PADDR(c->queue[i].desc)/VBY2PG);
                }
+               if(i < 2){
+                       print("ethervirtio: no queues\n");
+                       pcidisable(p);
+                       free(c);
+                       continue;
+               }
                c->nqueue = i;          
        
                if(h == nil)
@@ -618,9 +629,8 @@ reset(Ether* edev)
        Ctlr *ctlr;
        int i;
 
-       if(ctlrhead == nil) {
+       if(ctlrhead == nil)
                ctlrhead = pciprobe(1);
-       }
 
        for(ctlr = ctlrhead; ctlr != nil; ctlr = ctlr->next){
                if(ctlr->active)
@@ -653,7 +663,6 @@ reset(Ether* edev)
 
        edev->attach = attach;
        edev->shutdown = shutdown;
-       edev->interrupt = interrupt;
        edev->ifstat = ifstat;
 
        if((ctlr->feat & (Fctrlvq|Fctrlrx)) == (Fctrlvq|Fctrlrx)){
@@ -661,6 +670,9 @@ reset(Ether* edev)
                edev->promiscuous = promiscuous;
        }
 
+       pcisetbme(ctlr->pcidev);
+       intrenable(edev->irq, interrupt, edev, edev->tbdf, edev->name);
+
        return 0;
 }