Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Resoved conflict on merge of 8254.c
[palacios.git] / palacios / src / devices / lnx_virtio_nic.c
index 507ffc2..3c519aa 100644 (file)
 #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
@@ -199,7 +203,7 @@ static int tx_one_pkt(struct guest_info * core,
     }
 
     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);
     }
 
@@ -248,11 +252,15 @@ static inline int get_desc_count(struct virtio_queue * q, int index) {
 }
 
 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, 
@@ -561,7 +569,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
     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);
     }
 
@@ -660,7 +668,7 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
        /* 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;
@@ -679,8 +687,8 @@ static int virtio_rx(uint8_t * buf, uint32_t size, void * private_data) {
 
     /* 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;
@@ -725,7 +733,7 @@ static int virtio_tx_flush(void * args){
            handle_pkt_tx(&(virtio->vm->cores[0]), virtio);
            v3_yield(NULL);
        }else {
-           vnet_thread_sleep(0);
+           vnet_thread_sleep(-1);
        }
     }
 
@@ -804,6 +812,7 @@ static int register_dev(struct virtio_dev_state * virtio,
     return 0;
 }
 
+
 #define RATE_UPPER_THRESHOLD 10  /* 10000 pkts per second, around 100Mbits */
 #define RATE_LOWER_THRESHOLD 1
 #define PROFILE_PERIOD 10000 /*us*/
@@ -815,6 +824,10 @@ static void virtio_nic_timer(struct guest_info * core,
     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;
 
@@ -890,11 +903,15 @@ static int connect_fn(struct v3_vm_info * info,
        
     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 = vnet_thread_create(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;
 }