int isr = ((nic_state->regs.isr & nic_state->regs.imr) & 0xffff);
if(isr & 0xffff){
- v3_pci_raise_irq(nic_state->pci_bus, 0, nic_state->pci_dev);
+ v3_pci_raise_irq(nic_state->pci_bus, nic_state->pci_dev, 0);
nic_state->statistic.tx_interrupts ++;
}
}
static void prom9346_decode_command(struct EEprom9346 * eeprom, uint8_t command) {
- PrintDebug("RTL8139: eeprom command 0x%02x\n", command);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom command 0x%02x\n", command);
switch (command & Chip9346_op_mask) {
case Chip9346_op_read:
eeprom->eedo = 0;
eeprom->tick = 0;
eeprom->mode = Chip9346_data_read;
- PrintDebug("RTL8139: eeprom read from address 0x%02x data=0x%04x\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom read from address 0x%02x data=0x%04x\n",
eeprom->address, eeprom->output);
}
break;
eeprom->input = 0;
eeprom->tick = 0;
eeprom->mode = Chip9346_none; /* Chip9346_data_write */
- PrintDebug("RTL8139: eeprom begin write to address 0x%02x\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom begin write to address 0x%02x\n",
eeprom->address);
}
break;
eeprom->mode = Chip9346_none;
switch (command & Chip9346_op_ext_mask) {
case Chip9346_op_write_enable:
- PrintDebug("RTL8139: eeprom write enabled\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom write enabled\n");
break;
case Chip9346_op_write_all:
- PrintDebug("RTL8139: eeprom begin write all\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom begin write all\n");
break;
case Chip9346_op_write_disable:
- PrintDebug("RTL8139: eeprom write disabled\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom write disabled\n");
break;
}
break;
++ eeprom->tick;
- PrintDebug("eeprom: tick %d eedi=%d eedo=%d\n", eeprom->tick, eeprom->eedi, eeprom->eedo);
+ PrintDebug(VM_NONE, VCORE_NONE, "eeprom: tick %d eedi=%d eedo=%d\n", eeprom->tick, eeprom->eedi, eeprom->eedo);
switch (eeprom->mode) {
case Chip9346_enter_command_mode:
eeprom->mode = Chip9346_read_command;
eeprom->tick = 0;
eeprom->input = 0;
- PrintDebug("eeprom: +++ synchronized, begin command read\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "eeprom: +++ synchronized, begin command read\n");
}
break;
eeprom->input = 0;
eeprom->tick = 0;
- PrintDebug("eeprom: +++ end of read, awaiting next command\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "eeprom: +++ end of read, awaiting next command\n");
#else
// original behaviour
++eeprom->address;
case Chip9346_data_write:
eeprom->input = (eeprom->input << 1) | (bit & 1);
if (eeprom->tick == 16) {
- PrintDebug("RTL8139: eeprom write to address 0x%02x data=0x%04x\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom write to address 0x%02x data=0x%04x\n",
eeprom->address, eeprom->input);
eeprom->contents[eeprom->address] = eeprom->input;
{
eeprom->contents[i] = eeprom->input;
}
- PrintDebug("RTL8139: eeprom filled with data=0x%04x\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: eeprom filled with data=0x%04x\n",
eeprom->input);
eeprom->mode = Chip9346_enter_command_mode;
eeprom->eesk = eesk;
eeprom->eedi = eedi;
- PrintDebug("eeprom: +++ wires CS=%d SK=%d DI=%d DO=%d\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "eeprom: +++ wires CS=%d SK=%d DI=%d DO=%d\n",
eeprom->eecs, eeprom->eesk, eeprom->eedi, eeprom->eedo);
if (old_eecs == 0 && eecs) {
eeprom->output = 0;
eeprom->mode = Chip9346_enter_command_mode;
- PrintDebug("=== eeprom: begin access, enter command mode\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "=== eeprom: begin access, enter command mode\n");
}
if (eecs == 0) {
- PrintDebug("=== eeprom: end access\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "=== eeprom: end access\n");
return;
}
struct rtl8139_regs *regs = &(nic_state->regs);
int i;
- PrintDebug("Rtl8139: Reset\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "Rtl8139: Reset\n");
/* restore MAC address */
memcpy(regs->id, nic_state->mac, ETH_ALEN);
static void rtl8139_9346cr_write(struct rtl8139_state * nic_state, uint32_t val) {
val &= 0xff;
- PrintDebug("RTL8139: 9346CR write val=0x%02x\n", val);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: 9346CR write val=0x%02x\n", val);
/* mask unwriteable bits */
val = SET_MASKED(val, 0x31, nic_state->regs.cmd9346);
}
}
- PrintDebug("RTL8139: 9346CR read val=0x%02x\n", ret);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: 9346CR read val=0x%02x\n", ret);
return ret;
}
addr_t guestpa, host_rxbuf;
guestpa = (addr_t)regs->rbstart;
- v3_gpa_to_hva(&(nic_state->vm->cores[0]), guestpa, &host_rxbuf);
+ if (v3_gpa_to_hva(&(nic_state->vm->cores[0]), guestpa, &host_rxbuf)) {
+ PrintError(VM_NONE, VCORE_NONE, "RTL8139: cannot translate address\n");
+ return;
+ }
//wrap to the front of rx buffer
if (regs->cbr + size > nic_state->rx_bufsize){
wrap = MOD2(regs->cbr + size, nic_state->rx_bufsize);
if (wrap && !(nic_state->rx_bufsize < 64*1024 && rtl8139_rxwrap(nic_state))){
- PrintDebug("RTL8139: rx packet wrapped in buffer at %d\n", size-wrap);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: rx packet wrapped in buffer at %d\n", size-wrap);
if (size > wrap){
memcpy((void *)(host_rxbuf + regs->cbr), buf, size-wrap);
uint32_t header, val;
uint8_t bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+ header = 0;
+
if (regs->rcr & AcceptAllPhys) {
- PrintDebug("RTL8139: packet received in promiscuous mode\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: packet received in promiscuous mode\n");
} else {
if (!memcmp(pkt, bcast_addr, 6)) {
if (!(regs->rcr & AcceptBroadcast)){
- PrintDebug("RTL8139: broadcast packet rejected\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: broadcast packet rejected\n");
return -1;
}
header |= Rx_Broadcast;
- PrintDebug("RTL8139: broadcast packet received\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: broadcast packet received\n");
} else if (pkt[0] & 0x01) {
// multicast
if (!(regs->rcr & AcceptMulticast)){
- PrintDebug("RTL8139: multicast packet rejected\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: multicast packet rejected\n");
return -1;
}
int mcast_idx = compute_mcast_idx(pkt);
if (!(regs->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))){
- PrintDebug("RTL8139: multicast address mismatch\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: multicast address mismatch\n");
return -1;
}
header |= Rx_Multicast;
- PrintDebug("RTL8139: multicast packet received\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: multicast packet received\n");
} else if (!compare_ethaddr(regs->id, pkt)){
if (!(regs->rcr & AcceptMyPhys)){
- PrintDebug("RTL8139: rejecting physical address matching packet\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: rejecting physical address matching packet\n");
return -1;
}
header |= Rx_Physical;
- PrintDebug("RTL8139: physical address matching packet received\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: physical address matching packet received\n");
} else {
- PrintDebug("RTL8139: unknown packet\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: unknown packet\n");
return -1;
}
}
if(1){
- PrintDebug("RTL8139: in ring Rx mode\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: in ring Rx mode\n");
int avail = MOD2(rxbufsize + regs->capr - regs->cbr, rxbufsize);
if (avail != 0 && len + 8 >= avail){
- PrintError("rx overflow: rx buffer length %d head 0x%04x read 0x%04x === available 0x%04x need 0x%04x\n",
+ PrintError(VM_NONE, VCORE_NONE, "rx overflow: rx buffer length %d head 0x%04x read 0x%04x === available 0x%04x need 0x%04x\n",
rxbufsize, regs->cbr, regs->capr, avail, len + 8);
regs->isr |= ISR_Rxovw;
// correct buffer write pointer
regs->cbr = MOD2((regs->cbr + 3) & ~0x3, rxbufsize);
- PrintDebug("RTL8139: received: rx buffer length %d CBR: 0x%04x CAPR: 0x%04x\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: received: rx buffer length %d CBR: 0x%04x CAPR: 0x%04x\n",
rxbufsize, regs->cbr, regs->capr);
}
struct rtl8139_state *nic_state = (struct rtl8139_state *)private_data;
if (!rtl8139_receiver_enabled(nic_state)){
- PrintDebug("RTL8139: receiver disabled\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: receiver disabled\n");
nic_state->statistic.rx_dropped ++;
return 0;
}
static void rtl8139_rcr_write(struct rtl8139_state * nic_state, uint32_t val) {
- PrintDebug("RTL8139: RCR write val=0x%08x\n", val);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: RCR write val=0x%08x\n", val);
val = SET_MASKED(val, 0xf0fc0040, nic_state->regs.rcr);
nic_state->regs.rcr = val;
// reset buffer size and read/write pointers
rtl8139_reset_rxbuf(nic_state, 8192 << ((nic_state->regs.rcr >> 11) & 0x3));
- PrintDebug("RTL8139: RCR write reset buffer size to %d\n", nic_state->rx_bufsize);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: RCR write reset buffer size to %d\n", nic_state->rx_bufsize);
}
return 1;
}
- PrintDebug("RTL8139: Configuration registers are unwriteable\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: Configuration registers are unwriteable\n");
return 0;
}
unread = MOD2(regs->cbr + nic_state->rx_bufsize - regs->capr, nic_state->rx_bufsize);
if (unread != 0){
- PrintDebug("RTL8139: receiver buffer data available 0x%04x\n", unread);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: receiver buffer data available 0x%04x\n", unread);
return 0;
}
- PrintDebug("RTL8139: receiver buffer is empty\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: receiver buffer is empty\n");
return 1;
}
static void rtl8139_cmd_write(struct rtl8139_state * nic_state, uint32_t val){
val &= 0xff;
- PrintDebug("RTL8139: Cmd write val=0x%08x\n", val);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: Cmd write val=0x%08x\n", val);
if (val & CMD_Rst){
- PrintDebug("RTL8139: Cmd reset\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: Cmd reset\n");
rtl8139_reset(nic_state);
}
if (val & CMD_Re){
- PrintDebug("RTL8139: Cmd enable receiver\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: Cmd enable receiver\n");
}
if (val & CMD_Te){
- PrintDebug("RTL8139: Cmd enable transmitter\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: Cmd enable transmitter\n");
}
val = SET_MASKED(val, 0xe3, nic_state->regs.cmd);
addr_t pkt_gpa = 0, hostva = 0;
if (!transmitter_enabled(nic_state)){
- PrintError("RTL8139: fail to send from descriptor %d: transmitter disabled\n", descriptor);
+ PrintError(VM_NONE, VCORE_NONE, "RTL8139: fail to send from descriptor %d: transmitter disabled\n", descriptor);
return 0;
}
if (regs->tsd[descriptor] & TSD_Own){
- PrintError("RTL8139: fail to send from descriptor %d: owned by host\n", descriptor);
+ PrintError(VM_NONE, VCORE_NONE, "RTL8139: fail to send from descriptor %d: owned by host\n", descriptor);
return 0;
}
txsize = regs->tsd[descriptor] & 0x1fff;
pkt_gpa = (addr_t) regs->tsad[descriptor];
- PrintDebug("RTL8139: sending %d bytes from guest memory at 0x%08x\n", txsize, regs->tsad[descriptor]);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: sending %d bytes from guest memory at 0x%08x\n", txsize, regs->tsad[descriptor]);
- v3_gpa_to_hva(&(nic_state->vm->cores[0]), (addr_t)pkt_gpa, &hostva);
+ if (v3_gpa_to_hva(&(nic_state->vm->cores[0]), (addr_t)pkt_gpa, &hostva)) {
+ PrintError(VM_NONE, VCORE_NONE, "RTL8139: Cannot translate address\n");
+ return -1;
+ }
+
pkt = (uchar_t *)hostva;
#ifdef V3_CONFIG_DEBUG_RTL8139
#endif
if (TxLoopBack == (regs->tcr & TxLoopBack)){ /* loopback test */
- PrintDebug(("RTL8139: transmit loopback mode\n"));
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: transmit loopback mode\n");
rx_one_pkt(nic_state, pkt, txsize);
} else{
if (nic_state->net_ops->send(pkt, txsize, nic_state->backend_data) == 0){
- PrintDebug("RTL8139: Sent %d bytes from descriptor %d\n", txsize, descriptor);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: Sent %d bytes from descriptor %d\n", txsize, descriptor);
nic_state->statistic.tx_pkts ++;
nic_state->statistic.tx_bytes += txsize;
} else {
- PrintError("Rtl8139: Sending packet error: 0x%p\n", pkt);
+ PrintError(VM_NONE, VCORE_NONE, "Rtl8139: Sending packet error: 0x%p\n", pkt);
nic_state->statistic.tx_dropped ++;
}
}
uint8_t descriptor,
uint32_t val){
if (!transmitter_enabled(nic_state)){
- PrintDebug("RTL8139: TxStatus write val=0x%08x descriptor=%d, Transmitter not enabled\n", val, descriptor);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: TxStatus write val=0x%08x descriptor=%d, Transmitter not enabled\n", val, descriptor);
return;
}
- PrintDebug("RTL8139: TSD write val=0x%08x descriptor=%d\n", val, descriptor);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: TSD write val=0x%08x descriptor=%d\n", val, descriptor);
// mask read-only bits
val &= ~0xff00c000;
|((regs->tsd[1] & TSD_Own)?TSAD_OWN1:0)
|((regs->tsd[0] & TSD_Own)?TSAD_OWN0:0) ;
- PrintDebug("RTL8139: txsad read val=0x%04x\n", (int)ret);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: txsad read val=0x%04x\n", (int)ret);
return ret;
}
static inline void rtl8139_isr_write(struct rtl8139_state * nic_state, uint32_t val) {
struct rtl8139_regs *regs = &(nic_state->regs);
- PrintDebug("RTL8139: ISR write val=0x%04x\n", val);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: ISR write val=0x%04x\n", val);
uint16_t newisr = regs->isr & ~val;
memcpy(&val, src, length);
- PrintDebug("rtl8139 mmio write: addr:0x%x (%u bytes): 0x%x\n", (int)guest_addr, length, val);
+ PrintDebug(VM_NONE, VCORE_NONE, "rtl8139 mmio write: addr:0x%x (%u bytes): 0x%x\n", (int)guest_addr, length, val);
switch(idx) {
case RTL8139_IDR0 ... RTL8139_IDR0 + 5:
/* this value is off by 16 */
nic_state->regs.capr = MOD2(val + 0x10, nic_state->rx_bufsize);
- PrintDebug("RTL 8139: CAPR write: rx buffer length %d head 0x%04x read 0x%04x\n",
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL 8139: CAPR write: rx buffer length %d head 0x%04x read 0x%04x\n",
nic_state->rx_bufsize, nic_state->regs.cbr, nic_state->regs.capr);
}
break;
break;
case RTL8139_IMR:
{
- PrintDebug("RTL8139: IMR write val=0x%04x\n", val);
+ PrintDebug(VM_NONE, VCORE_NONE, "RTL8139: IMR write val=0x%04x\n", val);
/* mask unwriteable bits */
val = SET_MASKED(val, 0x1e00, nic_state->regs.imr);
nic_state->regs.config5 = val & 0xff;
break;
default:
- PrintDebug("rtl8139 write error: invalid port: 0x%x\n", idx);
+ PrintDebug(VM_NONE, VCORE_NONE, "rtl8139 write error: invalid port: 0x%x\n", idx);
}
return length;
memcpy(dst, &val, length);
- PrintDebug("rtl8139 mmio read: port:0x%x (%u bytes): 0x%x\n", (int)guest_addr, length, val);
+ PrintDebug(VM_NONE, VCORE_NONE, "rtl8139 mmio read: port:0x%x (%u bytes): 0x%x\n", (int)guest_addr, length, val);
return length;
}
static int rtl8139_init_state(struct rtl8139_state *nic_state) {
- PrintDebug("rtl8139: init_state\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "rtl8139: init_state\n");
nic_state->regs.tsd[0] = nic_state->regs.tsd[1] = nic_state->regs.tsd[2] = nic_state->regs.tsd[3] = TSD_Own;
}
static int rtl8139_stop_device(struct rtl8139_state * nic_state) {
- PrintDebug("rtl8139: stop device\n");
+ PrintDebug(VM_NONE, VCORE_NONE, "rtl8139: stop device\n");
nic_state->regs.cmd &= ~(CMD_Re | CMD_Te);
int i;
if (base_addr <= 0){
- PrintError("In RTL8139: Fail to Hook IO Space, base address 0x%x\n", (int) base_addr);
+ PrintError(VM_NONE, VCORE_NONE, "In RTL8139: Fail to Hook IO Space, base address 0x%x\n", (int) base_addr);
return -1;
}
if (type == PCI_BAR_IO){
- PrintDebug("In RTL8139: Hook IO ports starting from %x, size %d\n", (int) base_addr, size);
+ PrintDebug(VM_NONE, VCORE_NONE, "In RTL8139: Hook IO ports starting from %x, size %d\n", (int) base_addr, size);
for (i = 0; i < 0xff; i++){
v3_dev_hook_io(nic_state->dev, base_addr + i, &rtl8139_ioport_read, &rtl8139_ioport_write);
}
} else if (type == PCI_BAR_MEM32) {
- PrintDebug("In RTL8139: Hook memory space starting from %x, size %d\n", (int) base_addr, size);
+ PrintDebug(VM_NONE, VCORE_NONE, "In RTL8139: Hook memory space starting from %x, size %d\n", (int) base_addr, size);
//hook memory mapped I/O
v3_hook_full_mem(nic_state->vm, nic_state->vm->cores[0].cpu_id, base_addr, base_addr + 0xff,
&rtl8139_mmio_read, &rtl8139_mmio_write, nic_state);
} else {
- PrintError("In RTL8139: unknown memory type: start %x, size %d\n", (int) base_addr, size);
+ PrintError(VM_NONE, VCORE_NONE, "In RTL8139: unknown memory type: start %x, size %d\n", (int) base_addr, size);
}
return 0;
int i;
if (nic_state->pci_bus == NULL) {
- PrintError("RTL8139: Not attached to any PCI bus\n");
+ PrintError(VM_NONE, VCORE_NONE, "RTL8139: Not attached to any PCI bus\n");
return -1;
}
}
bars[0].type = PCI_BAR_IO;
- bars[0].default_base_port = 0xc100;
+ bars[0].default_base_port = -1;
bars[0].num_ports = 0x100;
bars[0].io_read = rtl8139_ioport_read;
pci_dev = v3_pci_register_device(nic_state->pci_bus, PCI_STD_DEVICE, 0, -1, 0,
"RTL8139", bars,
- NULL, NULL, NULL, nic_state);
+ NULL, NULL, NULL, NULL, nic_state);
if (pci_dev == NULL) {
- PrintError("RTL8139: Could not register PCI Device\n");
+ PrintError(VM_NONE, VCORE_NONE, "RTL8139: Could not register PCI Device\n");
return -1;
}
char * macstr = v3_cfg_val(cfg, "mac");
nic_state = (struct rtl8139_state *)V3_Malloc(sizeof(struct rtl8139_state));
+
+ if (!nic_state) {
+ PrintError(vm, VCORE_NONE, "Cannot allocate in init\n");
+ return -1;
+ }
+
memset(nic_state, 0, sizeof(struct rtl8139_state));
nic_state->pci_bus = pci_bus;
nic_state->vm = vm;
if (macstr != NULL && !str2mac(macstr, nic_state->mac)) {
- PrintDebug("RTL8139: Mac specified %s\n", macstr);
+ PrintDebug(vm, VCORE_NONE, "RTL8139: Mac specified %s\n", macstr);
}else {
- PrintDebug("RTL8139: MAC not specified\n");
+ PrintDebug(vm, VCORE_NONE, "RTL8139: 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("RTL8139: Could not attach device %s\n", dev_id);
+ PrintError(vm, VCORE_NONE, "RTL8139: 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("RTL8139: Could not register %s as net frontend\n", dev_id);
+ PrintError(vm, VCORE_NONE, "RTL8139: Could not register %s as net frontend\n", dev_id);
v3_remove_device(dev);
V3_Free(nic_state);
return -1;