net: convert xen to NICState

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
Mark McLoughlin 2009-11-25 18:49:28 +00:00 committed by Anthony Liguori
parent f1d078c341
commit 658788c560
1 changed files with 29 additions and 17 deletions

View File

@ -41,6 +41,7 @@
#include "hw.h" #include "hw.h"
#include "net.h" #include "net.h"
#include "net/checksum.h" #include "net/checksum.h"
#include "net/util.h"
#include "qemu-char.h" #include "qemu-char.h"
#include "xen_backend.h" #include "xen_backend.h"
@ -56,7 +57,8 @@ struct XenNetDev {
struct netif_rx_sring *rxs; struct netif_rx_sring *rxs;
netif_tx_back_ring_t tx_ring; netif_tx_back_ring_t tx_ring;
netif_rx_back_ring_t rx_ring; netif_rx_back_ring_t rx_ring;
VLANClientState *vs; NICConf conf;
NICState *nic;
}; };
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
@ -179,9 +181,9 @@ static void net_tx_packets(struct XenNetDev *netdev)
tmpbuf = qemu_malloc(XC_PAGE_SIZE); tmpbuf = qemu_malloc(XC_PAGE_SIZE);
memcpy(tmpbuf, page + txreq.offset, txreq.size); memcpy(tmpbuf, page + txreq.offset, txreq.size);
net_checksum_calculate(tmpbuf, txreq.size); net_checksum_calculate(tmpbuf, txreq.size);
qemu_send_packet(netdev->vs, tmpbuf, txreq.size); qemu_send_packet(&netdev->nic->nc, tmpbuf, txreq.size);
} else { } else {
qemu_send_packet(netdev->vs, page + txreq.offset, txreq.size); qemu_send_packet(&netdev->nic->nc, page + txreq.offset, txreq.size);
} }
xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1); xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
net_tx_response(netdev, &txreq, NETIF_RSP_OKAY); net_tx_response(netdev, &txreq, NETIF_RSP_OKAY);
@ -223,9 +225,9 @@ static void net_rx_response(struct XenNetDev *netdev,
#define NET_IP_ALIGN 2 #define NET_IP_ALIGN 2
static int net_rx_ok(VLANClientState *vc) static int net_rx_ok(VLANClientState *nc)
{ {
struct XenNetDev *netdev = vc->opaque; struct XenNetDev *netdev = DO_UPCAST(NICState, nc, nc)->opaque;
RING_IDX rc, rp; RING_IDX rc, rp;
if (netdev->xendev.be_state != XenbusStateConnected) if (netdev->xendev.be_state != XenbusStateConnected)
@ -243,9 +245,9 @@ static int net_rx_ok(VLANClientState *vc)
return 1; return 1;
} }
static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size) static ssize_t net_rx_packet(VLANClientState *nc, const uint8_t *buf, size_t size)
{ {
struct XenNetDev *netdev = vc->opaque; struct XenNetDev *netdev = DO_UPCAST(NICState, nc, nc)->opaque;
netif_rx_request_t rxreq; netif_rx_request_t rxreq;
RING_IDX rc, rp; RING_IDX rc, rp;
void *page; void *page;
@ -288,10 +290,16 @@ static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t siz
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */
static NetClientInfo net_xen_info = {
.type = NET_CLIENT_TYPE_NIC,
.size = sizeof(NICState),
.can_receive = net_rx_ok,
.receive = net_rx_packet,
};
static int net_init(struct XenDevice *xendev) static int net_init(struct XenDevice *xendev)
{ {
struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev);
VLANState *vlan;
/* read xenstore entries */ /* read xenstore entries */
if (netdev->mac == NULL) if (netdev->mac == NULL)
@ -301,12 +309,16 @@ static int net_init(struct XenDevice *xendev)
if (netdev->mac == NULL) if (netdev->mac == NULL)
return -1; return -1;
vlan = qemu_find_vlan(netdev->xendev.dev, 1); if (net_parse_macaddr(netdev->conf.macaddr.a, netdev->mac) < 0)
netdev->vs = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, return -1;
vlan, NULL, "xen", NULL,
net_rx_ok, net_rx_packet, NULL, NULL, netdev->conf.vlan = qemu_find_vlan(netdev->xendev.dev, 1);
NULL, netdev); netdev->conf.peer = NULL;
snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str),
netdev->nic = qemu_new_nic(&net_xen_info, &netdev->conf,
"xen", NULL, netdev);
snprintf(netdev->nic->nc.info_str, sizeof(netdev->nic->nc.info_str),
"nic: xenbus vif macaddr=%s", netdev->mac); "nic: xenbus vif macaddr=%s", netdev->mac);
/* fill info */ /* fill info */
@ -376,9 +388,9 @@ static void net_disconnect(struct XenDevice *xendev)
xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1); xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1);
netdev->rxs = NULL; netdev->rxs = NULL;
} }
if (netdev->vs) { if (netdev->nic) {
qemu_del_vlan_client(netdev->vs); qemu_del_vlan_client(&netdev->nic->nc);
netdev->vs = NULL; netdev->nic = NULL;
} }
} }