nic_state->statistics.rx_interrupts ++;
- PrintDebug("NE2000: Raise IRQ\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000: Raise IRQ\n");
}
return 0;
static int tx_one_pkt(struct ne2k_state * nic_state, uchar_t *pkt, uint32_t length) {
#ifdef V3_CONFIG_DEBUG_NE2K
- PrintDebug("NE2000: Send Packet:\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000: Send Packet:\n");
v3_hexdump(pkt, length, NULL, 0);
#endif
}
if (ne2k_rxbuf_full(regs)) {
- PrintError("Ne2k: received buffer overflow\n");
+ PrintError(VM_NONE, VCORE_NONE, "Ne2k: received buffer overflow\n");
return -1;
}
struct ne2k_state * nic_state = (struct ne2k_state *)private_data;
#ifdef V3_CONFIG_DEBUG_NE2K
- PrintDebug("\nNe2k: Packet Received:\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "\nNe2k: Packet Received:\n");
v3_hexdump(buf, size, NULL, 0);
#endif
val = mem_readl(nic_state, addr);
break;
default:
- PrintError("ne2k_data_read error: invalid length %d\n", length);
+ PrintError(VM_NONE, VCORE_NONE, "ne2k_data_read error: invalid length %d\n", length);
val = 0x0;
}
dma_update(nic_state, length);
memcpy(dst, &val, length);
- PrintDebug("NE2000 read: port:0x%x (%u bytes): 0x%x", port & 0x1f, length, val);
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000 read: port:0x%x (%u bytes): 0x%x", port & 0x1f, length, val);
return length;
}
mem_writel(nic_state, addr, val);
break;
default:
- PrintError("NE2000 port write error: invalid length %d\n", length);
+ PrintError(VM_NONE, VCORE_NONE, "NE2000 port write error: invalid length %d\n", length);
}
dma_update(nic_state, length);
- PrintDebug("NE2000: Write port:0x%x (%u bytes): 0x%x\n", port & 0x1f, length, val);
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000: Write port:0x%x (%u bytes): 0x%x\n", port & 0x1f, length, val);
return length;
}
static int reset_device(struct ne2k_state * nic_state) {
ne2k_init_state(nic_state);
- PrintDebug("NE2000: Reset device\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000: Reset device\n");
return 0;
}
struct ne2k_registers * regs = (struct ne2k_registers *)&(nic_state->context);
if (length != 1) {
- PrintError("Invalid write length to NE2000 Command register\n");
+ PrintError(core->vm_info, core, "Invalid write length to NE2000 Command register\n");
return -1;
}
struct ne2k_state * nic_state = (struct ne2k_state *)private_data;
if (length != 1) {
- PrintError("Invalid read length to NE2000 Command register\n");
+ PrintError(core->vm_info, core, "Invalid read length to NE2000 Command register\n");
return -1;
}
*(uint8_t *)dst = nic_state->context.cmd.val;
- PrintDebug("ne2k_read: port:0x%x val: 0x%x\n", port, *(uint8_t *)dst);
+ PrintDebug(core->vm_info, core, "ne2k_read: port:0x%x val: 0x%x\n", port, *(uint8_t *)dst);
return length;
}
uint8_t page = regs->cmd.pg_sel;
if (length != 1){
- PrintError("NE2000 port write error: length %d port 0x%xnot equal to 1\n", length, port);
+ PrintError(core->vm_info, core, "NE2000 port write error: length %d port 0x%xnot equal to 1\n", length, port);
return -1;
}
uint8_t val = *(uint8_t *)src;
- PrintDebug("NE2000: write port:0x%x val: 0x%x\n", port, (uint8_t)val);
+ PrintDebug(core->vm_info, core, "NE2000: write port:0x%x val: 0x%x\n", port, (uint8_t)val);
if (page == 0) {
switch (idx) {
break;
default:
- PrintError("NE2000 port write error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 port write error: invalid port:0x%x\n", port);
return -1;
}
} else if (page == 1) {
break;
default:
- PrintError("NE2000 write port error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 write port error: invalid port:0x%x\n", port);
return -1;
}
} else if (page == 2) {
break;
default:
- PrintError("NE2000 write port error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 write port error: invalid port:0x%x\n", port);
return -1;
}
} else {
- PrintError("NE2000: Invalid Register Page Value\n");
+ PrintError(core->vm_info, core, "NE2000: Invalid Register Page Value\n");
return -1;
}
uint8_t page = regs->cmd.pg_sel;
if (length > 1) {
- PrintError("ne2k_read error: length %d\n", length);
+ PrintError(core->vm_info, core, "ne2k_read error: length %d\n", length);
return length;
}
break;
default:
- PrintError("NE2000 port read error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 port read error: invalid port:0x%x\n", port);
return -1;
}
} else if (page == 1) {
break;
default:
- PrintError("ne2k_read error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "ne2k_read error: invalid port:0x%x\n", port);
return -1;
}
} else if (page == 2) {
*(uint8_t *)dst = regs->imr.val;
break;
default:
- PrintError("NE2000 port read error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 port read error: invalid port:0x%x\n", port);
return -1;
}
} else {
- PrintError("NE2000 port read: Invalid Register Page Value\n");
+ PrintError(core->vm_info, core, "NE2000 port read: Invalid Register Page Value\n");
return -1;
}
- PrintDebug("NE2000 port read: port:0x%x val: 0x%x\n", port, *(uint8_t *)dst);
+ PrintDebug(core->vm_info, core, "NE2000 port read: port:0x%x val: 0x%x\n", port, *(uint8_t *)dst);
return length;
}
break;
default:
- PrintError("NE2000 port write error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 port write error: invalid port:0x%x\n", port);
return -1;
}
break;
default:
- PrintError("NE2000 port read error: invalid port:0x%x\n", port);
+ PrintError(core->vm_info, core, "NE2000 port read error: invalid port:0x%x\n", port);
return -1;
}
}
-static int pci_config_update(uint_t reg_num,
+static int pci_config_update(struct pci_device * pci_dev,
+ uint32_t reg_num,
void * src,
uint_t length,
void * private_data) {
- PrintDebug("PCI Config Update\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "PCI Config Update\n");
/* Do we need this? */
struct v3_pci_bar bars[6];
struct pci_device * pci_dev = NULL;
- PrintDebug("NE2000: PCI Enabled\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000: PCI Enabled\n");
for (i = 0; i < 6; i++) {
bars[i].type = PCI_BAR_NONE;
if (pci_dev == NULL) {
- PrintError("NE2000: Could not register PCI Device\n");
+ PrintError(VM_NONE, VCORE_NONE, "NE2000: Could not register PCI Device\n");
return -1;
}
nic_state->pci_dev = pci_dev;
}else {
- PrintDebug("NE2000: Not attached to PCI\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "NE2000: Not attached to PCI\n");
v3_dev_hook_io(nic_state->dev, NIC_REG_BASE_PORT , &ne2k_cmd_read, &ne2k_cmd_write);
char * macstr = v3_cfg_val(cfg, "mac");
nic_state = (struct ne2k_state *)V3_Malloc(sizeof(struct ne2k_state));
+
+ if (!nic_state) {
+ PrintError(vm, VCORE_NONE, "Cannot allocate in init\n");
+ return -1;
+ }
+
memset(nic_state, 0, sizeof(struct ne2k_state));
nic_state->pci_bus = pci_bus;
nic_state->vm = vm;
if (macstr != NULL && !str2mac(macstr, nic_state->mac)) {
- PrintDebug("NE2000: Mac specified %s\n", macstr);
+ PrintDebug(vm, VCORE_NONE, "NE2000: Mac specified %s\n", macstr);
}else {
- PrintDebug("NE2000: MAC not specified\n");
+ PrintDebug(vm, VCORE_NONE, "NE2000: MAC not specified\n");
random_ethaddr(nic_state->mac);
}
struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, nic_state);
if (dev == NULL) {
- PrintError("NE2000: Could not attach device %s\n", dev_id);
+ PrintError(vm, VCORE_NONE, "NE2000: Could not attach device %s\n", dev_id);
V3_Free(nic_state);
return -1;
}
nic_state->dev = dev;
if (v3_dev_add_net_frontend(vm, dev_id, connect_fn, (void *)nic_state) == -1) {
- PrintError("NE2000: Could not register %s as net frontend\n", dev_id);
+ PrintError(vm, VCORE_NONE, "NE2000: Could not register %s as net frontend\n", dev_id);
v3_remove_device(dev);
V3_Free(nic_state);
return -1;