]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/pc/ether8139.c
kernel: cleanup the software mouse cursor mess
[plan9front.git] / sys / src / 9 / pc / ether8139.c
index f304df603c11124b6c1e180a4cbbbbe7c3da7d3a..21a1cad3981e77cefcf8d6fbaac8e4c3e692f300 100644 (file)
@@ -11,8 +11,7 @@
 #include "io.h"
 #include "../port/error.h"
 #include "../port/netif.h"
-
-#include "etherif.h"
+#include "../port/etherif.h"
 
 enum {                                 /* registers */
        Idr0            = 0x0000,       /* MAC address */
@@ -403,7 +402,7 @@ rtl8139init(Ether* edev)
        /*
         * Receiver
         */
-       alloc = (uchar*)ROUNDUP((ulong)ctlr->alloc, 32);
+       alloc = ctlr->alloc;
        ctlr->rbstart = alloc;
        alloc += ctlr->rblen+16;
        memset(ctlr->rbstart, 0, ctlr->rblen+16);
@@ -453,7 +452,11 @@ rtl8139attach(Ether* edev)
        qlock(&ctlr->alock);
        if(ctlr->alloc == nil){
                ctlr->rblen = 1<<((Rblen>>RblenSHIFT)+13);
-               ctlr->alloc = mallocz(ctlr->rblen+16 + Ntd*Tdbsz + 32, 0);
+               ctlr->alloc = mallocalign(ctlr->rblen+16 + Ntd*Tdbsz, 32, 0, 0);
+               if(ctlr->alloc == nil){
+                       qunlock(&ctlr->alock);
+                       error(Enomem);
+               }
                rtl8139init(edev);
        }
        qunlock(&ctlr->alock);
@@ -475,7 +478,7 @@ rtl8139txstart(Ether* edev)
                size = BLEN(bp);
 
                td = &ctlr->td[ctlr->tdh];
-               if(((int)bp->rp) & 0x03){
+               if(((uintptr)bp->rp) & 0x03){
                        memmove(td->data, bp->rp, size);
                        freeb(bp);
                        csr32w(ctlr, td->tsad, PCIWADDR(td->data));
@@ -580,7 +583,7 @@ rtl8139receive(Ether* edev)
                                bp->wp += length;
                        }
                        bp->wp -= 4;
-                       etheriq(edev, bp, 1);
+                       etheriq(edev, bp);
                }
 
                capr = ROUNDUP(capr, 4);
@@ -678,7 +681,7 @@ rtl8139match(Ether* edev, int id)
 {
        Pcidev *p;
        Ctlr *ctlr;
-       int i, port;
+       int port;
 
        /*
         * Any adapter matches if no edev->port is supplied,
@@ -698,20 +701,10 @@ rtl8139match(Ether* edev, int id)
                        print("rtl8139: port %#ux in use\n", port);
                        continue;
                }
-
-               if(pcigetpms(p) > 0){
-                       pcisetpms(p, 0);
-       
-                       for(i = 0; i < 6; i++)
-                               pcicfgw32(p, PciBAR0+i*4, p->mem[i].bar);
-                       pcicfgw8(p, PciINTL, p->intl);
-                       pcicfgw8(p, PciLTR, p->ltr);
-                       pcicfgw8(p, PciCLS, p->cls);
-                       pcicfgw16(p, PciPCR, p->pcr);
-               }
-
+               pcienable(p);
                ctlr->port = port;
                if(rtl8139reset(ctlr)) {
+                       pcidisable(p);
                        iofree(port);
                        continue;
                }
@@ -752,6 +745,10 @@ rtl8139pnp(Ether* edev)
                        if(p->ccrb != 0x02 || p->ccru != 0)
                                continue;
                        ctlr = malloc(sizeof(Ctlr));
+                       if(ctlr == nil){
+                               print("rtl8139: can't allocate memory\n");
+                               continue;
+                       }
                        ctlr->pcidev = p;
                        ctlr->id = (p->did<<16)|p->vid;
 
@@ -809,7 +806,6 @@ rtl8139pnp(Ether* edev)
 
        edev->attach = rtl8139attach;
        edev->transmit = rtl8139transmit;
-       edev->interrupt = rtl8139interrupt;
        edev->ifstat = rtl8139ifstat;
 
        edev->arg = edev;
@@ -817,6 +813,8 @@ rtl8139pnp(Ether* edev)
        edev->multicast = rtl8139multicast;
 //     edev->shutdown = rtl8139shutdown;
 
+       intrenable(edev->irq, rtl8139interrupt, edev, edev->tbdf, edev->name);
+
        /*
         * This should be much more dynamic but will do for now.
         */