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.


added machine check framework
[palacios-OLD.git] / palacios / src / devices / lnx_virtio_nic.c
index a9825b9..ca56633 100644 (file)
@@ -115,11 +115,7 @@ struct virtio_net_state {
 #define ERR_VIRTIO_TXQ_DISABLED 6
 
 
-static int virtio_free(struct vm_device * dev) 
-{
-       
-    return 0;
-}
+
 
 static int virtio_init_state(struct virtio_net_state * virtio) 
 {
@@ -173,7 +169,7 @@ pkt_tx(struct guest_info * core,
        return -ERR_VIRTIO_OTHER;
     }
 
-    return virtio->net_ops->send(buf, len, virtio->backend_data, NULL);
+    return virtio->net_ops->send(buf, len, virtio->backend_data);
 }
 
 
@@ -236,8 +232,10 @@ static int handle_rx_kick(struct guest_info *core,
 
     flags = v3_lock_irqsave(virtio->rx_lock);
 
-    virtio->net_ops->start_rx(virtio->backend_data);
-    //disable_cb(&virtio->rx_vq);
+    if(virtio->net_ops->start_rx != NULL){
+       virtio->net_ops->start_rx(virtio->backend_data);
+    }
+       //disable_cb(&virtio->rx_vq);
 
     v3_unlock_irqrestore(virtio->rx_lock, flags);
        
@@ -651,12 +649,26 @@ exit:
     return ret_val;
 }
 
+static int virtio_free(struct virtio_dev_state * virtio) {
+    struct virtio_net_state * backend = NULL;
+    struct virtio_net_state * tmp = NULL;
+
+
+    list_for_each_entry_safe(backend, tmp, &(virtio->dev_list), dev_link) {
+
+       // unregister from PCI
+
+       list_del(&(backend->dev_link));
+       V3_Free(backend);
+    }
+
+    V3_Free(virtio);
+    return 0;
+}
+
 
 static struct v3_device_ops dev_ops = {
-    .free = virtio_free,
-    .reset = NULL,
-    .start = NULL,
-    .stop = NULL,
+    .free = (int (*)(void *))virtio_free,
 };
 
 
@@ -767,6 +779,10 @@ static int register_dev(struct virtio_dev_state * virtio,
     
     virtio_init_state(net_state);
 
+
+    /* Add backend to list of devices */
+    list_add(&(net_state->dev_link), &(virtio->dev_list));
+
     return 0;
 }
 
@@ -783,6 +799,8 @@ static int connect_fn(struct v3_vm_info * info,
 
     net_state->net_ops = ops;
     net_state->backend_data = private_data;
+    net_state->virtio_dev = virtio;
+       
 
     ops->recv = virtio_rx;
     ops->poll = virtio_nic_poll;
@@ -812,14 +830,17 @@ static int virtio_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     virtio_state->pci_bus = pci_bus;
     virtio_state->vm = vm;
 
-    struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, virtio_state);
-    if (v3_attach_device(vm, dev) == -1) {
+    struct vm_device * dev = v3_add_device(vm, dev_id, &dev_ops, virtio_state);
+
+    if (dev == NULL) {
        PrintError("Virtio NIC: Could not attach device %s\n", dev_id);
+       V3_Free(virtio_state);
        return -1;
     }
 
     if (v3_dev_add_net_frontend(vm, dev_id, connect_fn, (void *)virtio_state) == -1) {
        PrintError("Virtio NIC: Could not register %s as net frontend\n", dev_id);
+       v3_remove_device(dev);
        return -1;
     }