Skip to content

Instantly share code, notes, and snippets.

@oraccha
Created October 10, 2010 01:19
Show Gist options
  • Save oraccha/618812 to your computer and use it in GitHub Desktop.
Save oraccha/618812 to your computer and use it in GitHub Desktop.
static void
igbepci(void)
{
int cls;
Pcidev *p;
Ctlr *ctlr;
void *mem;
p = nil;
while(p = pcimatch(p, 0, 0)){
if(p->ccrb != 0x02 || p->ccru != 0)
continue;
switch((p->did<<16)|p->vid){
default:
continue;
case i82543gc:
case i82544ei:
case i82544eif:
case i82544gc:
case i82547ei:
case i82540em:
case i82540eplp:
case i82541gi:
case i82547gi:
case i82541gi2:
case i82541pi:
case i82545em:
case i82545gmc:
case i82546gb:
case i82546eb:
break;
}
mem = vmap(p->mem[0].bar & ~0x0F, p->mem[0].size);
if(mem == nil){
print("igbe: can't map %8.8luX\n", p->mem[0].bar);
continue;
}
cls = pcicfgr8(p, PciCLS);
switch(cls){
default:
print("igbe: unexpected CLS - %d\n", cls*4);
break;
case 0x00:
case 0xFF:
print("igbe: unusable CLS - %d\n", cls*4);
/*
continue;
*/
#define CACHELINESZ 32
cls = CACHELINESZ / sizeof(long);
pcicfgw8(p, PciCLS, cls);
break;
case 0x08:
case 0x10:
break;
}
ctlr = malloc(sizeof(Ctlr));
ctlr->port = p->mem[0].bar & ~0x0F;
ctlr->pcidev = p;
ctlr->id = (p->did<<16)|p->vid;
ctlr->cls = cls*4;
ctlr->nic = mem;
if(igbereset(ctlr)){
free(ctlr);
vunmap(mem, p->mem[0].size);
continue;
}
pcisetbme(p);
if(igbectlrhead != nil)
igbectlrtail->next = ctlr;
else
igbectlrhead = ctlr;
igbectlrtail = ctlr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment