From patchwork Wed Nov 25 18:49:28 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark McLoughlin X-Patchwork-Id: 39426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4D6BC1007D1 for ; Thu, 26 Nov 2009 06:14:55 +1100 (EST) Received: from localhost ([127.0.0.1]:39853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDNKF-0007ns-K9 for incoming@patchwork.ozlabs.org; Wed, 25 Nov 2009 14:14:51 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDMyj-0007PN-0D for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:37 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDMyb-0007Jb-Hm for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:33 -0500 Received: from [199.232.76.173] (port=49012 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDMyZ-0007Io-S3 for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:27 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32307) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDMyY-0000F9-UO for qemu-devel@nongnu.org; Wed, 25 Nov 2009 13:52:27 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqPFl016126 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Nov 2009 13:52:26 -0500 Received: from blaa.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nAPIqMKJ031165; Wed, 25 Nov 2009 13:52:25 -0500 Received: by blaa.localdomain (Postfix, from userid 500) id E543D39B4; Wed, 25 Nov 2009 18:49:42 +0000 (GMT) From: Mark McLoughlin To: qemu-devel@nongnu.org Date: Wed, 25 Nov 2009 18:49:28 +0000 Message-Id: <1259174977-26212-36-git-send-email-markmc@redhat.com> In-Reply-To: <1259174977-26212-1-git-send-email-markmc@redhat.com> References: <1259174977-26212-1-git-send-email-markmc@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Mark McLoughlin Subject: [Qemu-devel] [PATCH 35/44] net: convert xen to NICState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Mark McLoughlin --- hw/xen_nic.c | 46 +++++++++++++++++++++++++++++----------------- 1 files changed, 29 insertions(+), 17 deletions(-) diff --git a/hw/xen_nic.c b/hw/xen_nic.c index bcf161c..08055b8 100644 --- a/hw/xen_nic.c +++ b/hw/xen_nic.c @@ -41,6 +41,7 @@ #include "hw.h" #include "net.h" #include "net/checksum.h" +#include "net/util.h" #include "qemu-char.h" #include "xen_backend.h" @@ -56,7 +57,8 @@ struct XenNetDev { struct netif_rx_sring *rxs; netif_tx_back_ring_t tx_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); memcpy(tmpbuf, page + txreq.offset, 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 { - 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); 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 -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; if (netdev->xendev.be_state != XenbusStateConnected) @@ -243,9 +245,9 @@ static int net_rx_ok(VLANClientState *vc) 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; RING_IDX rc, rp; 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) { struct XenNetDev *netdev = container_of(xendev, struct XenNetDev, xendev); - VLANState *vlan; /* read xenstore entries */ if (netdev->mac == NULL) @@ -301,12 +309,16 @@ static int net_init(struct XenDevice *xendev) if (netdev->mac == NULL) return -1; - vlan = qemu_find_vlan(netdev->xendev.dev, 1); - netdev->vs = qemu_new_vlan_client(NET_CLIENT_TYPE_NIC, - vlan, NULL, "xen", NULL, - net_rx_ok, net_rx_packet, NULL, NULL, - NULL, netdev); - snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str), + if (net_parse_macaddr(netdev->conf.macaddr.a, netdev->mac) < 0) + return -1; + + netdev->conf.vlan = qemu_find_vlan(netdev->xendev.dev, 1); + netdev->conf.peer = NULL; + + 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); /* fill info */ @@ -376,9 +388,9 @@ static void net_disconnect(struct XenDevice *xendev) xc_gnttab_munmap(netdev->xendev.gnttabdev, netdev->rxs, 1); netdev->rxs = NULL; } - if (netdev->vs) { - qemu_del_vlan_client(netdev->vs); - netdev->vs = NULL; + if (netdev->nic) { + qemu_del_vlan_client(&netdev->nic->nc); + netdev->nic = NULL; } }