X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fpara_net.c;h=46e1418365e0800533c037128edab37cb8921e2f;hb=4454a172129d12e97793c9c353339b85d3335af4;hp=405b9c6c1416f3519c6a74c2fc28667910743b83;hpb=a5347db03b69dc64ce283e67b624f63baa0c364e;p=palacios.git diff --git a/palacios/src/devices/para_net.c b/palacios/src/devices/para_net.c index 405b9c6..46e1418 100644 --- a/palacios/src/devices/para_net.c +++ b/palacios/src/devices/para_net.c @@ -17,8 +17,9 @@ * redistribute, and modify it as specified in the file "V3VEE_LICENSE". */ -#include + #include +#include #include #include @@ -38,8 +39,13 @@ static int tx_call(struct guest_info * info, uint_t call_no, void * priv_data) { addr_t pkt_gpa = info->vm_regs.rbx; int pkt_len = info->vm_regs.rcx; uchar_t * pkt = V3_Malloc(pkt_len); + + if (!pkt) { + PrintError(info->vm_info, info, "Cannot allocate in transmit!\n"); + return -1; + } - PrintDebug("Transmitting Packet\n"); + PrintDebug(info->vm_info, info, "Transmitting Packet\n"); if (read_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) { return -1; @@ -56,7 +62,7 @@ static int rx_call(struct guest_info * info, uint_t call_no, void * priv_data) { uint_t pkt_len = 0; uchar_t * pkt = NULL; - PrintDebug("Receiving Packet\n"); + PrintDebug(info->vm_info, info, "Receiving Packet\n"); return -1; if (write_guest_pa_memory(info, pkt_gpa, pkt_len, pkt) != -1) { @@ -72,56 +78,67 @@ static int macaddr_call(struct guest_info * info, uint_t call_no, void * priv_da addr_t mac_gpa = info->vm_regs.rbx; - PrintDebug("Returning MAC ADDR\n"); + PrintDebug(info->vm_info, info, "Returning MAC ADDR\n"); if (write_guest_pa_memory(info, mac_gpa, 6, nic->mac_addr) != 6) { - PrintError("Could not write mac address\n"); + PrintError(info->vm_info, info, "Could not write mac address\n"); return -1; } return 0; } -static int net_init(struct vm_device * dev) { - struct nic_state * nic = (struct nic_state *)dev->private_data; - - v3_register_hypercall(dev->vm, TX_HYPERCALL, tx_call, nic); - v3_register_hypercall(dev->vm, RX_HYPERCALL, rx_call, nic); - v3_register_hypercall(dev->vm, MACADDR_HYPERCALL, macaddr_call, nic); - nic->mac_addr[0] = 0x52; - nic->mac_addr[1] = 0x54; - nic->mac_addr[2] = 0x00; - nic->mac_addr[3] = 0x12; - nic->mac_addr[4] = 0x34; - nic->mac_addr[5] = 0x56; +static int net_free(struct vm_device * dev) { return 0; } -static int net_deinit(struct vm_device * dev) { - return 0; -} - - -static struct vm_device_ops dev_ops = { - .init = net_init, - .deinit = net_deinit, +static struct v3_device_ops dev_ops = { + .free = net_free, .reset = NULL, .start = NULL, .stop = NULL, }; -struct vm_device * v3_create_para_net() { + + +static int net_init(struct guest_info * vm, v3_cfg_tree_t * cfg) { struct nic_state * state = NULL; + char * dev_id = v3_cfg_val(cfg, "ID"); state = (struct nic_state *)V3_Malloc(sizeof(struct nic_state)); - PrintDebug("Creating VMNet Device\n"); + if (!state) { + PrintError(info->vm_info, info, "Cannot allocate in init\n"); + return -1; + } + + PrintDebug(info->vm_info, info, "Creating VMNet Device\n"); + + struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, state); + + if (v3_attach_device(vm, dev) == -1) { + PrintError(info->vm_info, info, "Could not attach device %s\n", dev_id); + return -1; + } - struct vm_device * device = v3_create_device("VMNET", &dev_ops, state); - return device; + v3_register_hypercall(vm, TX_HYPERCALL, tx_call, state); + v3_register_hypercall(vm, RX_HYPERCALL, rx_call, state); + v3_register_hypercall(vm, MACADDR_HYPERCALL, macaddr_call, state); + + state->mac_addr[0] = 0x52; + state->mac_addr[1] = 0x54; + state->mac_addr[2] = 0x00; + state->mac_addr[3] = 0x12; + state->mac_addr[4] = 0x34; + state->mac_addr[5] = 0x56; + + return 0; } + + +device_register("VMNET", net_init)