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.


add interrupt deinitialization to devices
[palacios.git] / palacios / src / devices / lnx_virtio_nic.c
index a9825b9..899909f 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,17 @@ exit:
     return ret_val;
 }
 
+static int virtio_free(struct virtio_net_state * virtio) {
+       
+    // unregister from PCI
+
+    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,
 };
 
 
@@ -783,6 +786,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 +817,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;
     }