#include "io.h"
#include "../port/error.h"
#include "../port/netif.h"
-
-#include "etherif.h"
+#include "../port/etherif.h"
enum { /* registers */
Idr0 = 0x0000, /* MAC address */
/*
* 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);
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);
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));
bp->wp += length;
}
bp->wp -= 4;
- etheriq(edev, bp, 1);
+ etheriq(edev, bp);
}
capr = ROUNDUP(capr, 4);
{
Pcidev *p;
Ctlr *ctlr;
- int i, port;
+ int port;
/*
* Any adapter matches if no edev->port is supplied,
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;
}
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;
edev->attach = rtl8139attach;
edev->transmit = rtl8139transmit;
- edev->interrupt = rtl8139interrupt;
edev->ifstat = rtl8139ifstat;
edev->arg = 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.
*/