#include <devices/lnx_virtio_pci.h>
#include <palacios/vm_guest_mem.h>
#include <palacios/vmm_sprintf.h>
-#include <palacios/vmm_vnet.h>
+#include <vnet/vnet.h>
#include <palacios/vmm_lock.h>
#include <palacios/vmm_util.h>
#include <devices/pci.h>
#define PrintDebug(fmt, args...)
#endif
+#ifndef V3_CONFIG_VNET
+static int net_debug = 0;
+#endif
+
#define TX_QUEUE_SIZE 4096
#define RX_QUEUE_SIZE 4096
#define CTRL_QUEUE_SIZE 64
uint8_t mergeable_rx_bufs;
struct v3_timer * timer;
- void * poll_thread;
+ struct vnet_thread * poll_thread;
struct nic_statistics stats;
}
V3_Net_Print(2, "Virtio-NIC: virtio_tx: size: %d\n", len);
- if(v3_net_debug >= 4){
+ if(net_debug >= 4){
v3_hexdump(buf, len, NULL, 0);
}
}
static inline void enable_cb(struct virtio_queue *queue){
- queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG;
+ if(queue->used){
+ queue->used->flags &= ~ VRING_NO_NOTIFY_FLAG;
+ }
}
static inline void disable_cb(struct virtio_queue *queue) {
- queue->used->flags |= VRING_NO_NOTIFY_FLAG;
+ if(queue->used){
+ queue->used->flags |= VRING_NO_NOTIFY_FLAG;
+ }
}
static int handle_pkt_tx(struct guest_info * core,
virtio_setup_queue(core, virtio, &virtio->tx_vq, pfn, page_addr);
if(virtio->tx_notify == 0){
disable_cb(&virtio->tx_vq);
- V3_THREAD_WAKEUP(virtio->poll_thread);
+ vnet_thread_wakeup(virtio->poll_thread);
}
break;
case 2:
unsigned long flags;
V3_Net_Print(2, "Virtio-NIC: virtio_rx: size: %d\n", size);
- if(v3_net_debug >= 4){
+ if(net_debug >= 4){
v3_hexdump(buf, size, NULL, 0);
}
/* kick guest to refill the queue */
virtio->virtio_cfg.pci_isr = 0x1;
v3_pci_raise_irq(virtio->virtio_dev->pci_bus, 0, virtio->pci_dev);
- v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].cpu_id, 0);
+ v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].pcpu_id, 0);
virtio->stats.rx_interrupts ++;
goto err_exit;
/* notify guest if it is in guest mode */
if(virtio->rx_notify == 1 &&
- V3_Get_CPU() != virtio->virtio_dev->vm->cores[0].cpu_id){
- v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].cpu_id, 0);
+ V3_Get_CPU() != virtio->virtio_dev->vm->cores[0].pcpu_id){
+ v3_interrupt_cpu(virtio->virtio_dev->vm, virtio->virtio_dev->vm->cores[0].pcpu_id, 0);
}
return 0;
handle_pkt_tx(&(virtio->vm->cores[0]), virtio);
v3_yield(NULL);
}else {
- V3_THREAD_SLEEP();
+ vnet_thread_sleep(-1);
}
}
return 0;
}
+
#define RATE_UPPER_THRESHOLD 10 /* 10000 pkts per second, around 100Mbits */
#define RATE_LOWER_THRESHOLD 1
#define PROFILE_PERIOD 10000 /*us*/
uint64_t period_us;
static int profile_ms = 0;
+ if(!net_state->status){ /* VNIC is not in working status */
+ return;
+ }
+
period_us = (1000*cpu_cycles)/cpu_freq;
net_state->past_us += period_us;
V3_Print("Virtio NIC: Switch TX to VMM driven mode\n");
disable_cb(&(net_state->tx_vq));
net_state->tx_notify = 0;
- V3_THREAD_WAKEUP(net_state->poll_thread);
+ vnet_thread_wakeup(net_state->poll_thread);
}
if(tx_rate < RATE_LOWER_THRESHOLD && net_state->tx_notify == 0){
net_state->timer = v3_add_timer(&(info->cores[0]),&timer_ops,net_state);
+ PrintError("net_state 0x%p\n", (void *)net_state);
+
ops->recv = virtio_rx;
ops->frontend_data = net_state;
memcpy(ops->fnt_mac, virtio->mac, ETH_ALEN);
- net_state->poll_thread = V3_CREATE_THREAD(virtio_tx_flush, (void *)net_state, "Virtio_Poll");
+ net_state->poll_thread = vnet_start_thread(virtio_tx_flush, (void *)net_state, "Virtio_Poll");
+
+ net_state->status = 1;
return 0;
}