X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_nic.c;h=a21bdb82b374bc75caaa8dba2efd7afc0c826ab6;hp=f68d3df88456ce27a6046af309d04dffdb92a83a;hb=9f4b6075333bb578af9516d252028c6174e0bb40;hpb=d287b841e1a6f753fe57a01a5e11b8a069844b2a diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index f68d3df..a21bdb8 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -108,7 +108,7 @@ struct virtio_net_state { #if 1 //Temporarly for debug static void print_packet(uchar_t *pkt, int size) { - PrintDebug("Vnet: print_data_packet: size: %d\n", size); + PrintDebug("Virtio Nic: print_data_packet: size: %d\n", size); v3_hexdump(pkt, size, NULL, 0); } @@ -124,7 +124,11 @@ static int send(uint8_t * buf, uint32_t count, void * private_data, struct vm_de struct virtio_net_state *virtio_state = (struct virtio_net_state *)private_data; if (virtio_state == temp_net_states[0]) - __virtio_dev_send(buf, count, temp_net_states[1]); + __virtio_dev_send(buf, count, temp_net_states[1]); + + if (virtio_state == temp_net_states[1]){ //return a RARP packet + __virtio_dev_send(buf, count, temp_net_states[0]); + } return count; } @@ -179,7 +183,7 @@ static int pkt_write(struct virtio_net_state * virtio, struct vring_desc * buf_d uint8_t * buf = NULL; uint32_t len = buf_desc->length; - PrintDebug("Handling Virtio Net write, net_state: %p\n", virtio); + PrintDebug("Virtio NIC: Handling Virtio Write, net_state: %p\n", virtio); if (guest_pa_to_host_va(virtio->virtio_dev->vm, buf_desc->addr_gpa, (addr_t *)&(buf)) == -1) { PrintError("Could not translate buffer address\n"); @@ -247,7 +251,7 @@ static int send_pkt_to_guest(struct virtio_net_state * virtio, uchar_t * buf, ui PrintDebug("VIRTIO NIC: sending packet to net_state %p, size:%d", virtio, size); if (!raw) { - data_len -= hdr_len; + data_len -= hdr_len; } build_receive_header(&hdr, buf, 1); @@ -280,21 +284,42 @@ static int send_pkt_to_guest(struct virtio_net_state * virtio, uchar_t * buf, ui //copy header to the header descriptor memcpy((void *)hdr_addr, &hdr, sizeof(struct virtio_net_hdr)); + //Zheng 01/02/2010: zero payload + if (offset >= data_len) { + hdr_desc->flags &= ~VIRTIO_NEXT_FLAG; + } + //copy data to the next descriptors - for (buf_idx = 0; offset < data_len; buf_idx = q->desc[hdr_idx].next) { + //Zheng 01/02/2010: put data into the next descriptor, rather than 0! + for (buf_idx = hdr_desc->next; offset < data_len; buf_idx = q->desc[hdr_idx].next) { + // for (buf_idx = 0; offset < data_len; buf_idx = q->desc[hdr_idx].next) { struct vring_desc * buf_desc = &(q->desc[buf_idx]); uint32_t len = 0; - buf_desc->flags = VIRTIO_NEXT_FLAG; + //Zheng 01/02/2010: commented this - we need to check + // if there still is some data left + //buf_desc->flags = VIRTIO_NEXT_FLAG; + + PrintError("JACK: copying packet to up desc (len = %d)\n", data_len - offset); + v3_hexdump(buf + offset, data_len - offset, NULL, 0); + len = copy_data_to_desc(virtio, buf_desc, buf + offset, data_len - offset); offset += len; + + //Zheng 01/02/2010: check if there still is some data left + if (offset < data_len) { + buf_desc->flags = VIRTIO_NEXT_FLAG; + } + buf_desc->length = len; // TODO: do we need this? + PrintError("JACK: setting buffer descriptor length to %d)\n", buf_desc->length); } + 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 = data_len; // What do we set this to???? + q->used->ring[q->used->index % q->queue_size].length = data_len + hdr_len; // This should be the total length of data sent to guest (header+pkt_data) q->used->index++; q->cur_avail_idx++; @@ -306,6 +331,8 @@ static int send_pkt_to_guest(struct virtio_net_state * virtio, uchar_t * buf, ui virtio->virtio_cfg.pci_isr = 0x1; } + + PrintError("\n\n\n\n"); return offset; }