X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_nic.c;h=400cb0c0aad3ab77ecc5e3e0d8762caad9267d74;hb=9a32111c4074aafd55cd9590a24bd5c751a6fe61;hp=6300eb8aa1e4380091533670da65ce354629728d;hpb=020108512c01b113a5e8cca88a8facdc5ba5488a;p=palacios.git diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index 6300eb8..400cb0c 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -1,3 +1,4 @@ + /* * This file is part of the Palacios Virtual Machine Monitor developed * by the V3VEE Project with funding from the United States National @@ -131,8 +132,6 @@ struct virtio_net_state { uint8_t mergeable_rx_bufs; struct v3_timer * timer; - struct vnet_thread * poll_thread; - struct nic_statistics stats; struct v3_dev_net_ops * net_ops; @@ -200,7 +199,7 @@ static int tx_one_pkt(struct guest_info * core, PrintDebug("Could not translate buffer address\n"); return -1; } - + V3_Net_Print(2, "Virtio-NIC: virtio_tx: size: %d\n", len); if(net_debug >= 4){ v3_hexdump(buf, len, NULL, 0); @@ -210,10 +209,10 @@ static int tx_one_pkt(struct guest_info * core, virtio->stats.tx_dropped ++; return -1; } - + virtio->stats.tx_pkts ++; virtio->stats.tx_bytes += len; - + return 0; } @@ -227,7 +226,7 @@ static inline int copy_data_to_desc(struct guest_info * core, uint_t dst_offset){ uint32_t len; uint8_t * desc_buf = NULL; - + if (v3_gpa_to_hva(core, desc->addr_gpa, (addr_t *)&(desc_buf)) == -1) { PrintDebug("Could not translate buffer address\n"); return -1; @@ -302,17 +301,19 @@ static int handle_pkt_tx(struct guest_info * core, /* here we assumed that one ethernet pkt is not splitted into multiple buffer */ struct vring_desc * buf_desc = &(q->desc[desc_idx]); if (tx_one_pkt(core, virtio_state, buf_desc) == -1) { - PrintError("Virtio NIC: Error handling nic operation\n"); - goto exit_error; + PrintError("Virtio NIC: Fails to send packet\n"); } if(buf_desc->next & VIRTIO_NEXT_FLAG){ PrintError("Virtio NIC: TX more buffer need to read\n"); } - - q->used->ring[q->used->index % q->queue_size].id = q->avail->ring[q->cur_avail_idx % q->queue_size]; - q->used->ring[q->used->index % q->queue_size].length = buf_desc->length; /* What do we set this to???? */ - q->used->index ++; + q->used->ring[q->used->index % q->queue_size].id = + q->avail->ring[q->cur_avail_idx % q->queue_size]; + + q->used->ring[q->used->index % q->queue_size].length = + buf_desc->length; /* What do we set this to???? */ + + q->used->index ++; q->cur_avail_idx ++; if(++txed >= quote && quote > 0){ @@ -320,9 +321,9 @@ static int handle_pkt_tx(struct guest_info * core, break; } } - + v3_unlock_irqrestore(virtio_state->tx_lock, flags); - + if (txed && !(q->avail->flags & VIRTIO_NO_IRQ_FLAG)) { v3_pci_raise_irq(virtio_state->virtio_dev->pci_bus, 0, virtio_state->pci_dev); @@ -330,16 +331,14 @@ static int handle_pkt_tx(struct guest_info * core, virtio_state->stats.rx_interrupts ++; } - V3_Print("Virtio Intr Line %d\n", virtio_state->pci_dev->config_header.intr_line); - if(txed > 0) { V3_Net_Print(2, "Virtio Handle TX: txed pkts: %d, left %d\n", txed, left); } return left; - -exit_error: - + + exit_error: + v3_unlock_irqrestore(virtio_state->tx_lock, flags); return -1; } @@ -425,8 +424,8 @@ static int virtio_io_write(struct guest_info *core, pfn, page_addr); if(virtio->tx_notify == 0){ disable_cb(&virtio->tx_vq); - vnet_thread_wakeup(virtio->poll_thread); } + virtio->status = 1; break; case 2: virtio_setup_queue(core, virtio, @@ -760,7 +759,12 @@ static struct v3_device_ops dev_ops = { static int virtio_poll(int quote, void * data){ struct virtio_net_state * virtio = (struct virtio_net_state *)data; - return handle_pkt_tx(&(virtio->vm->cores[0]), virtio, quote); + if (virtio->status) { + + return handle_pkt_tx(&(virtio->vm->cores[0]), virtio, quote); + } + + return 0; } static int register_dev(struct virtio_dev_state * virtio, @@ -838,7 +842,6 @@ 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*/ @@ -870,7 +873,6 @@ static void virtio_nic_timer(struct guest_info * core, V3_Print("Virtio NIC: Switch TX to VMM driven mode\n"); disable_cb(&(net_state->tx_vq)); net_state->tx_notify = 0; - vnet_thread_wakeup(net_state->poll_thread); } if(tx_rate < RATE_LOWER_THRESHOLD && net_state->tx_notify == 0){ @@ -924,11 +926,12 @@ 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; - net_state->tx_notify = 0; - net_state->rx_notify = 0; + + net_state->tx_notify = 1; + net_state->rx_notify = 1; net_state->timer = v3_add_timer(&(info->cores[0]), - &timer_ops,net_state); + &timer_ops,net_state); ops->recv = virtio_rx; ops->poll = virtio_poll; @@ -938,8 +941,6 @@ static int connect_fn(struct v3_vm_info * info, ops->config.fnt_mac = V3_Malloc(ETH_ALEN); memcpy(ops->config.fnt_mac, virtio->mac, ETH_ALEN); - net_state->status = 1; - return 0; }